SDL: updated libiconv and libicu, removed prebuilt binaries, now they should be built on the fly
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
# Makefile to build precompiled libraries, which cannot be built using standard NDK makefiles
|
||||
# TODO: libboost, libffmpeg, libpython (used only in GemRB)
|
||||
|
||||
ARCHES32 := armeabi armeabi-v7a x86 mips
|
||||
ARCHES32 := armeabi-v7a x86
|
||||
ARCHES64 := arm64-v8a x86_64
|
||||
|
||||
ICONV := $(foreach ARCH, $(ARCHES32), iconv/lib/$(ARCH)/libiconv.so iconv/lib/$(ARCH)/libcharset.so)
|
||||
ICONV := $(foreach ARCH, $(ARCHES32) $(ARCHES64), iconv/lib/$(ARCH)/libiconv.so iconv/lib/$(ARCH)/libcharset.so)
|
||||
|
||||
ICU_LIBS := data i18n io le lx test tu uc
|
||||
ICU := $(foreach ARCH, $(ARCHES32), $(foreach NAME, $(ICU_LIBS), icuuc/lib/$(ARCH)/libicu$(NAME).a))
|
||||
ICU_LIBS := icudata icui18n icuio icutest icutu icuuc iculx icu-le-hb harfbuzz
|
||||
ICU := $(foreach ARCH, $(ARCHES32) $(ARCHES64), $(foreach NAME, $(ICU_LIBS), icuuc/lib/$(ARCH)/lib$(NAME).a))
|
||||
|
||||
OPENSSL := $(foreach ARCH, $(ARCHES32) $(ARCHES64), openssl/lib-$(ARCH)/libcrypto.so.sdl.1.so openssl/lib-$(ARCH)/libssl.so.sdl.1.so)
|
||||
|
||||
@@ -20,14 +20,15 @@ prebuilt-libraries: $(LIBS)
|
||||
$(ICONV) $(ICU):
|
||||
cd iconv/src && \
|
||||
./build.sh && \
|
||||
for ARCH in $(ARCHES32); do \
|
||||
mkdir -p ../lib/$$ARCH ; \
|
||||
for ARCH in $(ARCHES32) $(ARCHES64); do \
|
||||
mkdir -p ../lib/$$ARCH ../include ; \
|
||||
cp -f $$ARCH/libiconv.so $$ARCH/libcharset.so ../lib/$$ARCH/ ; \
|
||||
cp -f $$ARCH/include/*.h ../include/ ; \
|
||||
mkdir -p ../../icuuc/lib/$$ARCH ../../icuuc/include/layout ../../icuuc/include/unicode ; \
|
||||
cp -f $$ARCH/libicu*.a ../../icuuc/lib/$$ARCH/ ; \
|
||||
cp -f $$ARCH/include/layout/*.h ../../icuuc/include/layout/ ; \
|
||||
mkdir -p ../../icuuc/lib/$$ARCH ../../icuuc/include/unicode ../../icuuc/include/layout ; \
|
||||
cp -f $$ARCH/libicu*.a $$ARCH/libharfbuzz.a ../../icuuc/lib/$$ARCH/ ; \
|
||||
cp -f $$ARCH/include/unicode/*.h ../../icuuc/include/unicode/ ; \
|
||||
cp -f $$ARCH/include/layout/*.h ../../icuuc/include/layout/ ; \
|
||||
cp -f $$ARCH/include/icu-le-hb/layout/*.h ../../icuuc/include/layout/ ; \
|
||||
done
|
||||
|
||||
$(OPENSSL):
|
||||
|
||||
@@ -2,20 +2,11 @@ LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
ifneq ($(TARGET_ARCH_ABI),armeabi-v7a-hard) # Pre-compiled lib disabled for armhf ABI
|
||||
ifneq ($(TARGET_ARCH_ABI),arm64-v8a) # Not supported yet
|
||||
ifneq ($(TARGET_ARCH_ABI),x86_64) # Not supported yet
|
||||
ifneq ($(TARGET_ARCH_ABI),mips64) # Not supported yet
|
||||
|
||||
LOCAL_MODULE := $(notdir $(LOCAL_PATH))
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(NDK_TOOLCHAIN_VERSION)/include
|
||||
|
||||
LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so
|
||||
LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/$(NDK_TOOLCHAIN_VERSION)/lib$(LOCAL_MODULE).so
|
||||
|
||||
include $(PREBUILT_SHARED_LIBRARY)
|
||||
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1,242 +0,0 @@
|
||||
/* Copyright (C) 1999-2003, 2005-2006, 2008-2011 Free Software Foundation, Inc.
|
||||
This file is part of the GNU LIBICONV Library.
|
||||
|
||||
The GNU LIBICONV Library is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
The GNU LIBICONV Library is distributed in the hope that it will be
|
||||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU LIBICONV Library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* When installed, this file is called "iconv.h". */
|
||||
|
||||
#ifndef _LIBICONV_H
|
||||
#define _LIBICONV_H
|
||||
|
||||
#define _LIBICONV_VERSION 0x010E /* version number: (major<<8) + minor */
|
||||
extern int _libiconv_version; /* Likewise */
|
||||
|
||||
/* We would like to #include any system header file which could define
|
||||
iconv_t, 1. in order to eliminate the risk that the user gets compilation
|
||||
errors because some other system header file includes /usr/include/iconv.h
|
||||
which defines iconv_t or declares iconv after this file, 2. when compiling
|
||||
for LIBICONV_PLUG, we need the proper iconv_t type in order to produce
|
||||
binary compatible code.
|
||||
But gcc's #include_next is not portable. Thus, once libiconv's iconv.h
|
||||
has been installed in /usr/local/include, there is no way any more to
|
||||
include the original /usr/include/iconv.h. We simply have to get away
|
||||
without it.
|
||||
Ad 1. The risk that a system header file does
|
||||
#include "iconv.h" or #include_next "iconv.h"
|
||||
is small. They all do #include <iconv.h>.
|
||||
Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
|
||||
has to be a scalar type because (iconv_t)(-1) is a possible return value
|
||||
from iconv_open().) */
|
||||
|
||||
/* Define iconv_t ourselves. */
|
||||
#undef iconv_t
|
||||
#define iconv_t libiconv_t
|
||||
typedef void* iconv_t;
|
||||
|
||||
/* Get size_t declaration.
|
||||
Get wchar_t declaration if it exists. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get errno declaration and values. */
|
||||
#include <errno.h>
|
||||
/* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
|
||||
have EILSEQ in a different header. On these systems, define EILSEQ
|
||||
ourselves. */
|
||||
#ifndef EILSEQ
|
||||
#define EILSEQ
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
|
||||
encoding ‘tocode’. */
|
||||
#ifndef LIBICONV_PLUG
|
||||
#define iconv_open libiconv_open
|
||||
#endif
|
||||
extern iconv_t iconv_open (const char* tocode, const char* fromcode);
|
||||
|
||||
/* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
|
||||
starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
|
||||
‘*outbuf’.
|
||||
Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
|
||||
Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
|
||||
#ifndef LIBICONV_PLUG
|
||||
#define iconv libiconv
|
||||
#endif
|
||||
extern size_t iconv (iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
|
||||
|
||||
/* Frees resources allocated for conversion descriptor ‘cd’. */
|
||||
#ifndef LIBICONV_PLUG
|
||||
#define iconv_close libiconv_close
|
||||
#endif
|
||||
extern int iconv_close (iconv_t cd);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef LIBICONV_PLUG
|
||||
|
||||
/* Nonstandard extensions. */
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
|
||||
<wchar.h>.
|
||||
BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
||||
included before <wchar.h>. */
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* A type that holds all memory needed by a conversion descriptor.
|
||||
A pointer to such an object can be used as an iconv_t. */
|
||||
typedef struct {
|
||||
void* dummy1[28];
|
||||
#if 1
|
||||
mbstate_t dummy2;
|
||||
#endif
|
||||
} iconv_allocation_t;
|
||||
|
||||
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
|
||||
encoding ‘tocode’ into preallocated memory. Returns an error indicator
|
||||
(0 or -1 with errno set). */
|
||||
#define iconv_open_into libiconv_open_into
|
||||
extern int iconv_open_into (const char* tocode, const char* fromcode,
|
||||
iconv_allocation_t* resultp);
|
||||
|
||||
/* Control of attributes. */
|
||||
#define iconvctl libiconvctl
|
||||
extern int iconvctl (iconv_t cd, int request, void* argument);
|
||||
|
||||
/* Hook performed after every successful conversion of a Unicode character. */
|
||||
typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
|
||||
/* Hook performed after every successful conversion of a wide character. */
|
||||
typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
|
||||
/* Set of hooks. */
|
||||
struct iconv_hooks {
|
||||
iconv_unicode_char_hook uc_hook;
|
||||
iconv_wide_char_hook wc_hook;
|
||||
void* data;
|
||||
};
|
||||
|
||||
/* Fallback function. Invoked when a small number of bytes could not be
|
||||
converted to a Unicode character. This function should process all
|
||||
bytes from inbuf and may produce replacement Unicode characters by calling
|
||||
the write_replacement callback repeatedly. */
|
||||
typedef void (*iconv_unicode_mb_to_uc_fallback)
|
||||
(const char* inbuf, size_t inbufsize,
|
||||
void (*write_replacement) (const unsigned int *buf, size_t buflen,
|
||||
void* callback_arg),
|
||||
void* callback_arg,
|
||||
void* data);
|
||||
/* Fallback function. Invoked when a Unicode character could not be converted
|
||||
to the target encoding. This function should process the character and
|
||||
may produce replacement bytes (in the target encoding) by calling the
|
||||
write_replacement callback repeatedly. */
|
||||
typedef void (*iconv_unicode_uc_to_mb_fallback)
|
||||
(unsigned int code,
|
||||
void (*write_replacement) (const char *buf, size_t buflen,
|
||||
void* callback_arg),
|
||||
void* callback_arg,
|
||||
void* data);
|
||||
#if 1
|
||||
/* Fallback function. Invoked when a number of bytes could not be converted to
|
||||
a wide character. This function should process all bytes from inbuf and may
|
||||
produce replacement wide characters by calling the write_replacement
|
||||
callback repeatedly. */
|
||||
typedef void (*iconv_wchar_mb_to_wc_fallback)
|
||||
(const char* inbuf, size_t inbufsize,
|
||||
void (*write_replacement) (const wchar_t *buf, size_t buflen,
|
||||
void* callback_arg),
|
||||
void* callback_arg,
|
||||
void* data);
|
||||
/* Fallback function. Invoked when a wide character could not be converted to
|
||||
the target encoding. This function should process the character and may
|
||||
produce replacement bytes (in the target encoding) by calling the
|
||||
write_replacement callback repeatedly. */
|
||||
typedef void (*iconv_wchar_wc_to_mb_fallback)
|
||||
(wchar_t code,
|
||||
void (*write_replacement) (const char *buf, size_t buflen,
|
||||
void* callback_arg),
|
||||
void* callback_arg,
|
||||
void* data);
|
||||
#else
|
||||
/* If the wchar_t type does not exist, these two fallback functions are never
|
||||
invoked. Their argument list therefore does not matter. */
|
||||
typedef void (*iconv_wchar_mb_to_wc_fallback) ();
|
||||
typedef void (*iconv_wchar_wc_to_mb_fallback) ();
|
||||
#endif
|
||||
/* Set of fallbacks. */
|
||||
struct iconv_fallbacks {
|
||||
iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
|
||||
iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
|
||||
iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
|
||||
iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
|
||||
void* data;
|
||||
};
|
||||
|
||||
/* Requests for iconvctl. */
|
||||
#define ICONV_TRIVIALP 0 /* int *argument */
|
||||
#define ICONV_GET_TRANSLITERATE 1 /* int *argument */
|
||||
#define ICONV_SET_TRANSLITERATE 2 /* const int *argument */
|
||||
#define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */
|
||||
#define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */
|
||||
#define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */
|
||||
#define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */
|
||||
|
||||
/* Listing of locale independent encodings. */
|
||||
#define iconvlist libiconvlist
|
||||
extern void iconvlist (int (*do_one) (unsigned int namescount,
|
||||
const char * const * names,
|
||||
void* data),
|
||||
void* data);
|
||||
|
||||
/* Canonicalize an encoding name.
|
||||
The result is either a canonical encoding name, or name itself. */
|
||||
extern const char * iconv_canonicalize (const char * name);
|
||||
|
||||
/* Support for relocatable packages. */
|
||||
|
||||
/* Sets the original and the current installation prefix of the package.
|
||||
Relocation simply replaces a pathname starting with the original prefix
|
||||
by the corresponding pathname with the current prefix instead. Both
|
||||
prefixes should be directory names without trailing slash (i.e. use ""
|
||||
instead of "/"). */
|
||||
extern void libiconv_set_relocation_prefix (const char *orig_prefix,
|
||||
const char *curr_prefix);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _LIBICONV_H */
|
||||
@@ -1,46 +0,0 @@
|
||||
/* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU CHARSET Library.
|
||||
|
||||
The GNU CHARSET Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU CHARSET Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with the GNU CHARSET Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
#ifndef _LIBCHARSET_H
|
||||
#define _LIBCHARSET_H
|
||||
|
||||
#include <localcharset.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Support for relocatable packages. */
|
||||
|
||||
/* Sets the original and the current installation prefix of the package.
|
||||
Relocation simply replaces a pathname starting with the original prefix
|
||||
by the corresponding pathname with the current prefix instead. Both
|
||||
prefixes should be directory names without trailing slash (i.e. use ""
|
||||
instead of "/"). */
|
||||
extern void libcharset_set_relocation_prefix (const char *orig_prefix,
|
||||
const char *curr_prefix);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _LIBCHARSET_H */
|
||||
@@ -1,42 +0,0 @@
|
||||
/* Determine a canonical name for the current locale's character encoding.
|
||||
Copyright (C) 2000-2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU CHARSET Library.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
USA. */
|
||||
|
||||
#ifndef _LOCALCHARSET_H
|
||||
#define _LOCALCHARSET_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine the current locale's character encoding, and canonicalize it
|
||||
into one of the canonical names listed in config.charset.
|
||||
The result must not be freed; it is statically allocated.
|
||||
If the canonical name cannot be determined, the result is a non-canonical
|
||||
name. */
|
||||
extern const char * locale_charset (void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _LOCALCHARSET_H */
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
Submodule project/jni/iconv/src updated: a6a6531070...48bca80cd2
Symlink
+1
@@ -0,0 +1 @@
|
||||
icuuc
|
||||
@@ -2,11 +2,6 @@ LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
ifneq ($(TARGET_ARCH_ABI),armeabi-v7a-hard) # Pre-compiled lib disabled for armhf ABI
|
||||
ifneq ($(TARGET_ARCH_ABI),arm64-v8a) # Not supported yet
|
||||
ifneq ($(TARGET_ARCH_ABI),x86_64) # Not supported yet
|
||||
ifneq ($(TARGET_ARCH_ABI),mips64) # Not supported yet
|
||||
|
||||
LOCAL_MODULE := $(notdir $(LOCAL_PATH))
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
@@ -18,8 +13,3 @@ obj/local/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).a: $(LOCAL_PATH)/$(LOCAL_SRC_FIL
|
||||
cp -f $< $@
|
||||
|
||||
include $(PREBUILT_STATIC_LIBRARY)
|
||||
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
Binary file not shown.
@@ -1,550 +0,0 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LEFONTINSTANCE_H
|
||||
#define __LEFONTINSTANCE_H
|
||||
|
||||
#include "LETypes.h"
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Layout Engine Font Instance object
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Instances of this class are used by <code>LEFontInstance::mapCharsToGlyphs</code> and
|
||||
* <code>LEFontInstance::mapCharToGlyph</code> to adjust character codes before the character
|
||||
* to glyph mapping process. Examples of this are filtering out control characters
|
||||
* and character mirroring - replacing a character which has both a left and a right
|
||||
* hand form with the opposite form.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class LECharMapper /* not : public UObject because this is an interface/mixin class */
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual ~LECharMapper();
|
||||
|
||||
/**
|
||||
* This method does the adjustments.
|
||||
*
|
||||
* @param ch - the input character
|
||||
*
|
||||
* @return the adjusted character
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual LEUnicode32 mapChar(LEUnicode32 ch) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a forward reference to the class which holds the per-glyph
|
||||
* storage.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class LEGlyphStorage;
|
||||
|
||||
/**
|
||||
* This is a virtual base class that serves as the interface between a LayoutEngine
|
||||
* and the platform font environment. It allows a LayoutEngine to access font tables, do
|
||||
* character to glyph mapping, and obtain metrics information without knowing any platform
|
||||
* specific details. There are also a few utility methods for converting between points,
|
||||
* pixels and funits. (font design units)
|
||||
*
|
||||
* An instance of an <code>LEFontInstance</code> represents a font at a particular point
|
||||
* size. Each instance can represent either a single physical font, or a composite font.
|
||||
* A composite font is a collection of physical fonts, each of which contains a subset of
|
||||
* the characters contained in the composite font.
|
||||
*
|
||||
* Note: with the exception of <code>getSubFont</code>, the methods in this class only
|
||||
* make sense for a physical font. If you have an <code>LEFontInstance</code> which
|
||||
* represents a composite font you should only call the methods below which have
|
||||
* an <code>LEGlyphID</code>, an <code>LEUnicode</code> or an <code>LEUnicode32</code>
|
||||
* as one of the arguments because these can be used to select a particular subfont.
|
||||
*
|
||||
* Subclasses which implement composite fonts should supply an implementation of these
|
||||
* methods with some default behavior such as returning constant values, or using the
|
||||
* values from the first subfont.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_LAYOUT_API LEFontInstance : public UObject
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* This virtual destructor is here so that the subclass
|
||||
* destructors can be invoked through the base class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual ~LEFontInstance();
|
||||
|
||||
/**
|
||||
* Get a physical font which can render the given text. For composite fonts,
|
||||
* if there is no single physical font which can render all of the text,
|
||||
* return a physical font which can render an initial substring of the text,
|
||||
* and set the <code>offset</code> parameter to the end of that substring.
|
||||
*
|
||||
* Internally, the LayoutEngine works with runs of text all in the same
|
||||
* font and script, so it is best to call this method with text which is
|
||||
* in a single script, passing the script code in as a hint. If you don't
|
||||
* know the script of the text, you can use zero, which is the script code
|
||||
* for characters used in more than one script.
|
||||
*
|
||||
* The default implementation of this method is intended for instances of
|
||||
* <code>LEFontInstance</code> which represent a physical font. It returns
|
||||
* <code>this</code> and indicates that the entire string can be rendered.
|
||||
*
|
||||
* This method will return a valid <code>LEFontInstance</code> unless you
|
||||
* have passed illegal parameters, or an internal error has been encountered.
|
||||
* For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>
|
||||
* to indicate that the returned font may not be able to render all of
|
||||
* the text. Whenever a valid font is returned, the <code>offset</code> parameter
|
||||
* will be advanced by at least one.
|
||||
*
|
||||
* Subclasses which implement composite fonts must override this method.
|
||||
* Where it makes sense, they should use the script code as a hint to render
|
||||
* characters from the COMMON script in the font which is used for the given
|
||||
* script. For example, if the input text is a series of Arabic words separated
|
||||
* by spaces, and the script code passed in is <code>arabScriptCode</code> you
|
||||
* should return the font used for Arabic characters for all of the input text,
|
||||
* including the spaces. If, on the other hand, the input text contains characters
|
||||
* which cannot be rendered by the font used for Arabic characters, but which can
|
||||
* be rendered by another font, you should return that font for those characters.
|
||||
*
|
||||
* @param chars - the array of Unicode characters.
|
||||
* @param offset - a pointer to the starting offset in the text. On exit this
|
||||
* will be set the the limit offset of the text which can be
|
||||
* rendered using the returned font.
|
||||
* @param limit - the limit offset for the input text.
|
||||
* @param script - the script hint.
|
||||
* @param success - set to an error code if the arguments are illegal, or no font
|
||||
* can be returned for some reason. May also be set to
|
||||
* <code>LE_NO_SUBFONT_WARNING</code> if the subfont which
|
||||
* was returned cannot render all of the text.
|
||||
*
|
||||
* @return an <code>LEFontInstance</code> for the sub font which can render the characters, or
|
||||
* <code>NULL</code> if there is an error.
|
||||
*
|
||||
* @see LEScripts.h
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual const LEFontInstance *getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const;
|
||||
|
||||
//
|
||||
// Font file access
|
||||
//
|
||||
|
||||
/**
|
||||
* This method reads a table from the font. Note that in general,
|
||||
* it only makes sense to call this method on an <code>LEFontInstance</code>
|
||||
* which represents a physical font - i.e. one which has been returned by
|
||||
* <code>getSubFont()</code>. This is because each subfont in a composite font
|
||||
* will have different tables, and there's no way to know which subfont to access.
|
||||
*
|
||||
* Subclasses which represent composite fonts should always return <code>NULL</code>.
|
||||
*
|
||||
* Note that implementing this function does not allow for range checking.
|
||||
* Subclasses that desire the safety of range checking must implement the
|
||||
* variation which has a length parameter.
|
||||
*
|
||||
* @param tableTag - the four byte table tag. (e.g. 'cmap')
|
||||
*
|
||||
* @return the address of the table in memory, or <code>NULL</code>
|
||||
* if the table doesn't exist.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual const void *getFontTable(LETag tableTag) const = 0;
|
||||
|
||||
/**
|
||||
* This method reads a table from the font. Note that in general,
|
||||
* it only makes sense to call this method on an <code>LEFontInstance</code>
|
||||
* which represents a physical font - i.e. one which has been returned by
|
||||
* <code>getSubFont()</code>. This is because each subfont in a composite font
|
||||
* will have different tables, and there's no way to know which subfont to access.
|
||||
*
|
||||
* Subclasses which represent composite fonts should always return <code>NULL</code>.
|
||||
*
|
||||
* This version sets a length, for range checking.
|
||||
* Note that range checking can only be accomplished if this function is
|
||||
* implemented in subclasses.
|
||||
*
|
||||
* @param tableTag - the four byte table tag. (e.g. 'cmap')
|
||||
* @param length - ignored on entry, on exit will be the length of the table if known, or -1 if unknown.
|
||||
* @return the address of the table in memory, or <code>NULL</code>
|
||||
* if the table doesn't exist.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
virtual const void* getFontTable(LETag tableTag, size_t &length) const { length=-1; return getFontTable(tableTag); } /* -1 = unknown length */
|
||||
|
||||
/**
|
||||
* This method is used to determine if the font can
|
||||
* render the given character. This can usually be done
|
||||
* by looking the character up in the font's character
|
||||
* to glyph mapping.
|
||||
*
|
||||
* The default implementation of this method will return
|
||||
* <code>TRUE</code> if <code>mapCharToGlyph(ch)</code>
|
||||
* returns a non-zero value.
|
||||
*
|
||||
* @param ch - the character to be tested
|
||||
*
|
||||
* @return <code>TRUE</code> if the font can render ch.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_bool canDisplay(LEUnicode32 ch) const;
|
||||
|
||||
/**
|
||||
* This method returns the number of design units in
|
||||
* the font's EM square.
|
||||
*
|
||||
* @return the number of design units pre EM.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual le_int32 getUnitsPerEM() const = 0;
|
||||
|
||||
/**
|
||||
* This method maps an array of character codes to an array of glyph
|
||||
* indices, using the font's character to glyph map.
|
||||
*
|
||||
* The default implementation iterates over all of the characters and calls
|
||||
* <code>mapCharToGlyph(ch, mapper)</code> on each one. It also handles surrogate
|
||||
* characters, storing the glyph ID for the high surrogate, and a deleted glyph (0xFFFF)
|
||||
* for the low surrogate.
|
||||
*
|
||||
* Most sublcasses will not need to implement this method.
|
||||
*
|
||||
* @param chars - the character array
|
||||
* @param offset - the index of the first character
|
||||
* @param count - the number of characters
|
||||
* @param reverse - if <code>TRUE</code>, store the glyph indices in reverse order.
|
||||
* @param mapper - the character mapper.
|
||||
* @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.
|
||||
* @param glyphStorage - the object which contains the output glyph array
|
||||
*
|
||||
* @see LECharMapper
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, le_bool filterZeroWidth, LEGlyphStorage &glyphStorage) const;
|
||||
|
||||
/**
|
||||
* This method maps a single character to a glyph index, using the
|
||||
* font's character to glyph map. The default implementation of this
|
||||
* method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.
|
||||
*
|
||||
* @param ch - the character
|
||||
* @param mapper - the character mapper
|
||||
* @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.
|
||||
*
|
||||
* @return the glyph index
|
||||
*
|
||||
* @see LECharMapper
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const;
|
||||
|
||||
/**
|
||||
* This method maps a single character to a glyph index, using the
|
||||
* font's character to glyph map. The default implementation of this
|
||||
* method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.
|
||||
*
|
||||
* @param ch - the character
|
||||
* @param mapper - the character mapper
|
||||
*
|
||||
* @return the glyph index
|
||||
*
|
||||
* @see LECharMapper
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
|
||||
|
||||
/**
|
||||
* This method maps a single character to a glyph index, using the
|
||||
* font's character to glyph map. There is no default implementation
|
||||
* of this method because it requires information about the platform
|
||||
* font implementation.
|
||||
*
|
||||
* @param ch - the character
|
||||
*
|
||||
* @return the glyph index
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const = 0;
|
||||
|
||||
//
|
||||
// Metrics
|
||||
//
|
||||
|
||||
/**
|
||||
* This method gets the X and Y advance of a particular glyph, in pixels.
|
||||
*
|
||||
* @param glyph - the glyph index
|
||||
* @param advance - the X and Y pixel values will be stored here
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const = 0;
|
||||
|
||||
/**
|
||||
* This method gets the hinted X and Y pixel coordinates of a particular
|
||||
* point in the outline of the given glyph.
|
||||
*
|
||||
* @param glyph - the glyph index
|
||||
* @param pointNumber - the number of the point
|
||||
* @param point - the point's X and Y pixel values will be stored here
|
||||
*
|
||||
* @return <code>TRUE</code> if the point coordinates could be stored.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const = 0;
|
||||
|
||||
/**
|
||||
* This method returns the width of the font's EM square
|
||||
* in pixels.
|
||||
*
|
||||
* @return the pixel width of the EM square
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual float getXPixelsPerEm() const = 0;
|
||||
|
||||
/**
|
||||
* This method returns the height of the font's EM square
|
||||
* in pixels.
|
||||
*
|
||||
* @return the pixel height of the EM square
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual float getYPixelsPerEm() const = 0;
|
||||
|
||||
/**
|
||||
* This method converts font design units in the
|
||||
* X direction to points.
|
||||
*
|
||||
* @param xUnits - design units in the X direction
|
||||
*
|
||||
* @return points in the X direction
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float xUnitsToPoints(float xUnits) const;
|
||||
|
||||
/**
|
||||
* This method converts font design units in the
|
||||
* Y direction to points.
|
||||
*
|
||||
* @param yUnits - design units in the Y direction
|
||||
*
|
||||
* @return points in the Y direction
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float yUnitsToPoints(float yUnits) const;
|
||||
|
||||
/**
|
||||
* This method converts font design units to points.
|
||||
*
|
||||
* @param units - X and Y design units
|
||||
* @param points - set to X and Y points
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void unitsToPoints(LEPoint &units, LEPoint &points) const;
|
||||
|
||||
/**
|
||||
* This method converts pixels in the
|
||||
* X direction to font design units.
|
||||
*
|
||||
* @param xPixels - pixels in the X direction
|
||||
*
|
||||
* @return font design units in the X direction
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float xPixelsToUnits(float xPixels) const;
|
||||
|
||||
/**
|
||||
* This method converts pixels in the
|
||||
* Y direction to font design units.
|
||||
*
|
||||
* @param yPixels - pixels in the Y direction
|
||||
*
|
||||
* @return font design units in the Y direction
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float yPixelsToUnits(float yPixels) const;
|
||||
|
||||
/**
|
||||
* This method converts pixels to font design units.
|
||||
*
|
||||
* @param pixels - X and Y pixel
|
||||
* @param units - set to X and Y font design units
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void pixelsToUnits(LEPoint &pixels, LEPoint &units) const;
|
||||
|
||||
/**
|
||||
* Get the X scale factor from the font's transform. The default
|
||||
* implementation of <code>transformFunits()</code> will call this method.
|
||||
*
|
||||
* @return the X scale factor.
|
||||
*
|
||||
*
|
||||
* @see transformFunits
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float getScaleFactorX() const = 0;
|
||||
|
||||
/**
|
||||
* Get the Y scale factor from the font's transform. The default
|
||||
* implementation of <code>transformFunits()</code> will call this method.
|
||||
*
|
||||
* @return the Yscale factor.
|
||||
*
|
||||
* @see transformFunits
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual float getScaleFactorY() const = 0;
|
||||
|
||||
/**
|
||||
* This method transforms an X, Y point in font design units to a
|
||||
* pixel coordinate, applying the font's transform. The default
|
||||
* implementation of this method calls <code>getScaleFactorX()</code>
|
||||
* and <code>getScaleFactorY()</code>.
|
||||
*
|
||||
* @param xFunits - the X coordinate in font design units
|
||||
* @param yFunits - the Y coordinate in font design units
|
||||
* @param pixels - the tranformed co-ordinate in pixels
|
||||
*
|
||||
* @see getScaleFactorX
|
||||
* @see getScaleFactorY
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
|
||||
|
||||
/**
|
||||
* This is a convenience method used to convert
|
||||
* values in a 16.16 fixed point format to floating point.
|
||||
*
|
||||
* @param fixed - the fixed point value
|
||||
*
|
||||
* @return the floating point value
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static inline float fixedToFloat(le_int32 fixed);
|
||||
|
||||
/**
|
||||
* This is a convenience method used to convert
|
||||
* floating point values to 16.16 fixed point format.
|
||||
*
|
||||
* @param theFloat - the floating point value
|
||||
*
|
||||
* @return the fixed point value
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static inline le_int32 floatToFixed(float theFloat);
|
||||
|
||||
//
|
||||
// These methods won't ever be called by the LayoutEngine,
|
||||
// but are useful for clients of <code>LEFontInstance</code> who
|
||||
// need to render text.
|
||||
//
|
||||
|
||||
/**
|
||||
* Get the font's ascent.
|
||||
*
|
||||
* @return the font's ascent, in points. This value
|
||||
* will always be positive.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getAscent() const = 0;
|
||||
|
||||
/**
|
||||
* Get the font's descent.
|
||||
*
|
||||
* @return the font's descent, in points. This value
|
||||
* will always be positive.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getDescent() const = 0;
|
||||
|
||||
/**
|
||||
* Get the font's leading.
|
||||
*
|
||||
* @return the font's leading, in points. This value
|
||||
* will always be positive.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getLeading() const = 0;
|
||||
|
||||
/**
|
||||
* Get the line height required to display text in
|
||||
* this font. The default implementation of this method
|
||||
* returns the sum of the ascent, descent, and leading.
|
||||
*
|
||||
* @return the line height, in points. This vaule will
|
||||
* always be positive.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getLineHeight() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static UClassID getStaticClassID();
|
||||
|
||||
};
|
||||
|
||||
inline float LEFontInstance::fixedToFloat(le_int32 fixed)
|
||||
{
|
||||
return (float) (fixed / 65536.0);
|
||||
}
|
||||
|
||||
inline le_int32 LEFontInstance::floatToFixed(float theFloat)
|
||||
{
|
||||
return (le_int32) (theFloat * 65536.0);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LEGLYPHFILTER__H
|
||||
#define __LEGLYPHFILTER__H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This is a helper class that is used to
|
||||
* recognize a set of glyph indices.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LEGlyphFilter /* not : public UObject because this is an interface/mixin class */ {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @internal
|
||||
*/
|
||||
virtual ~LEGlyphFilter();
|
||||
|
||||
/**
|
||||
* This method is used to test a particular
|
||||
* glyph index to see if it is in the set
|
||||
* recognized by the filter.
|
||||
*
|
||||
* @param glyph - the glyph index to be tested
|
||||
*
|
||||
* @return TRUE if the glyph index is in the set.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual le_bool accept(LEGlyphID glyph) const = 0;
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,546 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1998-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __LEGLYPHSTORAGE_H
|
||||
#define __LEGLYPHSTORAGE_H
|
||||
|
||||
#include "LETypes.h"
|
||||
#include "LEInsertionList.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
|
||||
* For each glyph it holds the glyph ID, the index of the backing store character
|
||||
* which produced the glyph, the X and Y position of the glyph and an auxillary data
|
||||
* pointer.
|
||||
*
|
||||
* The storage is growable using the <code>LEInsertionList</code> class.
|
||||
*
|
||||
*
|
||||
* @see LEInsertionList.h
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The number of entries in the per-glyph arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fGlyphCount;
|
||||
|
||||
/**
|
||||
* The glyph ID array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LEGlyphID *fGlyphs;
|
||||
|
||||
/**
|
||||
* The char indices array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 *fCharIndices;
|
||||
|
||||
/**
|
||||
* The glyph positions array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
float *fPositions;
|
||||
|
||||
/**
|
||||
* The auxillary data array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_uint32 *fAuxData;
|
||||
|
||||
|
||||
/**
|
||||
* The insertion list, used to grow the above arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LEInsertionList *fInsertionList;
|
||||
|
||||
/**
|
||||
* The source index while growing the data arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fSrcIndex;
|
||||
|
||||
/**
|
||||
* The destination index used while growing the data arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fDestIndex;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>
|
||||
* will call this method once for each insertion.
|
||||
*
|
||||
* @param atPosition the position of the insertion
|
||||
* @param count the number of glyphs being inserted
|
||||
* @param newGlyphs the address of the new glyph IDs
|
||||
*
|
||||
* @return <code>true</code> if <code>LEInsertionList</code> should stop
|
||||
* processing the insertion list after this insertion.
|
||||
*
|
||||
* @see LEInsertionList.h
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates an empty <code>LEGlyphStorage</code> object. You must call
|
||||
* <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>
|
||||
* to allocate the data.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
LEGlyphStorage();
|
||||
|
||||
/**
|
||||
* The destructor. This will deallocate all of the arrays.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
~LEGlyphStorage();
|
||||
|
||||
/**
|
||||
* This method returns the number of glyphs in the glyph array.
|
||||
*
|
||||
* @return the number of glyphs in the glyph array
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline le_int32 getGlyphCount() const;
|
||||
|
||||
/**
|
||||
* This method copies the glyph array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold all
|
||||
* the glyphs.
|
||||
*
|
||||
* @param glyphs - the destiniation glyph array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the glyph array into a caller supplied array,
|
||||
* ORing in extra bits. (This functionality is needed by the JDK,
|
||||
* which uses 32 bits pre glyph idex, with the high 16 bits encoding
|
||||
* the composite font slot number)
|
||||
*
|
||||
* @param glyphs - the destination (32 bit) glyph array
|
||||
* @param extraBits - this value will be ORed with each glyph index
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param indexBase - an offset which will be added to each index
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the position array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold an
|
||||
* X and Y position for each glyph, plus an extra X and Y for the
|
||||
* advance of the last glyph.
|
||||
*
|
||||
* @param positions - the destiniation position array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getGlyphPositions(float positions[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method returns the X and Y position of the glyph at
|
||||
* the given index.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param glyphIndex - the index of the glyph
|
||||
*
|
||||
* Output parameters:
|
||||
* @param x - the glyph's X position
|
||||
* @param y - the glyph's Y position
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method allocates the glyph array, the char indices array and the insertion list. You
|
||||
* must call this method before using the object. This method also initializes the char indices
|
||||
* array.
|
||||
*
|
||||
* @param initialGlyphCount the initial size of the glyph and char indices arrays.
|
||||
* @param rightToLeft <code>true</code> if the original input text is right to left.
|
||||
* @param success set to an error code if the storage cannot be allocated of if the initial
|
||||
* glyph count is not positive.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method allocates the storage for the glyph positions. It allocates one extra X, Y
|
||||
* position pair for the position just after the last glyph.
|
||||
*
|
||||
* @param success set to an error code if the positions array cannot be allocated.
|
||||
*
|
||||
* @return the number of X, Y position pairs allocated.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
le_int32 allocatePositions(LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method allocates the storage for the auxillary glyph data.
|
||||
*
|
||||
* @param success set to an error code if the aulillary data array cannot be allocated.
|
||||
*
|
||||
* @return the size of the auxillary data array.
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
le_int32 allocateAuxData(LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Copy the entire auxillary data array.
|
||||
*
|
||||
* @param auxData the auxillary data array will be copied to this address
|
||||
* @param success set to an error code if the data cannot be copied
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void getAuxData(le_uint32 auxData[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* Get the glyph ID for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index into the glyph array
|
||||
* @param success set to an error code if the glyph ID cannot be retrieved.
|
||||
*
|
||||
* @return the glyph ID
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* Get the char index for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index into the glyph array
|
||||
* @param success set to an error code if the char index cannot be retrieved.
|
||||
*
|
||||
* @return the character index
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
le_int32 getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the auxillary data for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index into the glyph array
|
||||
* @param success set to an error code if the auxillary data cannot be retrieved.
|
||||
*
|
||||
* @return the auxillary data
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
le_uint32 getAuxData(le_int32 glyphIndex, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This operator allows direct access to the glyph array
|
||||
* using the index operator.
|
||||
*
|
||||
* @param glyphIndex the index into the glyph array
|
||||
*
|
||||
* @return a reference to the given location in the glyph array
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline LEGlyphID &operator[](le_int32 glyphIndex) const;
|
||||
|
||||
/**
|
||||
* Call this method to replace a single glyph in the glyph array
|
||||
* with multiple glyphs. This method uses the <code>LEInsertionList</code>
|
||||
* to do the insertion. It returns the address of storage where the new
|
||||
* glyph IDs can be stored. They will not actually be inserted into the
|
||||
* glyph array until <code>applyInsertions</code> is called.
|
||||
*
|
||||
* @param atIndex the index of the glyph to be replaced
|
||||
* @param insertCount the number of glyphs to replace it with
|
||||
* @param success set to an error code if the auxillary data cannot be retrieved.
|
||||
*
|
||||
* @return the address at which to store the replacement glyphs.
|
||||
*
|
||||
* @see LEInsertionList.h
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount, LEErrorCode& success);
|
||||
|
||||
/**
|
||||
* Call this method to replace a single glyph in the glyph array
|
||||
* with multiple glyphs. This method uses the <code>LEInsertionList</code>
|
||||
* to do the insertion. It returns the address of storage where the new
|
||||
* glyph IDs can be stored. They will not actually be inserted into the
|
||||
* glyph array until <code>applyInsertions</code> is called.
|
||||
*
|
||||
* Note: Don't use this version, use the other version of this function which has an error code.
|
||||
*
|
||||
* @param atIndex the index of the glyph to be replaced
|
||||
* @param insertCount the number of glyphs to replace it with
|
||||
*
|
||||
* @return the address at which to store the replacement glyphs.
|
||||
*
|
||||
* @see LEInsertionList.h
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount);
|
||||
|
||||
/**
|
||||
* This method is used to reposition glyphs during Indic v2 processing. It moves
|
||||
* all of the relevant glyph information ( glyph, indices, positions, and auxData ),
|
||||
* from the source position to the target position, and also allows for a marker bit
|
||||
* to be set in the target glyph's auxData so that it won't be reprocessed later in the
|
||||
* cycle.
|
||||
*
|
||||
* @param fromPosition - position of the glyph to be moved
|
||||
* @param toPosition - target position of the glyph
|
||||
* @param marker marker bit
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
void moveGlyph(le_int32 fromPosition, le_int32 toPosition, le_uint32 marker);
|
||||
|
||||
/**
|
||||
* This method causes all of the glyph insertions recorded by
|
||||
* <code>insertGlyphs</code> to be applied to the glyph array. The
|
||||
* new slots in the char indices and the auxillary data arrays
|
||||
* will be filled in with the values for the glyph being replaced.
|
||||
*
|
||||
* @return the new size of the glyph array
|
||||
*
|
||||
* @see LEInsertionList.h
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
le_int32 applyInsertions();
|
||||
|
||||
/**
|
||||
* Set the glyph ID for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index of the glyph
|
||||
* @param glyphID the new glyph ID
|
||||
* @param success will be set to an error code if the glyph ID cannot be set.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Set the char index for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index of the glyph
|
||||
* @param charIndex the new char index
|
||||
* @param success will be set to an error code if the char index cannot be set.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Set the X, Y position for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index of the glyph
|
||||
* @param x the new X position
|
||||
* @param y the new Y position
|
||||
* @param success will be set to an error code if the position cannot be set.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Adjust the X, Y position for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index of the glyph
|
||||
* @param xAdjust the adjustment to the glyph's X position
|
||||
* @param yAdjust the adjustment to the glyph's Y position
|
||||
* @param success will be set to an error code if the glyph's position cannot be adjusted.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Set the auxillary data for a particular glyph.
|
||||
*
|
||||
* @param glyphIndex the index of the glyph
|
||||
* @param auxData the new auxillary data
|
||||
* @param success will be set to an error code if the auxillary data cannot be set.
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void setAuxData(le_int32 glyphIndex, le_uint32 auxData, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Delete the glyph array and replace it with the one
|
||||
* in <code>from</code>. Set the glyph array pointer
|
||||
* in <code>from</code> to <code>NULL</code>.
|
||||
*
|
||||
* @param from the <code>LEGlyphStorage</code> object from which
|
||||
* to get the new glyph array.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptGlyphArray(LEGlyphStorage &from);
|
||||
|
||||
/**
|
||||
* Delete the char indices array and replace it with the one
|
||||
* in <code>from</code>. Set the char indices array pointer
|
||||
* in <code>from</code> to <code>NULL</code>.
|
||||
*
|
||||
* @param from the <code>LEGlyphStorage</code> object from which
|
||||
* to get the new char indices array.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptCharIndicesArray(LEGlyphStorage &from);
|
||||
|
||||
/**
|
||||
* Delete the position array and replace it with the one
|
||||
* in <code>from</code>. Set the position array pointer
|
||||
* in <code>from</code> to <code>NULL</code>.
|
||||
*
|
||||
* @param from the <code>LEGlyphStorage</code> object from which
|
||||
* to get the new position array.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptPositionArray(LEGlyphStorage &from);
|
||||
|
||||
/**
|
||||
* Delete the auxillary data array and replace it with the one
|
||||
* in <code>from</code>. Set the auxillary data array pointer
|
||||
* in <code>from</code> to <code>NULL</code>.
|
||||
*
|
||||
* @param from the <code>LEGlyphStorage</code> object from which
|
||||
* to get the new auxillary data array.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptAuxDataArray(LEGlyphStorage &from);
|
||||
|
||||
/**
|
||||
* Change the glyph count of this object to be the same
|
||||
* as the one in <code>from</code>.
|
||||
*
|
||||
* @param from the <code>LEGlyphStorage</code> object from which
|
||||
* to get the new glyph count.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptGlyphCount(LEGlyphStorage &from);
|
||||
|
||||
/**
|
||||
* Change the glyph count of this object to the given value.
|
||||
*
|
||||
* @param newGlyphCount the new glyph count.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptGlyphCount(le_int32 newGlyphCount);
|
||||
|
||||
/**
|
||||
* This method frees the glyph, character index, position and
|
||||
* auxillary data arrays so that the LayoutEngine can be reused
|
||||
* to layout a different characer array. (This method is also called
|
||||
* by the destructor)
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
static UClassID getStaticClassID();
|
||||
};
|
||||
|
||||
inline le_int32 LEGlyphStorage::getGlyphCount() const
|
||||
{
|
||||
return fGlyphCount;
|
||||
}
|
||||
|
||||
inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const
|
||||
{
|
||||
return fGlyphs[glyphIndex];
|
||||
}
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1998-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __LEINSERTIONLIST_H
|
||||
#define __LEINSERTIONLIST_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
struct InsertionRecord;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This class encapsulates the callback used by <code>LEInsertionList</code>
|
||||
* to apply an insertion from the insertion list.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class U_LAYOUT_API LEInsertionCallback
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method will be called by <code>LEInsertionList::applyInsertions</code> for each
|
||||
* entry on the insertion list.
|
||||
*
|
||||
* @param atPosition the position of the insertion
|
||||
* @param count the number of glyphs to insert
|
||||
* @param newGlyphs the address of the glyphs to insert
|
||||
*
|
||||
* @return <code>TRUE</code> if <code>LEInsertions::applyInsertions</code> should
|
||||
* stop after applying this insertion.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]) = 0;
|
||||
|
||||
/**
|
||||
* The destructor
|
||||
*/
|
||||
virtual ~LEInsertionCallback();
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is used to keep track of insertions to an array of
|
||||
* <code>LEGlyphIDs</code>. The insertions are kept on a linked
|
||||
* list of <code>InsertionRecords</code> so that the glyph array
|
||||
* doesn't have to be grown for each insertion. The insertions are
|
||||
* stored on the list from leftmost to rightmost to make it easier
|
||||
* to do the insertions.
|
||||
*
|
||||
* The insertions are applied to the array by calling the
|
||||
* <code>applyInsertions</code> method, which calls a client
|
||||
* supplied <code>LEInsertionCallback</code> object to actually
|
||||
* apply the individual insertions.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LEInsertionList : public UObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct an empty insertion list.
|
||||
*
|
||||
* @param rightToLeft <code>TRUE</code> if the glyphs are stored
|
||||
* in the array in right to left order.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LEInsertionList(le_bool rightToLeft);
|
||||
|
||||
/**
|
||||
* The destructor.
|
||||
*/
|
||||
~LEInsertionList();
|
||||
|
||||
/**
|
||||
* Add an entry to the insertion list.
|
||||
*
|
||||
* @param position the glyph at this position in the array will be
|
||||
* replaced by the new glyphs.
|
||||
* @param count the number of new glyphs
|
||||
* @param success set to an error code if the auxillary data cannot be retrieved.
|
||||
*
|
||||
* @return the address of an array in which to store the new glyphs. This will
|
||||
* <em>not</em> be in the glyph array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LEGlyphID *insert(le_int32 position, le_int32 count, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Return the number of new glyphs that have been inserted.
|
||||
*
|
||||
* @return the number of new glyphs which have been inserted
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 getGrowAmount();
|
||||
|
||||
/**
|
||||
* Call the <code>LEInsertionCallback</code> once for each
|
||||
* entry on the insertion list.
|
||||
*
|
||||
* @param callback the <code>LEInsertionCallback</code> to call for each insertion.
|
||||
*
|
||||
* @return <code>TRUE</code> if <code>callback</code> returned <code>TRUE</code> to
|
||||
* terminate the insertion list processing.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_bool applyInsertions(LEInsertionCallback *callback);
|
||||
|
||||
/**
|
||||
* Empty the insertion list and free all associated
|
||||
* storage.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static UClassID getStaticClassID();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The head of the insertion list.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
InsertionRecord *head;
|
||||
|
||||
/**
|
||||
* The tail of the insertion list.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
InsertionRecord *tail;
|
||||
|
||||
/**
|
||||
* The total number of new glyphs on the insertion list.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 growAmount;
|
||||
|
||||
/**
|
||||
* Set to <code>TRUE</code> if the glyphs are in right
|
||||
* to left order. Since we want the rightmost insertion
|
||||
* to be first on the list, we need to append the
|
||||
* insertions in this case. Otherwise they're prepended.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_bool append;
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2010. All Rights Reserved.
|
||||
*
|
||||
* WARNING: THIS FILE IS MACHINE GENERATED. DO NOT HAND EDIT IT UNLESS
|
||||
* YOU REALLY KNOW WHAT YOU'RE DOING.
|
||||
*
|
||||
* Generated on: 10/26/2010 02:53:33 PM PDT
|
||||
*/
|
||||
|
||||
#ifndef __LELANGUAGES_H
|
||||
#define __LELANGUAGES_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: List of language codes for LayoutEngine
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A provisional list of language codes. For now,
|
||||
* this is just a list of languages which the LayoutEngine
|
||||
* supports.
|
||||
*
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
|
||||
enum LanguageCodes {
|
||||
nullLanguageCode = 0,
|
||||
araLanguageCode = 1,
|
||||
asmLanguageCode = 2,
|
||||
benLanguageCode = 3,
|
||||
farLanguageCode = 4,
|
||||
gujLanguageCode = 5,
|
||||
hinLanguageCode = 6,
|
||||
iwrLanguageCode = 7,
|
||||
jiiLanguageCode = 8,
|
||||
janLanguageCode = 9,
|
||||
kanLanguageCode = 10,
|
||||
kokLanguageCode = 11,
|
||||
korLanguageCode = 12,
|
||||
kshLanguageCode = 13,
|
||||
malLanguageCode = 14,
|
||||
marLanguageCode = 15,
|
||||
mlrLanguageCode = 16,
|
||||
mniLanguageCode = 17,
|
||||
oriLanguageCode = 18,
|
||||
sanLanguageCode = 19,
|
||||
sndLanguageCode = 20,
|
||||
snhLanguageCode = 21,
|
||||
syrLanguageCode = 22,
|
||||
tamLanguageCode = 23,
|
||||
telLanguageCode = 24,
|
||||
thaLanguageCode = 25,
|
||||
urdLanguageCode = 26,
|
||||
zhpLanguageCode = 27,
|
||||
zhsLanguageCode = 28,
|
||||
zhtLanguageCode = 29,
|
||||
|
||||
/** New language codes added 03/13/2008 @stable ICU 4.0 */
|
||||
afkLanguageCode = 30,
|
||||
belLanguageCode = 31,
|
||||
bgrLanguageCode = 32,
|
||||
catLanguageCode = 33,
|
||||
cheLanguageCode = 34,
|
||||
copLanguageCode = 35,
|
||||
csyLanguageCode = 36,
|
||||
danLanguageCode = 37,
|
||||
deuLanguageCode = 38,
|
||||
dznLanguageCode = 39,
|
||||
ellLanguageCode = 40,
|
||||
engLanguageCode = 41,
|
||||
espLanguageCode = 42,
|
||||
etiLanguageCode = 43,
|
||||
euqLanguageCode = 44,
|
||||
finLanguageCode = 45,
|
||||
fraLanguageCode = 46,
|
||||
gaeLanguageCode = 47,
|
||||
hauLanguageCode = 48,
|
||||
hrvLanguageCode = 49,
|
||||
hunLanguageCode = 50,
|
||||
hyeLanguageCode = 51,
|
||||
indLanguageCode = 52,
|
||||
itaLanguageCode = 53,
|
||||
khmLanguageCode = 54,
|
||||
mngLanguageCode = 55,
|
||||
mtsLanguageCode = 56,
|
||||
nepLanguageCode = 57,
|
||||
nldLanguageCode = 58,
|
||||
pasLanguageCode = 59,
|
||||
plkLanguageCode = 60,
|
||||
ptgLanguageCode = 61,
|
||||
romLanguageCode = 62,
|
||||
rusLanguageCode = 63,
|
||||
skyLanguageCode = 64,
|
||||
slvLanguageCode = 65,
|
||||
sqiLanguageCode = 66,
|
||||
srbLanguageCode = 67,
|
||||
sveLanguageCode = 68,
|
||||
tibLanguageCode = 69,
|
||||
trkLanguageCode = 70,
|
||||
welLanguageCode = 71,
|
||||
|
||||
languageCodeCount = 72
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2013. All Rights Reserved.
|
||||
*
|
||||
* WARNING: THIS FILE IS MACHINE GENERATED. DO NOT HAND EDIT IT UNLESS
|
||||
* YOU REALLY KNOW WHAT YOU'RE DOING.
|
||||
*
|
||||
* Generated on: 11/01/2011 04:08:09 PM PDT
|
||||
*/
|
||||
|
||||
#ifndef __LESCRIPTS_H
|
||||
#define __LESCRIPTS_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Constants for Unicode script values
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Constants for Unicode script values, generated using
|
||||
* ICU4J's <code>UScript</code> class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
|
||||
enum ScriptCodes {
|
||||
zyyyScriptCode = 0,
|
||||
zinhScriptCode = 1,
|
||||
qaaiScriptCode = zinhScriptCode, /* manually added alias, for API stability */
|
||||
arabScriptCode = 2,
|
||||
armnScriptCode = 3,
|
||||
bengScriptCode = 4,
|
||||
bopoScriptCode = 5,
|
||||
cherScriptCode = 6,
|
||||
coptScriptCode = 7,
|
||||
cyrlScriptCode = 8,
|
||||
dsrtScriptCode = 9,
|
||||
devaScriptCode = 10,
|
||||
ethiScriptCode = 11,
|
||||
georScriptCode = 12,
|
||||
gothScriptCode = 13,
|
||||
grekScriptCode = 14,
|
||||
gujrScriptCode = 15,
|
||||
guruScriptCode = 16,
|
||||
haniScriptCode = 17,
|
||||
hangScriptCode = 18,
|
||||
hebrScriptCode = 19,
|
||||
hiraScriptCode = 20,
|
||||
kndaScriptCode = 21,
|
||||
kanaScriptCode = 22,
|
||||
khmrScriptCode = 23,
|
||||
laooScriptCode = 24,
|
||||
latnScriptCode = 25,
|
||||
mlymScriptCode = 26,
|
||||
mongScriptCode = 27,
|
||||
mymrScriptCode = 28,
|
||||
ogamScriptCode = 29,
|
||||
italScriptCode = 30,
|
||||
oryaScriptCode = 31,
|
||||
runrScriptCode = 32,
|
||||
sinhScriptCode = 33,
|
||||
syrcScriptCode = 34,
|
||||
tamlScriptCode = 35,
|
||||
teluScriptCode = 36,
|
||||
thaaScriptCode = 37,
|
||||
thaiScriptCode = 38,
|
||||
tibtScriptCode = 39,
|
||||
/**
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
|
||||
cansScriptCode = 40,
|
||||
/**
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
|
||||
yiiiScriptCode = 41,
|
||||
tglgScriptCode = 42,
|
||||
hanoScriptCode = 43,
|
||||
buhdScriptCode = 44,
|
||||
tagbScriptCode = 45,
|
||||
/**
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
|
||||
braiScriptCode = 46,
|
||||
cprtScriptCode = 47,
|
||||
limbScriptCode = 48,
|
||||
linbScriptCode = 49,
|
||||
osmaScriptCode = 50,
|
||||
shawScriptCode = 51,
|
||||
taleScriptCode = 52,
|
||||
ugarScriptCode = 53,
|
||||
/**
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
|
||||
hrktScriptCode = 54,
|
||||
/**
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
|
||||
bugiScriptCode = 55,
|
||||
glagScriptCode = 56,
|
||||
kharScriptCode = 57,
|
||||
syloScriptCode = 58,
|
||||
taluScriptCode = 59,
|
||||
tfngScriptCode = 60,
|
||||
xpeoScriptCode = 61,
|
||||
/**
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
|
||||
baliScriptCode = 62,
|
||||
batkScriptCode = 63,
|
||||
blisScriptCode = 64,
|
||||
brahScriptCode = 65,
|
||||
chamScriptCode = 66,
|
||||
cirtScriptCode = 67,
|
||||
cyrsScriptCode = 68,
|
||||
egydScriptCode = 69,
|
||||
egyhScriptCode = 70,
|
||||
egypScriptCode = 71,
|
||||
geokScriptCode = 72,
|
||||
hansScriptCode = 73,
|
||||
hantScriptCode = 74,
|
||||
hmngScriptCode = 75,
|
||||
hungScriptCode = 76,
|
||||
indsScriptCode = 77,
|
||||
javaScriptCode = 78,
|
||||
kaliScriptCode = 79,
|
||||
latfScriptCode = 80,
|
||||
latgScriptCode = 81,
|
||||
lepcScriptCode = 82,
|
||||
linaScriptCode = 83,
|
||||
mandScriptCode = 84,
|
||||
mayaScriptCode = 85,
|
||||
meroScriptCode = 86,
|
||||
nkooScriptCode = 87,
|
||||
orkhScriptCode = 88,
|
||||
permScriptCode = 89,
|
||||
phagScriptCode = 90,
|
||||
phnxScriptCode = 91,
|
||||
plrdScriptCode = 92,
|
||||
roroScriptCode = 93,
|
||||
saraScriptCode = 94,
|
||||
syreScriptCode = 95,
|
||||
syrjScriptCode = 96,
|
||||
syrnScriptCode = 97,
|
||||
tengScriptCode = 98,
|
||||
vaiiScriptCode = 99,
|
||||
vispScriptCode = 100,
|
||||
xsuxScriptCode = 101,
|
||||
zxxxScriptCode = 102,
|
||||
zzzzScriptCode = 103,
|
||||
/**
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
|
||||
cariScriptCode = 104,
|
||||
jpanScriptCode = 105,
|
||||
lanaScriptCode = 106,
|
||||
lyciScriptCode = 107,
|
||||
lydiScriptCode = 108,
|
||||
olckScriptCode = 109,
|
||||
rjngScriptCode = 110,
|
||||
saurScriptCode = 111,
|
||||
sgnwScriptCode = 112,
|
||||
sundScriptCode = 113,
|
||||
moonScriptCode = 114,
|
||||
mteiScriptCode = 115,
|
||||
/**
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
|
||||
armiScriptCode = 116,
|
||||
avstScriptCode = 117,
|
||||
cakmScriptCode = 118,
|
||||
koreScriptCode = 119,
|
||||
kthiScriptCode = 120,
|
||||
maniScriptCode = 121,
|
||||
phliScriptCode = 122,
|
||||
phlpScriptCode = 123,
|
||||
phlvScriptCode = 124,
|
||||
prtiScriptCode = 125,
|
||||
samrScriptCode = 126,
|
||||
tavtScriptCode = 127,
|
||||
zmthScriptCode = 128,
|
||||
zsymScriptCode = 129,
|
||||
/**
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
|
||||
bamuScriptCode = 130,
|
||||
lisuScriptCode = 131,
|
||||
nkgbScriptCode = 132,
|
||||
sarbScriptCode = 133,
|
||||
/**
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
|
||||
bassScriptCode = 134,
|
||||
duplScriptCode = 135,
|
||||
elbaScriptCode = 136,
|
||||
granScriptCode = 137,
|
||||
kpelScriptCode = 138,
|
||||
lomaScriptCode = 139,
|
||||
mendScriptCode = 140,
|
||||
mercScriptCode = 141,
|
||||
narbScriptCode = 142,
|
||||
nbatScriptCode = 143,
|
||||
palmScriptCode = 144,
|
||||
sindScriptCode = 145,
|
||||
waraScriptCode = 146,
|
||||
/**
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
|
||||
afakScriptCode = 147,
|
||||
jurcScriptCode = 148,
|
||||
mrooScriptCode = 149,
|
||||
nshuScriptCode = 150,
|
||||
shrdScriptCode = 151,
|
||||
soraScriptCode = 152,
|
||||
takrScriptCode = 153,
|
||||
tangScriptCode = 154,
|
||||
woleScriptCode = 155,
|
||||
/**
|
||||
* @stable ICU 49
|
||||
*/
|
||||
|
||||
hluwScriptCode = 156, /* bump to match current ICU */
|
||||
khojScriptCode = 157,
|
||||
tirhScriptCode = 158,
|
||||
|
||||
/**
|
||||
* @stable ICU 52
|
||||
*/
|
||||
aghbScriptCode = 159,
|
||||
mahjScriptCode = 160,
|
||||
|
||||
/**
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
scriptCodeCount
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LESWAPS_H
|
||||
#define __LESWAPS_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Endian independent access to data for LayoutEngine
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A convenience macro which invokes the swapWord member function
|
||||
* from a concise call.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
#define SWAPW(value) LESwaps::swapWord((le_uint16)(value))
|
||||
|
||||
/**
|
||||
* A convenience macro which invokes the swapLong member function
|
||||
* from a concise call.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
#define SWAPL(value) LESwaps::swapLong((le_uint32)(value))
|
||||
|
||||
/**
|
||||
* This class is used to access data which stored in big endian order
|
||||
* regardless of the conventions of the platform.
|
||||
*
|
||||
* All methods are static and inline in an attempt to induce the compiler
|
||||
* to do most of the calculations at compile time.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Reads a big-endian 16-bit word and returns a native-endian value.
|
||||
* No-op on a big-endian platform, byte-swaps on a little-endian platform.
|
||||
*
|
||||
* @param value - the word to be byte swapped
|
||||
*
|
||||
* @return the byte swapped word
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static le_uint16 swapWord(le_uint16 value)
|
||||
{
|
||||
#if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \
|
||||
(defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \
|
||||
defined(__BIG_ENDIAN__)
|
||||
// Fastpath when we know that the platform is big-endian.
|
||||
return value;
|
||||
#else
|
||||
// Reads a big-endian value on any platform.
|
||||
const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value);
|
||||
return (le_uint16)((p[0] << 8) | p[1]);
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a big-endian 32-bit word and returns a native-endian value.
|
||||
* No-op on a big-endian platform, byte-swaps on a little-endian platform.
|
||||
*
|
||||
* @param value - the long to be byte swapped
|
||||
*
|
||||
* @return the byte swapped long
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static le_uint32 swapLong(le_uint32 value)
|
||||
{
|
||||
#if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \
|
||||
(defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \
|
||||
defined(__BIG_ENDIAN__)
|
||||
// Fastpath when we know that the platform is big-endian.
|
||||
return value;
|
||||
#else
|
||||
// Reads a big-endian value on any platform.
|
||||
const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value);
|
||||
return (le_uint32)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
|
||||
#endif
|
||||
};
|
||||
|
||||
private:
|
||||
LESwaps() {} // private - forbid instantiation
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,418 +0,0 @@
|
||||
/*
|
||||
* -*- c++ -*-
|
||||
*
|
||||
* (C) Copyright IBM Corp. and others 2013 - All Rights Reserved
|
||||
*
|
||||
* Range checking
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LETABLEREFERENCE_H
|
||||
#define __LETABLEREFERENCE_H
|
||||
|
||||
#include "LETypes.h"
|
||||
#include "LEFontInstance.h"
|
||||
|
||||
|
||||
#define kQuestionmarkTableTag 0x3F3F3F3FUL
|
||||
#define kTildeTableTag 0x7e7e7e7eUL
|
||||
#ifdef __cplusplus
|
||||
|
||||
// internal - interface for range checking
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
#if LE_ASSERT_BAD_FONT
|
||||
class LETableReference; // fwd
|
||||
/**
|
||||
* defined in OpenTypeUtilities.cpp
|
||||
* @internal
|
||||
*/
|
||||
extern void _debug_LETableReference(const char *f, int l, const char *msg, const LETableReference *what, const void *ptr, size_t len);
|
||||
|
||||
#define LE_DEBUG_TR(x) _debug_LETableReference(__FILE__, __LINE__, x, this, NULL, 0);
|
||||
#define LE_DEBUG_TR3(x,y,z) _debug_LETableReference(__FILE__, __LINE__, x, this, (const void*)y, (size_t)z);
|
||||
#if 0
|
||||
#define LE_TRACE_TR(x) _debug_LETableReference(__FILE__, __LINE__, x, this, NULL, 0);
|
||||
#else
|
||||
#define LE_TRACE_TR(x)
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define LE_DEBUG_TR(x)
|
||||
#define LE_DEBUG_TR3(x,y,z)
|
||||
#define LE_TRACE_TR(x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class LETableReference {
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
* Construct from a specific tag
|
||||
*/
|
||||
LETableReference(const LEFontInstance* font, LETag tableTag, LEErrorCode &success) :
|
||||
fFont(font), fTag(tableTag), fParent(NULL), fStart(NULL),fLength(LE_UINTPTR_MAX) {
|
||||
loadTable(success);
|
||||
LE_TRACE_TR("INFO: new table load")
|
||||
}
|
||||
|
||||
LETableReference(const LETableReference &parent, LEErrorCode &success) : fFont(parent.fFont), fTag(parent.fTag), fParent(&parent), fStart(parent.fStart), fLength(parent.fLength) {
|
||||
if(LE_FAILURE(success)) {
|
||||
clear();
|
||||
}
|
||||
LE_TRACE_TR("INFO: new clone")
|
||||
}
|
||||
|
||||
LETableReference(const le_uint8* data, size_t length = LE_UINTPTR_MAX) :
|
||||
fFont(NULL), fTag(kQuestionmarkTableTag), fParent(NULL), fStart(data), fLength(length) {
|
||||
LE_TRACE_TR("INFO: new raw")
|
||||
}
|
||||
LETableReference() :
|
||||
fFont(NULL), fTag(kQuestionmarkTableTag), fParent(NULL), fStart(NULL), fLength(0) {
|
||||
LE_TRACE_TR("INFO: new empty")
|
||||
}
|
||||
|
||||
~LETableReference() {
|
||||
fTag=kTildeTableTag;
|
||||
LE_TRACE_TR("INFO: new dtor")
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param length if LE_UINTPTR_MAX means "whole table"
|
||||
* subset
|
||||
*/
|
||||
LETableReference(const LETableReference &parent, size_t offset, size_t length,
|
||||
LEErrorCode &err) :
|
||||
fFont(parent.fFont), fTag(parent.fTag), fParent(&parent),
|
||||
fStart((parent.fStart)+offset), fLength(length) {
|
||||
if(LE_SUCCESS(err)) {
|
||||
if(isEmpty()) {
|
||||
//err = LE_MISSING_FONT_TABLE_ERROR;
|
||||
clear(); // it's just empty. Not an error.
|
||||
} else if(offset >= fParent->fLength) {
|
||||
LE_DEBUG_TR3("offset out of range: (%p) +%d", NULL, offset);
|
||||
err = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
||||
clear();
|
||||
} else {
|
||||
if(fLength == LE_UINTPTR_MAX &&
|
||||
fParent->fLength != LE_UINTPTR_MAX) {
|
||||
fLength = (fParent->fLength) - offset; // decrement length as base address is incremented
|
||||
}
|
||||
if(fLength != LE_UINTPTR_MAX) { // if we have bounds:
|
||||
if(offset+fLength > fParent->fLength) {
|
||||
LE_DEBUG_TR3("offset+fLength out of range: (%p) +%d", NULL, offset+fLength);
|
||||
err = LE_INDEX_OUT_OF_BOUNDS_ERROR; // exceeded
|
||||
clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clear();
|
||||
}
|
||||
LE_TRACE_TR("INFO: new subset")
|
||||
}
|
||||
|
||||
const void* getAlias() const { return (const void*)fStart; }
|
||||
const void* getAliasRAW() const { LE_DEBUG_TR("getAliasRAW()"); return (const void*)fStart; }
|
||||
le_bool isEmpty() const { return fStart==NULL || fLength==0; }
|
||||
le_bool isValid() const { return !isEmpty(); }
|
||||
le_bool hasBounds() const { return fLength!=LE_UINTPTR_MAX; }
|
||||
void clear() { fLength=0; fStart=NULL; }
|
||||
size_t getLength() const { return fLength; }
|
||||
const LEFontInstance* getFont() const { return fFont; }
|
||||
LETag getTag() const { return fTag; }
|
||||
const LETableReference* getParent() const { return fParent; }
|
||||
|
||||
void addOffset(size_t offset, LEErrorCode &success) {
|
||||
if(hasBounds()) {
|
||||
if(offset > fLength) {
|
||||
LE_DEBUG_TR("addOffset off end");
|
||||
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
||||
return;
|
||||
} else {
|
||||
fLength -= offset;
|
||||
}
|
||||
}
|
||||
fStart += offset;
|
||||
}
|
||||
|
||||
size_t ptrToOffset(const void *atPtr, LEErrorCode &success) const {
|
||||
if(atPtr==NULL) return 0;
|
||||
if(LE_FAILURE(success)) return LE_UINTPTR_MAX;
|
||||
if((atPtr < fStart) ||
|
||||
(hasBounds() && (atPtr > fStart+fLength))) {
|
||||
LE_DEBUG_TR3("ptrToOffset args out of range: %p", atPtr, 0);
|
||||
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
||||
return LE_UINTPTR_MAX;
|
||||
}
|
||||
return ((const le_uint8*)atPtr)-fStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp down the length, for range checking.
|
||||
*/
|
||||
size_t contractLength(size_t newLength) {
|
||||
if(fLength!=LE_UINTPTR_MAX&&newLength>0&&newLength<=fLength) {
|
||||
fLength = newLength;
|
||||
}
|
||||
return fLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an error if offset+length off end
|
||||
*/
|
||||
public:
|
||||
size_t verifyLength(size_t offset, size_t length, LEErrorCode &success) {
|
||||
if(isValid()&&
|
||||
LE_SUCCESS(success) &&
|
||||
fLength!=LE_UINTPTR_MAX && length!=LE_UINTPTR_MAX && offset!=LE_UINTPTR_MAX &&
|
||||
(offset+length)>fLength) {
|
||||
LE_DEBUG_TR3("verifyLength failed (%p) %d",NULL, offset+length);
|
||||
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
||||
#if LE_ASSERT_BAD_FONT
|
||||
fprintf(stderr, "offset=%lu, len=%lu, would be at %p, (%lu) off end. End at %p\n", offset,length, fStart+offset+length, (offset+length-fLength), (offset+length-fLength)+fStart);
|
||||
#endif
|
||||
}
|
||||
return fLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change parent link to another
|
||||
*/
|
||||
LETableReference &reparent(const LETableReference &base) {
|
||||
fParent = &base;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove parent link. Factory functions should do this.
|
||||
*/
|
||||
void orphan(void) {
|
||||
fParent=NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
const LEFontInstance* fFont;
|
||||
LETag fTag;
|
||||
const LETableReference *fParent;
|
||||
const le_uint8 *fStart; // keep as 8 bit internally, for pointer math
|
||||
size_t fLength;
|
||||
|
||||
void loadTable(LEErrorCode &success) {
|
||||
if(LE_SUCCESS(success)) {
|
||||
fStart = (const le_uint8*)(fFont->getFontTable(fTag, fLength)); // note - a null table is not an error.
|
||||
}
|
||||
}
|
||||
|
||||
void setRaw(const void *data, size_t length = LE_UINTPTR_MAX) {
|
||||
fFont = NULL;
|
||||
fTag = kQuestionmarkTableTag;
|
||||
fParent = NULL;
|
||||
fStart = (const le_uint8*)data;
|
||||
fLength = length;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
class LETableVarSizer {
|
||||
public:
|
||||
inline static size_t getSize();
|
||||
};
|
||||
|
||||
// base definition- could override for adjustments
|
||||
template<class T> inline
|
||||
size_t LETableVarSizer<T>::getSize() {
|
||||
return sizeof(T);
|
||||
}
|
||||
|
||||
/**
|
||||
* \def LE_VAR_ARRAY
|
||||
* @param x Type (T)
|
||||
* @param y some member that is of length ANY_NUMBER
|
||||
* Call this after defining a class, for example:
|
||||
* LE_VAR_ARRAY(FeatureListTable,featureRecordArray)
|
||||
* this is roughly equivalent to:
|
||||
* template<> inline size_t LETableVarSizer<FeatureListTable>::getSize() { return sizeof(FeatureListTable) - (sizeof(le_uint16)*ANY_NUMBER); }
|
||||
* it's a specialization that informs the LETableReference subclasses to NOT include the variable array in the size.
|
||||
* dereferencing NULL is valid here because we never actually dereference it, just inside sizeof.
|
||||
*/
|
||||
#define LE_VAR_ARRAY(x,y) template<> inline size_t LETableVarSizer<x>::getSize() { return sizeof(x) - (sizeof(((const x*)0)->y)); }
|
||||
/**
|
||||
* \def LE_CORRECT_SIZE
|
||||
* @param x type (T)
|
||||
* @param y fixed size for T
|
||||
*/
|
||||
#define LE_CORRECT_SIZE(x,y) template<> inline size_t LETableVarSizer<x>::getSize() { return y; }
|
||||
|
||||
/**
|
||||
* Open a new entry based on an existing table
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def LE_UNBOUNDED_ARRAY
|
||||
* define an array with no *known* bound. Will trim to available size.
|
||||
* @internal
|
||||
*/
|
||||
#define LE_UNBOUNDED_ARRAY LE_UINT32_MAX
|
||||
|
||||
template<class T>
|
||||
class LEReferenceToArrayOf : public LETableReference {
|
||||
public:
|
||||
LEReferenceToArrayOf(const LETableReference &parent, LEErrorCode &success, size_t offset, le_uint32 count)
|
||||
: LETableReference(parent, offset, LE_UINTPTR_MAX, success), fCount(count) {
|
||||
LE_TRACE_TR("INFO: new RTAO by offset")
|
||||
if(LE_SUCCESS(success)) {
|
||||
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
|
||||
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
|
||||
}
|
||||
LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
|
||||
}
|
||||
if(LE_FAILURE(success)) {
|
||||
fCount=0;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
LEReferenceToArrayOf(const LETableReference &parent, LEErrorCode &success, const T* array, le_uint32 count)
|
||||
: LETableReference(parent, parent.ptrToOffset(array, success), LE_UINTPTR_MAX, success), fCount(count) {
|
||||
LE_TRACE_TR("INFO: new RTAO")
|
||||
if(LE_SUCCESS(success)) {
|
||||
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
|
||||
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
|
||||
}
|
||||
LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
|
||||
}
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
LEReferenceToArrayOf(const LETableReference &parent, LEErrorCode &success, const T* array, size_t offset, le_uint32 count)
|
||||
: LETableReference(parent, parent.ptrToOffset(array, success)+offset, LE_UINTPTR_MAX, success), fCount(count) {
|
||||
LE_TRACE_TR("INFO: new RTAO")
|
||||
if(LE_SUCCESS(success)) {
|
||||
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
|
||||
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
|
||||
}
|
||||
LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
|
||||
}
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
|
||||
LEReferenceToArrayOf() :LETableReference(), fCount(0) {}
|
||||
|
||||
le_uint32 getCount() const { return fCount; }
|
||||
|
||||
using LETableReference::getAlias;
|
||||
|
||||
const T *getAlias(le_uint32 i, LEErrorCode &success) const {
|
||||
return ((const T*)(((const char*)getAlias())+getOffsetFor(i, success)));
|
||||
}
|
||||
|
||||
const T *getAliasRAW() const { LE_DEBUG_TR("getAliasRAW<>"); return (const T*)fStart; }
|
||||
|
||||
const T& getObject(le_uint32 i, LEErrorCode &success) const {
|
||||
return *getAlias(i,success);
|
||||
}
|
||||
|
||||
const T& operator()(le_uint32 i, LEErrorCode &success) const {
|
||||
return *getAlias(i,success);
|
||||
}
|
||||
|
||||
size_t getOffsetFor(le_uint32 i, LEErrorCode &success) const {
|
||||
if(LE_SUCCESS(success)&&i<getCount()) {
|
||||
return LETableVarSizer<T>::getSize()*i;
|
||||
} else {
|
||||
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LEReferenceToArrayOf<T> &reparent(const LETableReference &base) {
|
||||
fParent = &base;
|
||||
return *this;
|
||||
}
|
||||
|
||||
LEReferenceToArrayOf(const LETableReference& parent, LEErrorCode & success) : LETableReference(parent,0, LE_UINTPTR_MAX, success), fCount(0) {
|
||||
LE_TRACE_TR("INFO: null RTAO")
|
||||
}
|
||||
|
||||
private:
|
||||
le_uint32 fCount;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
class LEReferenceTo : public LETableReference {
|
||||
public:
|
||||
/**
|
||||
* open a sub reference.
|
||||
* @param parent parent reference
|
||||
* @param success error status
|
||||
* @param atPtr location of reference - if NULL, will be at offset zero (i.e. downcast of parent). Otherwise must be a pointer within parent's bounds.
|
||||
*/
|
||||
inline LEReferenceTo(const LETableReference &parent, LEErrorCode &success, const void* atPtr)
|
||||
: LETableReference(parent, parent.ptrToOffset(atPtr, success), LE_UINTPTR_MAX, success) {
|
||||
verifyLength(0, LETableVarSizer<T>::getSize(), success);
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
/**
|
||||
* ptr plus offset
|
||||
*/
|
||||
inline LEReferenceTo(const LETableReference &parent, LEErrorCode &success, const void* atPtr, size_t offset)
|
||||
: LETableReference(parent, parent.ptrToOffset(atPtr, success)+offset, LE_UINTPTR_MAX, success) {
|
||||
verifyLength(0, LETableVarSizer<T>::getSize(), success);
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
inline LEReferenceTo(const LETableReference &parent, LEErrorCode &success, size_t offset)
|
||||
: LETableReference(parent, offset, LE_UINTPTR_MAX, success) {
|
||||
verifyLength(0, LETableVarSizer<T>::getSize(), success);
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
inline LEReferenceTo(const LETableReference &parent, LEErrorCode &success)
|
||||
: LETableReference(parent, 0, LE_UINTPTR_MAX, success) {
|
||||
verifyLength(0, LETableVarSizer<T>::getSize(), success);
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
inline LEReferenceTo(const LEFontInstance *font, LETag tableTag, LEErrorCode &success)
|
||||
: LETableReference(font, tableTag, success) {
|
||||
verifyLength(0, LETableVarSizer<T>::getSize(), success);
|
||||
if(LE_FAILURE(success)) clear();
|
||||
}
|
||||
inline LEReferenceTo(const le_uint8 *data, size_t length = LE_UINTPTR_MAX) : LETableReference(data, length) {}
|
||||
inline LEReferenceTo(const T *data, size_t length = LE_UINTPTR_MAX) : LETableReference((const le_uint8*)data, length) {}
|
||||
inline LEReferenceTo() : LETableReference(NULL) {}
|
||||
|
||||
inline LEReferenceTo<T>& operator=(const T* other) {
|
||||
setRaw(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
LEReferenceTo<T> &reparent(const LETableReference &base) {
|
||||
fParent = &base;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* roll forward by one <T> size.
|
||||
* same as addOffset(LETableVarSizer<T>::getSize(),success)
|
||||
*/
|
||||
void addObject(LEErrorCode &success) {
|
||||
addOffset(LETableVarSizer<T>::getSize(), success);
|
||||
}
|
||||
void addObject(size_t count, LEErrorCode &success) {
|
||||
addOffset(LETableVarSizer<T>::getSize()*count, success);
|
||||
}
|
||||
|
||||
const T *operator->() const { return getAlias(); }
|
||||
const T *getAlias() const { return (const T*)fStart; }
|
||||
const T *getAliasRAW() const { LE_DEBUG_TR("getAliasRAW<>"); return (const T*)fStart; }
|
||||
};
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,728 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. and others 1998-2013 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LETYPES_H
|
||||
#define __LETYPES_H
|
||||
|
||||
#if !defined(LE_USE_CMEMORY) && (defined(U_LAYOUT_IMPLEMENTATION) || defined(U_LAYOUTEX_IMPLEMENTATION) || defined(U_STATIC_IMPLEMENTATION) || defined(U_COMBINED_IMPLEMENTATION))
|
||||
#define LE_USE_CMEMORY
|
||||
#endif
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "unicode/uobject.h"
|
||||
#endif
|
||||
|
||||
#ifdef LE_USE_CMEMORY
|
||||
#include "cmemory.h"
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \brief C API: Basic definitions for the ICU LayoutEngine
|
||||
*/
|
||||
|
||||
/**
|
||||
* A type used for signed, 32-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef int32_t le_int32;
|
||||
|
||||
/**
|
||||
* A type used for unsigned, 32-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef uint32_t le_uint32;
|
||||
|
||||
/**
|
||||
* A type used for signed, 16-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef int16_t le_int16;
|
||||
|
||||
/**
|
||||
* A type used for unsigned, 16-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef uint16_t le_uint16;
|
||||
|
||||
/**
|
||||
* A type used for signed, 8-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef int8_t le_int8;
|
||||
|
||||
/**
|
||||
* A type used for unsigned, 8-bit integers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef uint8_t le_uint8;
|
||||
|
||||
|
||||
/**
|
||||
* A type used for boolean values.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef UBool le_bool;
|
||||
|
||||
#ifndef NULL
|
||||
/**
|
||||
* Used to represent empty pointers.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Used for four character tags.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef le_uint32 LETag;
|
||||
|
||||
/**
|
||||
* Used for 16-bit glyph indices as they're represented
|
||||
* in TrueType font tables.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
typedef le_uint16 TTGlyphID;
|
||||
|
||||
/**
|
||||
* Used for glyph indices. The low-order 16 bits are
|
||||
* the glyph ID within the font. The next 8 bits are
|
||||
* the sub-font ID within a compound font. The high-
|
||||
* order 8 bits are client defined. The LayoutEngine
|
||||
* will never change or look at the client defined bits.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
typedef le_uint32 LEGlyphID;
|
||||
|
||||
/**
|
||||
* Used to mask off the glyph ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_GLYPH_MASK 0x0000FFFF
|
||||
|
||||
/**
|
||||
* Used to shift the glyph ID part of an LEGlyphID
|
||||
* into the low-order bits.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_GLYPH_SHIFT 0
|
||||
|
||||
|
||||
/**
|
||||
* Used to mask off the sub-font ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_SUB_FONT_MASK 0x00FF0000
|
||||
|
||||
/**
|
||||
* Used to shift the sub-font ID part of an LEGlyphID
|
||||
* into the low-order bits.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_SUB_FONT_SHIFT 16
|
||||
|
||||
|
||||
/**
|
||||
* Used to mask off the client-defined part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_CLIENT_MASK 0xFF000000
|
||||
|
||||
/**
|
||||
* Used to shift the sub-font ID part of an LEGlyphID
|
||||
* into the low-order bits.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_CLIENT_SHIFT 24
|
||||
|
||||
|
||||
/**
|
||||
* A convenience macro to get the Glyph ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_GET_GLYPH(gid) ((gid & LE_GLYPH_MASK) >> LE_GLYPH_SHIFT)
|
||||
|
||||
/**
|
||||
* A convenience macro to get the sub-font ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_GET_SUB_FONT(gid) ((gid & LE_SUB_FONT_MASK) >> LE_SUB_FONT_SHIFT)
|
||||
|
||||
/**
|
||||
* A convenience macro to get the client-defined part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_GET_CLIENT(gid) ((gid & LE_CLIENT_MASK) >> LE_CLIENT_SHIFT)
|
||||
|
||||
|
||||
/**
|
||||
* A convenience macro to set the Glyph ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_SET_GLYPH(gid, glyph) ((gid & ~LE_GLYPH_MASK) | ((glyph << LE_GLYPH_SHIFT) & LE_GLYPH_MASK))
|
||||
|
||||
/**
|
||||
* A convenience macro to set the sub-font ID part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_SET_SUB_FONT(gid, font) ((gid & ~LE_SUB_FONT_MASK) | ((font << LE_SUB_FONT_SHIFT) & LE_SUB_FONT_MASK))
|
||||
|
||||
/**
|
||||
* A convenience macro to set the client-defined part of an LEGlyphID.
|
||||
*
|
||||
* @see LEGlyphID
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_SET_CLIENT(gid, client) ((gid & ~LE_CLIENT_MASK) | ((client << LE_CLIENT_SHIFT) & LE_CLIENT_MASK))
|
||||
|
||||
|
||||
/**
|
||||
* Used to represent 16-bit Unicode code points.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef UChar LEUnicode16;
|
||||
|
||||
/**
|
||||
* Used to represent 32-bit Unicode code points.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef UChar32 LEUnicode32;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Used to represent 16-bit Unicode code points.
|
||||
*
|
||||
* @deprecated since ICU 2.4. Use LEUnicode16 instead
|
||||
*/
|
||||
typedef UChar LEUnicode;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Used to hold a pair of (x, y) values which represent a point.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
struct LEPoint
|
||||
{
|
||||
/**
|
||||
* The x coordinate of the point.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
float fX;
|
||||
|
||||
/**
|
||||
* The y coordinate of the point.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
float fY;
|
||||
};
|
||||
|
||||
#ifndef __cplusplus
|
||||
/**
|
||||
* Used to hold a pair of (x, y) values which represent a point.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef struct LEPoint LEPoint;
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
||||
/**
|
||||
* \def
|
||||
* @internal
|
||||
*/
|
||||
#ifndef LE_ASSERT_BAD_FONT
|
||||
#define LE_ASSERT_BAD_FONT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def LE_DEBUG_BAD_FONT
|
||||
* @internal
|
||||
*/
|
||||
#if LE_ASSERT_BAD_FONT
|
||||
#include <stdio.h>
|
||||
#define LE_DEBUG_BAD_FONT(x) fprintf(stderr,"%s:%d: BAD FONT: %s\n", __FILE__, __LINE__, (x));
|
||||
#else
|
||||
#define LE_DEBUG_BAD_FONT(x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def LE_UINTPTR_MAX
|
||||
* Max value representable by a uintptr
|
||||
*/
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define LE_UINT32_MAX 0xFFFFFFFFU
|
||||
#else
|
||||
#define LE_UINT32_MAX UINT32_MAX
|
||||
#endif
|
||||
|
||||
#ifndef UINTPTR_MAX
|
||||
#define LE_UINTPTR_MAX LE_UINT32_MAX
|
||||
#else
|
||||
#define LE_UINTPTR_MAX UINTPTR_MAX
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Range check for overflow
|
||||
*/
|
||||
#define LE_RANGE_CHECK(type, count, ptrfn) (( (LE_UINTPTR_MAX / sizeof(type)) < (size_t)count ) ? NULL : (ptrfn))
|
||||
/**
|
||||
* A convenience macro to get the length of an array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_ARRAY_SIZE(array) (sizeof array / sizeof array[0])
|
||||
|
||||
#ifdef LE_USE_CMEMORY
|
||||
/**
|
||||
* A convenience macro for copying an array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
|
||||
|
||||
/**
|
||||
* Allocate an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_NEW_ARRAY(type, count) (type *) LE_RANGE_CHECK(type,count,uprv_malloc((count) * sizeof(type)))
|
||||
|
||||
/**
|
||||
* Re-allocate an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_GROW_ARRAY(array, newSize) uprv_realloc((void *) (array), (newSize) * sizeof (array)[0])
|
||||
|
||||
/**
|
||||
* Free an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_DELETE_ARRAY(array) uprv_free((void *) (array))
|
||||
#else
|
||||
|
||||
/* Not using ICU memory - use C std lib versions */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* A convenience macro to get the length of an array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_ARRAY_SIZE(array) (sizeof array / sizeof array[0])
|
||||
|
||||
/**
|
||||
* A convenience macro for copying an array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_ARRAY_COPY(dst, src, count) memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
|
||||
|
||||
/**
|
||||
* Allocate an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_NEW_ARRAY(type, count) LE_RANGE_CHECK(type,count,(type *) malloc((count) * sizeof(type)))
|
||||
|
||||
/**
|
||||
* Re-allocate an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_GROW_ARRAY(array, newSize) realloc((void *) (array), (newSize) * sizeof (array)[0])
|
||||
|
||||
/**
|
||||
* Free an array of basic types. This is used to isolate the rest of
|
||||
* the LayoutEngine code from cmemory.h.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#define LE_DELETE_ARRAY(array) free((void *) (array))
|
||||
|
||||
#endif
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* A macro to construct the four-letter tags used to
|
||||
* label TrueType tables, and for script, language and
|
||||
* feature tags in OpenType tables.
|
||||
*
|
||||
* WARNING: THIS MACRO WILL ONLY WORK CORRECTLY IF
|
||||
* THE ARGUMENT CHARACTERS ARE ASCII.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define LE_MAKE_TAG(a, b, c, d) \
|
||||
(((le_uint32)(a) << 24) | \
|
||||
((le_uint32)(b) << 16) | \
|
||||
((le_uint32)(c) << 8) | \
|
||||
(le_uint32)(d))
|
||||
|
||||
/**
|
||||
* This enumeration defines constants for the standard
|
||||
* TrueType, OpenType and AAT table tags.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
enum LETableTags {
|
||||
LE_ACNT_TABLE_TAG = 0x61636E74UL, /**< 'acnt' */
|
||||
LE_AVAR_TABLE_TAG = 0x61766172UL, /**< 'avar' */
|
||||
LE_BASE_TABLE_TAG = 0x42415345UL, /**< 'BASE' */
|
||||
LE_BDAT_TABLE_TAG = 0x62646174UL, /**< 'bdat' */
|
||||
LE_BHED_TABLE_TAG = 0x62686564UL, /**< 'bhed' */
|
||||
LE_BLOC_TABLE_TAG = 0x626C6F63UL, /**< 'bloc' */
|
||||
LE_BSLN_TABLE_TAG = 0x62736C6EUL, /**< 'bsln' */
|
||||
LE_CFF__TABLE_TAG = 0x43464620UL, /**< 'CFF ' */
|
||||
LE_CMAP_TABLE_TAG = 0x636D6170UL, /**< 'cmap' */
|
||||
LE_CVAR_TABLE_TAG = 0x63766172UL, /**< 'cvar' */
|
||||
LE_CVT__TABLE_TAG = 0x63767420UL, /**< 'cvt ' */
|
||||
LE_DSIG_TABLE_TAG = 0x44534947UL, /**< 'DSIG' */
|
||||
LE_EBDT_TABLE_TAG = 0x45424454UL, /**< 'EBDT' */
|
||||
LE_EBLC_TABLE_TAG = 0x45424C43UL, /**< 'EBLC' */
|
||||
LE_EBSC_TABLE_TAG = 0x45425343UL, /**< 'EBSC' */
|
||||
LE_FDSC_TABLE_TAG = 0x66647363UL, /**< 'fdsc' */
|
||||
LE_FEAT_TABLE_TAG = 0x66656174UL, /**< 'feat' */
|
||||
LE_FMTX_TABLE_TAG = 0x666D7478UL, /**< 'fmtx' */
|
||||
LE_FPGM_TABLE_TAG = 0x6670676DUL, /**< 'fpgm' */
|
||||
LE_FVAR_TABLE_TAG = 0x66766172UL, /**< 'fvar' */
|
||||
LE_GASP_TABLE_TAG = 0x67617370UL, /**< 'gasp' */
|
||||
LE_GDEF_TABLE_TAG = 0x47444546UL, /**< 'GDEF' */
|
||||
LE_GLYF_TABLE_TAG = 0x676C7966UL, /**< 'glyf' */
|
||||
LE_GPOS_TABLE_TAG = 0x47504F53UL, /**< 'GPOS' */
|
||||
LE_GSUB_TABLE_TAG = 0x47535542UL, /**< 'GSUB' */
|
||||
LE_GVAR_TABLE_TAG = 0x67766172UL, /**< 'gvar' */
|
||||
LE_HDMX_TABLE_TAG = 0x68646D78UL, /**< 'hdmx' */
|
||||
LE_HEAD_TABLE_TAG = 0x68656164UL, /**< 'head' */
|
||||
LE_HHEA_TABLE_TAG = 0x68686561UL, /**< 'hhea' */
|
||||
LE_HMTX_TABLE_TAG = 0x686D7478UL, /**< 'hmtx' */
|
||||
LE_HSTY_TABLE_TAG = 0x68737479UL, /**< 'hsty' */
|
||||
LE_JUST_TABLE_TAG = 0x6A757374UL, /**< 'just' */
|
||||
LE_JSTF_TABLE_TAG = 0x4A535446UL, /**< 'JSTF' */
|
||||
LE_KERN_TABLE_TAG = 0x6B65726EUL, /**< 'kern' */
|
||||
LE_LCAR_TABLE_TAG = 0x6C636172UL, /**< 'lcar' */
|
||||
LE_LOCA_TABLE_TAG = 0x6C6F6361UL, /**< 'loca' */
|
||||
LE_LTSH_TABLE_TAG = 0x4C545348UL, /**< 'LTSH' */
|
||||
LE_MAXP_TABLE_TAG = 0x6D617870UL, /**< 'maxp' */
|
||||
LE_MORT_TABLE_TAG = 0x6D6F7274UL, /**< 'mort' */
|
||||
LE_MORX_TABLE_TAG = 0x6D6F7278UL, /**< 'morx' */
|
||||
LE_NAME_TABLE_TAG = 0x6E616D65UL, /**< 'name' */
|
||||
LE_OPBD_TABLE_TAG = 0x6F706264UL, /**< 'opbd' */
|
||||
LE_OS_2_TABLE_TAG = 0x4F532F32UL, /**< 'OS/2' */
|
||||
LE_PCLT_TABLE_TAG = 0x50434C54UL, /**< 'PCLT' */
|
||||
LE_POST_TABLE_TAG = 0x706F7374UL, /**< 'post' */
|
||||
LE_PREP_TABLE_TAG = 0x70726570UL, /**< 'prep' */
|
||||
LE_PROP_TABLE_TAG = 0x70726F70UL, /**< 'prop' */
|
||||
LE_TRAK_TABLE_TAG = 0x7472616BUL, /**< 'trak' */
|
||||
LE_VDMX_TABLE_TAG = 0x56444D58UL, /**< 'VDMX' */
|
||||
LE_VHEA_TABLE_TAG = 0x76686561UL, /**< 'vhea' */
|
||||
LE_VMTX_TABLE_TAG = 0x766D7478UL, /**< 'vmtx' */
|
||||
LE_VORG_TABLE_TAG = 0x564F5247UL, /**< 'VORG' */
|
||||
LE_ZAPF_TABLE_TAG = 0x5A617066UL /**< 'Zapf' */
|
||||
};
|
||||
|
||||
/**
|
||||
* This enumeration defines constants for all
|
||||
* the common OpenType feature tags.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
enum LEFeatureTags {
|
||||
LE_AALT_FEATURE_TAG = 0x61616C74UL, /**< 'aalt' */
|
||||
LE_ABVF_FEATURE_TAG = 0x61627666UL, /**< 'abvf' */
|
||||
LE_ABVM_FEATURE_TAG = 0x6162766DUL, /**< 'abvm' */
|
||||
LE_ABVS_FEATURE_TAG = 0x61627673UL, /**< 'abvs' */
|
||||
LE_AFRC_FEATURE_TAG = 0x61667263UL, /**< 'afrc' */
|
||||
LE_AKHN_FEATURE_TAG = 0x616B686EUL, /**< 'akhn' */
|
||||
LE_BLWF_FEATURE_TAG = 0x626C7766UL, /**< 'blwf' */
|
||||
LE_BLWM_FEATURE_TAG = 0x626C776DUL, /**< 'blwm' */
|
||||
LE_BLWS_FEATURE_TAG = 0x626C7773UL, /**< 'blws' */
|
||||
LE_CALT_FEATURE_TAG = 0x63616C74UL, /**< 'calt' */
|
||||
LE_CASE_FEATURE_TAG = 0x63617365UL, /**< 'case' */
|
||||
LE_CCMP_FEATURE_TAG = 0x63636D70UL, /**< 'ccmp' */
|
||||
LE_CJCT_FEATURE_TAG = 0x636A6374UL, /**< 'cjct' */
|
||||
LE_CLIG_FEATURE_TAG = 0x636C6967UL, /**< 'clig' */
|
||||
LE_CPSP_FEATURE_TAG = 0x63707370UL, /**< 'cpsp' */
|
||||
LE_CSWH_FEATURE_TAG = 0x63737768UL, /**< 'cswh' */
|
||||
LE_CURS_FEATURE_TAG = 0x63757273UL, /**< 'curs' */
|
||||
LE_C2SC_FEATURE_TAG = 0x63327363UL, /**< 'c2sc' */
|
||||
LE_C2PC_FEATURE_TAG = 0x63327063UL, /**< 'c2pc' */
|
||||
LE_DIST_FEATURE_TAG = 0x64697374UL, /**< 'dist' */
|
||||
LE_DLIG_FEATURE_TAG = 0x646C6967UL, /**< 'dlig' */
|
||||
LE_DNOM_FEATURE_TAG = 0x646E6F6DUL, /**< 'dnom' */
|
||||
LE_EXPT_FEATURE_TAG = 0x65787074UL, /**< 'expt' */
|
||||
LE_FALT_FEATURE_TAG = 0x66616C74UL, /**< 'falt' */
|
||||
LE_FIN2_FEATURE_TAG = 0x66696E32UL, /**< 'fin2' */
|
||||
LE_FIN3_FEATURE_TAG = 0x66696E33UL, /**< 'fin3' */
|
||||
LE_FINA_FEATURE_TAG = 0x66696E61UL, /**< 'fina' */
|
||||
LE_FRAC_FEATURE_TAG = 0x66726163UL, /**< 'frac' */
|
||||
LE_FWID_FEATURE_TAG = 0x66776964UL, /**< 'fwid' */
|
||||
LE_HALF_FEATURE_TAG = 0x68616C66UL, /**< 'half' */
|
||||
LE_HALN_FEATURE_TAG = 0x68616C6EUL, /**< 'haln' */
|
||||
LE_HALT_FEATURE_TAG = 0x68616C74UL, /**< 'halt' */
|
||||
LE_HIST_FEATURE_TAG = 0x68697374UL, /**< 'hist' */
|
||||
LE_HKNA_FEATURE_TAG = 0x686B6E61UL, /**< 'hkna' */
|
||||
LE_HLIG_FEATURE_TAG = 0x686C6967UL, /**< 'hlig' */
|
||||
LE_HNGL_FEATURE_TAG = 0x686E676CUL, /**< 'hngl' */
|
||||
LE_HWID_FEATURE_TAG = 0x68776964UL, /**< 'hwid' */
|
||||
LE_INIT_FEATURE_TAG = 0x696E6974UL, /**< 'init' */
|
||||
LE_ISOL_FEATURE_TAG = 0x69736F6CUL, /**< 'isol' */
|
||||
LE_ITAL_FEATURE_TAG = 0x6974616CUL, /**< 'ital' */
|
||||
LE_JALT_FEATURE_TAG = 0x6A616C74UL, /**< 'jalt' */
|
||||
LE_JP78_FEATURE_TAG = 0x6A703738UL, /**< 'jp78' */
|
||||
LE_JP83_FEATURE_TAG = 0x6A703833UL, /**< 'jp83' */
|
||||
LE_JP90_FEATURE_TAG = 0x6A703930UL, /**< 'jp90' */
|
||||
LE_KERN_FEATURE_TAG = 0x6B65726EUL, /**< 'kern' */
|
||||
LE_LFBD_FEATURE_TAG = 0x6C666264UL, /**< 'lfbd' */
|
||||
LE_LIGA_FEATURE_TAG = 0x6C696761UL, /**< 'liga' */
|
||||
LE_LJMO_FEATURE_TAG = 0x6C6A6D6FUL, /**< 'ljmo' */
|
||||
LE_LNUM_FEATURE_TAG = 0x6C6E756DUL, /**< 'lnum' */
|
||||
LE_LOCL_FEATURE_TAG = 0x6C6F636CUL, /**< 'locl' */
|
||||
LE_MARK_FEATURE_TAG = 0x6D61726BUL, /**< 'mark' */
|
||||
LE_MED2_FEATURE_TAG = 0x6D656432UL, /**< 'med2' */
|
||||
LE_MEDI_FEATURE_TAG = 0x6D656469UL, /**< 'medi' */
|
||||
LE_MGRK_FEATURE_TAG = 0x6D67726BUL, /**< 'mgrk' */
|
||||
LE_MKMK_FEATURE_TAG = 0x6D6B6D6BUL, /**< 'mkmk' */
|
||||
LE_MSET_FEATURE_TAG = 0x6D736574UL, /**< 'mset' */
|
||||
LE_NALT_FEATURE_TAG = 0x6E616C74UL, /**< 'nalt' */
|
||||
LE_NLCK_FEATURE_TAG = 0x6E6C636BUL, /**< 'nlck' */
|
||||
LE_NUKT_FEATURE_TAG = 0x6E756B74UL, /**< 'nukt' */
|
||||
LE_NUMR_FEATURE_TAG = 0x6E756D72UL, /**< 'numr' */
|
||||
LE_ONUM_FEATURE_TAG = 0x6F6E756DUL, /**< 'onum' */
|
||||
LE_OPBD_FEATURE_TAG = 0x6F706264UL, /**< 'opbd' */
|
||||
LE_ORDN_FEATURE_TAG = 0x6F72646EUL, /**< 'ordn' */
|
||||
LE_ORNM_FEATURE_TAG = 0x6F726E6DUL, /**< 'ornm' */
|
||||
LE_PALT_FEATURE_TAG = 0x70616C74UL, /**< 'palt' */
|
||||
LE_PCAP_FEATURE_TAG = 0x70636170UL, /**< 'pcap' */
|
||||
LE_PNUM_FEATURE_TAG = 0x706E756DUL, /**< 'pnum' */
|
||||
LE_PREF_FEATURE_TAG = 0x70726566UL, /**< 'pref' */
|
||||
LE_PRES_FEATURE_TAG = 0x70726573UL, /**< 'pres' */
|
||||
LE_PSTF_FEATURE_TAG = 0x70737466UL, /**< 'pstf' */
|
||||
LE_PSTS_FEATURE_TAG = 0x70737473UL, /**< 'psts' */
|
||||
LE_PWID_FEATURE_TAG = 0x70776964UL, /**< 'pwid' */
|
||||
LE_QWID_FEATURE_TAG = 0x71776964UL, /**< 'qwid' */
|
||||
LE_RAND_FEATURE_TAG = 0x72616E64UL, /**< 'rand' */
|
||||
LE_RLIG_FEATURE_TAG = 0x726C6967UL, /**< 'rlig' */
|
||||
LE_RPHF_FEATURE_TAG = 0x72706866UL, /**< 'rphf' */
|
||||
LE_RKRF_FEATURE_TAG = 0x726B7266UL, /**< 'rkrf' */
|
||||
LE_RTBD_FEATURE_TAG = 0x72746264UL, /**< 'rtbd' */
|
||||
LE_RTLA_FEATURE_TAG = 0x72746C61UL, /**< 'rtla' */
|
||||
LE_RUBY_FEATURE_TAG = 0x72756279UL, /**< 'ruby' */
|
||||
LE_SALT_FEATURE_TAG = 0x73616C74UL, /**< 'salt' */
|
||||
LE_SINF_FEATURE_TAG = 0x73696E66UL, /**< 'sinf' */
|
||||
LE_SIZE_FEATURE_TAG = 0x73697A65UL, /**< 'size' */
|
||||
LE_SMCP_FEATURE_TAG = 0x736D6370UL, /**< 'smcp' */
|
||||
LE_SMPL_FEATURE_TAG = 0x736D706CUL, /**< 'smpl' */
|
||||
LE_SS01_FEATURE_TAG = 0x73733031UL, /**< 'ss01' */
|
||||
LE_SS02_FEATURE_TAG = 0x73733032UL, /**< 'ss02' */
|
||||
LE_SS03_FEATURE_TAG = 0x73733033UL, /**< 'ss03' */
|
||||
LE_SS04_FEATURE_TAG = 0x73733034UL, /**< 'ss04' */
|
||||
LE_SS05_FEATURE_TAG = 0x73733035UL, /**< 'ss05' */
|
||||
LE_SS06_FEATURE_TAG = 0x73733036UL, /**< 'ss06' */
|
||||
LE_SS07_FEATURE_TAG = 0x73733037UL, /**< 'ss07' */
|
||||
LE_SS08_FEATURE_TAG = 0x73733038UL, /**< 'ss08' */
|
||||
LE_SS09_FEATURE_TAG = 0x73733039UL, /**< 'ss09' */
|
||||
LE_SS10_FEATURE_TAG = 0x73733130UL, /**< 'ss10' */
|
||||
LE_SS11_FEATURE_TAG = 0x73733131UL, /**< 'ss11' */
|
||||
LE_SS12_FEATURE_TAG = 0x73733132UL, /**< 'ss12' */
|
||||
LE_SS13_FEATURE_TAG = 0x73733133UL, /**< 'ss13' */
|
||||
LE_SS14_FEATURE_TAG = 0x73733134UL, /**< 'ss14' */
|
||||
LE_SS15_FEATURE_TAG = 0x73733135UL, /**< 'ss15' */
|
||||
LE_SS16_FEATURE_TAG = 0x73733136UL, /**< 'ss16' */
|
||||
LE_SS17_FEATURE_TAG = 0x73733137UL, /**< 'ss17' */
|
||||
LE_SS18_FEATURE_TAG = 0x73733138UL, /**< 'ss18' */
|
||||
LE_SS19_FEATURE_TAG = 0x73733139UL, /**< 'ss19' */
|
||||
LE_SS20_FEATURE_TAG = 0x73733230UL, /**< 'ss20' */
|
||||
LE_SUBS_FEATURE_TAG = 0x73756273UL, /**< 'subs' */
|
||||
LE_SUPS_FEATURE_TAG = 0x73757073UL, /**< 'sups' */
|
||||
LE_SWSH_FEATURE_TAG = 0x73777368UL, /**< 'swsh' */
|
||||
LE_TITL_FEATURE_TAG = 0x7469746CUL, /**< 'titl' */
|
||||
LE_TJMO_FEATURE_TAG = 0x746A6D6FUL, /**< 'tjmo' */
|
||||
LE_TNAM_FEATURE_TAG = 0x746E616DUL, /**< 'tnam' */
|
||||
LE_TNUM_FEATURE_TAG = 0x746E756DUL, /**< 'tnum' */
|
||||
LE_TRAD_FEATURE_TAG = 0x74726164UL, /**< 'trad' */
|
||||
LE_TWID_FEATURE_TAG = 0x74776964UL, /**< 'twid' */
|
||||
LE_UNIC_FEATURE_TAG = 0x756E6963UL, /**< 'unic' */
|
||||
LE_VALT_FEATURE_TAG = 0x76616C74UL, /**< 'valt' */
|
||||
LE_VATU_FEATURE_TAG = 0x76617475UL, /**< 'vatu' */
|
||||
LE_VERT_FEATURE_TAG = 0x76657274UL, /**< 'vert' */
|
||||
LE_VHAL_FEATURE_TAG = 0x7668616CUL, /**< 'vhal' */
|
||||
LE_VJMO_FEATURE_TAG = 0x766A6D6FUL, /**< 'vjmo' */
|
||||
LE_VKNA_FEATURE_TAG = 0x766B6E61UL, /**< 'vkna' */
|
||||
LE_VKRN_FEATURE_TAG = 0x766B726EUL, /**< 'vkrn' */
|
||||
LE_VPAL_FEATURE_TAG = 0x7670616CUL, /**< 'vpal' */
|
||||
LE_VRT2_FEATURE_TAG = 0x76727432UL, /**< 'vrt2' */
|
||||
LE_ZERO_FEATURE_TAG = 0x7A65726FUL /**< 'zero' */
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
enum LEFeatureENUMs {
|
||||
LE_Kerning_FEATURE_ENUM = 0, /**< Requests Kerning. Formerly LayoutEngine::kTypoFlagKern */
|
||||
LE_Ligatures_FEATURE_ENUM = 1, /**< Requests Ligatures. Formerly LayoutEngine::kTypoFlagLiga */
|
||||
LE_CLIG_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_DLIG_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_HLIG_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_LIGA_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_RLIG_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SMCP_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_FRAC_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_AFRC_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_ZERO_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SWSH_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_CSWH_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SALT_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_NALT_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_RUBY_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS01_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS02_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS03_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS04_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS05_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS06_FEATURE_ENUM, /**< Feature specific enum */
|
||||
LE_SS07_FEATURE_ENUM, /**< Feature specific enum */
|
||||
|
||||
LE_CHAR_FILTER_FEATURE_ENUM = 31, /**< Apply CharSubstitutionFilter */
|
||||
LE_FEATURE_ENUM_MAX = LE_CHAR_FILTER_FEATURE_ENUM
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Flags for typographic features.
|
||||
* @internal
|
||||
* @{
|
||||
*/
|
||||
#define LE_Kerning_FEATURE_FLAG (1 << LE_Kerning_FEATURE_ENUM)
|
||||
#define LE_Ligatures_FEATURE_FLAG (1 << LE_Ligatures_FEATURE_ENUM)
|
||||
#define LE_CLIG_FEATURE_FLAG (1 << LE_CLIG_FEATURE_ENUM)
|
||||
#define LE_DLIG_FEATURE_FLAG (1 << LE_DLIG_FEATURE_ENUM)
|
||||
#define LE_HLIG_FEATURE_FLAG (1 << LE_HLIG_FEATURE_ENUM)
|
||||
#define LE_LIGA_FEATURE_FLAG (1 << LE_LIGA_FEATURE_ENUM)
|
||||
#define LE_RLIG_FEATURE_FLAG (1 << LE_RLIG_FEATURE_ENUM)
|
||||
#define LE_SMCP_FEATURE_FLAG (1 << LE_SMCP_FEATURE_ENUM)
|
||||
#define LE_FRAC_FEATURE_FLAG (1 << LE_FRAC_FEATURE_ENUM)
|
||||
#define LE_AFRC_FEATURE_FLAG (1 << LE_AFRC_FEATURE_ENUM)
|
||||
#define LE_ZERO_FEATURE_FLAG (1 << LE_ZERO_FEATURE_ENUM)
|
||||
#define LE_SWSH_FEATURE_FLAG (1 << LE_SWSH_FEATURE_ENUM)
|
||||
#define LE_CSWH_FEATURE_FLAG (1 << LE_CSWH_FEATURE_ENUM)
|
||||
#define LE_SALT_FEATURE_FLAG (1 << LE_SALT_FEATURE_ENUM)
|
||||
#define LE_NALT_FEATURE_FLAG (1 << LE_NALT_FEATURE_ENUM)
|
||||
#define LE_RUBY_FEATURE_FLAG (1 << LE_RUBY_FEATURE_ENUM)
|
||||
#define LE_SS01_FEATURE_FLAG (1 << LE_SS01_FEATURE_ENUM)
|
||||
#define LE_SS02_FEATURE_FLAG (1 << LE_SS02_FEATURE_ENUM)
|
||||
#define LE_SS03_FEATURE_FLAG (1 << LE_SS03_FEATURE_ENUM)
|
||||
#define LE_SS04_FEATURE_FLAG (1 << LE_SS04_FEATURE_ENUM)
|
||||
#define LE_SS05_FEATURE_FLAG (1 << LE_SS05_FEATURE_ENUM)
|
||||
#define LE_SS06_FEATURE_FLAG (1 << LE_SS06_FEATURE_ENUM)
|
||||
#define LE_SS07_FEATURE_FLAG (1 << LE_SS07_FEATURE_ENUM)
|
||||
|
||||
#define LE_CHAR_FILTER_FEATURE_FLAG (1 << LE_CHAR_FILTER_FEATURE_ENUM)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#define LE_DEFAULT_FEATURE_FLAG (LE_Kerning_FEATURE_FLAG | LE_Ligatures_FEATURE_FLAG) /**< default features */
|
||||
|
||||
/**
|
||||
* Error codes returned by the LayoutEngine.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
enum LEErrorCode {
|
||||
/* informational */
|
||||
LE_NO_SUBFONT_WARNING = U_USING_DEFAULT_WARNING, /**< The font does not contain subfonts. */
|
||||
|
||||
/* success */
|
||||
LE_NO_ERROR = U_ZERO_ERROR, /**< No error, no warning. */
|
||||
|
||||
/* failures */
|
||||
LE_ILLEGAL_ARGUMENT_ERROR = U_ILLEGAL_ARGUMENT_ERROR, /**< An illegal argument was detected. */
|
||||
LE_MEMORY_ALLOCATION_ERROR = U_MEMORY_ALLOCATION_ERROR, /**< Memory allocation error. */
|
||||
LE_INDEX_OUT_OF_BOUNDS_ERROR = U_INDEX_OUTOFBOUNDS_ERROR, /**< Trying to access an index that is out of bounds. */
|
||||
LE_NO_LAYOUT_ERROR = U_UNSUPPORTED_ERROR, /**< You must call layoutChars() first. */
|
||||
LE_INTERNAL_ERROR = U_INTERNAL_PROGRAM_ERROR, /**< An internal error was encountered. */
|
||||
LE_FONT_FILE_NOT_FOUND_ERROR = U_FILE_ACCESS_ERROR, /**< The requested font file cannot be opened. */
|
||||
LE_MISSING_FONT_TABLE_ERROR = U_MISSING_RESOURCE_ERROR /**< The requested font table does not exist. */
|
||||
};
|
||||
|
||||
#ifndef __cplusplus
|
||||
/**
|
||||
* Error codes returned by the LayoutEngine.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
typedef enum LEErrorCode LEErrorCode;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A convenience macro to test for the success of a LayoutEngine call.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
#define LE_SUCCESS(code) (U_SUCCESS((UErrorCode)code))
|
||||
|
||||
/**
|
||||
* A convenience macro to test for the failure of a LayoutEngine call.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
#define LE_FAILURE(code) (U_FAILURE((UErrorCode)code))
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,511 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. and others 1998-2013 - All Rights Reserved
|
||||
*/
|
||||
|
||||
#ifndef __LAYOUTENGINE_H
|
||||
#define __LAYOUTENGINE_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Virtual base class for complex text layout.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class LEFontInstance;
|
||||
class LEGlyphFilter;
|
||||
class LEGlyphStorage;
|
||||
|
||||
/**
|
||||
* This is a virtual base class used to do complex text layout. The text must all
|
||||
* be in a single font, script, and language. An instance of a LayoutEngine can be
|
||||
* created by calling the layoutEngineFactory method. Fonts are identified by
|
||||
* instances of the LEFontInstance class. Script and language codes are identified
|
||||
* by integer codes, which are defined in ScriptAndLanuageTags.h.
|
||||
*
|
||||
* Note that this class is not public API. It is declared public so that it can be
|
||||
* exported from the library that it is a part of.
|
||||
*
|
||||
* The input to the layout process is an array of characters in logical order,
|
||||
* and a starting X, Y position for the text. The output is an array of glyph indices,
|
||||
* an array of character indices for the glyphs, and an array of glyph positions.
|
||||
* These arrays are protected members of LayoutEngine which can be retreived by a
|
||||
* public method. The reset method can be called to free these arrays so that the
|
||||
* LayoutEngine can be reused.
|
||||
*
|
||||
* The layout process is done in three steps. There is a protected virtual method
|
||||
* for each step. These methods have a default implementation which only does
|
||||
* character to glyph mapping and default positioning using the glyph's advance
|
||||
* widths. Subclasses can override these methods for more advanced layout.
|
||||
* There is a public method which invokes the steps in the correct order.
|
||||
*
|
||||
* The steps are:
|
||||
*
|
||||
* 1) Glyph processing - character to glyph mapping and any other glyph processing
|
||||
* such as ligature substitution and contextual forms.
|
||||
*
|
||||
* 2) Glyph positioning - position the glyphs based on their advance widths.
|
||||
*
|
||||
* 3) Glyph position adjustments - adjustment of glyph positions for kerning,
|
||||
* accent placement, etc.
|
||||
*
|
||||
* NOTE: in all methods below, output parameters are references to pointers so
|
||||
* the method can allocate and free the storage as needed. All storage allocated
|
||||
* in this way is owned by the object which created it, and will be freed when it
|
||||
* is no longer needed, or when the object's destructor is invoked.
|
||||
*
|
||||
* @see LEFontInstance
|
||||
* @see ScriptAndLanguageTags.h
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
class U_LAYOUT_API LayoutEngine : public UObject {
|
||||
public:
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/** @internal Flag to request kerning. Use LE_Kerning_FEATURE_FLAG instead. */
|
||||
static const le_int32 kTypoFlagKern;
|
||||
/** @internal Flag to request ligatures. Use LE_Ligatures_FEATURE_FLAG instead. */
|
||||
static const le_int32 kTypoFlagLiga;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The object which holds the glyph storage
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LEGlyphStorage *fGlyphStorage;
|
||||
|
||||
/**
|
||||
* The font instance for the text font.
|
||||
*
|
||||
* @see LEFontInstance
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const LEFontInstance *fFontInstance;
|
||||
|
||||
/**
|
||||
* The script code for the text
|
||||
*
|
||||
* @see ScriptAndLanguageTags.h for script codes.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fScriptCode;
|
||||
|
||||
/**
|
||||
* The langauge code for the text
|
||||
*
|
||||
* @see ScriptAndLanguageTags.h for language codes.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fLanguageCode;
|
||||
|
||||
/**
|
||||
* The typographic control flags
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_int32 fTypoFlags;
|
||||
|
||||
/**
|
||||
* <code>TRUE</code> if <code>mapCharsToGlyphs</code> should replace ZWJ / ZWNJ with a glyph
|
||||
* with no contours.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
le_bool fFilterZeroWidth;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This constructs an instance for a given font, script and language. Subclass constructors
|
||||
* must call this constructor.
|
||||
*
|
||||
* @param fontInstance - the font for the text
|
||||
* @param scriptCode - the script for the text
|
||||
* @param languageCode - the language for the text
|
||||
* @param typoFlags - the typographic control flags for the text (a bitfield). Use kTypoFlagKern
|
||||
* if kerning is desired, kTypoFlagLiga if ligature formation is desired. Others are reserved.
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @see LEFontInstance
|
||||
* @see ScriptAndLanguageTags.h
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LayoutEngine(const LEFontInstance *fontInstance,
|
||||
le_int32 scriptCode,
|
||||
le_int32 languageCode,
|
||||
le_int32 typoFlags,
|
||||
LEErrorCode &success);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
// Do not enclose the protected default constructor with #ifndef U_HIDE_INTERNAL_API
|
||||
// or else the compiler will create a public default constructor.
|
||||
/**
|
||||
* This overrides the default no argument constructor to make it
|
||||
* difficult for clients to call it. Clients are expected to call
|
||||
* layoutEngineFactory.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
LayoutEngine();
|
||||
|
||||
/**
|
||||
* This method does any required pre-processing to the input characters. It
|
||||
* may generate output characters that differ from the input charcters due to
|
||||
* insertions, deletions, or reorderings. In such cases, it will also generate an
|
||||
* output character index array reflecting these changes.
|
||||
*
|
||||
* Subclasses must override this method.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param chars - the input character context
|
||||
* @param offset - the index of the first character to process
|
||||
* @param count - the number of characters to process
|
||||
* @param max - the number of characters in the input context
|
||||
* @param rightToLeft - TRUE if the characters are in a right to left directional run
|
||||
* @param outChars - the output character array, if different from the input
|
||||
* @param glyphStorage - the object that holds the per-glyph storage. The character index array may be set.
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @return the output character count (input character count if no change)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual le_int32 characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
|
||||
LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method does the glyph processing. It converts an array of characters
|
||||
* into an array of glyph indices and character indices. The characters to be
|
||||
* processed are passed in a surrounding context. The context is specified as
|
||||
* a starting address and a maximum character count. An offset and a count are
|
||||
* used to specify the characters to be processed.
|
||||
*
|
||||
* The default implementation of this method only does character to glyph mapping.
|
||||
* Subclasses needing more elaborate glyph processing must override this method.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param chars - the character context
|
||||
* @param offset - the offset of the first character to process
|
||||
* @param count - the number of characters to process
|
||||
* @param max - the number of characters in the context.
|
||||
* @param rightToLeft - TRUE if the text is in a right to left directional run
|
||||
* @param glyphStorage - the object which holds the per-glyph storage. The glyph and char indices arrays
|
||||
* will be set.
|
||||
*
|
||||
* Output parameters:
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @return the number of glyphs in the glyph index array
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual le_int32 computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method does basic glyph positioning. The default implementation positions
|
||||
* the glyphs based on their advance widths. This is sufficient for most uses. It
|
||||
* is not expected that many subclasses will override this method.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param glyphStorage - the object which holds the per-glyph storage. The glyph position array will be set.
|
||||
* @param x - the starting X position
|
||||
* @param y - the starting Y position
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual void positionGlyphs(LEGlyphStorage &glyphStorage, float x, float y, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method does positioning adjustments like accent positioning and
|
||||
* kerning. The default implementation does nothing. Subclasses needing
|
||||
* position adjustments must override this method.
|
||||
*
|
||||
* Note that this method has both characters and glyphs as input so that
|
||||
* it can use the character codes to determine glyph types if that information
|
||||
* isn't directly available. (e.g. Some Arabic OpenType fonts don't have a GDEF
|
||||
* table)
|
||||
*
|
||||
* @param chars - the input character context
|
||||
* @param offset - the offset of the first character to process
|
||||
* @param count - the number of characters to process
|
||||
* @param reverse - <code>TRUE</code> if the glyphs in the glyph array have been reordered
|
||||
* @param glyphStorage - the object which holds the per-glyph storage. The glyph positions will be
|
||||
* adjusted as needed.
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual void adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method gets a table from the font associated with
|
||||
* the text. The default implementation gets the table from
|
||||
* the font instance. Subclasses which need to get the tables
|
||||
* some other way must override this method.
|
||||
*
|
||||
* @param tableTag - the four byte table tag.
|
||||
* @param length - length to use
|
||||
*
|
||||
* @return the address of the table.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual const void *getFontTable(LETag tableTag, size_t &length) const;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
virtual const void *getFontTable(LETag tableTag) const { size_t ignored; return getFontTable(tableTag, ignored); }
|
||||
|
||||
/**
|
||||
* This method does character to glyph mapping. The default implementation
|
||||
* uses the font instance to do the mapping. It will allocate the glyph and
|
||||
* character index arrays if they're not already allocated. If it allocates the
|
||||
* character index array, it will fill it it.
|
||||
*
|
||||
* This method supports right to left
|
||||
* text with the ability to store the glyphs in reverse order, and by supporting
|
||||
* character mirroring, which will replace a character which has a left and right
|
||||
* form, such as parens, with the opposite form before mapping it to a glyph index.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param chars - the input character context
|
||||
* @param offset - the offset of the first character to be mapped
|
||||
* @param count - the number of characters to be mapped
|
||||
* @param reverse - if <code>TRUE</code>, the output will be in reverse order
|
||||
* @param mirror - if <code>TRUE</code>, do character mirroring
|
||||
* @param glyphStorage - the object which holds the per-glyph storage. The glyph and char
|
||||
* indices arrays will be filled in.
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @see LEFontInstance
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool mirror, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This is a convenience method that forces the advance width of mark
|
||||
* glyphs to be zero, which is required for proper selection and highlighting.
|
||||
*
|
||||
* @param glyphStorage - the object containing the per-glyph storage. The positions array will be modified.
|
||||
* @param markFilter - used to identify mark glyphs
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @see LEGlyphFilter
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
static void adjustMarkGlyphs(LEGlyphStorage &glyphStorage, LEGlyphFilter *markFilter, LEErrorCode &success);
|
||||
|
||||
|
||||
/**
|
||||
* This is a convenience method that forces the advance width of mark
|
||||
* glyphs to be zero, which is required for proper selection and highlighting.
|
||||
* This method uses the input characters to identify marks. This is required in
|
||||
* cases where the font does not contain enough information to identify them based
|
||||
* on the glyph IDs.
|
||||
*
|
||||
* @param chars - the array of input characters
|
||||
* @param charCount - the number of input characers
|
||||
* @param glyphStorage - the object containing the per-glyph storage. The positions array will be modified.
|
||||
* @param reverse - <code>TRUE</code> if the glyph array has been reordered
|
||||
* @param markFilter - used to identify mark glyphs
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @see LEGlyphFilter
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
static void adjustMarkGlyphs(const LEUnicode chars[], le_int32 charCount, le_bool reverse, LEGlyphStorage &glyphStorage, LEGlyphFilter *markFilter, LEErrorCode &success);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
public:
|
||||
/**
|
||||
* The destructor. It will free any storage allocated for the
|
||||
* glyph, character index and position arrays by calling the reset
|
||||
* method. It is declared virtual so that it will be invoked by the
|
||||
* subclass destructors.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual ~LayoutEngine();
|
||||
|
||||
/**
|
||||
* This method will invoke the layout steps in their correct order by calling
|
||||
* the computeGlyphs, positionGlyphs and adjustGlyphPosition methods. It will
|
||||
* compute the glyph, character index and position arrays.
|
||||
*
|
||||
* @param chars - the input character context
|
||||
* @param offset - the offset of the first character to process
|
||||
* @param count - the number of characters to process
|
||||
* @param max - the number of characters in the input context
|
||||
* @param rightToLeft - TRUE if the characers are in a right to left directional run
|
||||
* @param x - the initial X position
|
||||
* @param y - the initial Y position
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @return the number of glyphs in the glyph array
|
||||
*
|
||||
* Note: The glyph, character index and position array can be accessed
|
||||
* using the getter methods below.
|
||||
*
|
||||
* Note: If you call this method more than once, you must call the reset()
|
||||
* method first to free the glyph, character index and position arrays
|
||||
* allocated by the previous call.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual le_int32 layoutChars(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, float x, float y, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* This method returns the number of glyphs in the glyph array. Note
|
||||
* that the number of glyphs will be greater than or equal to the number
|
||||
* of characters used to create the LayoutEngine.
|
||||
*
|
||||
* @return the number of glyphs in the glyph array
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
le_int32 getGlyphCount() const;
|
||||
|
||||
/**
|
||||
* This method copies the glyph array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold all
|
||||
* the glyphs.
|
||||
*
|
||||
* @param glyphs - the destiniation glyph array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the glyph array into a caller supplied array,
|
||||
* ORing in extra bits. (This functionality is needed by the JDK,
|
||||
* which uses 32 bits pre glyph idex, with the high 16 bits encoding
|
||||
* the composite font slot number)
|
||||
*
|
||||
* @param glyphs - the destination (32 bit) glyph array
|
||||
* @param extraBits - this value will be ORed with each glyph index
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param indexBase - an offset which will be added to each index
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method copies the position array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold an
|
||||
* X and Y position for each glyph, plus an extra X and Y for the
|
||||
* advance of the last glyph.
|
||||
*
|
||||
* @param positions - the destiniation position array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void getGlyphPositions(float positions[], LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method returns the X and Y position of the glyph at
|
||||
* the given index.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param glyphIndex - the index of the glyph
|
||||
*
|
||||
* Output parameters:
|
||||
* @param x - the glyph's X position
|
||||
* @param y - the glyph's Y position
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;
|
||||
|
||||
/**
|
||||
* This method frees the glyph, character index and position arrays
|
||||
* so that the LayoutEngine can be reused to layout a different
|
||||
* characer array. (This method is also called by the destructor)
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual void reset();
|
||||
|
||||
/**
|
||||
* This method returns a LayoutEngine capable of laying out text
|
||||
* in the given font, script and langauge. Note that the LayoutEngine
|
||||
* returned may be a subclass of LayoutEngine.
|
||||
*
|
||||
* @param fontInstance - the font of the text
|
||||
* @param scriptCode - the script of the text
|
||||
* @param languageCode - the language of the text
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @return a LayoutEngine which can layout text in the given font.
|
||||
*
|
||||
* @see LEFontInstance
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static LayoutEngine *layoutEngineFactory(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* Override of existing call that provides flags to control typography.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
static LayoutEngine *layoutEngineFactory(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typo_flags, LEErrorCode &success);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static UClassID getStaticClassID();
|
||||
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,740 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2002-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __PARAGRAPHLAYOUT_H
|
||||
|
||||
#define __PARAGRAPHLAYOUT_H
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Paragraph Layout
|
||||
*/
|
||||
|
||||
/*
|
||||
* ParagraphLayout doesn't make much sense without
|
||||
* BreakIterator...
|
||||
*/
|
||||
#include "unicode/uscript.h"
|
||||
#if ! UCONFIG_NO_BREAK_ITERATION
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
#include "layout/LEFontInstance.h"
|
||||
#include "layout/LayoutEngine.h"
|
||||
#include "unicode/ubidi.h"
|
||||
#include "unicode/brkiter.h"
|
||||
|
||||
#include "layout/RunArrays.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* ParagraphLayout.
|
||||
*
|
||||
* The <code>ParagraphLayout</code> object will analyze the text into runs of text in the
|
||||
* same font, script and direction, and will create a <code>LayoutEngine</code> object for each run.
|
||||
* The <code>LayoutEngine</code> will transform the characters into glyph codes in visual order.
|
||||
*
|
||||
* Clients can use this to break a paragraph into lines, and to display the glyphs in each line.
|
||||
*
|
||||
*/
|
||||
class U_LAYOUTEX_API ParagraphLayout : public UObject
|
||||
{
|
||||
public:
|
||||
class VisualRun;
|
||||
|
||||
/**
|
||||
* This class represents a single line of text in a <code>ParagraphLayout</code>. They
|
||||
* can only be created by calling <code>ParagraphLayout::nextLine()</code>. Each line
|
||||
* consists of multiple visual runs, represented by <code>ParagraphLayout::VisualRun</code>
|
||||
* objects.
|
||||
*
|
||||
* @see ParagraphLayout
|
||||
* @see ParagraphLayout::VisualRun
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API Line : public UObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* The constructor is private since these objects can only be
|
||||
* created by <code>ParagraphLayout</code>. However, it is the
|
||||
* clients responsibility to destroy the objects, so the destructor
|
||||
* is public.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
~Line();
|
||||
|
||||
/**
|
||||
* Count the number of visual runs in the line.
|
||||
*
|
||||
* @return the number of visual runs.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 countRuns() const;
|
||||
|
||||
/**
|
||||
* Get the ascent of the line. This is the maximum ascent
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @return the ascent of the line.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 getAscent() const;
|
||||
|
||||
/**
|
||||
* Get the descent of the line. This is the maximum descent
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @return the descent of the line.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 getDescent() const;
|
||||
|
||||
/**
|
||||
* Get the leading of the line. This is the maximum leading
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @return the leading of the line.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 getLeading() const;
|
||||
|
||||
/**
|
||||
* Get the width of the line. This is a convenience method
|
||||
* which returns the last X position of the last visual run
|
||||
* in the line.
|
||||
*
|
||||
* @return the width of the line.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
le_int32 getWidth() const;
|
||||
|
||||
/**
|
||||
* Get a <code>ParagraphLayout::VisualRun</code> object for a given
|
||||
* visual run in the line.
|
||||
*
|
||||
* @param runIndex is the index of the run, in visual order.
|
||||
*
|
||||
* @return the <code>ParagraphLayout::VisualRun</code> object representing the
|
||||
* visual run. This object is owned by the <code>Line</code> object which
|
||||
* created it, and will remain valid for as long as the <code>Line</code>
|
||||
* object is valid.
|
||||
*
|
||||
* @see ParagraphLayout::VisualRun
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
const VisualRun *getVisualRun(le_int32 runIndex) const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
friend class ParagraphLayout;
|
||||
|
||||
le_int32 fAscent;
|
||||
le_int32 fDescent;
|
||||
le_int32 fLeading;
|
||||
|
||||
le_int32 fRunCount;
|
||||
le_int32 fRunCapacity;
|
||||
|
||||
VisualRun **fRuns;
|
||||
|
||||
inline Line();
|
||||
inline Line(const Line &other);
|
||||
inline Line &operator=(const Line & /*other*/) { return *this; };
|
||||
|
||||
void computeMetrics();
|
||||
|
||||
void append(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
|
||||
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
|
||||
};
|
||||
|
||||
/**
|
||||
* This object represents a single visual run in a line of text in
|
||||
* a paragraph. A visual run is text which is in the same font,
|
||||
* script, and direction. The text is represented by an array of
|
||||
* <code>LEGlyphIDs</code>, an array of (x, y) glyph positions and
|
||||
* a table which maps indices into the glyph array to indices into
|
||||
* the original character array which was used to create the paragraph.
|
||||
*
|
||||
* These objects are only created by <code>ParagraphLayout::Line</code> objects,
|
||||
* so their constructors and destructors are private.
|
||||
*
|
||||
* @see ParagraphLayout::Line
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API VisualRun : public UObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Get the <code>LEFontInstance</code> object which
|
||||
* represents the font of the visual run. This will always
|
||||
* be a non-composite font.
|
||||
*
|
||||
* @return the <code>LEFontInstance</code> object which represents the
|
||||
* font of the visual run.
|
||||
*
|
||||
* @see LEFontInstance
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline const LEFontInstance *getFont() const;
|
||||
|
||||
/**
|
||||
* Get the direction of the visual run.
|
||||
*
|
||||
* @return the direction of the run. This will be UBIDI_LTR if the
|
||||
* run is left-to-right and UBIDI_RTL if the line is right-to-left.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline UBiDiDirection getDirection() const;
|
||||
|
||||
/**
|
||||
* Get the number of glyphs in the visual run.
|
||||
*
|
||||
* @return the number of glyphs.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getGlyphCount() const;
|
||||
|
||||
/**
|
||||
* Get the glyphs in the visual run. Glyphs with the values <code>0xFFFE</code> and
|
||||
* <code>0xFFFF</code> should be ignored.
|
||||
*
|
||||
* @return the address of the array of glyphs for this visual run. The storage
|
||||
* is owned by the <code>VisualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>VisualRun</code> object is valid.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline const LEGlyphID *getGlyphs() const;
|
||||
|
||||
/**
|
||||
* Get the (x, y) positions of the glyphs in the visual run. To simplify storage
|
||||
* management, the x and y positions are stored in a single array with the x positions
|
||||
* at even offsets in the array and the corresponding y position in the following odd offset.
|
||||
* There is an extra (x, y) pair at the end of the array which represents the advance of
|
||||
* the final glyph in the run.
|
||||
*
|
||||
* @return the address of the array of glyph positions for this visual run. The storage
|
||||
* is owned by the <code>VisualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>VisualRun</code> object is valid.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline const float *getPositions() const;
|
||||
|
||||
/**
|
||||
* Get the glyph-to-character map for this visual run. This maps the indices into
|
||||
* the glyph array to indices into the character array used to create the paragraph.
|
||||
*
|
||||
* @return the address of the character-to-glyph map for this visual run. The storage
|
||||
* is owned by the <code>VisualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>VisualRun</code> object is valid.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline const le_int32 *getGlyphToCharMap() const;
|
||||
|
||||
/**
|
||||
* A convenience method which returns the ascent value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @return the ascent value of this run's font.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getAscent() const;
|
||||
|
||||
/**
|
||||
* A convenience method which returns the descent value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @return the descent value of this run's font.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getDescent() const;
|
||||
|
||||
/**
|
||||
* A convenience method which returns the leading value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @return the leading value of this run's font.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getLeading() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
const LEFontInstance *fFont;
|
||||
const UBiDiDirection fDirection;
|
||||
|
||||
const le_int32 fGlyphCount;
|
||||
|
||||
const LEGlyphID *fGlyphs;
|
||||
const float *fPositions;
|
||||
const le_int32 *fGlyphToCharMap;
|
||||
|
||||
friend class Line;
|
||||
|
||||
inline VisualRun();
|
||||
inline VisualRun(const VisualRun &other);
|
||||
inline VisualRun &operator=(const VisualRun &/*other*/) { return *this; };
|
||||
|
||||
inline VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
|
||||
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[]);
|
||||
|
||||
~VisualRun();
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a <code>ParagraphLayout</code> object for a styled paragraph. The paragraph is specified
|
||||
* as runs of text all in the same font. An <code>LEFontInstance</code> object and a limit offset
|
||||
* are specified for each font run. The limit offset is the offset of the character immediately
|
||||
* after the font run.
|
||||
*
|
||||
* Clients can optionally specify directional runs and / or script runs. If these aren't specified
|
||||
* they will be computed.
|
||||
*
|
||||
* If any errors are encountered during construction, <code>status</code> will be set, and the object
|
||||
* will be set to be empty.
|
||||
*
|
||||
* @param chars is an array of the characters in the paragraph
|
||||
*
|
||||
* @param count is the number of characters in the paragraph.
|
||||
*
|
||||
* @param fontRuns a pointer to a <code>FontRuns</code> object representing the font runs.
|
||||
*
|
||||
* @param levelRuns is a pointer to a <code>ValueRuns</code> object representing the directional levels.
|
||||
* If this pointer in <code>NULL</code> the levels will be determined by running the Unicde
|
||||
* Bidi algorithm.
|
||||
*
|
||||
* @param scriptRuns is a pointer to a <code>ValueRuns</code> object representing script runs.
|
||||
* If this pointer in <code>NULL</code> the script runs will be determined using the
|
||||
* Unicode code points.
|
||||
*
|
||||
* @param localeRuns is a pointer to a <code>LocaleRuns</code> object representing locale runs.
|
||||
* The <code>Locale</code> objects are used to determind the language of the text. If this
|
||||
* pointer is <code>NULL</code> the default locale will be used for all of the text.
|
||||
*
|
||||
* @param paragraphLevel is the directionality of the paragraph, as in the UBiDi object.
|
||||
*
|
||||
* @param vertical is <code>TRUE</code> if the paragraph should be set vertically.
|
||||
*
|
||||
* @param status will be set to any error code encountered during construction.
|
||||
*
|
||||
* @see ubidi.h
|
||||
* @see LEFontInstance.h
|
||||
* @see LayoutEngine.h
|
||||
* @see RunArrays.h
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
ParagraphLayout(const LEUnicode chars[], le_int32 count,
|
||||
const FontRuns *fontRuns,
|
||||
const ValueRuns *levelRuns,
|
||||
const ValueRuns *scriptRuns,
|
||||
const LocaleRuns *localeRuns,
|
||||
UBiDiLevel paragraphLevel, le_bool vertical,
|
||||
LEErrorCode &status);
|
||||
|
||||
/**
|
||||
* The destructor. Virtual so that it works correctly with
|
||||
* sublcasses.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
~ParagraphLayout();
|
||||
|
||||
// Note: the following is #if 0'd out because there's no good
|
||||
// way to implement it without either calling layoutEngineFactory()
|
||||
// or duplicating the logic there...
|
||||
#if 0
|
||||
/**
|
||||
* Examine the given styled paragraph and determine if it contains any text which
|
||||
* requires complex processing. (i.e. that cannot be correctly rendered by
|
||||
* just mapping the characters to glyphs and rendering them in order)
|
||||
*
|
||||
* @param chars is an array of the characters in the paragraph
|
||||
*
|
||||
* @param count is the number of characters in the paragraph.
|
||||
*
|
||||
* @param fontRuns is a pointer to a <code>FontRuns</code> object representing the font runs.
|
||||
*
|
||||
* @return <code>TRUE</code> if the paragraph contains complex text.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static le_bool isComplex(const LEUnicode chars[], le_int32 count, const FontRuns *fontRuns);
|
||||
#else
|
||||
/**
|
||||
* Examine the given text and determine if it contains characters in any
|
||||
* script which requires complex processing to be rendered correctly.
|
||||
*
|
||||
* @param chars is an array of the characters in the paragraph
|
||||
*
|
||||
* @param count is the number of characters in the paragraph.
|
||||
*
|
||||
* @return <code>TRUE</code> if any of the text requires complex processing.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static le_bool isComplex(const LEUnicode chars[], le_int32 count);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Return the resolved paragraph level. This is useful for those cases
|
||||
* where the bidi analysis has determined the level based on the first
|
||||
* strong character in the paragraph.
|
||||
*
|
||||
* @return the resolved paragraph level.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline UBiDiLevel getParagraphLevel();
|
||||
|
||||
/**
|
||||
* Return the directionality of the text in the paragraph.
|
||||
*
|
||||
* @return <code>UBIDI_LTR</code> if the text is all left to right,
|
||||
* <code>UBIDI_RTL</code> if the text is all right to left,
|
||||
* or <code>UBIDI_MIXED</code> if the text has mixed direction.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline UBiDiDirection getTextDirection();
|
||||
|
||||
/**
|
||||
* Return the max ascent value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @return the ascent value.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getAscent() const;
|
||||
|
||||
/**
|
||||
* Return the max descent value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @return the decent value.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getDescent() const;
|
||||
|
||||
/**
|
||||
* Return the max leading value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @return the leading value.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual le_int32 getLeading() const;
|
||||
|
||||
/**
|
||||
* Reset line breaking to start from the beginning of the paragraph.
|
||||
*
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline void reflow();
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
*
|
||||
* Convenience method for determining if paragraph layout processing is complete ( i.e. there
|
||||
* are no more lines left to process. )
|
||||
*
|
||||
* @return true if there are no more lines to be processed
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
inline le_bool isDone() const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Return a <code>ParagraphLayout::Line</code> object which represents next line
|
||||
* in the paragraph. The width of the line is specified each time so that it can
|
||||
* be varied to support arbitrary paragraph shapes.
|
||||
*
|
||||
* @param width is the width of the line. If <code>width</code> is less than or equal
|
||||
* to zero, a <code>ParagraphLayout::Line</code> object representing the
|
||||
* rest of the paragraph will be returned.
|
||||
*
|
||||
* @return a <code>ParagraphLayout::Line</code> object which represents the line. The caller
|
||||
* is responsible for deleting the object. Returns <code>NULL</code> if there are no
|
||||
* more lines in the paragraph.
|
||||
*
|
||||
* @see ParagraphLayout::Line
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
Line *nextLine(float width);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
struct StyleRunInfo
|
||||
{
|
||||
LayoutEngine *engine;
|
||||
const LEFontInstance *font;
|
||||
const Locale *locale;
|
||||
LEGlyphID *glyphs;
|
||||
float *positions;
|
||||
UScriptCode script;
|
||||
UBiDiLevel level;
|
||||
le_int32 runBase;
|
||||
le_int32 runLimit;
|
||||
le_int32 glyphBase;
|
||||
le_int32 glyphCount;
|
||||
};
|
||||
|
||||
ParagraphLayout() {};
|
||||
ParagraphLayout(const ParagraphLayout & /*other*/) : UObject( ){};
|
||||
inline ParagraphLayout &operator=(const ParagraphLayout & /*other*/) { return *this; };
|
||||
|
||||
void computeLevels(UBiDiLevel paragraphLevel);
|
||||
|
||||
Line *computeVisualRuns();
|
||||
void appendRun(Line *line, le_int32 run, le_int32 firstChar, le_int32 lastChar);
|
||||
|
||||
void computeScripts();
|
||||
|
||||
void computeLocales();
|
||||
|
||||
void computeSubFonts(const FontRuns *fontRuns, LEErrorCode &status);
|
||||
|
||||
void computeMetrics();
|
||||
|
||||
le_int32 getLanguageCode(const Locale *locale);
|
||||
|
||||
le_int32 getCharRun(le_int32 charIndex);
|
||||
|
||||
static le_bool isComplex(UScriptCode script);
|
||||
|
||||
le_int32 previousBreak(le_int32 charIndex);
|
||||
|
||||
|
||||
const LEUnicode *fChars;
|
||||
le_int32 fCharCount;
|
||||
|
||||
const FontRuns *fFontRuns;
|
||||
const ValueRuns *fLevelRuns;
|
||||
const ValueRuns *fScriptRuns;
|
||||
const LocaleRuns *fLocaleRuns;
|
||||
|
||||
le_bool fVertical;
|
||||
le_bool fClientLevels;
|
||||
le_bool fClientScripts;
|
||||
le_bool fClientLocales;
|
||||
|
||||
UBiDiLevel *fEmbeddingLevels;
|
||||
|
||||
le_int32 fAscent;
|
||||
le_int32 fDescent;
|
||||
le_int32 fLeading;
|
||||
|
||||
le_int32 *fGlyphToCharMap;
|
||||
le_int32 *fCharToMinGlyphMap;
|
||||
le_int32 *fCharToMaxGlyphMap;
|
||||
float *fGlyphWidths;
|
||||
le_int32 fGlyphCount;
|
||||
|
||||
UBiDi *fParaBidi;
|
||||
UBiDi *fLineBidi;
|
||||
|
||||
le_int32 *fStyleRunLimits;
|
||||
le_int32 *fStyleIndices;
|
||||
StyleRunInfo *fStyleRunInfo;
|
||||
le_int32 fStyleRunCount;
|
||||
|
||||
BreakIterator *fBreakIterator;
|
||||
le_int32 fLineStart;
|
||||
le_int32 fLineEnd;
|
||||
|
||||
le_int32 fFirstVisualRun;
|
||||
le_int32 fLastVisualRun;
|
||||
float fVisualRunLastX;
|
||||
float fVisualRunLastY;
|
||||
};
|
||||
|
||||
inline UBiDiLevel ParagraphLayout::getParagraphLevel()
|
||||
{
|
||||
return ubidi_getParaLevel(fParaBidi);
|
||||
}
|
||||
|
||||
inline UBiDiDirection ParagraphLayout::getTextDirection()
|
||||
{
|
||||
return ubidi_getDirection(fParaBidi);
|
||||
}
|
||||
|
||||
inline void ParagraphLayout::reflow()
|
||||
{
|
||||
fLineEnd = 0;
|
||||
}
|
||||
|
||||
inline ParagraphLayout::Line::Line()
|
||||
: UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
|
||||
{
|
||||
// nothing else to do
|
||||
}
|
||||
|
||||
inline ParagraphLayout::Line::Line(const Line & /*other*/)
|
||||
: UObject(), fAscent(0), fDescent(0), fLeading(0), fRunCount(0), fRunCapacity(0), fRuns(NULL)
|
||||
{
|
||||
// nothing else to do
|
||||
}
|
||||
|
||||
inline le_int32 ParagraphLayout::Line::countRuns() const
|
||||
{
|
||||
return fRunCount;
|
||||
}
|
||||
|
||||
inline const LEFontInstance *ParagraphLayout::VisualRun::getFont() const
|
||||
{
|
||||
return fFont;
|
||||
}
|
||||
|
||||
inline UBiDiDirection ParagraphLayout::VisualRun::getDirection() const
|
||||
{
|
||||
return fDirection;
|
||||
}
|
||||
|
||||
inline le_int32 ParagraphLayout::VisualRun::getGlyphCount() const
|
||||
{
|
||||
return fGlyphCount;
|
||||
}
|
||||
|
||||
inline const LEGlyphID *ParagraphLayout::VisualRun::getGlyphs() const
|
||||
{
|
||||
return fGlyphs;
|
||||
}
|
||||
|
||||
inline const float *ParagraphLayout::VisualRun::getPositions() const
|
||||
{
|
||||
return fPositions;
|
||||
}
|
||||
|
||||
inline const le_int32 *ParagraphLayout::VisualRun::getGlyphToCharMap() const
|
||||
{
|
||||
return fGlyphToCharMap;
|
||||
}
|
||||
|
||||
inline le_int32 ParagraphLayout::VisualRun::getAscent() const
|
||||
{
|
||||
return fFont->getAscent();
|
||||
}
|
||||
|
||||
inline le_int32 ParagraphLayout::VisualRun::getDescent() const
|
||||
{
|
||||
return fFont->getDescent();
|
||||
}
|
||||
|
||||
inline le_int32 ParagraphLayout::VisualRun::getLeading() const
|
||||
{
|
||||
return fFont->getLeading();
|
||||
}
|
||||
|
||||
inline ParagraphLayout::VisualRun::VisualRun()
|
||||
: UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
inline ParagraphLayout::VisualRun::VisualRun(const VisualRun &/*other*/)
|
||||
: UObject(), fFont(NULL), fDirection(UBIDI_LTR), fGlyphCount(0), fGlyphs(NULL), fPositions(NULL), fGlyphToCharMap(NULL)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
inline ParagraphLayout::VisualRun::VisualRun(const LEFontInstance *font, UBiDiDirection direction, le_int32 glyphCount,
|
||||
const LEGlyphID glyphs[], const float positions[], const le_int32 glyphToCharMap[])
|
||||
: fFont(font), fDirection(direction), fGlyphCount(glyphCount),
|
||||
fGlyphs(glyphs), fPositions(positions), fGlyphToCharMap(glyphToCharMap)
|
||||
{
|
||||
// nothing else needs to be done!
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,676 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2003-2008, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __RUNARRAYS_H
|
||||
|
||||
#define __RUNARRAYS_H
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
#include "layout/LEFontInstance.h"
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: base class for building classes which represent data that is associated with runs of text.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* The initial size of an array if it is unspecified.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define INITIAL_CAPACITY 16
|
||||
|
||||
/**
|
||||
* When an array needs to grow, it will double in size until
|
||||
* it becomes this large, then it will grow by this amount.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
#define CAPACITY_GROW_LIMIT 128
|
||||
|
||||
/**
|
||||
* The <code>RunArray</code> class is a base class for building classes
|
||||
* which represent data that is associated with runs of text. This class
|
||||
* maintains an array of limit indices into the text, subclasses
|
||||
* provide one or more arrays of data.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API RunArray : public UObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a <code>RunArray</code> object from a pre-existing
|
||||
* array of limit indices.
|
||||
*
|
||||
* @param limits is an array of limit indices. This array must remain
|
||||
* valid until the <code>RunArray</code> object is destroyed.
|
||||
*
|
||||
* @param count is the number of entries in the limit array.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline RunArray(const le_int32 *limits, le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>RunArray</code> object. Clients can add limit
|
||||
* indices array using the <code>add</code> method.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the limit indices array. If
|
||||
* this value is zero, no array will be allocated.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
RunArray(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* The destructor; virtual so that subclass destructors are invoked as well.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual ~RunArray();
|
||||
|
||||
/**
|
||||
* Get the number of entries in the limit indices array.
|
||||
*
|
||||
* @return the number of entries in the limit indices array.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getCount() const;
|
||||
|
||||
/**
|
||||
* Reset the limit indices array. This method sets the number of entries in the
|
||||
* limit indices array to zero. It does not delete the array.
|
||||
*
|
||||
* Note: Subclass arrays will also be reset and not deleted.
|
||||
*
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
inline void reset();
|
||||
|
||||
/**
|
||||
* Get the last limit index. This is the number of characters in
|
||||
* the text.
|
||||
*
|
||||
* @return the last limit index.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getLimit() const;
|
||||
|
||||
/**
|
||||
* Get the limit index for a particular run of text.
|
||||
*
|
||||
* @param run is the run. This is an index into the limit index array.
|
||||
*
|
||||
* @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline le_int32 getLimit(le_int32 run) const;
|
||||
|
||||
/**
|
||||
* Add a limit index to the limit indices array and return the run index
|
||||
* where it was stored. If the array does not exist, it will be created by
|
||||
* calling the <code>init</code> method. If it is full, it will be grown by
|
||||
* calling the <code>grow</code> method.
|
||||
*
|
||||
* If the <code>RunArray</code> object was created with a client-supplied
|
||||
* limit indices array, this method will return a run index of -1.
|
||||
*
|
||||
* Subclasses should not override this method. Rather they should provide
|
||||
* a new <code>add</code> method which takes a limit index along with whatever
|
||||
* other data they implement. The new <code>add</code> method should
|
||||
* first call this method to grow the data arrays, and use the return value
|
||||
* to store the data in their own arrays.
|
||||
*
|
||||
* @param limit is the limit index to add to the array.
|
||||
*
|
||||
* @return the run index where the limit index was stored, or -1 if the limit index cannt be stored.
|
||||
*
|
||||
* @see init
|
||||
* @see grow
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 add(le_int32 limit);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Create a data array with the given initial size. This method will be
|
||||
* called by the <code>add</code> method if there is no limit indices
|
||||
* array. Subclasses which override this method must also call it from
|
||||
* the overriding method to create the limit indices array.
|
||||
*
|
||||
* @param capacity is the initial size of the data array.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void init(le_int32 capacity);
|
||||
|
||||
/**
|
||||
* Grow a data array to the given initial size. This method will be
|
||||
* called by the <code>add</code> method if the limit indices
|
||||
* array is full. Subclasses which override this method must also call it from
|
||||
* the overriding method to grow the limit indices array.
|
||||
*
|
||||
* @param capacity is the initial size of the data array.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual void grow(le_int32 capacity);
|
||||
|
||||
/**
|
||||
* Set by the constructors to indicate whether
|
||||
* or not the client supplied the data arrays.
|
||||
* If they were supplied by the client, the
|
||||
* <code>add</code> method won't change the arrays
|
||||
* and the destructor won't delete them.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_bool fClientArrays;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
le_int32 ensureCapacity();
|
||||
|
||||
inline RunArray();
|
||||
inline RunArray(const RunArray & /*other*/);
|
||||
inline RunArray &operator=(const RunArray & /*other*/) { return *this; };
|
||||
|
||||
const le_int32 *fLimits;
|
||||
le_int32 fCount;
|
||||
le_int32 fCapacity;
|
||||
};
|
||||
|
||||
inline RunArray::RunArray()
|
||||
: UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline RunArray::RunArray(const RunArray & /*other*/)
|
||||
: UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline RunArray::RunArray(const le_int32 *limits, le_int32 count)
|
||||
: UObject(), fClientArrays(TRUE), fLimits(limits), fCount(count), fCapacity(count)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline le_int32 RunArray::getCount() const
|
||||
{
|
||||
return fCount;
|
||||
}
|
||||
|
||||
inline void RunArray::reset()
|
||||
{
|
||||
fCount = 0;
|
||||
}
|
||||
|
||||
inline le_int32 RunArray::getLimit(le_int32 run) const
|
||||
{
|
||||
if (run < 0 || run >= fCount) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fLimits[run];
|
||||
}
|
||||
|
||||
inline le_int32 RunArray::getLimit() const
|
||||
{
|
||||
return getLimit(fCount - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>FontRuns</code> class associates pointers to <code>LEFontInstance</code>
|
||||
* objects with runs of text.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API FontRuns : public RunArray
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a <code>FontRuns</code> object from pre-existing arrays of fonts
|
||||
* and limit indices.
|
||||
*
|
||||
* @param fonts is the address of an array of pointers to <code>LEFontInstance</code> objects. This
|
||||
* array, and the <code>LEFontInstance</code> objects to which it points must remain
|
||||
* valid until the <code>FontRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until
|
||||
* the <code>FontRuns</code> object is destroyed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>FontRuns</code> object. Clients can add font and limit
|
||||
* indices arrays using the <code>add</code> method.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the font and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
FontRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* The destructor; virtual so that subclass destructors are invoked as well.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual ~FontRuns();
|
||||
|
||||
/**
|
||||
* Get the <code>LEFontInstance</code> object assoicated with the given run
|
||||
* of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param run is the index into the font and limit indices arrays.
|
||||
*
|
||||
* @return the <code>LEFontInstance</code> associated with the given text run.
|
||||
*
|
||||
* @see RunArray::getLimit
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
const LEFontInstance *getFont(le_int32 run) const;
|
||||
|
||||
|
||||
/**
|
||||
* Add an <code>LEFontInstance</code> and limit index pair to the data arrays and return
|
||||
* the run index where the data was stored. This method calls
|
||||
* <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
|
||||
*
|
||||
* If the <code>FontRuns</code> object was created with a client-supplied
|
||||
* font and limit indices arrays, this method will return a run index of -1.
|
||||
*
|
||||
* Subclasses should not override this method. Rather they should provide a new <code>add</code>
|
||||
* method which takes a font and a limit index along with whatever other data they implement.
|
||||
* The new <code>add</code> method should first call this method to grow the font and limit indices
|
||||
* arrays, and use the returned run index to store data their own arrays.
|
||||
*
|
||||
* @param font is the address of the <code>LEFontInstance</code> to add. This object must
|
||||
* remain valid until the <code>FontRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the font and limit index were stored, or -1 if the data cannot be stored.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 add(const LEFontInstance *font, le_int32 limit);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
protected:
|
||||
virtual void init(le_int32 capacity);
|
||||
virtual void grow(le_int32 capacity);
|
||||
|
||||
private:
|
||||
|
||||
inline FontRuns();
|
||||
inline FontRuns(const FontRuns &other);
|
||||
inline FontRuns &operator=(const FontRuns & /*other*/) { return *this; };
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
const LEFontInstance **fFonts;
|
||||
};
|
||||
|
||||
inline FontRuns::FontRuns()
|
||||
: RunArray(0), fFonts(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline FontRuns::FontRuns(const FontRuns & /*other*/)
|
||||
: RunArray(0), fFonts(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline FontRuns::FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count)
|
||||
: RunArray(limits, count), fFonts(fonts)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>LocaleRuns</code> class associates pointers to <code>Locale</code>
|
||||
* objects with runs of text.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API LocaleRuns : public RunArray
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a <code>LocaleRuns</code> object from pre-existing arrays of locales
|
||||
* and limit indices.
|
||||
*
|
||||
* @param locales is the address of an array of pointers to <code>Locale</code> objects. This array,
|
||||
* and the <code>Locale</code> objects to which it points, must remain valid until
|
||||
* the <code>LocaleRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until the
|
||||
* <code>LocaleRuns</code> object is destroyed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>LocaleRuns</code> object. Clients can add locale and limit
|
||||
* indices arrays using the <code>add</code> method.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the locale and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
LocaleRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* The destructor; virtual so that subclass destructors are invoked as well.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual ~LocaleRuns();
|
||||
|
||||
/**
|
||||
* Get the <code>Locale</code> object assoicated with the given run
|
||||
* of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param run is the index into the font and limit indices arrays.
|
||||
*
|
||||
* @return the <code>Locale</code> associated with the given text run.
|
||||
*
|
||||
* @see RunArray::getLimit
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
const Locale *getLocale(le_int32 run) const;
|
||||
|
||||
|
||||
/**
|
||||
* Add a <code>Locale</code> and limit index pair to the data arrays and return
|
||||
* the run index where the data was stored. This method calls
|
||||
* <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
|
||||
*
|
||||
* If the <code>LocaleRuns</code> object was created with a client-supplied
|
||||
* locale and limit indices arrays, this method will return a run index of -1.
|
||||
*
|
||||
* Subclasses should not override this method. Rather they should provide a new <code>add</code>
|
||||
* method which takes a locale and a limit index along with whatever other data they implement.
|
||||
* The new <code>add</code> method should first call this method to grow the font and limit indices
|
||||
* arrays, and use the returned run index to store data their own arrays.
|
||||
*
|
||||
* @param locale is the address of the <code>Locale</code> to add. This object must remain valid
|
||||
* until the <code>LocaleRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 add(const Locale *locale, le_int32 limit);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
protected:
|
||||
virtual void init(le_int32 capacity);
|
||||
virtual void grow(le_int32 capacity);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const Locale **fLocales;
|
||||
|
||||
private:
|
||||
|
||||
inline LocaleRuns();
|
||||
inline LocaleRuns(const LocaleRuns &other);
|
||||
inline LocaleRuns &operator=(const LocaleRuns & /*other*/) { return *this; };
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
};
|
||||
|
||||
inline LocaleRuns::LocaleRuns()
|
||||
: RunArray(0), fLocales(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline LocaleRuns::LocaleRuns(const LocaleRuns & /*other*/)
|
||||
: RunArray(0), fLocales(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline LocaleRuns::LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count)
|
||||
: RunArray(limits, count), fLocales(locales)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ValueRuns</code> class associates integer values with runs of text.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
class U_LAYOUTEX_API ValueRuns : public RunArray
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a <code>ValueRuns</code> object from pre-existing arrays of values
|
||||
* and limit indices.
|
||||
*
|
||||
* @param values is the address of an array of integer. This array must remain valid until
|
||||
* the <code>ValueRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until
|
||||
* the <code>ValueRuns</code> object is destroyed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
inline ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>ValueRuns</code> object. Clients can add value and limit
|
||||
* indices arrays using the <code>add</code> method.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the value and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see add
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
ValueRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* The destructor; virtual so that subclass destructors are invoked as well.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual ~ValueRuns();
|
||||
|
||||
/**
|
||||
* Get the integer value assoicated with the given run
|
||||
* of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param run is the index into the font and limit indices arrays.
|
||||
*
|
||||
* @return the integer value associated with the given text run.
|
||||
*
|
||||
* @see RunArray::getLimit
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 getValue(le_int32 run) const;
|
||||
|
||||
|
||||
/**
|
||||
* Add an integer value and limit index pair to the data arrays and return
|
||||
* the run index where the data was stored. This method calls
|
||||
* <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
|
||||
*
|
||||
* If the <code>ValueRuns</code> object was created with a client-supplied
|
||||
* font and limit indices arrays, this method will return a run index of -1.
|
||||
*
|
||||
* Subclasses should not override this method. Rather they should provide a new <code>add</code>
|
||||
* method which takes an integer value and a limit index along with whatever other data they implement.
|
||||
* The new <code>add</code> method should first call this method to grow the font and limit indices
|
||||
* arrays, and use the returned run index to store data their own arrays.
|
||||
*
|
||||
* @param value is the integer value to add
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the value and limit index were stored, or -1 if the data cannot be stored.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
le_int32 add(le_int32 value, le_int32 limit);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
protected:
|
||||
virtual void init(le_int32 capacity);
|
||||
virtual void grow(le_int32 capacity);
|
||||
|
||||
private:
|
||||
|
||||
inline ValueRuns();
|
||||
inline ValueRuns(const ValueRuns &other);
|
||||
inline ValueRuns &operator=(const ValueRuns & /*other*/) { return *this; };
|
||||
|
||||
/**
|
||||
* The address of this static class variable serves as this class's ID
|
||||
* for ICU "poor man's RTTI".
|
||||
*/
|
||||
static const char fgClassID;
|
||||
|
||||
const le_int32 *fValues;
|
||||
};
|
||||
|
||||
inline ValueRuns::ValueRuns()
|
||||
: RunArray(0), fValues(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline ValueRuns::ValueRuns(const ValueRuns & /*other*/)
|
||||
: RunArray(0), fValues(NULL)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
inline ValueRuns::ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count)
|
||||
: RunArray(limits, count), fValues(values)
|
||||
{
|
||||
// nothing else to do...
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LOENGINE_H
|
||||
#define __LOENGINE_H
|
||||
|
||||
#include "LETypes.h"
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* \file
|
||||
* \brief C API for complex text layout.
|
||||
* \internal
|
||||
*
|
||||
* This is a technology preview. The API may
|
||||
* change significantly.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The opaque type for a LayoutEngine.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
typedef void le_engine;
|
||||
|
||||
/**
|
||||
* The opaque type for a font instance.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
typedef void le_font;
|
||||
|
||||
/**
|
||||
* This function returns an le_engine capable of laying out text
|
||||
* in the given font, script and langauge. Note that the LayoutEngine
|
||||
* returned may be a subclass of LayoutEngine.
|
||||
*
|
||||
* @param font - the font of the text
|
||||
* @param scriptCode - the script of the text
|
||||
* @param languageCode - the language of the text
|
||||
* @param typo_flags - flags that control layout features like kerning and ligatures.
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @return an le_engine which can layout text in the given font.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_engine * U_EXPORT2
|
||||
le_create(const le_font *font,
|
||||
le_int32 scriptCode,
|
||||
le_int32 languageCode,
|
||||
le_int32 typo_flags,
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function closes the given LayoutEngine. After
|
||||
* it returns, the le_engine is no longer valid.
|
||||
*
|
||||
* @param engine - the LayoutEngine to close.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_close(le_engine *engine);
|
||||
|
||||
/**
|
||||
* This routine will compute the glyph, character index and position arrays.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param chars - the input character context
|
||||
* @param offset - the offset of the first character to process
|
||||
* @param count - the number of characters to process
|
||||
* @param max - the number of characters in the input context
|
||||
* @param rightToLeft - TRUE if the characers are in a right to left directional run
|
||||
* @param x - the initial X position
|
||||
* @param y - the initial Y position
|
||||
* @param success - output parameter set to an error code if the operation fails
|
||||
*
|
||||
* @return the number of glyphs in the glyph array
|
||||
*
|
||||
* Note: The glyph, character index and position array can be accessed
|
||||
* using the getter routines below.
|
||||
*
|
||||
* Note: If you call this function more than once, you must call the reset()
|
||||
* function first to free the glyph, character index and position arrays
|
||||
* allocated by the previous call.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
le_layoutChars(le_engine *engine,
|
||||
const LEUnicode chars[],
|
||||
le_int32 offset,
|
||||
le_int32 count,
|
||||
le_int32 max,
|
||||
le_bool rightToLeft,
|
||||
float x,
|
||||
float y,
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function returns the number of glyphs in the glyph array. Note
|
||||
* that the number of glyphs will be greater than or equal to the number
|
||||
* of characters used to create the LayoutEngine.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param success - output parameter set to an error code if the operation fails.
|
||||
*
|
||||
* @return the number of glyphs in the glyph array
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
le_getGlyphCount(le_engine *engine,
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function copies the glyph array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold all
|
||||
* the glyphs.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param glyphs - the destiniation glyph array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_getGlyphs(le_engine *engine,
|
||||
LEGlyphID glyphs[],
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_getCharIndices(le_engine *engine,
|
||||
le_int32 charIndices[],
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function copies the character index array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold a
|
||||
* character index for each glyph.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param charIndices - the destiniation character index array
|
||||
* @param indexBase - an offset that will be added to each index.
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_getCharIndicesWithBase(le_engine *engine,
|
||||
le_int32 charIndices[],
|
||||
le_int32 indexBase,
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function copies the position array into a caller supplied array.
|
||||
* The caller must ensure that the array is large enough to hold an
|
||||
* X and Y position for each glyph, plus an extra X and Y for the
|
||||
* advance of the last glyph.
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param positions - the destiniation position array
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_getGlyphPositions(le_engine *engine,
|
||||
float positions[],
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function returns the X and Y position of the glyph at
|
||||
* the given index.
|
||||
*
|
||||
* Input parameters:
|
||||
* @param engine - the LayoutEngine
|
||||
* @param glyphIndex - the index of the glyph
|
||||
*
|
||||
* Output parameters:
|
||||
* @param x - the glyph's X position
|
||||
* @param y - the glyph's Y position
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_getGlyphPosition(le_engine *engine,
|
||||
le_int32 glyphIndex,
|
||||
float *x,
|
||||
float *y,
|
||||
LEErrorCode *success);
|
||||
|
||||
/**
|
||||
* This function frees the glyph, character index and position arrays
|
||||
* so that the LayoutEngine can be reused to layout a different
|
||||
* characer array. (This function is also called by le_close)
|
||||
*
|
||||
* @param engine - the LayoutEngine
|
||||
* @param success - set to an error code if the operation fails
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
le_reset(le_engine *engine,
|
||||
LEErrorCode *success);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#endif
|
||||
@@ -1,466 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PLAYOUT_H
|
||||
#define __PLAYOUT_H
|
||||
|
||||
/*
|
||||
* ParagraphLayout doesn't make much sense without
|
||||
* BreakIterator...
|
||||
*/
|
||||
#include "unicode/ubidi.h"
|
||||
#if ! UCONFIG_NO_BREAK_ITERATION
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
#include "plruns.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API for paragraph layout.
|
||||
*
|
||||
* This is a technology preview. The API may
|
||||
* change significantly.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The opaque type for a paragraph layout.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
typedef void pl_paragraph;
|
||||
|
||||
/**
|
||||
* The opaque type for a line in a paragraph layout.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
typedef void pl_line;
|
||||
|
||||
/**
|
||||
* The opaque type for a visual run in a line.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
typedef void pl_visualRun;
|
||||
|
||||
/**
|
||||
* Construct a <code>ParagraphLayout</code> object for a styled paragraph. The paragraph is specified
|
||||
* as runs of text all in the same font. An <code>LEFontInstance</code> object and a limit offset
|
||||
* are specified for each font run. The limit offset is the offset of the character immediately
|
||||
* after the font run.
|
||||
*
|
||||
* Clients can optionally specify directional runs and / or script runs. If these aren't specified
|
||||
* they will be computed.
|
||||
*
|
||||
* If any errors are encountered during construction, <code>status</code> will be set, and the object
|
||||
* will be set to be empty.
|
||||
*
|
||||
* @param chars is an array of the characters in the paragraph
|
||||
*
|
||||
* @param count is the number of characters in the paragraph.
|
||||
*
|
||||
* @param fontRuns a pointer to a <code>pl_fontRuns</code> object representing the font runs.
|
||||
*
|
||||
* @param levelRuns is a pointer to a <code>pl_valueRuns</code> object representing the directional levels.
|
||||
* If this pointer in <code>NULL</code> the levels will be determined by running the Unicde
|
||||
* Bidi algorithm.
|
||||
*
|
||||
* @param scriptRuns is a pointer to a <code>pl_valueRuns</code> object representing script runs.
|
||||
* If this pointer in <code>NULL</code> the script runs will be determined using the
|
||||
* Unicode code points.
|
||||
*
|
||||
* @param localeRuns is a pointer to a <code>pl_localeRuns</code> object representing locale runs.
|
||||
* The <code>Locale</code> objects are used to determind the language of the text. If this
|
||||
* pointer is <code>NULL</code> the default locale will be used for all of the text.
|
||||
*
|
||||
* @param paragraphLevel is the directionality of the paragraph, as in the UBiDi object.
|
||||
*
|
||||
* @param vertical is <code>TRUE</code> if the paragraph should be set vertically.
|
||||
*
|
||||
* @param status will be set to any error code encountered during construction.
|
||||
*
|
||||
* @return a pointer to the newly created <code>pl_paragraph</code> object. The object
|
||||
* will remain valid until <code>pl_close</code> is called.
|
||||
*
|
||||
* @see ubidi.h
|
||||
* @see longine.h
|
||||
* @see plruns.h
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_paragraph * U_EXPORT2
|
||||
pl_create(const LEUnicode chars[],
|
||||
le_int32 count,
|
||||
const pl_fontRuns *fontRuns,
|
||||
const pl_valueRuns *levelRuns,
|
||||
const pl_valueRuns *scriptRuns,
|
||||
const pl_localeRuns *localeRuns,
|
||||
UBiDiLevel paragraphLevel,
|
||||
le_bool vertical,
|
||||
LEErrorCode *status);
|
||||
|
||||
/**
|
||||
* Close the given paragraph layout object.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code> object to be
|
||||
* closed. Once this routine returns the object
|
||||
* can no longer be referenced
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_close(pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Examine the given text and determine if it contains characters in any
|
||||
* script which requires complex processing to be rendered correctly.
|
||||
*
|
||||
* @param chars is an array of the characters in the paragraph
|
||||
*
|
||||
* @param count is the number of characters in the paragraph.
|
||||
*
|
||||
* @return <code>TRUE</code> if any of the text requires complex processing.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
U_INTERNAL le_bool U_EXPORT2
|
||||
pl_isComplex(const LEUnicode chars[],
|
||||
le_int32 count);
|
||||
|
||||
/**
|
||||
* Return the resolved paragraph level. This is useful for those cases
|
||||
* where the bidi analysis has determined the level based on the first
|
||||
* strong character in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @return the resolved paragraph level.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL UBiDiLevel U_EXPORT2
|
||||
pl_getParagraphLevel(pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Return the directionality of the text in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @return <code>UBIDI_LTR</code> if the text is all left to right,
|
||||
* <code>UBIDI_RTL</code> if the text is all right to left,
|
||||
* or <code>UBIDI_MIXED</code> if the text has mixed direction.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL UBiDiDirection U_EXPORT2
|
||||
pl_getTextDirection(pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Get the max ascent value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* Return the max ascent value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @return the ascent value.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getAscent(const pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Return the max descent value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @return the decent value.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getDescent(const pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Return the max leading value for all the fonts
|
||||
* in the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @return the leading value.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLeading(const pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Reset line breaking to start from the beginning of the paragraph.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_reflow(pl_paragraph *paragraph);
|
||||
|
||||
/**
|
||||
* Return a <code>pl_line</code> object which represents next line
|
||||
* in the paragraph. The width of the line is specified each time so that it can
|
||||
* be varied to support arbitrary paragraph shapes.
|
||||
*
|
||||
* @param paragraph the <code>pl_paragraph</code>
|
||||
* @param width is the width of the line. If <code>width</code> is less than or equal
|
||||
* to zero, a <code>ParagraphLayout::Line</code> object representing the
|
||||
* rest of the paragraph will be returned.
|
||||
*
|
||||
* @return a <code>ParagraphLayout::Line</code> object which represents the line. The caller
|
||||
* is responsible for deleting the object. Returns <code>NULL</code> if there are no
|
||||
* more lines in the paragraph.
|
||||
*
|
||||
* @see pl_line
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_line * U_EXPORT2
|
||||
pl_nextLine(pl_paragraph *paragraph, float width);
|
||||
|
||||
/**
|
||||
* Close the given line object. Line objects are created
|
||||
* by <code>pl_nextLine</code> but it is the client's responsibility
|
||||
* to close them by calling this routine.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object to close.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_closeLine(pl_line *line);
|
||||
|
||||
/**
|
||||
* Count the number of visual runs in the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
*
|
||||
* @return the number of visual runs.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_countLineRuns(const pl_line *line);
|
||||
|
||||
/**
|
||||
* Get the ascent of the line. This is the maximum ascent
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
*
|
||||
* @return the ascent of the line.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLineAscent(const pl_line *line);
|
||||
|
||||
/**
|
||||
* Get the descent of the line. This is the maximum descent
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
*
|
||||
* @return the descent of the line.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLineDescent(const pl_line *line);
|
||||
|
||||
/**
|
||||
* Get the leading of the line. This is the maximum leading
|
||||
* of all the fonts on the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
*
|
||||
* @return the leading of the line.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLineLeading(const pl_line *line);
|
||||
|
||||
/**
|
||||
* Get the width of the line. This is a convenience method
|
||||
* which returns the last X position of the last visual run
|
||||
* in the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
*
|
||||
* @return the width of the line.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLineWidth(const pl_line *line);
|
||||
|
||||
/**
|
||||
* Get a <code>ParagraphLayout::VisualRun</code> object for a given
|
||||
* visual run in the line.
|
||||
*
|
||||
* @param line the <code>pl_line</code> object.
|
||||
* @param runIndex is the index of the run, in visual order.
|
||||
*
|
||||
* @return the <code>pl_visualRun</code> object representing the
|
||||
* visual run. This object is owned by the <code>pl_line</code> object which
|
||||
* created it, and will remain valid for as long as the <code>pl_line</code>
|
||||
* object is valid.
|
||||
*
|
||||
* @see pl_visualRun
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const pl_visualRun * U_EXPORT2
|
||||
pl_getLineVisualRun(const pl_line *line, le_int32 runIndex);
|
||||
|
||||
/**
|
||||
* Get the <code>le_font</code> object which
|
||||
* represents the font of the visual run. This will always
|
||||
* be a non-composite font.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the <code>le_font</code> object which represents the
|
||||
* font of the visual run.
|
||||
*
|
||||
* @see le_font
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const le_font * U_EXPORT2
|
||||
pl_getVisualRunFont(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* Get the direction of the visual run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the direction of the run. This will be <code>UBIDI_LTR</code> if the
|
||||
* run is left-to-right and <code>UBIDI_RTL</code> if the line is right-to-left.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL UBiDiDirection U_EXPORT2
|
||||
pl_getVisualRunDirection(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* Get the number of glyphs in the visual run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the number of glyphs.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getVisualRunGlyphCount(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* Get the glyphs in the visual run. Glyphs with the values <code>0xFFFE</code> and
|
||||
* <code>0xFFFF</code> should be ignored.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the address of the array of glyphs for this visual run. The storage
|
||||
* is owned by the <code>pl_visualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>pl_visualRun</code> object is valid.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const LEGlyphID * U_EXPORT2
|
||||
pl_getVisualRunGlyphs(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* Get the (x, y) positions of the glyphs in the visual run. To simplify storage
|
||||
* management, the x and y positions are stored in a single array with the x positions
|
||||
* at even offsets in the array and the corresponding y position in the following odd offset.
|
||||
* There is an extra (x, y) pair at the end of the array which represents the advance of
|
||||
* the final glyph in the run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the address of the array of glyph positions for this visual run. The storage
|
||||
* is owned by the <code>pl_visualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>pl_visualRun</code> object is valid.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const float * U_EXPORT2
|
||||
pl_getVisualRunPositions(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* Get the glyph-to-character map for this visual run. This maps the indices into
|
||||
* the glyph array to indices into the character array used to create the paragraph.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the address of the character-to-glyph map for this visual run. The storage
|
||||
* is owned by the <code>pl_visualRun</code> object and must not be deleted.
|
||||
* It will remain valid as long as the <code>pl_visualRun</code> object is valid.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const le_int32 * U_EXPORT2
|
||||
pl_getVisualRunGlyphToCharMap(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* A convenience method which returns the ascent value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the ascent value of this run's font.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getVisualRunAscent(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* A convenience method which returns the descent value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the descent value of this run's font.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getVisualRunDescent(const pl_visualRun *run);
|
||||
|
||||
/**
|
||||
* A convenience method which returns the leading value for the font
|
||||
* associated with this run.
|
||||
*
|
||||
* @param run the <code>pl_visualRun</code> object.
|
||||
*
|
||||
* @return the leading value of this run's font.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getVisualRunLeading(const pl_visualRun *run);
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,441 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PLRUNS_H
|
||||
#define __PLRUNS_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
||||
#include "unicode/ubidi.h"
|
||||
#include "layout/LETypes.h"
|
||||
|
||||
#include "layout/loengine.h"
|
||||
|
||||
/**
|
||||
* Opaque datatype representing an array of font runs
|
||||
*/
|
||||
typedef void pl_fontRuns;
|
||||
/**
|
||||
* Opaque datatype representing an array of value runs
|
||||
*/
|
||||
typedef void pl_valueRuns;
|
||||
/**
|
||||
* Opaque datatype representing an array of locale runs
|
||||
*/
|
||||
typedef void pl_localeRuns;
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API for run arrays.
|
||||
*
|
||||
* This is a technology preview. The API may
|
||||
* change significantly.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Construct a <code>pl_fontRuns</code> object from pre-existing arrays of fonts
|
||||
* and limit indices.
|
||||
*
|
||||
* @param fonts is the address of an array of pointers to <code>le_font</code> objects. This
|
||||
* array, and the <code>le_font</code> objects to which it points must remain
|
||||
* valid until the <code>pl_fontRuns</code> object is closed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until
|
||||
* the <code>pl_fontRuns</code> object is closed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_fontRuns * U_EXPORT2
|
||||
pl_openFontRuns(const le_font **fonts,
|
||||
const le_int32 *limits,
|
||||
le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>pl_fontRuns</code> object. Clients can add font and limit
|
||||
* indices arrays using the <code>pl_addFontRun</code> routine.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the font and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see pl_addFontRun
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_fontRuns * U_EXPORT2
|
||||
pl_openEmptyFontRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* Close the given <code>pl_fontRuns</code> object. Once this
|
||||
* call returns, the object can no longer be referenced.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_closeFontRuns(pl_fontRuns *fontRuns);
|
||||
|
||||
/**
|
||||
* Get the number of font runs.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* @return the number of entries in the limit indices array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getFontRunCount(const pl_fontRuns *fontRuns);
|
||||
|
||||
/**
|
||||
* Reset the number of font runs to zero.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_resetFontRuns(pl_fontRuns *fontRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for the last font run. This is the
|
||||
* number of characters in the text.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* @return the last limit index.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getFontRunLastLimit(const pl_fontRuns *fontRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for a particular font run.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
* @param run is the run. This is an index into the limit index array.
|
||||
*
|
||||
* @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getFontRunLimit(const pl_fontRuns *fontRuns,
|
||||
le_int32 run);
|
||||
|
||||
/**
|
||||
* Get the <code>le_font</code> object assoicated with the given run
|
||||
* of text. Use <code>pl_getFontRunLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
* @param run is the index into the font and limit indices arrays.
|
||||
*
|
||||
* @return the <code>le_font</code> associated with the given text run.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const le_font * U_EXPORT2
|
||||
pl_getFontRunFont(const pl_fontRuns *fontRuns,
|
||||
le_int32 run);
|
||||
|
||||
|
||||
/**
|
||||
* Add a new font run to the given <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* If the <code>pl_fontRuns</code> object was not created by calling
|
||||
* <code>pl_openEmptyFontRuns</code>, this method will return a run index of -1.
|
||||
*
|
||||
* @param fontRuns is the <code>pl_fontRuns</code> object.
|
||||
*
|
||||
* @param font is the address of the <code>le_font</code> to add. This object must
|
||||
* remain valid until the <code>pl_fontRuns</code> object is closed.
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the font and limit index were stored, or -1 if
|
||||
* the run cannot be added.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_addFontRun(pl_fontRuns *fontRuns,
|
||||
const le_font *font,
|
||||
le_int32 limit);
|
||||
|
||||
/**
|
||||
* Construct a <code>pl_valueRuns</code> object from pre-existing arrays of values
|
||||
* and limit indices.
|
||||
*
|
||||
* @param values is the address of an array of values. This array must remain valid until
|
||||
the <code>pl_valueRuns</code> object is closed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until
|
||||
* the <code>pl_valueRuns</code> object is closed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_valueRuns * U_EXPORT2
|
||||
pl_openValueRuns(const le_int32 *values,
|
||||
const le_int32 *limits,
|
||||
le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>pl_valueRuns</code> object. Clients can add values and limits
|
||||
* using the <code>pl_addValueRun</code> routine.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the value and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see pl_addValueRun
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_valueRuns * U_EXPORT2
|
||||
pl_openEmptyValueRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* Close the given <code>pl_valueRuns</code> object. Once this
|
||||
* call returns, the object can no longer be referenced.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_closeValueRuns(pl_valueRuns *valueRuns);
|
||||
|
||||
/**
|
||||
* Get the number of value runs.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* @return the number of value runs.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getValueRunCount(const pl_valueRuns *valueRuns);
|
||||
|
||||
/**
|
||||
* Reset the number of value runs to zero.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_resetValueRuns(pl_valueRuns *valueRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for the last value run. This is the
|
||||
* number of characters in the text.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* @return the last limit index.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getValueRunLastLimit(const pl_valueRuns *valueRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for a particular value run.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
* @param run is the run index.
|
||||
*
|
||||
* @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getValueRunLimit(const pl_valueRuns *valueRuns,
|
||||
le_int32 run);
|
||||
|
||||
/**
|
||||
* Get the value assoicated with the given run * of text. Use
|
||||
* <code>pl_getValueRunLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
* @param run is the run index.
|
||||
*
|
||||
* @return the value associated with the given text run.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getValueRunValue(const pl_valueRuns *valueRuns,
|
||||
le_int32 run);
|
||||
|
||||
|
||||
/**
|
||||
* Add a new font run to the given <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* If the <code>pl_valueRuns</code> object was not created by calling
|
||||
* <code>pl_openEmptyFontRuns</code>, this method will return a run index of -1.
|
||||
*
|
||||
* @param valueRuns is the <code>pl_valueRuns</code> object.
|
||||
*
|
||||
* @param value is the value to add.
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the font and limit index were stored, or -1 if
|
||||
* the run cannot be added.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_addValueRun(pl_valueRuns *valueRuns,
|
||||
le_int32 value,
|
||||
le_int32 limit);
|
||||
|
||||
/**
|
||||
* Construct a <code>pl_localeRuns</code> object from pre-existing arrays of fonts
|
||||
* and limit indices.
|
||||
*
|
||||
* @param locales is the address of an array of pointers to locale name strings. This
|
||||
* array must remain valid until the <code>pl_localeRuns</code> object is destroyed.
|
||||
*
|
||||
* @param limits is the address of an array of limit indices. This array must remain valid until
|
||||
* the <code>pl_valueRuns</code> object is destroyed.
|
||||
*
|
||||
* @param count is the number of entries in the two arrays.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_localeRuns * U_EXPORT2
|
||||
pl_openLocaleRuns(const char **locales,
|
||||
const le_int32 *limits,
|
||||
le_int32 count);
|
||||
|
||||
/**
|
||||
* Construct an empty <code>pl_localeRuns</code> object. Clients can add font and limit
|
||||
* indices arrays using the <code>pl_addFontRun</code> routine.
|
||||
*
|
||||
* @param initialCapacity is the initial size of the font and limit indices arrays. If
|
||||
* this value is zero, no arrays will be allocated.
|
||||
*
|
||||
* @see pl_addLocaleRun
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL pl_localeRuns * U_EXPORT2
|
||||
pl_openEmptyLocaleRuns(le_int32 initialCapacity);
|
||||
|
||||
/**
|
||||
* Close the given <code>pl_localeRuns</code> object. Once this
|
||||
* call returns, the object can no longer be referenced.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_closeLocaleRuns(pl_localeRuns *localeRuns);
|
||||
|
||||
/**
|
||||
* Get the number of font runs.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* @return the number of entries in the limit indices array.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLocaleRunCount(const pl_localeRuns *localeRuns);
|
||||
|
||||
/**
|
||||
* Reset the number of locale runs to zero.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
pl_resetLocaleRuns(pl_localeRuns *localeRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for the last font run. This is the
|
||||
* number of characters in the text.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* @return the last limit index.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLocaleRunLastLimit(const pl_localeRuns *localeRuns);
|
||||
|
||||
/**
|
||||
* Get the limit index for a particular font run.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
* @param run is the run. This is an index into the limit index array.
|
||||
*
|
||||
* @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_getLocaleRunLimit(const pl_localeRuns *localeRuns,
|
||||
le_int32 run);
|
||||
|
||||
/**
|
||||
* Get the <code>le_font</code> object assoicated with the given run
|
||||
* of text. Use <code>pl_getLocaleRunLimit(run)</code> to get the corresponding
|
||||
* limit index.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
* @param run is the index into the font and limit indices arrays.
|
||||
*
|
||||
* @return the <code>le_font</code> associated with the given text run.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL const char * U_EXPORT2
|
||||
pl_getLocaleRunLocale(const pl_localeRuns *localeRuns,
|
||||
le_int32 run);
|
||||
|
||||
|
||||
/**
|
||||
* Add a new run to the given <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* If the <code>pl_localeRuns</code> object was not created by calling
|
||||
* <code>pl_openEmptyLocaleRuns</code>, this method will return a run index of -1.
|
||||
*
|
||||
* @param localeRuns is the <code>pl_localeRuns</code> object.
|
||||
*
|
||||
* @param locale is the name of the locale to add. This name must
|
||||
* remain valid until the <code>pl_localeRuns</code> object is closed.
|
||||
*
|
||||
* @param limit is the limit index to add
|
||||
*
|
||||
* @return the run index where the font and limit index were stored, or -1 if
|
||||
* the run cannot be added.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL le_int32 U_EXPORT2
|
||||
pl_addLocaleRun(pl_localeRuns *localeRuns,
|
||||
const char *locale,
|
||||
le_int32 limit);
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
#endif
|
||||
@@ -1,761 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2011-2013 International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef INDEXCHARS_H
|
||||
#define INDEXCHARS_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
|
||||
#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Index Characters
|
||||
*/
|
||||
|
||||
U_CDECL_BEGIN
|
||||
|
||||
/**
|
||||
* Constants for Alphabetic Index Label Types.
|
||||
* The form of these enum constants anticipates having a plain C API
|
||||
* for Alphabetic Indexes that will also use them.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
typedef enum UAlphabeticIndexLabelType {
|
||||
/**
|
||||
* Normal Label, typically the starting letter of the names
|
||||
* in the bucket with this label.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
U_ALPHAINDEX_NORMAL = 0,
|
||||
|
||||
/**
|
||||
* Undeflow Label. The bucket with this label contains names
|
||||
* in scripts that sort before any of the bucket labels in this index.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
U_ALPHAINDEX_UNDERFLOW = 1,
|
||||
|
||||
/**
|
||||
* Inflow Label. The bucket with this label contains names
|
||||
* in scripts that sort between two of the bucket labels in this index.
|
||||
* Inflow labels are created when an index contains normal labels for
|
||||
* multiple scripts, and skips other scripts that sort between some of the
|
||||
* included scripts.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
U_ALPHAINDEX_INFLOW = 2,
|
||||
|
||||
/**
|
||||
* Overflow Label. Te bucket with this label contains names in scripts
|
||||
* that sort after all of the bucket labels in this index.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
U_ALPHAINDEX_OVERFLOW = 3
|
||||
} UAlphabeticIndexLabelType;
|
||||
|
||||
|
||||
struct UHashtable;
|
||||
U_CDECL_END
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// Forward Declarations
|
||||
|
||||
class BucketList;
|
||||
class Collator;
|
||||
class RuleBasedCollator;
|
||||
class StringEnumeration;
|
||||
class UnicodeSet;
|
||||
class UVector;
|
||||
|
||||
/**
|
||||
* AlphabeticIndex supports the creation of a UI index appropriate for a given language.
|
||||
* It can support either direct use, or use with a client that doesn't support localized collation.
|
||||
* The following is an example of what an index might look like in a UI:
|
||||
*
|
||||
* <pre>
|
||||
* <b>... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ...</b>
|
||||
*
|
||||
* <b>A</b>
|
||||
* Addison
|
||||
* Albertson
|
||||
* Azensky
|
||||
* <b>B</b>
|
||||
* Baker
|
||||
* ...
|
||||
* </pre>
|
||||
*
|
||||
* The class can generate a list of labels for use as a UI "index", that is, a list of
|
||||
* clickable characters (or character sequences) that allow the user to see a segment
|
||||
* (bucket) of a larger "target" list. That is, each label corresponds to a bucket in
|
||||
* the target list, where everything in the bucket is greater than or equal to the character
|
||||
* (according to the locale's collation). Strings can be added to the index;
|
||||
* they will be in sorted order in the right bucket.
|
||||
* <p>
|
||||
* The class also supports having buckets for strings before the first (underflow),
|
||||
* after the last (overflow), and between scripts (inflow). For example, if the index
|
||||
* is constructed with labels for Russian and English, Greek characters would fall
|
||||
* into an inflow bucket between the other two scripts.
|
||||
* <p>
|
||||
* The AlphabeticIndex class is not intended for public subclassing.
|
||||
*
|
||||
* <p><em>Note:</em> If you expect to have a lot of ASCII or Latin characters
|
||||
* as well as characters from the user's language,
|
||||
* then it is a good idea to call addLabels(Locale::getEnglish(), status).</p>
|
||||
*
|
||||
* <h2>Direct Use</h2>
|
||||
* <p>The following shows an example of building an index directly.
|
||||
* The "show..." methods below are just to illustrate usage.
|
||||
*
|
||||
* <pre>
|
||||
* // Create a simple index. "Item" is assumed to be an application
|
||||
* // defined type that the application's UI and other processing knows about,
|
||||
* // and that has a name.
|
||||
*
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
|
||||
* index->addLabels(additionalLocale, status);
|
||||
* for (Item *item in some source of Items ) {
|
||||
* index->addRecord(item->name(), item, status);
|
||||
* }
|
||||
* ...
|
||||
* // Show index at top. We could skip or gray out empty buckets
|
||||
*
|
||||
* while (index->nextBucket(status)) {
|
||||
* if (showAll || index->getBucketRecordCount() != 0) {
|
||||
* showLabelAtTop(UI, index->getBucketLabel());
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
* // Show the buckets with their contents, skipping empty buckets
|
||||
*
|
||||
* index->resetBucketIterator(status);
|
||||
* while (index->nextBucket(status)) {
|
||||
* if (index->getBucketRecordCount() != 0) {
|
||||
* showLabelInList(UI, index->getBucketLabel());
|
||||
* while (index->nextRecord(status)) {
|
||||
* showIndexedItem(UI, static_cast<Item *>(index->getRecordData()))
|
||||
* </pre>
|
||||
*
|
||||
* The caller can build different UIs using this class.
|
||||
* For example, an index character could be omitted or grayed-out
|
||||
* if its bucket is empty. Small buckets could also be combined based on size, such as:
|
||||
*
|
||||
* <pre>
|
||||
* <b>... A-F G-N O-Z ...</b>
|
||||
* </pre>
|
||||
*
|
||||
* <h2>Client Support</h2>
|
||||
* <p>Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself,
|
||||
* to support sorting on a client that doesn't support AlphabeticIndex functionality.
|
||||
*
|
||||
* <p>The ImmutableIndex is both immutable and thread-safe.
|
||||
* The corresponding AlphabeticIndex methods are not thread-safe because
|
||||
* they "lazily" build the index buckets.
|
||||
* <ul>
|
||||
* <li>ImmutableIndex.getBucket(index) provides random access to all
|
||||
* buckets and their labels and label types.
|
||||
* <li>The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1)
|
||||
* can be used to get a list of the labels,
|
||||
* such as "...", "A", "B",..., and send that list to the client.
|
||||
* <li>When the client has a new name, it sends that name to the server.
|
||||
* The server needs to call the following methods,
|
||||
* and communicate the bucketIndex and collationKey back to the client.
|
||||
*
|
||||
* <pre>
|
||||
* int32_t bucketIndex = index.getBucketIndex(name, status);
|
||||
* const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional
|
||||
* int32_t skLength = collator.getSortKey(name, sk, skCapacity);
|
||||
* </pre>
|
||||
*
|
||||
* <li>The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a
|
||||
* sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_I18N_API AlphabeticIndex: public UObject {
|
||||
public:
|
||||
#ifdef U_HIDE_DRAFT_API
|
||||
class Bucket;
|
||||
#else
|
||||
/**
|
||||
* An index "bucket" with a label string and type.
|
||||
* It is referenced by getBucketIndex(),
|
||||
* and returned by ImmutableIndex.getBucket().
|
||||
*
|
||||
* The Bucket class is not intended for public subclassing.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
class U_I18N_API Bucket : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual ~Bucket();
|
||||
|
||||
/**
|
||||
* Returns the label string.
|
||||
*
|
||||
* @return the label string for the bucket
|
||||
* @draft ICU 51
|
||||
*/
|
||||
const UnicodeString &getLabel() const { return label_; }
|
||||
/**
|
||||
* Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
|
||||
*
|
||||
* @return the bucket label type
|
||||
* @draft ICU 51
|
||||
*/
|
||||
UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
|
||||
|
||||
private:
|
||||
friend class AlphabeticIndex;
|
||||
friend class BucketList;
|
||||
|
||||
UnicodeString label_;
|
||||
UnicodeString lowerBoundary_;
|
||||
UAlphabeticIndexLabelType labelType_;
|
||||
Bucket *displayBucket_;
|
||||
int32_t displayIndex_;
|
||||
UVector *records_; // Records are owned by the inputList_ vector.
|
||||
|
||||
Bucket(const UnicodeString &label, // Parameter strings are copied.
|
||||
const UnicodeString &lowerBoundary,
|
||||
UAlphabeticIndexLabelType type);
|
||||
};
|
||||
|
||||
/**
|
||||
* Immutable, thread-safe version of AlphabeticIndex.
|
||||
* This class provides thread-safe methods for bucketing,
|
||||
* and random access to buckets and their properties,
|
||||
* but does not offer adding records to the index.
|
||||
*
|
||||
* The ImmutableIndex class is not intended for public subclassing.
|
||||
*
|
||||
* @draft ICU 51
|
||||
*/
|
||||
class U_I18N_API ImmutableIndex : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual ~ImmutableIndex();
|
||||
|
||||
/**
|
||||
* Returns the number of index buckets and labels, including underflow/inflow/overflow.
|
||||
*
|
||||
* @return the number of index buckets
|
||||
* @draft ICU 51
|
||||
*/
|
||||
int32_t getBucketCount() const;
|
||||
|
||||
/**
|
||||
* Finds the index bucket for the given name and returns the number of that bucket.
|
||||
* Use getBucket() to get the bucket's properties.
|
||||
*
|
||||
* @param name the string to be sorted into an index bucket
|
||||
* @return the bucket number for the name
|
||||
* @draft ICU 51
|
||||
*/
|
||||
int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Returns the index-th bucket. Returns NULL if the index is out of range.
|
||||
*
|
||||
* @param index bucket number
|
||||
* @return the index-th bucket
|
||||
* @draft ICU 51
|
||||
*/
|
||||
const Bucket *getBucket(int32_t index) const;
|
||||
|
||||
private:
|
||||
friend class AlphabeticIndex;
|
||||
|
||||
ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
|
||||
: buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
|
||||
|
||||
BucketList *buckets_;
|
||||
Collator *collatorPrimaryOnly_;
|
||||
};
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/**
|
||||
* Construct an AlphabeticIndex object for the specified locale. If the locale's
|
||||
* data does not include index characters, a set of them will be
|
||||
* synthesized based on the locale's exemplar characters. The locale
|
||||
* determines the sorting order for both the index characters and the
|
||||
* user item names appearing under each Index character.
|
||||
*
|
||||
* @param locale the desired locale.
|
||||
* @param status Error code, will be set with the reason if the construction
|
||||
* of the AlphabeticIndex object fails.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
AlphabeticIndex(const Locale &locale, UErrorCode &status);
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Construct an AlphabeticIndex that uses a specific collator.
|
||||
*
|
||||
* The index will be created with no labels; the addLabels() function must be called
|
||||
* after creation to add the desired labels to the index.
|
||||
*
|
||||
* The index adopts the collator, and is responsible for deleting it.
|
||||
* The caller should make no further use of the collator after creating the index.
|
||||
*
|
||||
* @param collator The collator to use to order the contents of this index.
|
||||
* @param status Error code, will be set with the reason if the
|
||||
* operation fails.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/**
|
||||
* Add Labels to this Index. The labels are additions to those
|
||||
* that are already in the index; they do not replace the existing
|
||||
* ones.
|
||||
* @param additions The additional characters to add to the index, such as A-Z.
|
||||
* @param status Error code, will be set with the reason if the
|
||||
* operation fails.
|
||||
* @return this, for chaining
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Add the index characters from a Locale to the index. The labels
|
||||
* are added to those that are already in the index; they do not replace the
|
||||
* existing index characters. The collation order for this index is not
|
||||
* changed; it remains that of the locale that was originally specified
|
||||
* when creating this Index.
|
||||
*
|
||||
* @param locale The locale whose index characters are to be added.
|
||||
* @param status Error code, will be set with the reason if the
|
||||
* operation fails.
|
||||
* @return this, for chaining
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual ~AlphabeticIndex();
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Builds an immutable, thread-safe version of this instance, without data records.
|
||||
*
|
||||
* @return an immutable index instance
|
||||
* @draft ICU 51
|
||||
*/
|
||||
ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/**
|
||||
* Get the Collator that establishes the ordering of the items in this index.
|
||||
* Ownership of the collator remains with the AlphabeticIndex instance.
|
||||
*
|
||||
* The returned collator is a reference to the internal collator used by this
|
||||
* index. It may be safely used to compare the names of items or to get
|
||||
* sort keys for names. However if any settings need to be changed,
|
||||
* or other non-const methods called, a cloned copy must be made first.
|
||||
*
|
||||
* @return The collator
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const RuleBasedCollator &getCollator() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the default label used for abbreviated buckets <i>between</i> other index characters.
|
||||
* For example, consider the labels when Latin and Greek are used:
|
||||
* X Y Z ... Α Β Γ.
|
||||
*
|
||||
* @return inflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const UnicodeString &getInflowLabel() const;
|
||||
|
||||
/**
|
||||
* Set the default label used for abbreviated buckets <i>between</i> other index characters.
|
||||
* An inflow label will be automatically inserted if two otherwise-adjacent label characters
|
||||
* are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek,
|
||||
* sorts between the two. The default inflow character is an ellipsis (...)
|
||||
*
|
||||
* @param inflowLabel the new Inflow label.
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
|
||||
|
||||
|
||||
/**
|
||||
* Get the special label used for items that sort after the last normal label,
|
||||
* and that would not otherwise have an appropriate label.
|
||||
*
|
||||
* @return the overflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const UnicodeString &getOverflowLabel() const;
|
||||
|
||||
|
||||
/**
|
||||
* Set the label used for items that sort after the last normal label,
|
||||
* and that would not otherwise have an appropriate label.
|
||||
*
|
||||
* @param overflowLabel the new overflow label.
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Get the special label used for items that sort before the first normal label,
|
||||
* and that would not otherwise have an appropriate label.
|
||||
*
|
||||
* @return underflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const UnicodeString &getUnderflowLabel() const;
|
||||
|
||||
/**
|
||||
* Set the label used for items that sort before the first normal label,
|
||||
* and that would not otherwise have an appropriate label.
|
||||
*
|
||||
* @param underflowLabel the new underflow label.
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
|
||||
|
||||
|
||||
/**
|
||||
* Get the limit on the number of labels permitted in the index.
|
||||
* The number does not include over, under and inflow labels.
|
||||
*
|
||||
* @return maxLabelCount maximum number of labels.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual int32_t getMaxLabelCount() const;
|
||||
|
||||
/**
|
||||
* Set a limit on the number of labels permitted in the index.
|
||||
* The number does not include over, under and inflow labels.
|
||||
* Currently, if the number is exceeded, then every
|
||||
* nth item is removed to bring the count down.
|
||||
* A more sophisticated mechanism may be available in the future.
|
||||
*
|
||||
* @param maxLabelCount the maximum number of labels.
|
||||
* @param status error code
|
||||
* @return This, for chaining
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
|
||||
|
||||
|
||||
/**
|
||||
* Add a record to the index. Each record will be associated with an index Bucket
|
||||
* based on the record's name. The list of records for each bucket will be sorted
|
||||
* based on the collation ordering of the names in the index's locale.
|
||||
* Records with duplicate names are permitted; they will be kept in the order
|
||||
* that they were added.
|
||||
*
|
||||
* @param name The display name for the Record. The Record will be placed in
|
||||
* a bucket based on this name.
|
||||
* @param data An optional pointer to user data associated with this
|
||||
* item. When iterating the contents of a bucket, both the
|
||||
* data pointer the name will be available for each Record.
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return This, for chaining.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Remove all Records from the Index. The set of Buckets, which define the headings under
|
||||
* which records are classified, is not altered.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return This, for chaining.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &clearRecords(UErrorCode &status);
|
||||
|
||||
|
||||
/** Get the number of labels in this index.
|
||||
* Note: may trigger lazy index construction.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return The number of labels in this index, including any under, over or
|
||||
* in-flow labels.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual int32_t getBucketCount(UErrorCode &status);
|
||||
|
||||
|
||||
/** Get the total number of Records in this index, that is, the number
|
||||
* of <name, data> pairs added.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return The number of records in this index, that is, the total number
|
||||
* of (name, data) items added with addRecord().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual int32_t getRecordCount(UErrorCode &status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given the name of a record, return the zero-based index of the Bucket
|
||||
* in which the item should appear. The name need not be in the index.
|
||||
* A Record will not be added to the index by this function.
|
||||
* Bucket numbers are zero-based, in Bucket iteration order.
|
||||
*
|
||||
* @param itemName The name whose bucket position in the index is to be determined.
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return The bucket number for this name.
|
||||
* @stable ICU 4.8
|
||||
*
|
||||
*/
|
||||
virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
|
||||
|
||||
|
||||
/**
|
||||
* Get the zero based index of the current Bucket from an iteration
|
||||
* over the Buckets of this index. Return -1 if no iteration is in process.
|
||||
* @return the index of the current Bucket
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual int32_t getBucketIndex() const;
|
||||
|
||||
|
||||
/**
|
||||
* Advance the iteration over the Buckets of this index. Return FALSE if
|
||||
* there are no more Buckets.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
|
||||
* an enumeration of its contents are in process.
|
||||
*
|
||||
* @return TRUE if success, FALSE if at end of iteration
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool nextBucket(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Return the name of the Label of the current bucket from an iteration over the buckets.
|
||||
* If the iteration is before the first Bucket (nextBucket() has not been called),
|
||||
* or after the last, return an empty string.
|
||||
*
|
||||
* @return the bucket label.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const UnicodeString &getBucketLabel() const;
|
||||
|
||||
/**
|
||||
* Return the type of the label for the current Bucket (selected by the
|
||||
* iteration over Buckets.)
|
||||
*
|
||||
* @return the label type.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UAlphabeticIndexLabelType getBucketLabelType() const;
|
||||
|
||||
/**
|
||||
* Get the number of <name, data> Records in the current Bucket.
|
||||
* If the current bucket iteration position is before the first label or after the
|
||||
* last, return 0.
|
||||
*
|
||||
* @return the number of Records.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual int32_t getBucketRecordCount() const;
|
||||
|
||||
|
||||
/**
|
||||
* Reset the Bucket iteration for this index. The next call to nextBucket()
|
||||
* will restart the iteration at the first label.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* @return this, for chaining.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Advance to the next record in the current Bucket.
|
||||
* When nextBucket() is called, Record iteration is reset to just before the
|
||||
* first Record in the new Bucket.
|
||||
*
|
||||
* @param status Error code, will be set with the reason if the operation fails.
|
||||
* U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
|
||||
* an enumeration of its contents are in process.
|
||||
* @return TRUE if successful, FALSE when the iteration advances past the last item.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool nextRecord(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Get the name of the current Record.
|
||||
* Return an empty string if the Record iteration position is before first
|
||||
* or after the last.
|
||||
*
|
||||
* @return The name of the current index item.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const UnicodeString &getRecordName() const;
|
||||
|
||||
|
||||
/**
|
||||
* Return the data pointer of the Record currently being iterated over.
|
||||
* Return NULL if the current iteration position before the first item in this Bucket,
|
||||
* or after the last.
|
||||
*
|
||||
* @return The current Record's data pointer.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const void *getRecordData() const;
|
||||
|
||||
|
||||
/**
|
||||
* Reset the Record iterator position to before the first Record in the current Bucket.
|
||||
*
|
||||
* @return This, for chaining.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual AlphabeticIndex &resetRecordIterator();
|
||||
|
||||
private:
|
||||
/**
|
||||
* No Copy constructor.
|
||||
* @internal
|
||||
*/
|
||||
AlphabeticIndex(const AlphabeticIndex &other);
|
||||
|
||||
/**
|
||||
* No assignment.
|
||||
*/
|
||||
AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
|
||||
|
||||
/**
|
||||
* No Equality operators.
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool operator==(const AlphabeticIndex& other) const;
|
||||
|
||||
/**
|
||||
* Inequality operator.
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool operator!=(const AlphabeticIndex& other) const;
|
||||
|
||||
// Common initialization, for use from all constructors.
|
||||
void init(const Locale *locale, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* This method is called to get the index exemplars. Normally these come from the locale directly,
|
||||
* but if they aren't available, we have to synthesize them.
|
||||
*/
|
||||
void addIndexExemplars(const Locale &locale, UErrorCode &status);
|
||||
/**
|
||||
* Add Chinese index characters from the tailoring.
|
||||
*/
|
||||
UBool addChineseIndexCharacters(UErrorCode &errorCode);
|
||||
|
||||
UVector *firstStringsInScript(UErrorCode &status);
|
||||
|
||||
static UnicodeString separated(const UnicodeString &item);
|
||||
|
||||
/**
|
||||
* Determine the best labels to use.
|
||||
* This is based on the exemplars, but we also process to make sure that they are unique,
|
||||
* and sort differently, and that the overall list is small enough.
|
||||
*/
|
||||
void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
|
||||
BucketList *createBucketList(UErrorCode &errorCode) const;
|
||||
void initBuckets(UErrorCode &errorCode);
|
||||
void clearBuckets();
|
||||
void internalResetBucketIterator();
|
||||
|
||||
public:
|
||||
|
||||
// The Record is declared public only to allow access from
|
||||
// implementation code written in plain C.
|
||||
// It is not intended for public use.
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* A (name, data) pair, to be sorted by name into one of the index buckets.
|
||||
* The user data is not used by the index implementation.
|
||||
* @internal
|
||||
*/
|
||||
struct Record: public UMemory {
|
||||
const UnicodeString name_;
|
||||
const void *data_;
|
||||
Record(const UnicodeString &name, const void *data);
|
||||
~Record();
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Holds all user records before they are distributed into buckets.
|
||||
* Type of contents is (Record *)
|
||||
* @internal
|
||||
*/
|
||||
UVector *inputList_;
|
||||
|
||||
int32_t labelsIterIndex_; // Index of next item to return.
|
||||
int32_t itemsIterIndex_;
|
||||
Bucket *currentBucket_; // While an iteration of the index in underway,
|
||||
// point to the bucket for the current label.
|
||||
// NULL when no iteration underway.
|
||||
|
||||
int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
|
||||
|
||||
UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
|
||||
// of those explicitly set by the user plus
|
||||
// those from locales. Raw values, before
|
||||
// crunching into bucket labels.
|
||||
|
||||
UVector *firstCharsInScripts_; // The first character from each script,
|
||||
// in collation order.
|
||||
|
||||
RuleBasedCollator *collator_;
|
||||
RuleBasedCollator *collatorPrimaryOnly_;
|
||||
|
||||
// Lazy evaluated: null means that we have not built yet.
|
||||
BucketList *buckets_;
|
||||
|
||||
UnicodeString inflowLabel_;
|
||||
UnicodeString overflowLabel_;
|
||||
UnicodeString underflowLabel_;
|
||||
UnicodeString overflowComparisonString_;
|
||||
|
||||
UnicodeString emptyString_;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* UCONFIG_NO_COLLATION / UCONFIG_NO_NORMALIZATION */
|
||||
#endif
|
||||
@@ -1,232 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: appendable.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010dec07
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __APPENDABLE_H__
|
||||
#define __APPENDABLE_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (UChars).
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class UnicodeString;
|
||||
|
||||
/**
|
||||
* Base class for objects to which Unicode characters and strings can be appended.
|
||||
* Combines elements of Java Appendable and ICU4C ByteSink.
|
||||
*
|
||||
* This class can be used in APIs where it does not matter whether the actual destination is
|
||||
* a UnicodeString, a UChar[] array, a UnicodeSet, or any other object
|
||||
* that receives and processes characters and/or strings.
|
||||
*
|
||||
* Implementation classes must implement at least appendCodeUnit(UChar).
|
||||
* The base class provides default implementations for the other methods.
|
||||
*
|
||||
* The methods do not take UErrorCode parameters.
|
||||
* If an error occurs (e.g., out-of-memory),
|
||||
* in addition to returning FALSE from failing operations,
|
||||
* the implementation must prevent unexpected behavior (e.g., crashes)
|
||||
* from further calls and should make the error condition available separately
|
||||
* (e.g., store a UErrorCode, make/keep a UnicodeString bogus).
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API Appendable : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
~Appendable();
|
||||
|
||||
/**
|
||||
* Appends a 16-bit code unit.
|
||||
* @param c code unit
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendCodeUnit(UChar c) = 0;
|
||||
|
||||
/**
|
||||
* Appends a code point.
|
||||
* The default implementation calls appendCodeUnit(UChar) once or twice.
|
||||
* @param c code point 0..0x10ffff
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendCodePoint(UChar32 c);
|
||||
|
||||
/**
|
||||
* Appends a string.
|
||||
* The default implementation calls appendCodeUnit(UChar) for each code unit.
|
||||
* @param s string, must not be NULL if length!=0
|
||||
* @param length string length, or -1 if NUL-terminated
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendString(const UChar *s, int32_t length);
|
||||
|
||||
/**
|
||||
* Tells the object that the caller is going to append roughly
|
||||
* appendCapacity UChars. A subclass might use this to pre-allocate
|
||||
* a larger buffer if necessary.
|
||||
* The default implementation does nothing. (It always returns TRUE.)
|
||||
* @param appendCapacity estimated number of UChars that will be appended
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool reserveAppendCapacity(int32_t appendCapacity);
|
||||
|
||||
/**
|
||||
* Returns a writable buffer for appending and writes the buffer's capacity to
|
||||
* *resultCapacity. Guarantees *resultCapacity>=minCapacity.
|
||||
* May return a pointer to the caller-owned scratch buffer which must have
|
||||
* scratchCapacity>=minCapacity.
|
||||
* The returned buffer is only valid until the next operation
|
||||
* on this Appendable.
|
||||
*
|
||||
* After writing at most *resultCapacity UChars, call appendString() with the
|
||||
* pointer returned from this function and the number of UChars written.
|
||||
* Many appendString() implementations will avoid copying UChars if this function
|
||||
* returned an internal buffer.
|
||||
*
|
||||
* Partial usage example:
|
||||
* \code
|
||||
* int32_t capacity;
|
||||
* UChar* buffer = app.getAppendBuffer(..., &capacity);
|
||||
* ... Write n UChars into buffer, with n <= capacity.
|
||||
* app.appendString(buffer, n);
|
||||
* \endcode
|
||||
* In many implementations, that call to append will avoid copying UChars.
|
||||
*
|
||||
* If the Appendable allocates or reallocates an internal buffer, it should use
|
||||
* the desiredCapacityHint if appropriate.
|
||||
* If a caller cannot provide a reasonable guess at the desired capacity,
|
||||
* it should pass desiredCapacityHint=0.
|
||||
*
|
||||
* If a non-scratch buffer is returned, the caller may only pass
|
||||
* a prefix to it to appendString().
|
||||
* That is, it is not correct to pass an interior pointer to appendString().
|
||||
*
|
||||
* The default implementation always returns the scratch buffer.
|
||||
*
|
||||
* @param minCapacity required minimum capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param desiredCapacityHint desired capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param scratch default caller-owned buffer
|
||||
* @param scratchCapacity capacity of the scratch buffer
|
||||
* @param resultCapacity pointer to an integer which will be set to the
|
||||
* capacity of the returned buffer
|
||||
* @return a buffer with *resultCapacity>=minCapacity
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UChar *getAppendBuffer(int32_t minCapacity,
|
||||
int32_t desiredCapacityHint,
|
||||
UChar *scratch, int32_t scratchCapacity,
|
||||
int32_t *resultCapacity);
|
||||
};
|
||||
|
||||
/**
|
||||
* An Appendable implementation which writes to a UnicodeString.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API UnicodeStringAppendable : public Appendable {
|
||||
public:
|
||||
/**
|
||||
* Aliases the UnicodeString (keeps its reference) for writing.
|
||||
* @param s The UnicodeString to which this Appendable will write.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
explicit UnicodeStringAppendable(UnicodeString &s) : str(s) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
~UnicodeStringAppendable();
|
||||
|
||||
/**
|
||||
* Appends a 16-bit code unit to the string.
|
||||
* @param c code unit
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendCodeUnit(UChar c);
|
||||
|
||||
/**
|
||||
* Appends a code point to the string.
|
||||
* @param c code point 0..0x10ffff
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendCodePoint(UChar32 c);
|
||||
|
||||
/**
|
||||
* Appends a string to the UnicodeString.
|
||||
* @param s string, must not be NULL if length!=0
|
||||
* @param length string length, or -1 if NUL-terminated
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool appendString(const UChar *s, int32_t length);
|
||||
|
||||
/**
|
||||
* Tells the UnicodeString that the caller is going to append roughly
|
||||
* appendCapacity UChars.
|
||||
* @param appendCapacity estimated number of UChars that will be appended
|
||||
* @return TRUE if the operation succeeded
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UBool reserveAppendCapacity(int32_t appendCapacity);
|
||||
|
||||
/**
|
||||
* Returns a writable buffer for appending and writes the buffer's capacity to
|
||||
* *resultCapacity. Guarantees *resultCapacity>=minCapacity.
|
||||
* May return a pointer to the caller-owned scratch buffer which must have
|
||||
* scratchCapacity>=minCapacity.
|
||||
* The returned buffer is only valid until the next write operation
|
||||
* on the UnicodeString.
|
||||
*
|
||||
* For details see Appendable::getAppendBuffer().
|
||||
*
|
||||
* @param minCapacity required minimum capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param desiredCapacityHint desired capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param scratch default caller-owned buffer
|
||||
* @param scratchCapacity capacity of the scratch buffer
|
||||
* @param resultCapacity pointer to an integer which will be set to the
|
||||
* capacity of the returned buffer
|
||||
* @return a buffer with *resultCapacity>=minCapacity
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual UChar *getAppendBuffer(int32_t minCapacity,
|
||||
int32_t desiredCapacityHint,
|
||||
UChar *scratch, int32_t scratchCapacity,
|
||||
int32_t *resultCapacity);
|
||||
|
||||
private:
|
||||
UnicodeString &str;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // __APPENDABLE_H__
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef BASICTZ_H
|
||||
#define BASICTZ_H
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: ICU TimeZone base class
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/timezone.h"
|
||||
#include "unicode/tzrule.h"
|
||||
#include "unicode/tztrans.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// forward declarations
|
||||
class UVector;
|
||||
|
||||
/**
|
||||
* <code>BasicTimeZone</code> is an abstract class extending <code>TimeZone</code>.
|
||||
* This class provides some additional methods to access time zone transitions and rules.
|
||||
* All ICU <code>TimeZone</code> concrete subclasses extend this class.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
class U_I18N_API BasicTimeZone: public TimeZone {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual ~BasicTimeZone();
|
||||
|
||||
/**
|
||||
* Gets the first time zone transition after the base time.
|
||||
* @param base The base time.
|
||||
* @param inclusive Whether the base time is inclusive or not.
|
||||
* @param result Receives the first transition after the base time.
|
||||
* @return TRUE if the transition is found.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the most recent time zone transition before the base time.
|
||||
* @param base The base time.
|
||||
* @param inclusive Whether the base time is inclusive or not.
|
||||
* @param result Receives the most recent transition before the base time.
|
||||
* @return TRUE if the transition is found.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
|
||||
|
||||
/**
|
||||
* Checks if the time zone has equivalent transitions in the time range.
|
||||
* This method returns true when all of transition times, from/to standard
|
||||
* offsets and DST savings used by this time zone match the other in the
|
||||
* time range.
|
||||
* @param tz The <code>BasicTimeZone</code> object to be compared with.
|
||||
* @param start The start time of the evaluated time range (inclusive)
|
||||
* @param end The end time of the evaluated time range (inclusive)
|
||||
* @param ignoreDstAmount
|
||||
* When true, any transitions with only daylight saving amount
|
||||
* changes will be ignored, except either of them is zero.
|
||||
* For example, a transition from rawoffset 3:00/dstsavings 1:00
|
||||
* to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison,
|
||||
* but a transtion from rawoffset 2:00/dstsavings 1:00 to
|
||||
* rawoffset 3:00/dstsavings 0:00 is included.
|
||||
* @param ec Output param to filled in with a success or an error.
|
||||
* @return true if the other time zone has the equivalent transitions in the
|
||||
* time range.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end,
|
||||
UBool ignoreDstAmount, UErrorCode& ec) const;
|
||||
|
||||
/**
|
||||
* Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
|
||||
* for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
|
||||
* <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
|
||||
* @param status Receives error status code.
|
||||
* @return The number of <code>TimeZoneRule</code>s representing time transitions.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual int32_t countTransitionRules(UErrorCode& status) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
|
||||
* which represent time transitions for this time zone. On successful return,
|
||||
* the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
|
||||
* the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
|
||||
* instances up to the size specified by trscount. The results are referencing the
|
||||
* rule instance held by this time zone instance. Therefore, after this time zone
|
||||
* is destructed, they are no longer available.
|
||||
* @param initial Receives the initial timezone rule
|
||||
* @param trsrules Receives the timezone transition rules
|
||||
* @param trscount On input, specify the size of the array 'transitions' receiving
|
||||
* the timezone transition rules. On output, actual number of
|
||||
* rules filled in the array will be set.
|
||||
* @param status Receives error status code.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
|
||||
const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the set of time zone rules valid at the specified time. Some known external time zone
|
||||
* implementations are not capable to handle historic time zone rule changes. Also some
|
||||
* implementations can only handle certain type of rule definitions.
|
||||
* If this time zone does not use any daylight saving time within about 1 year from the specified
|
||||
* time, only the <code>InitialTimeZone</code> is returned. Otherwise, the rule for standard
|
||||
* time and daylight saving time transitions are returned in addition to the
|
||||
* <code>InitialTimeZoneRule</code>. The standard and daylight saving time transition rules are
|
||||
* represented by <code>AnnualTimeZoneRule</code> with <code>DateTimeRule::DOW</code> for its date
|
||||
* rule and <code>DateTimeRule::WALL_TIME</code> for its time rule. Because daylight saving time
|
||||
* rule is changing time to time in many time zones and also mapping a transition time rule to
|
||||
* different type is lossy transformation, the set of rules returned by this method may be valid
|
||||
* for short period of time.
|
||||
* The time zone rule objects returned by this method is owned by the caller, so the caller is
|
||||
* responsible for deleting them after use.
|
||||
* @param date The date used for extracting time zone rules.
|
||||
* @param initial Receives the <code>InitialTimeZone</code>, always not NULL.
|
||||
* @param std Receives the <code>AnnualTimeZoneRule</code> for standard time transitions.
|
||||
* When this time time zone does not observe daylight saving times around the
|
||||
* specified date, NULL is set.
|
||||
* @param dst Receives the <code>AnnualTimeZoneRule</code> for daylight saving time
|
||||
* transitions. When this time zone does not observer daylight saving times
|
||||
* around the specified date, NULL is set.
|
||||
* @param status Receives error status code.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual void getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial,
|
||||
AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const;
|
||||
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* The time type option bit flags used by getOffsetFromLocal
|
||||
* @internal
|
||||
*/
|
||||
enum {
|
||||
kStandard = 0x01,
|
||||
kDaylight = 0x03,
|
||||
kFormer = 0x04,
|
||||
kLatter = 0x0C
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Get time zone offsets from local wall time.
|
||||
* @internal
|
||||
*/
|
||||
virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
|
||||
int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
|
||||
|
||||
protected:
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* The time type option bit masks used by getOffsetFromLocal
|
||||
* @internal
|
||||
*/
|
||||
enum {
|
||||
kStdDstMask = kDaylight,
|
||||
kFormerLatterMask = kLatter
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
BasicTimeZone();
|
||||
|
||||
/**
|
||||
* Construct a timezone with a given ID.
|
||||
* @param id a system time zone ID
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
BasicTimeZone(const UnicodeString &id);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param source the object to be copied.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
BasicTimeZone(const BasicTimeZone& source);
|
||||
|
||||
/**
|
||||
* Gets the set of TimeZoneRule instances applicable to the specified time and after.
|
||||
* @param start The start date used for extracting time zone rules
|
||||
* @param initial Receives the InitialTimeZone, always not NULL
|
||||
* @param transitionRules Receives the transition rules, could be NULL
|
||||
* @param status Receives error status code
|
||||
*/
|
||||
void getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial, UVector*& transitionRules,
|
||||
UErrorCode& status) const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // BASICTZ_H
|
||||
|
||||
//eof
|
||||
@@ -1,648 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File brkiter.h
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/18/97 aliu Added typedef for TextCount. Made DONE const.
|
||||
* 05/07/97 aliu Fixed DLL declaration.
|
||||
* 07/09/97 jfitz Renamed BreakIterator and interface synced with JDK
|
||||
* 08/11/98 helena Sync-up JDK1.2.
|
||||
* 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef BRKITER_H
|
||||
#define BRKITER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Break Iterator.
|
||||
*/
|
||||
|
||||
#if UCONFIG_NO_BREAK_ITERATION
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/*
|
||||
* Allow the declaration of APIs with pointers to BreakIterator
|
||||
* even when break iteration is removed from the build.
|
||||
*/
|
||||
class BreakIterator;
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#else
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/chariter.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/ubrk.h"
|
||||
#include "unicode/strenum.h"
|
||||
#include "unicode/utext.h"
|
||||
#include "unicode/umisc.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* The BreakIterator class implements methods for finding the location
|
||||
* of boundaries in text. BreakIterator is an abstract base class.
|
||||
* Instances of BreakIterator maintain a current position and scan over
|
||||
* text returning the index of characters where boundaries occur.
|
||||
* <p>
|
||||
* Line boundary analysis determines where a text string can be broken
|
||||
* when line-wrapping. The mechanism correctly handles punctuation and
|
||||
* hyphenated words.
|
||||
* <p>
|
||||
* Sentence boundary analysis allows selection with correct
|
||||
* interpretation of periods within numbers and abbreviations, and
|
||||
* trailing punctuation marks such as quotation marks and parentheses.
|
||||
* <p>
|
||||
* Word boundary analysis is used by search and replace functions, as
|
||||
* well as within text editing applications that allow the user to
|
||||
* select words with a double click. Word selection provides correct
|
||||
* interpretation of punctuation marks within and following
|
||||
* words. Characters that are not part of a word, such as symbols or
|
||||
* punctuation marks, have word-breaks on both sides.
|
||||
* <p>
|
||||
* Character boundary analysis allows users to interact with
|
||||
* characters as they expect to, for example, when moving the cursor
|
||||
* through a text string. Character boundary analysis provides correct
|
||||
* navigation of through character strings, regardless of how the
|
||||
* character is stored. For example, an accented character might be
|
||||
* stored as a base character and a diacritical mark. What users
|
||||
* consider to be a character can differ between languages.
|
||||
* <p>
|
||||
* The text boundary positions are found according to the rules
|
||||
* described in Unicode Standard Annex #29, Text Boundaries, and
|
||||
* Unicode Standard Annex #14, Line Breaking Properties. These
|
||||
* are available at http://www.unicode.org/reports/tr14/ and
|
||||
* http://www.unicode.org/reports/tr29/.
|
||||
* <p>
|
||||
* In addition to the C++ API defined in this header file, a
|
||||
* plain C API with equivalent functionality is defined in the
|
||||
* file ubrk.h
|
||||
* <p>
|
||||
* Code snippets illustrating the use of the Break Iterator APIs
|
||||
* are available in the ICU User Guide,
|
||||
* http://icu-project.org/userguide/boundaryAnalysis.html
|
||||
* and in the sample program icu/source/samples/break/break.cpp
|
||||
*
|
||||
*/
|
||||
class U_COMMON_API BreakIterator : public UObject {
|
||||
public:
|
||||
/**
|
||||
* destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~BreakIterator();
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this
|
||||
* one. The other object should be an instance of the same subclass of
|
||||
* BreakIterator. Objects of different subclasses are considered
|
||||
* unequal.
|
||||
* <P>
|
||||
* Return true if this BreakIterator is at the same position in the
|
||||
* same text, and is the same class and type (word, line, etc.) of
|
||||
* BreakIterator, as the argument. Text is considered the same if
|
||||
* it contains the same characters, it need not be the same
|
||||
* object, and styles are not considered.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const BreakIterator&) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the complement of the result of operator==
|
||||
* @param rhs The BreakIterator to be compared for inequality
|
||||
* @return the complement of the result of operator==
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const BreakIterator& rhs) const { return !operator==(rhs); }
|
||||
|
||||
/**
|
||||
* Return a polymorphic copy of this object. This is an abstract
|
||||
* method which subclasses implement.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual BreakIterator* clone(void) const = 0;
|
||||
|
||||
/**
|
||||
* Return a polymorphic class ID for this object. Different subclasses
|
||||
* will return distinct unequal values.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const = 0;
|
||||
|
||||
/**
|
||||
* Return a CharacterIterator over the text being analyzed.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual CharacterIterator& getText(void) const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Get a UText for the text being analyzed.
|
||||
* The returned UText is a shallow clone of the UText used internally
|
||||
* by the break iterator implementation. It can safely be used to
|
||||
* access the text without impacting any break iterator operations,
|
||||
* but the underlying text itself must not be altered.
|
||||
*
|
||||
* @param fillIn A UText to be filled in. If NULL, a new UText will be
|
||||
* allocated to hold the result.
|
||||
* @param status receives any error codes.
|
||||
* @return The current UText for this break iterator. If an input
|
||||
* UText was provided, it will always be returned.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
virtual UText *getUText(UText *fillIn, UErrorCode &status) const = 0;
|
||||
|
||||
/**
|
||||
* Change the text over which this operates. The text boundary is
|
||||
* reset to the start.
|
||||
* @param text The UnicodeString used to change the text.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setText(const UnicodeString &text) = 0;
|
||||
|
||||
/**
|
||||
* Reset the break iterator to operate over the text represented by
|
||||
* the UText. The iterator position is reset to the start.
|
||||
*
|
||||
* This function makes a shallow clone of the supplied UText. This means
|
||||
* that the caller is free to immediately close or otherwise reuse the
|
||||
* Utext that was passed as a parameter, but that the underlying text itself
|
||||
* must not be altered while being referenced by the break iterator.
|
||||
*
|
||||
* All index positions returned by break iterator functions are
|
||||
* native indices from the UText. For example, when breaking UTF-8
|
||||
* encoded text, the break positions returned by next(), previous(), etc.
|
||||
* will be UTF-8 string indices, not UTF-16 positions.
|
||||
*
|
||||
* @param text The UText used to change the text.
|
||||
* @param status receives any error codes.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
virtual void setText(UText *text, UErrorCode &status) = 0;
|
||||
|
||||
/**
|
||||
* Change the text over which this operates. The text boundary is
|
||||
* reset to the start.
|
||||
* Note that setText(UText *) provides similar functionality to this function,
|
||||
* and is more efficient.
|
||||
* @param it The CharacterIterator used to change the text.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptText(CharacterIterator* it) = 0;
|
||||
|
||||
enum {
|
||||
/**
|
||||
* DONE is returned by previous() and next() after all valid
|
||||
* boundaries have been returned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DONE = (int32_t)-1
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the iterator position to the index of the first character in the text being scanned.
|
||||
* @return The index of the first character in the text being scanned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t first(void) = 0;
|
||||
|
||||
/**
|
||||
* Set the iterator position to the index immediately BEYOND the last character in the text being scanned.
|
||||
* @return The index immediately BEYOND the last character in the text being scanned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t last(void) = 0;
|
||||
|
||||
/**
|
||||
* Set the iterator position to the boundary preceding the current boundary.
|
||||
* @return The character index of the previous text boundary or DONE if all
|
||||
* boundaries have been returned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t previous(void) = 0;
|
||||
|
||||
/**
|
||||
* Advance the iterator to the boundary following the current boundary.
|
||||
* @return The character index of the next text boundary or DONE if all
|
||||
* boundaries have been returned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t next(void) = 0;
|
||||
|
||||
/**
|
||||
* Return character index of the current interator position within the text.
|
||||
* @return The boundary most recently returned.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t current(void) const = 0;
|
||||
|
||||
/**
|
||||
* Advance the iterator to the first boundary following the specified offset.
|
||||
* The value returned is always greater than the offset or
|
||||
* the value BreakIterator.DONE
|
||||
* @param offset the offset to begin scanning.
|
||||
* @return The first boundary after the specified offset.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t following(int32_t offset) = 0;
|
||||
|
||||
/**
|
||||
* Set the iterator position to the first boundary preceding the specified offset.
|
||||
* The value returned is always smaller than the offset or
|
||||
* the value BreakIterator.DONE
|
||||
* @param offset the offset to begin scanning.
|
||||
* @return The first boundary before the specified offset.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t preceding(int32_t offset) = 0;
|
||||
|
||||
/**
|
||||
* Return true if the specfied position is a boundary position.
|
||||
* As a side effect, the current position of the iterator is set
|
||||
* to the first boundary position at or following the specified offset.
|
||||
* @param offset the offset to check.
|
||||
* @return True if "offset" is a boundary position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool isBoundary(int32_t offset) = 0;
|
||||
|
||||
/**
|
||||
* Set the iterator position to the nth boundary from the current boundary
|
||||
* @param n the number of boundaries to move by. A value of 0
|
||||
* does nothing. Negative values move to previous boundaries
|
||||
* and positive values move to later boundaries.
|
||||
* @return The new iterator position, or
|
||||
* DONE if there are fewer than |n| boundaries in the specfied direction.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t next(int32_t n) = 0;
|
||||
|
||||
/**
|
||||
* For RuleBasedBreakIterators, return the status tag from the
|
||||
* break rule that determined the most recently
|
||||
* returned break position.
|
||||
* <p>
|
||||
* For break iterator types that do not support a rule status,
|
||||
* a default value of 0 is returned.
|
||||
* <p>
|
||||
* @return the status from the break rule that determined the most recently
|
||||
* returned break position.
|
||||
* @see RuleBaseBreakIterator::getRuleStatus()
|
||||
* @see UWordBreak
|
||||
* @draft ICU 52
|
||||
*/
|
||||
virtual int32_t getRuleStatus() const;
|
||||
|
||||
/**
|
||||
* For RuleBasedBreakIterators, get the status (tag) values from the break rule(s)
|
||||
* that determined the most recently returned break position.
|
||||
* <p>
|
||||
* For break iterator types that do not support rule status,
|
||||
* no values are returned.
|
||||
* <p>
|
||||
* The returned status value(s) are stored into an array provided by the caller.
|
||||
* The values are stored in sorted (ascending) order.
|
||||
* If the capacity of the output array is insufficient to hold the data,
|
||||
* the output will be truncated to the available length, and a
|
||||
* U_BUFFER_OVERFLOW_ERROR will be signaled.
|
||||
* <p>
|
||||
* @see RuleBaseBreakIterator::getRuleStatusVec
|
||||
*
|
||||
* @param fillInVec an array to be filled in with the status values.
|
||||
* @param capacity the length of the supplied vector. A length of zero causes
|
||||
* the function to return the number of status values, in the
|
||||
* normal way, without attemtping to store any values.
|
||||
* @param status receives error codes.
|
||||
* @return The number of rule status values from rules that determined
|
||||
* the most recent boundary returned by the break iterator.
|
||||
* In the event of a U_BUFFER_OVERFLOW_ERROR, the return value
|
||||
* is the total number of status values that were available,
|
||||
* not the reduced number that were actually returned.
|
||||
* @see getRuleStatus
|
||||
* @draft ICU 52
|
||||
*/
|
||||
virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Create BreakIterator for word-breaks using the given locale.
|
||||
* Returns an instance of a BreakIterator implementing word breaks.
|
||||
* WordBreak is useful for word selection (ex. double click)
|
||||
* @param where the locale.
|
||||
* @param status the error code
|
||||
* @return A BreakIterator for word-breaks. The UErrorCode& status
|
||||
* parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of U_SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. U_USING_DEFAULT_WARNING indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static BreakIterator* U_EXPORT2
|
||||
createWordInstance(const Locale& where, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create BreakIterator for line-breaks using specified locale.
|
||||
* Returns an instance of a BreakIterator implementing line breaks. Line
|
||||
* breaks are logically possible line breaks, actual line breaks are
|
||||
* usually determined based on display width.
|
||||
* LineBreak is useful for word wrapping text.
|
||||
* @param where the locale.
|
||||
* @param status The error code.
|
||||
* @return A BreakIterator for line-breaks. The UErrorCode& status
|
||||
* parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of U_SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. U_USING_DEFAULT_WARNING indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static BreakIterator* U_EXPORT2
|
||||
createLineInstance(const Locale& where, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create BreakIterator for character-breaks using specified locale
|
||||
* Returns an instance of a BreakIterator implementing character breaks.
|
||||
* Character breaks are boundaries of combining character sequences.
|
||||
* @param where the locale.
|
||||
* @param status The error code.
|
||||
* @return A BreakIterator for character-breaks. The UErrorCode& status
|
||||
* parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of U_SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. U_USING_DEFAULT_WARNING indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static BreakIterator* U_EXPORT2
|
||||
createCharacterInstance(const Locale& where, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create BreakIterator for sentence-breaks using specified locale
|
||||
* Returns an instance of a BreakIterator implementing sentence breaks.
|
||||
* @param where the locale.
|
||||
* @param status The error code.
|
||||
* @return A BreakIterator for sentence-breaks. The UErrorCode& status
|
||||
* parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of U_SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. U_USING_DEFAULT_WARNING indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static BreakIterator* U_EXPORT2
|
||||
createSentenceInstance(const Locale& where, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create BreakIterator for title-casing breaks using the specified locale
|
||||
* Returns an instance of a BreakIterator implementing title breaks.
|
||||
* The iterator returned locates title boundaries as described for
|
||||
* Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration,
|
||||
* please use Word Boundary iterator.{@link #createWordInstance }
|
||||
*
|
||||
* @param where the locale.
|
||||
* @param status The error code.
|
||||
* @return A BreakIterator for title-breaks. The UErrorCode& status
|
||||
* parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of U_SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. U_USING_DEFAULT_WARNING indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
static BreakIterator* U_EXPORT2
|
||||
createTitleInstance(const Locale& where, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Get the set of Locales for which TextBoundaries are installed.
|
||||
* <p><b>Note:</b> this will not return locales added through the register
|
||||
* call. To see the registered locales too, use the getAvailableLocales
|
||||
* function that returns a StringEnumeration object </p>
|
||||
* @param count the output parameter of number of elements in the locale list
|
||||
* @return available locales
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
|
||||
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the desired langauge.
|
||||
* @param objectLocale must be from getAvailableLocales.
|
||||
* @param displayLocale specifies the desired locale for output.
|
||||
* @param name the fill-in parameter of the return value
|
||||
* Uses best match.
|
||||
* @return user-displayable name
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
|
||||
const Locale& displayLocale,
|
||||
UnicodeString& name);
|
||||
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the langauge of the
|
||||
* default locale.
|
||||
* @param objectLocale must be from getMatchingLocales
|
||||
* @param name the fill-in parameter of the return value
|
||||
* @return user-displayable name
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
|
||||
UnicodeString& name);
|
||||
|
||||
/**
|
||||
* Deprecated functionality. Use clone() instead.
|
||||
*
|
||||
* Thread safe client-buffer-based cloning operation
|
||||
* Do NOT call delete on a safeclone, since 'new' is not used to create it.
|
||||
* @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
|
||||
* If buffer is not large enough, new memory will be allocated.
|
||||
* @param BufferSize reference to size of allocated space.
|
||||
* If BufferSize == 0, a sufficient size for use in cloning will
|
||||
* be returned ('pre-flighting')
|
||||
* If BufferSize is not enough for a stack-based safe clone,
|
||||
* new memory will be allocated.
|
||||
* @param status to indicate whether the operation went on smoothly or there were errors
|
||||
* An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were
|
||||
* necessary.
|
||||
* @return pointer to the new clone
|
||||
*
|
||||
* @deprecated ICU 52. Use clone() instead.
|
||||
*/
|
||||
virtual BreakIterator * createBufferClone(void *stackBuffer,
|
||||
int32_t &BufferSize,
|
||||
UErrorCode &status) = 0;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
|
||||
/**
|
||||
* Determine whether the BreakIterator was created in user memory by
|
||||
* createBufferClone(), and thus should not be deleted. Such objects
|
||||
* must be closed by an explicit call to the destructor (not delete).
|
||||
* @deprecated ICU 52. Always delete the BreakIterator.
|
||||
*/
|
||||
inline UBool isBufferClone(void);
|
||||
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
#if !UCONFIG_NO_SERVICE
|
||||
/**
|
||||
* Register a new break iterator of the indicated kind, to use in the given locale.
|
||||
* The break iterator will be adopted. Clones of the iterator will be returned
|
||||
* if a request for a break iterator of the given kind matches or falls back to
|
||||
* this locale.
|
||||
* @param toAdopt the BreakIterator instance to be adopted
|
||||
* @param locale the Locale for which this instance is to be registered
|
||||
* @param kind the type of iterator for which this instance is to be registered
|
||||
* @param status the in/out status code, no special meanings are assigned
|
||||
* @return a registry key that can be used to unregister this instance
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
static URegistryKey U_EXPORT2 registerInstance(BreakIterator* toAdopt,
|
||||
const Locale& locale,
|
||||
UBreakIteratorType kind,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Unregister a previously-registered BreakIterator using the key returned from the
|
||||
* register call. Key becomes invalid after a successful call and should not be used again.
|
||||
* The BreakIterator corresponding to the key will be deleted.
|
||||
* @param key the registry key returned by a previous call to registerInstance
|
||||
* @param status the in/out status code, no special meanings are assigned
|
||||
* @return TRUE if the iterator for the key was successfully unregistered
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Return a StringEnumeration over the locales available at the time of the call,
|
||||
* including registered locales.
|
||||
* @return a StringEnumeration over the locales available at the time of the call
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the locale for this break iterator. Two flavors are available: valid and
|
||||
* actual locale.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/** Get the locale for this break iterator object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @param status error code for the operation
|
||||
* @return the locale
|
||||
* @internal
|
||||
*/
|
||||
const char *getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Set the subject text string upon which the break iterator is operating
|
||||
* without changing any other aspect of the matching state.
|
||||
* The new and previous text strings must have the same content.
|
||||
*
|
||||
* This function is intended for use in environments where ICU is operating on
|
||||
* strings that may move around in memory. It provides a mechanism for notifying
|
||||
* ICU that the string has been relocated, and providing a new UText to access the
|
||||
* string in its new position.
|
||||
*
|
||||
* Note that the break iterator implementation never copies the underlying text
|
||||
* of a string being processed, but always operates directly on the original text
|
||||
* provided by the user. Refreshing simply drops the references to the old text
|
||||
* and replaces them with references to the new.
|
||||
*
|
||||
* Caution: this function is normally used only by very specialized,
|
||||
* system-level code. One example use case is with garbage collection that moves
|
||||
* the text in memory.
|
||||
*
|
||||
* @param input The new (moved) text string.
|
||||
* @param status Receives errors detected by this function.
|
||||
* @return *this
|
||||
*
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual BreakIterator &refreshInputText(UText *input, UErrorCode &status) = 0;
|
||||
|
||||
private:
|
||||
static BreakIterator* buildInstance(const Locale& loc, const char *type, int32_t kind, UErrorCode& status);
|
||||
static BreakIterator* createInstance(const Locale& loc, int32_t kind, UErrorCode& status);
|
||||
static BreakIterator* makeInstance(const Locale& loc, int32_t kind, UErrorCode& status);
|
||||
|
||||
friend class ICUBreakIteratorFactory;
|
||||
friend class ICUBreakIteratorService;
|
||||
|
||||
protected:
|
||||
// Do not enclose protected default/copy constructors with #ifndef U_HIDE_INTERNAL_API
|
||||
// or else the compiler will create a public ones.
|
||||
/** @internal */
|
||||
BreakIterator();
|
||||
/** @internal */
|
||||
BreakIterator (const BreakIterator &other) : UObject(other) {}
|
||||
|
||||
private:
|
||||
|
||||
/** @internal */
|
||||
char actualLocale[ULOC_FULLNAME_CAPACITY];
|
||||
char validLocale[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
/**
|
||||
* The assignment operator has no real implementation.
|
||||
* It's provided to make the compiler happy. Do not call.
|
||||
*/
|
||||
BreakIterator& operator=(const BreakIterator&);
|
||||
};
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
|
||||
inline UBool BreakIterator::isBufferClone()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
||||
|
||||
#endif // _BRKITER
|
||||
//eof
|
||||
@@ -1,257 +0,0 @@
|
||||
// Copyright (C) 2009-2012, International Business Machines
|
||||
// Corporation and others. All Rights Reserved.
|
||||
//
|
||||
// Copyright 2007 Google Inc. All Rights Reserved.
|
||||
// Author: sanjay@google.com (Sanjay Ghemawat)
|
||||
//
|
||||
// Abstract interface that consumes a sequence of bytes (ByteSink).
|
||||
//
|
||||
// Used so that we can write a single piece of code that can operate
|
||||
// on a variety of output string types.
|
||||
//
|
||||
// Various implementations of this interface are provided:
|
||||
// ByteSink:
|
||||
// CheckedArrayByteSink Write to a flat array, with bounds checking
|
||||
// StringByteSink Write to an STL string
|
||||
|
||||
// This code is a contribution of Google code, and the style used here is
|
||||
// a compromise between the original Google code and the ICU coding guidelines.
|
||||
// For example, data types are ICU-ified (size_t,int->int32_t),
|
||||
// and API comments doxygen-ified, but function names and behavior are
|
||||
// as in the original, if possible.
|
||||
// Assertion-style error handling, not available in ICU, was changed to
|
||||
// parameter "pinning" similar to UnicodeString.
|
||||
//
|
||||
// In addition, this is only a partial port of the original Google code,
|
||||
// limited to what was needed so far. The (nearly) complete original code
|
||||
// is in the ICU svn repository at icuhtml/trunk/design/strings/contrib
|
||||
// (see ICU ticket 6765, r25517).
|
||||
|
||||
#ifndef __BYTESTREAM_H__
|
||||
#define __BYTESTREAM_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Interface for writing bytes, and implementation classes.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/std_string.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A ByteSink can be filled with bytes.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
class U_COMMON_API ByteSink : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
ByteSink() { }
|
||||
/**
|
||||
* Virtual destructor.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual ~ByteSink();
|
||||
|
||||
/**
|
||||
* Append "bytes[0,n-1]" to this.
|
||||
* @param bytes the pointer to the bytes
|
||||
* @param n the number of bytes; must be non-negative
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual void Append(const char* bytes, int32_t n) = 0;
|
||||
|
||||
/**
|
||||
* Returns a writable buffer for appending and writes the buffer's capacity to
|
||||
* *result_capacity. Guarantees *result_capacity>=min_capacity.
|
||||
* May return a pointer to the caller-owned scratch buffer which must have
|
||||
* scratch_capacity>=min_capacity.
|
||||
* The returned buffer is only valid until the next operation
|
||||
* on this ByteSink.
|
||||
*
|
||||
* After writing at most *result_capacity bytes, call Append() with the
|
||||
* pointer returned from this function and the number of bytes written.
|
||||
* Many Append() implementations will avoid copying bytes if this function
|
||||
* returned an internal buffer.
|
||||
*
|
||||
* Partial usage example:
|
||||
* int32_t capacity;
|
||||
* char* buffer = sink->GetAppendBuffer(..., &capacity);
|
||||
* ... Write n bytes into buffer, with n <= capacity.
|
||||
* sink->Append(buffer, n);
|
||||
* In many implementations, that call to Append will avoid copying bytes.
|
||||
*
|
||||
* If the ByteSink allocates or reallocates an internal buffer, it should use
|
||||
* the desired_capacity_hint if appropriate.
|
||||
* If a caller cannot provide a reasonable guess at the desired capacity,
|
||||
* it should pass desired_capacity_hint=0.
|
||||
*
|
||||
* If a non-scratch buffer is returned, the caller may only pass
|
||||
* a prefix to it to Append().
|
||||
* That is, it is not correct to pass an interior pointer to Append().
|
||||
*
|
||||
* The default implementation always returns the scratch buffer.
|
||||
*
|
||||
* @param min_capacity required minimum capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param desired_capacity_hint desired capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param scratch default caller-owned buffer
|
||||
* @param scratch_capacity capacity of the scratch buffer
|
||||
* @param result_capacity pointer to an integer which will be set to the
|
||||
* capacity of the returned buffer
|
||||
* @return a buffer with *result_capacity>=min_capacity
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual char* GetAppendBuffer(int32_t min_capacity,
|
||||
int32_t desired_capacity_hint,
|
||||
char* scratch, int32_t scratch_capacity,
|
||||
int32_t* result_capacity);
|
||||
|
||||
/**
|
||||
* Flush internal buffers.
|
||||
* Some byte sinks use internal buffers or provide buffering
|
||||
* and require calling Flush() at the end of the stream.
|
||||
* The ByteSink should be ready for further Append() calls after Flush().
|
||||
* The default implementation of Flush() does nothing.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual void Flush();
|
||||
|
||||
private:
|
||||
ByteSink(const ByteSink &); // copy constructor not implemented
|
||||
ByteSink &operator=(const ByteSink &); // assignment operator not implemented
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Some standard implementations
|
||||
|
||||
/**
|
||||
* Implementation of ByteSink that writes to a flat byte array,
|
||||
* with bounds-checking:
|
||||
* This sink will not write more than capacity bytes to outbuf.
|
||||
* If more than capacity bytes are Append()ed, then excess bytes are ignored,
|
||||
* and Overflowed() will return true.
|
||||
* Overflow does not cause a runtime error.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
class U_COMMON_API CheckedArrayByteSink : public ByteSink {
|
||||
public:
|
||||
/**
|
||||
* Constructs a ByteSink that will write to outbuf[0..capacity-1].
|
||||
* @param outbuf buffer to write to
|
||||
* @param capacity size of the buffer
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CheckedArrayByteSink(char* outbuf, int32_t capacity);
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual ~CheckedArrayByteSink();
|
||||
/**
|
||||
* Returns the sink to its original state, without modifying the buffer.
|
||||
* Useful for reusing both the buffer and the sink for multiple streams.
|
||||
* Resets the state to NumberOfBytesWritten()=NumberOfBytesAppended()=0
|
||||
* and Overflowed()=FALSE.
|
||||
* @return *this
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual CheckedArrayByteSink& Reset();
|
||||
/**
|
||||
* Append "bytes[0,n-1]" to this.
|
||||
* @param bytes the pointer to the bytes
|
||||
* @param n the number of bytes; must be non-negative
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual void Append(const char* bytes, int32_t n);
|
||||
/**
|
||||
* Returns a writable buffer for appending and writes the buffer's capacity to
|
||||
* *result_capacity. For details see the base class documentation.
|
||||
* @param min_capacity required minimum capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param desired_capacity_hint desired capacity of the returned buffer;
|
||||
* must be non-negative
|
||||
* @param scratch default caller-owned buffer
|
||||
* @param scratch_capacity capacity of the scratch buffer
|
||||
* @param result_capacity pointer to an integer which will be set to the
|
||||
* capacity of the returned buffer
|
||||
* @return a buffer with *result_capacity>=min_capacity
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual char* GetAppendBuffer(int32_t min_capacity,
|
||||
int32_t desired_capacity_hint,
|
||||
char* scratch, int32_t scratch_capacity,
|
||||
int32_t* result_capacity);
|
||||
/**
|
||||
* Returns the number of bytes actually written to the sink.
|
||||
* @return number of bytes written to the buffer
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
int32_t NumberOfBytesWritten() const { return size_; }
|
||||
/**
|
||||
* Returns true if any bytes were discarded, i.e., if there was an
|
||||
* attempt to write more than 'capacity' bytes.
|
||||
* @return TRUE if more than 'capacity' bytes were Append()ed
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UBool Overflowed() const { return overflowed_; }
|
||||
/**
|
||||
* Returns the number of bytes appended to the sink.
|
||||
* If Overflowed() then NumberOfBytesAppended()>NumberOfBytesWritten()
|
||||
* else they return the same number.
|
||||
* @return number of bytes written to the buffer
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
int32_t NumberOfBytesAppended() const { return appended_; }
|
||||
private:
|
||||
char* outbuf_;
|
||||
const int32_t capacity_;
|
||||
int32_t size_;
|
||||
int32_t appended_;
|
||||
UBool overflowed_;
|
||||
CheckedArrayByteSink(); ///< default constructor not implemented
|
||||
CheckedArrayByteSink(const CheckedArrayByteSink &); ///< copy constructor not implemented
|
||||
CheckedArrayByteSink &operator=(const CheckedArrayByteSink &); ///< assignment operator not implemented
|
||||
};
|
||||
|
||||
#if U_HAVE_STD_STRING
|
||||
|
||||
/**
|
||||
* Implementation of ByteSink that writes to a "string".
|
||||
* The StringClass is usually instantiated with a std::string.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
template<typename StringClass>
|
||||
class StringByteSink : public ByteSink {
|
||||
public:
|
||||
/**
|
||||
* Constructs a ByteSink that will append bytes to the dest string.
|
||||
* @param dest pointer to string object to append to
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
StringByteSink(StringClass* dest) : dest_(dest) { }
|
||||
/**
|
||||
* Append "bytes[0,n-1]" to this.
|
||||
* @param data the pointer to the bytes
|
||||
* @param n the number of bytes; must be non-negative
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual void Append(const char* data, int32_t n) { dest_->append(data, n); }
|
||||
private:
|
||||
StringClass* dest_;
|
||||
StringByteSink(); ///< default constructor not implemented
|
||||
StringByteSink(const StringByteSink &); ///< copy constructor not implemented
|
||||
StringByteSink &operator=(const StringByteSink &); ///< assignment operator not implemented
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // __BYTESTREAM_H__
|
||||
@@ -1,519 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: bytestrie.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010sep25
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __BYTESTRIE_H__
|
||||
#define __BYTESTRIE_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Trie for mapping byte sequences to integer values.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/ustringtrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class ByteSink;
|
||||
class BytesTrieBuilder;
|
||||
class CharString;
|
||||
class UVector32;
|
||||
|
||||
/**
|
||||
* Light-weight, non-const reader class for a BytesTrie.
|
||||
* Traverses a byte-serialized data structure with minimal state,
|
||||
* for mapping byte sequences to non-negative integer values.
|
||||
*
|
||||
* This class owns the serialized trie data only if it was constructed by
|
||||
* the builder's build() method.
|
||||
* The public constructor and the copy constructor only alias the data (only copy the pointer).
|
||||
* There is no assignment operator.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API BytesTrie : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructs a BytesTrie reader instance.
|
||||
*
|
||||
* The trieBytes must contain a copy of a byte sequence from the BytesTrieBuilder,
|
||||
* starting with the first byte of that sequence.
|
||||
* The BytesTrie object will not read more bytes than
|
||||
* the BytesTrieBuilder generated in the corresponding build() call.
|
||||
*
|
||||
* The array is not copied/cloned and must not be modified while
|
||||
* the BytesTrie object is in use.
|
||||
*
|
||||
* @param trieBytes The byte array that contains the serialized trie.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrie(const void *trieBytes)
|
||||
: ownedArray_(NULL), bytes_(static_cast<const uint8_t *>(trieBytes)),
|
||||
pos_(bytes_), remainingMatchLength_(-1) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
~BytesTrie();
|
||||
|
||||
/**
|
||||
* Copy constructor, copies the other trie reader object and its state,
|
||||
* but not the byte array which will be shared. (Shallow copy.)
|
||||
* @param other Another BytesTrie object.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrie(const BytesTrie &other)
|
||||
: ownedArray_(NULL), bytes_(other.bytes_),
|
||||
pos_(other.pos_), remainingMatchLength_(other.remainingMatchLength_) {}
|
||||
|
||||
/**
|
||||
* Resets this trie to its initial state.
|
||||
* @return *this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrie &reset() {
|
||||
pos_=bytes_;
|
||||
remainingMatchLength_=-1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* BytesTrie state object, for saving a trie's current state
|
||||
* and resetting the trie back to this state later.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class State : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty State.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
State() { bytes=NULL; }
|
||||
private:
|
||||
friend class BytesTrie;
|
||||
|
||||
const uint8_t *bytes;
|
||||
const uint8_t *pos;
|
||||
int32_t remainingMatchLength;
|
||||
};
|
||||
|
||||
/**
|
||||
* Saves the state of this trie.
|
||||
* @param state The State object to hold the trie's state.
|
||||
* @return *this
|
||||
* @see resetToState
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const BytesTrie &saveState(State &state) const {
|
||||
state.bytes=bytes_;
|
||||
state.pos=pos_;
|
||||
state.remainingMatchLength=remainingMatchLength_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this trie to the saved state.
|
||||
* If the state object contains no state, or the state of a different trie,
|
||||
* then this trie remains unchanged.
|
||||
* @param state The State object which holds a saved trie state.
|
||||
* @return *this
|
||||
* @see saveState
|
||||
* @see reset
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrie &resetToState(const State &state) {
|
||||
if(bytes_==state.bytes && bytes_!=NULL) {
|
||||
pos_=state.pos;
|
||||
remainingMatchLength_=state.remainingMatchLength;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the byte sequence so far matches, whether it has a value,
|
||||
* and whether another input byte can continue a matching byte sequence.
|
||||
* @return The match/value Result.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UStringTrieResult current() const;
|
||||
|
||||
/**
|
||||
* Traverses the trie from the initial state for this input byte.
|
||||
* Equivalent to reset().next(inByte).
|
||||
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
|
||||
* Values below -0x100 and above 0xff will never match.
|
||||
* @return The match/value Result.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
inline UStringTrieResult first(int32_t inByte) {
|
||||
remainingMatchLength_=-1;
|
||||
if(inByte<0) {
|
||||
inByte+=0x100;
|
||||
}
|
||||
return nextImpl(bytes_, inByte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the trie from the current state for this input byte.
|
||||
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
|
||||
* Values below -0x100 and above 0xff will never match.
|
||||
* @return The match/value Result.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(int32_t inByte);
|
||||
|
||||
/**
|
||||
* Traverses the trie from the current state for this byte sequence.
|
||||
* Equivalent to
|
||||
* \code
|
||||
* Result result=current();
|
||||
* for(each c in s)
|
||||
* if(!USTRINGTRIE_HAS_NEXT(result)) return USTRINGTRIE_NO_MATCH;
|
||||
* result=next(c);
|
||||
* return result;
|
||||
* \endcode
|
||||
* @param s A string or byte sequence. Can be NULL if length is 0.
|
||||
* @param length The length of the byte sequence. Can be -1 if NUL-terminated.
|
||||
* @return The match/value Result.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(const char *s, int32_t length);
|
||||
|
||||
/**
|
||||
* Returns a matching byte sequence's value if called immediately after
|
||||
* current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE.
|
||||
* getValue() can be called multiple times.
|
||||
*
|
||||
* Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!
|
||||
* @return The value for the byte sequence so far.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
inline int32_t getValue() const {
|
||||
const uint8_t *pos=pos_;
|
||||
int32_t leadByte=*pos++;
|
||||
// U_ASSERT(leadByte>=kMinValueLead);
|
||||
return readValue(pos, leadByte>>1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether all byte sequences reachable from the current state
|
||||
* map to the same value.
|
||||
* @param uniqueValue Receives the unique value, if this function returns TRUE.
|
||||
* (output-only)
|
||||
* @return TRUE if all byte sequences reachable from the current state
|
||||
* map to the same value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
inline UBool hasUniqueValue(int32_t &uniqueValue) const {
|
||||
const uint8_t *pos=pos_;
|
||||
// Skip the rest of a pending linear-match node.
|
||||
return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds each byte which continues the byte sequence from the current state.
|
||||
* That is, each byte b for which it would be next(b)!=USTRINGTRIE_NO_MATCH now.
|
||||
* @param out Each next byte is appended to this object.
|
||||
* (Only uses the out.Append(s, length) method.)
|
||||
* @return the number of bytes which continue the byte sequence from here
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getNextBytes(ByteSink &out) const;
|
||||
|
||||
/**
|
||||
* Iterator for all of the (byte sequence, value) pairs in a BytesTrie.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API Iterator : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Iterates from the root of a byte-serialized BytesTrie.
|
||||
* @param trieBytes The trie bytes.
|
||||
* @param maxStringLength If 0, the iterator returns full strings/byte sequences.
|
||||
* Otherwise, the iterator returns strings with this maximum length.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
Iterator(const void *trieBytes, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Iterates from the current state of the specified BytesTrie.
|
||||
* @param trie The trie whose state will be copied for iteration.
|
||||
* @param maxStringLength If 0, the iterator returns full strings/byte sequences.
|
||||
* Otherwise, the iterator returns strings with this maximum length.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
Iterator(const BytesTrie &trie, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
~Iterator();
|
||||
|
||||
/**
|
||||
* Resets this iterator to its initial state.
|
||||
* @return *this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
Iterator &reset();
|
||||
|
||||
/**
|
||||
* @return TRUE if there are more elements.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool hasNext() const;
|
||||
|
||||
/**
|
||||
* Finds the next (byte sequence, value) pair if there is one.
|
||||
*
|
||||
* If the byte sequence is truncated to the maximum length and does not
|
||||
* have a real value, then the value is set to -1.
|
||||
* In this case, this "not a real value" is indistinguishable from
|
||||
* a real value of -1.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return TRUE if there is another element.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool next(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* @return The NUL-terminated byte sequence for the last successful next().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const StringPiece &getString() const { return sp_; }
|
||||
/**
|
||||
* @return The value for the last successful next().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getValue() const { return value_; }
|
||||
|
||||
private:
|
||||
UBool truncateAndStop();
|
||||
|
||||
const uint8_t *branchNext(const uint8_t *pos, int32_t length, UErrorCode &errorCode);
|
||||
|
||||
const uint8_t *bytes_;
|
||||
const uint8_t *pos_;
|
||||
const uint8_t *initialPos_;
|
||||
int32_t remainingMatchLength_;
|
||||
int32_t initialRemainingMatchLength_;
|
||||
|
||||
CharString *str_;
|
||||
StringPiece sp_;
|
||||
int32_t maxLength_;
|
||||
int32_t value_;
|
||||
|
||||
// The stack stores pairs of integers for backtracking to another
|
||||
// outbound edge of a branch node.
|
||||
// The first integer is an offset from bytes_.
|
||||
// The second integer has the str_->length() from before the node in bits 15..0,
|
||||
// and the remaining branch length in bits 24..16. (Bits 31..25 are unused.)
|
||||
// (We could store the remaining branch length minus 1 in bits 23..16 and not use bits 31..24,
|
||||
// but the code looks more confusing that way.)
|
||||
UVector32 *stack_;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class BytesTrieBuilder;
|
||||
|
||||
/**
|
||||
* Constructs a BytesTrie reader instance.
|
||||
* Unlike the public constructor which just aliases an array,
|
||||
* this constructor adopts the builder's array.
|
||||
* This constructor is only called by the builder.
|
||||
*/
|
||||
BytesTrie(void *adoptBytes, const void *trieBytes)
|
||||
: ownedArray_(static_cast<uint8_t *>(adoptBytes)),
|
||||
bytes_(static_cast<const uint8_t *>(trieBytes)),
|
||||
pos_(bytes_), remainingMatchLength_(-1) {}
|
||||
|
||||
// No assignment operator.
|
||||
BytesTrie &operator=(const BytesTrie &other);
|
||||
|
||||
inline void stop() {
|
||||
pos_=NULL;
|
||||
}
|
||||
|
||||
// Reads a compact 32-bit integer.
|
||||
// pos is already after the leadByte, and the lead byte is already shifted right by 1.
|
||||
static int32_t readValue(const uint8_t *pos, int32_t leadByte);
|
||||
static inline const uint8_t *skipValue(const uint8_t *pos, int32_t leadByte) {
|
||||
// U_ASSERT(leadByte>=kMinValueLead);
|
||||
if(leadByte>=(kMinTwoByteValueLead<<1)) {
|
||||
if(leadByte<(kMinThreeByteValueLead<<1)) {
|
||||
++pos;
|
||||
} else if(leadByte<(kFourByteValueLead<<1)) {
|
||||
pos+=2;
|
||||
} else {
|
||||
pos+=3+((leadByte>>1)&1);
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
static inline const uint8_t *skipValue(const uint8_t *pos) {
|
||||
int32_t leadByte=*pos++;
|
||||
return skipValue(pos, leadByte);
|
||||
}
|
||||
|
||||
// Reads a jump delta and jumps.
|
||||
static const uint8_t *jumpByDelta(const uint8_t *pos);
|
||||
|
||||
static inline const uint8_t *skipDelta(const uint8_t *pos) {
|
||||
int32_t delta=*pos++;
|
||||
if(delta>=kMinTwoByteDeltaLead) {
|
||||
if(delta<kMinThreeByteDeltaLead) {
|
||||
++pos;
|
||||
} else if(delta<kFourByteDeltaLead) {
|
||||
pos+=2;
|
||||
} else {
|
||||
pos+=3+(delta&1);
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
static inline UStringTrieResult valueResult(int32_t node) {
|
||||
return (UStringTrieResult)(USTRINGTRIE_INTERMEDIATE_VALUE-(node&kValueIsFinal));
|
||||
}
|
||||
|
||||
// Handles a branch node for both next(byte) and next(string).
|
||||
UStringTrieResult branchNext(const uint8_t *pos, int32_t length, int32_t inByte);
|
||||
|
||||
// Requires remainingLength_<0.
|
||||
UStringTrieResult nextImpl(const uint8_t *pos, int32_t inByte);
|
||||
|
||||
// Helper functions for hasUniqueValue().
|
||||
// Recursively finds a unique value (or whether there is not a unique one)
|
||||
// from a branch.
|
||||
static const uint8_t *findUniqueValueFromBranch(const uint8_t *pos, int32_t length,
|
||||
UBool haveUniqueValue, int32_t &uniqueValue);
|
||||
// Recursively finds a unique value (or whether there is not a unique one)
|
||||
// starting from a position on a node lead byte.
|
||||
static UBool findUniqueValue(const uint8_t *pos, UBool haveUniqueValue, int32_t &uniqueValue);
|
||||
|
||||
// Helper functions for getNextBytes().
|
||||
// getNextBytes() when pos is on a branch node.
|
||||
static void getNextBranchBytes(const uint8_t *pos, int32_t length, ByteSink &out);
|
||||
static void append(ByteSink &out, int c);
|
||||
|
||||
// BytesTrie data structure
|
||||
//
|
||||
// The trie consists of a series of byte-serialized nodes for incremental
|
||||
// string/byte sequence matching. The root node is at the beginning of the trie data.
|
||||
//
|
||||
// Types of nodes are distinguished by their node lead byte ranges.
|
||||
// After each node, except a final-value node, another node follows to
|
||||
// encode match values or continue matching further bytes.
|
||||
//
|
||||
// Node types:
|
||||
// - Value node: Stores a 32-bit integer in a compact, variable-length format.
|
||||
// The value is for the string/byte sequence so far.
|
||||
// One node bit indicates whether the value is final or whether
|
||||
// matching continues with the next node.
|
||||
// - Linear-match node: Matches a number of bytes.
|
||||
// - Branch node: Branches to other nodes according to the current input byte.
|
||||
// The node byte is the length of the branch (number of bytes to select from)
|
||||
// minus 1. It is followed by a sub-node:
|
||||
// - If the length is at most kMaxBranchLinearSubNodeLength, then
|
||||
// there are length-1 (key, value) pairs and then one more comparison byte.
|
||||
// If one of the key bytes matches, then the value is either a final value for
|
||||
// the string/byte sequence so far, or a "jump" delta to the next node.
|
||||
// If the last byte matches, then matching continues with the next node.
|
||||
// (Values have the same encoding as value nodes.)
|
||||
// - If the length is greater than kMaxBranchLinearSubNodeLength, then
|
||||
// there is one byte and one "jump" delta.
|
||||
// If the input byte is less than the sub-node byte, then "jump" by delta to
|
||||
// the next sub-node which will have a length of length/2.
|
||||
// (The delta has its own compact encoding.)
|
||||
// Otherwise, skip the "jump" delta to the next sub-node
|
||||
// which will have a length of length-length/2.
|
||||
|
||||
// Node lead byte values.
|
||||
|
||||
// 00..0f: Branch node. If node!=0 then the length is node+1, otherwise
|
||||
// the length is one more than the next byte.
|
||||
|
||||
// For a branch sub-node with at most this many entries, we drop down
|
||||
// to a linear search.
|
||||
static const int32_t kMaxBranchLinearSubNodeLength=5;
|
||||
|
||||
// 10..1f: Linear-match node, match 1..16 bytes and continue reading the next node.
|
||||
static const int32_t kMinLinearMatch=0x10;
|
||||
static const int32_t kMaxLinearMatchLength=0x10;
|
||||
|
||||
// 20..ff: Variable-length value node.
|
||||
// If odd, the value is final. (Otherwise, intermediate value or jump delta.)
|
||||
// Then shift-right by 1 bit.
|
||||
// The remaining lead byte value indicates the number of following bytes (0..4)
|
||||
// and contains the value's top bits.
|
||||
static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength; // 0x20
|
||||
// It is a final value if bit 0 is set.
|
||||
static const int32_t kValueIsFinal=1;
|
||||
|
||||
// Compact value: After testing bit 0, shift right by 1 and then use the following thresholds.
|
||||
static const int32_t kMinOneByteValueLead=kMinValueLead/2; // 0x10
|
||||
static const int32_t kMaxOneByteValue=0x40; // At least 6 bits in the first byte.
|
||||
|
||||
static const int32_t kMinTwoByteValueLead=kMinOneByteValueLead+kMaxOneByteValue+1; // 0x51
|
||||
static const int32_t kMaxTwoByteValue=0x1aff;
|
||||
|
||||
static const int32_t kMinThreeByteValueLead=kMinTwoByteValueLead+(kMaxTwoByteValue>>8)+1; // 0x6c
|
||||
static const int32_t kFourByteValueLead=0x7e;
|
||||
|
||||
// A little more than Unicode code points. (0x11ffff)
|
||||
static const int32_t kMaxThreeByteValue=((kFourByteValueLead-kMinThreeByteValueLead)<<16)-1;
|
||||
|
||||
static const int32_t kFiveByteValueLead=0x7f;
|
||||
|
||||
// Compact delta integers.
|
||||
static const int32_t kMaxOneByteDelta=0xbf;
|
||||
static const int32_t kMinTwoByteDeltaLead=kMaxOneByteDelta+1; // 0xc0
|
||||
static const int32_t kMinThreeByteDeltaLead=0xf0;
|
||||
static const int32_t kFourByteDeltaLead=0xfe;
|
||||
static const int32_t kFiveByteDeltaLead=0xff;
|
||||
|
||||
static const int32_t kMaxTwoByteDelta=((kMinThreeByteDeltaLead-kMinTwoByteDeltaLead)<<8)-1; // 0x2fff
|
||||
static const int32_t kMaxThreeByteDelta=((kFourByteDeltaLead-kMinThreeByteDeltaLead)<<16)-1; // 0xdffff
|
||||
|
||||
uint8_t *ownedArray_;
|
||||
|
||||
// Fixed value referencing the BytesTrie bytes.
|
||||
const uint8_t *bytes_;
|
||||
|
||||
// Iterator variables.
|
||||
|
||||
// Pointer to next trie byte to read. NULL if no more matches.
|
||||
const uint8_t *pos_;
|
||||
// Remaining length of a linear-match node, minus 1. Negative if not in such a node.
|
||||
int32_t remainingMatchLength_;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // __BYTESTRIE_H__
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: bytestriebuilder.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010sep25
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Builder for icu::BytesTrie
|
||||
*/
|
||||
|
||||
#ifndef __BYTESTRIEBUILDER_H__
|
||||
#define __BYTESTRIEBUILDER_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/stringtriebuilder.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class BytesTrieElement;
|
||||
class CharString;
|
||||
|
||||
/**
|
||||
* Builder class for BytesTrie.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty builder.
|
||||
* @param errorCode Standard ICU error code.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual ~BytesTrieBuilder();
|
||||
|
||||
/**
|
||||
* Adds a (byte sequence, value) pair.
|
||||
* The byte sequence must be unique.
|
||||
* The bytes will be copied; the builder does not keep
|
||||
* a reference to the input StringPiece or its data().
|
||||
* @param s The input byte sequence.
|
||||
* @param value The value associated with this byte sequence.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Builds a BytesTrie for the add()ed data.
|
||||
* Once built, no further data can be add()ed until clear() is called.
|
||||
*
|
||||
* A BytesTrie cannot be empty. At least one (byte sequence, value) pair
|
||||
* must have been add()ed.
|
||||
*
|
||||
* This method passes ownership of the builder's internal result array to the new trie object.
|
||||
* Another call to any build() variant will re-serialize the trie.
|
||||
* After clear() has been called, a new array will be used as well.
|
||||
* @param buildOption Build option, see UStringTrieBuildOption.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return A new BytesTrie for the add()ed data.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Builds a BytesTrie for the add()ed data and byte-serializes it.
|
||||
* Once built, no further data can be add()ed until clear() is called.
|
||||
*
|
||||
* A BytesTrie cannot be empty. At least one (byte sequence, value) pair
|
||||
* must have been add()ed.
|
||||
*
|
||||
* Multiple calls to buildStringPiece() return StringPieces referring to the
|
||||
* builder's same byte array, without rebuilding.
|
||||
* If buildStringPiece() is called after build(), the trie will be
|
||||
* re-serialized into a new array.
|
||||
* If build() is called after buildStringPiece(), the trie object will become
|
||||
* the owner of the previously returned array.
|
||||
* After clear() has been called, a new array will be used as well.
|
||||
* @param buildOption Build option, see UStringTrieBuildOption.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return A StringPiece which refers to the byte-serialized BytesTrie for the add()ed data.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Removes all (byte sequence, value) pairs.
|
||||
* New data can then be add()ed and a new trie can be built.
|
||||
* @return *this
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder &clear();
|
||||
|
||||
private:
|
||||
BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
|
||||
BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator
|
||||
|
||||
void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
virtual int32_t getElementStringLength(int32_t i) const;
|
||||
virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;
|
||||
virtual int32_t getElementValue(int32_t i) const;
|
||||
|
||||
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
|
||||
|
||||
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
|
||||
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
|
||||
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;
|
||||
|
||||
virtual UBool matchNodesCanHaveValues() const { return FALSE; }
|
||||
|
||||
virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
|
||||
virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
|
||||
virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class BTLinearMatchNode : public LinearMatchNode {
|
||||
public:
|
||||
BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
|
||||
virtual UBool operator==(const Node &other) const;
|
||||
virtual void write(StringTrieBuilder &builder);
|
||||
private:
|
||||
const char *s;
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
|
||||
Node *nextNode) const;
|
||||
|
||||
UBool ensureCapacity(int32_t length);
|
||||
virtual int32_t write(int32_t byte);
|
||||
int32_t write(const char *b, int32_t length);
|
||||
virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
|
||||
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
|
||||
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
|
||||
virtual int32_t writeDeltaTo(int32_t jumpTarget);
|
||||
|
||||
CharString *strings; // Pointer not object so we need not #include internal charstr.h.
|
||||
BytesTrieElement *elements;
|
||||
int32_t elementsCapacity;
|
||||
int32_t elementsLength;
|
||||
|
||||
// Byte serialization of the trie.
|
||||
// Grows from the back: bytesLength measures from the end of the buffer!
|
||||
char *bytes;
|
||||
int32_t bytesCapacity;
|
||||
int32_t bytesLength;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // __BYTESTRIEBUILDER_H__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,208 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2011, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CANITER_H
|
||||
#define CANITER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Canonical Iterator
|
||||
*/
|
||||
|
||||
/** Should permutation skip characters with combining class zero
|
||||
* Should be either TRUE or FALSE. This is a compile time option
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
#ifndef CANITER_SKIP_ZEROES
|
||||
#define CANITER_SKIP_ZEROES TRUE
|
||||
#endif
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class Hashtable;
|
||||
class Normalizer2;
|
||||
class Normalizer2Impl;
|
||||
|
||||
/**
|
||||
* This class allows one to iterate through all the strings that are canonically equivalent to a given
|
||||
* string. For example, here are some sample results:
|
||||
Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
|
||||
1: \\u0041\\u030A\\u0064\\u0307\\u0327
|
||||
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
|
||||
2: \\u0041\\u030A\\u0064\\u0327\\u0307
|
||||
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
|
||||
3: \\u0041\\u030A\\u1E0B\\u0327
|
||||
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
|
||||
4: \\u0041\\u030A\\u1E11\\u0307
|
||||
= {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
|
||||
5: \\u00C5\\u0064\\u0307\\u0327
|
||||
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
|
||||
6: \\u00C5\\u0064\\u0327\\u0307
|
||||
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
|
||||
7: \\u00C5\\u1E0B\\u0327
|
||||
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
|
||||
8: \\u00C5\\u1E11\\u0307
|
||||
= {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
|
||||
9: \\u212B\\u0064\\u0307\\u0327
|
||||
= {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
|
||||
10: \\u212B\\u0064\\u0327\\u0307
|
||||
= {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
|
||||
11: \\u212B\\u1E0B\\u0327
|
||||
= {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
|
||||
12: \\u212B\\u1E11\\u0307
|
||||
= {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
|
||||
*<br>Note: the code is intended for use with small strings, and is not suitable for larger ones,
|
||||
* since it has not been optimized for that situation.
|
||||
* Note, CanonicalIterator is not intended to be subclassed.
|
||||
* @author M. Davis
|
||||
* @author C++ port by V. Weinstein
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
class U_COMMON_API CanonicalIterator : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Construct a CanonicalIterator object
|
||||
* @param source string to get results for
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
CanonicalIterator(const UnicodeString &source, UErrorCode &status);
|
||||
|
||||
/** Destructor
|
||||
* Cleans pieces
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual ~CanonicalIterator();
|
||||
|
||||
/**
|
||||
* Gets the NFD form of the current source we are iterating over.
|
||||
* @return gets the source: NOTE: it is the NFD form of source
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
UnicodeString getSource();
|
||||
|
||||
/**
|
||||
* Resets the iterator so that one can start again from the beginning.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Get the next canonically equivalent string.
|
||||
* <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
|
||||
* @return the next string that is canonically equivalent. A bogus string is returned when
|
||||
* the iteration is done.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
UnicodeString next();
|
||||
|
||||
/**
|
||||
* Set a new source for this iterator. Allows object reuse.
|
||||
* @param newSource the source string to iterate against. This allows the same iterator to be used
|
||||
* while changing the source string, saving object creation.
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
void setSource(const UnicodeString &newSource, UErrorCode &status);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Dumb recursive implementation of permutation.
|
||||
* TODO: optimize
|
||||
* @param source the string to find permutations for
|
||||
* @param skipZeros determine if skip zeros
|
||||
* @param result the results in a set.
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @internal
|
||||
*/
|
||||
static void U_EXPORT2 permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
private:
|
||||
// ===================== PRIVATES ==============================
|
||||
// private default constructor
|
||||
CanonicalIterator();
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor. Private for now.
|
||||
* @internal
|
||||
*/
|
||||
CanonicalIterator(const CanonicalIterator& other);
|
||||
|
||||
/**
|
||||
* Assignment operator. Private for now.
|
||||
* @internal
|
||||
*/
|
||||
CanonicalIterator& operator=(const CanonicalIterator& other);
|
||||
|
||||
// fields
|
||||
UnicodeString source;
|
||||
UBool done;
|
||||
|
||||
// 2 dimensional array holds the pieces of the string with
|
||||
// their different canonically equivalent representations
|
||||
UnicodeString **pieces;
|
||||
int32_t pieces_length;
|
||||
int32_t *pieces_lengths;
|
||||
|
||||
// current is used in iterating to combine pieces
|
||||
int32_t *current;
|
||||
int32_t current_length;
|
||||
|
||||
// transient fields
|
||||
UnicodeString buffer;
|
||||
|
||||
const Normalizer2 &nfd;
|
||||
const Normalizer2Impl &nfcImpl;
|
||||
|
||||
// we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
|
||||
UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment)
|
||||
|
||||
//Set getEquivalents2(String segment);
|
||||
Hashtable *getEquivalents2(Hashtable *fillinResult, const UChar *segment, int32_t segLen, UErrorCode &status);
|
||||
//Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* See if the decomposition of cp2 is at segment starting at segmentPos
|
||||
* (with canonical rearrangment!)
|
||||
* If so, take the remainder, and return the equivalents
|
||||
*/
|
||||
//Set extract(int comp, String segment, int segmentPos, StringBuffer buffer);
|
||||
Hashtable *extract(Hashtable *fillinResult, UChar32 comp, const UChar *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
|
||||
//Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
|
||||
|
||||
void cleanPieces();
|
||||
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_NORMALIZATION */
|
||||
|
||||
#endif
|
||||
@@ -1,722 +0,0 @@
|
||||
/*
|
||||
********************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CHARITER_H
|
||||
#define CHARITER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/unistr.h"
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Character Iterator
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
/**
|
||||
* Abstract class that defines an API for forward-only iteration
|
||||
* on text objects.
|
||||
* This is a minimal interface for iteration without random access
|
||||
* or backwards iteration. It is especially useful for wrapping
|
||||
* streams with converters into an object for collation or
|
||||
* normalization.
|
||||
*
|
||||
* <p>Characters can be accessed in two ways: as code units or as
|
||||
* code points.
|
||||
* Unicode code points are 21-bit integers and are the scalar values
|
||||
* of Unicode characters. ICU uses the type UChar32 for them.
|
||||
* Unicode code units are the storage units of a given
|
||||
* Unicode/UCS Transformation Format (a character encoding scheme).
|
||||
* With UTF-16, all code points can be represented with either one
|
||||
* or two code units ("surrogates").
|
||||
* String storage is typically based on code units, while properties
|
||||
* of characters are typically determined using code point values.
|
||||
* Some processes may be designed to work with sequences of code units,
|
||||
* or it may be known that all characters that are important to an
|
||||
* algorithm can be represented with single code units.
|
||||
* Other processes will need to use the code point access functions.</p>
|
||||
*
|
||||
* <p>ForwardCharacterIterator provides nextPostInc() to access
|
||||
* a code unit and advance an internal position into the text object,
|
||||
* similar to a <code>return text[position++]</code>.<br>
|
||||
* It provides next32PostInc() to access a code point and advance an internal
|
||||
* position.</p>
|
||||
*
|
||||
* <p>next32PostInc() assumes that the current position is that of
|
||||
* the beginning of a code point, i.e., of its first code unit.
|
||||
* After next32PostInc(), this will be true again.
|
||||
* In general, access to code units and code points in the same
|
||||
* iteration loop should not be mixed. In UTF-16, if the current position
|
||||
* is on a second code unit (Low Surrogate), then only that code unit
|
||||
* is returned even by next32PostInc().</p>
|
||||
*
|
||||
* <p>For iteration with either function, there are two ways to
|
||||
* check for the end of the iteration. When there are no more
|
||||
* characters in the text object:
|
||||
* <ul>
|
||||
* <li>The hasNext() function returns FALSE.</li>
|
||||
* <li>nextPostInc() and next32PostInc() return DONE
|
||||
* when one attempts to read beyond the end of the text object.</li>
|
||||
* </ul>
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
* void function1(ForwardCharacterIterator &it) {
|
||||
* UChar32 c;
|
||||
* while(it.hasNext()) {
|
||||
* c=it.next32PostInc();
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void function1(ForwardCharacterIterator &it) {
|
||||
* UChar c;
|
||||
* while((c=it.nextPostInc())!=ForwardCharacterIterator::DONE) {
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* </p>
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API ForwardCharacterIterator : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Value returned by most of ForwardCharacterIterator's functions
|
||||
* when the iterator has reached the limits of its iteration.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum { DONE = 0xffff };
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~ForwardCharacterIterator();
|
||||
|
||||
/**
|
||||
* Returns true when both iterators refer to the same
|
||||
* character in the same character-storage object.
|
||||
* @param that The ForwardCharacterIterator to be compared for equality
|
||||
* @return true when both iterators refer to the same
|
||||
* character in the same character-storage object
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const ForwardCharacterIterator& that) const = 0;
|
||||
|
||||
/**
|
||||
* Returns true when the iterators refer to different
|
||||
* text-storage objects, or to different characters in the
|
||||
* same text-storage object.
|
||||
* @param that The ForwardCharacterIterator to be compared for inequality
|
||||
* @return true when the iterators refer to different
|
||||
* text-storage objects, or to different characters in the
|
||||
* same text-storage object
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline UBool operator!=(const ForwardCharacterIterator& that) const;
|
||||
|
||||
/**
|
||||
* Generates a hash code for this iterator.
|
||||
* @return the hash code.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t hashCode(void) const = 0;
|
||||
|
||||
/**
|
||||
* Returns a UClassID for this ForwardCharacterIterator ("poor man's
|
||||
* RTTI").<P> Despite the fact that this function is public,
|
||||
* DO NOT CONSIDER IT PART OF CHARACTERITERATOR'S API!
|
||||
* @return a UClassID for this ForwardCharacterIterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the current code unit for returning and advances to the next code unit
|
||||
* in the iteration range
|
||||
* (toward endIndex()). If there are
|
||||
* no more code units to return, returns DONE.
|
||||
* @return the current code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar nextPostInc(void) = 0;
|
||||
|
||||
/**
|
||||
* Gets the current code point for returning and advances to the next code point
|
||||
* in the iteration range
|
||||
* (toward endIndex()). If there are
|
||||
* no more code points to return, returns DONE.
|
||||
* @return the current code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 next32PostInc(void) = 0;
|
||||
|
||||
/**
|
||||
* Returns FALSE if there are no more code units or code points
|
||||
* at or after the current position in the iteration range.
|
||||
* This is used with nextPostInc() or next32PostInc() in forward
|
||||
* iteration.
|
||||
* @returns FALSE if there are no more code units or code points
|
||||
* at or after the current position in the iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool hasNext() = 0;
|
||||
|
||||
protected:
|
||||
/** Default constructor to be overridden in the implementing class. @stable ICU 2.0*/
|
||||
ForwardCharacterIterator();
|
||||
|
||||
/** Copy constructor to be overridden in the implementing class. @stable ICU 2.0*/
|
||||
ForwardCharacterIterator(const ForwardCharacterIterator &other);
|
||||
|
||||
/**
|
||||
* Assignment operator to be overridden in the implementing class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract class that defines an API for iteration
|
||||
* on text objects.
|
||||
* This is an interface for forward and backward iteration
|
||||
* and random access into a text object.
|
||||
*
|
||||
* <p>The API provides backward compatibility to the Java and older ICU
|
||||
* CharacterIterator classes but extends them significantly:
|
||||
* <ol>
|
||||
* <li>CharacterIterator is now a subclass of ForwardCharacterIterator.</li>
|
||||
* <li>While the old API functions provided forward iteration with
|
||||
* "pre-increment" semantics, the new one also provides functions
|
||||
* with "post-increment" semantics. They are more efficient and should
|
||||
* be the preferred iterator functions for new implementations.
|
||||
* The backward iteration always had "pre-decrement" semantics, which
|
||||
* are efficient.</li>
|
||||
* <li>Just like ForwardCharacterIterator, it provides access to
|
||||
* both code units and code points. Code point access versions are available
|
||||
* for the old and the new iteration semantics.</li>
|
||||
* <li>There are new functions for setting and moving the current position
|
||||
* without returning a character, for efficiency.</li>
|
||||
* </ol>
|
||||
*
|
||||
* See ForwardCharacterIterator for examples for using the new forward iteration
|
||||
* functions. For backward iteration, there is also a hasPrevious() function
|
||||
* that can be used analogously to hasNext().
|
||||
* The old functions work as before and are shown below.</p>
|
||||
*
|
||||
* <p>Examples for some of the new functions:</p>
|
||||
*
|
||||
* Forward iteration with hasNext():
|
||||
* \code
|
||||
* void forward1(CharacterIterator &it) {
|
||||
* UChar32 c;
|
||||
* for(it.setToStart(); it.hasNext();) {
|
||||
* c=it.next32PostInc();
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* Forward iteration more similar to loops with the old forward iteration,
|
||||
* showing a way to convert simple for() loops:
|
||||
* \code
|
||||
* void forward2(CharacterIterator &it) {
|
||||
* UChar c;
|
||||
* for(c=it.firstPostInc(); c!=CharacterIterator::DONE; c=it.nextPostInc()) {
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* Backward iteration with setToEnd() and hasPrevious():
|
||||
* \code
|
||||
* void backward1(CharacterIterator &it) {
|
||||
* UChar32 c;
|
||||
* for(it.setToEnd(); it.hasPrevious();) {
|
||||
* c=it.previous32();
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* Backward iteration with a more traditional for() loop:
|
||||
* \code
|
||||
* void backward2(CharacterIterator &it) {
|
||||
* UChar c;
|
||||
* for(c=it.last(); c!=CharacterIterator::DONE; c=it.previous()) {
|
||||
* // use c
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* Example for random access:
|
||||
* \code
|
||||
* void random(CharacterIterator &it) {
|
||||
* // set to the third code point from the beginning
|
||||
* it.move32(3, CharacterIterator::kStart);
|
||||
* // get a code point from here without moving the position
|
||||
* UChar32 c=it.current32();
|
||||
* // get the position
|
||||
* int32_t pos=it.getIndex();
|
||||
* // get the previous code unit
|
||||
* UChar u=it.previous();
|
||||
* // move back one more code unit
|
||||
* it.move(-1, CharacterIterator::kCurrent);
|
||||
* // set the position back to where it was
|
||||
* // and read the same code point c and move beyond it
|
||||
* it.setIndex(pos);
|
||||
* if(c!=it.next32PostInc()) {
|
||||
* exit(1); // CharacterIterator inconsistent
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* <p>Examples, especially for the old API:</p>
|
||||
*
|
||||
* Function processing characters, in this example simple output
|
||||
* <pre>
|
||||
* \code
|
||||
* void processChar( UChar c )
|
||||
* {
|
||||
* cout << " " << c;
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* Traverse the text from start to finish
|
||||
* <pre>
|
||||
* \code
|
||||
* void traverseForward(CharacterIterator& iter)
|
||||
* {
|
||||
* for(UChar c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
|
||||
* processChar(c);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* Traverse the text backwards, from end to start
|
||||
* <pre>
|
||||
* \code
|
||||
* void traverseBackward(CharacterIterator& iter)
|
||||
* {
|
||||
* for(UChar c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
|
||||
* processChar(c);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* Traverse both forward and backward from a given position in the text.
|
||||
* Calls to notBoundary() in this example represents some additional stopping criteria.
|
||||
* <pre>
|
||||
* \code
|
||||
* void traverseOut(CharacterIterator& iter, int32_t pos)
|
||||
* {
|
||||
* UChar c;
|
||||
* for (c = iter.setIndex(pos);
|
||||
* c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
|
||||
* c = iter.next()) {}
|
||||
* int32_t end = iter.getIndex();
|
||||
* for (c = iter.setIndex(pos);
|
||||
* c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
|
||||
* c = iter.previous()) {}
|
||||
* int32_t start = iter.getIndex() + 1;
|
||||
*
|
||||
* cout << "start: " << start << " end: " << end << endl;
|
||||
* for (c = iter.setIndex(start); iter.getIndex() < end; c = iter.next() ) {
|
||||
* processChar(c);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* Creating a StringCharacterIterator and calling the test functions
|
||||
* <pre>
|
||||
* \code
|
||||
* void CharacterIterator_Example( void )
|
||||
* {
|
||||
* cout << endl << "===== CharacterIterator_Example: =====" << endl;
|
||||
* UnicodeString text("Ein kleiner Satz.");
|
||||
* StringCharacterIterator iterator(text);
|
||||
* cout << "----- traverseForward: -----------" << endl;
|
||||
* traverseForward( iterator );
|
||||
* cout << endl << endl << "----- traverseBackward: ----------" << endl;
|
||||
* traverseBackward( iterator );
|
||||
* cout << endl << endl << "----- traverseOut: ---------------" << endl;
|
||||
* traverseOut( iterator, 7 );
|
||||
* cout << endl << endl << "-----" << endl;
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API CharacterIterator : public ForwardCharacterIterator {
|
||||
public:
|
||||
/**
|
||||
* Origin enumeration for the move() and move32() functions.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum EOrigin { kStart, kCurrent, kEnd };
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~CharacterIterator();
|
||||
|
||||
/**
|
||||
* Returns a pointer to a new CharacterIterator of the same
|
||||
* concrete class as this one, and referring to the same
|
||||
* character in the same text-storage object as this one. The
|
||||
* caller is responsible for deleting the new clone.
|
||||
* @return a pointer to a new CharacterIterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual CharacterIterator* clone(void) const = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first code unit in its
|
||||
* iteration range, and returns that code unit.
|
||||
* This can be used to begin an iteration with next().
|
||||
* @return the first code unit in its iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar first(void) = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first code unit in its
|
||||
* iteration range, returns that code unit, and moves the position
|
||||
* to the second code unit. This is an alternative to setToStart()
|
||||
* for forward iteration with nextPostInc().
|
||||
* @return the first code unit in its iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar firstPostInc(void);
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first code point in its
|
||||
* iteration range, and returns that code unit,
|
||||
* This can be used to begin an iteration with next32().
|
||||
* Note that an iteration with next32PostInc(), beginning with,
|
||||
* e.g., setToStart() or firstPostInc(), is more efficient.
|
||||
* @return the first code point in its iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 first32(void) = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first code point in its
|
||||
* iteration range, returns that code point, and moves the position
|
||||
* to the second code point. This is an alternative to setToStart()
|
||||
* for forward iteration with next32PostInc().
|
||||
* @return the first code point in its iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 first32PostInc(void);
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first code unit or code point in its
|
||||
* iteration range. This can be used to begin a forward
|
||||
* iteration with nextPostInc() or next32PostInc().
|
||||
* @return the start position of the iteration range
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t setToStart();
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the last code unit in its
|
||||
* iteration range, and returns that code unit.
|
||||
* This can be used to begin an iteration with previous().
|
||||
* @return the last code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar last(void) = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the last code point in its
|
||||
* iteration range, and returns that code unit.
|
||||
* This can be used to begin an iteration with previous32().
|
||||
* @return the last code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 last32(void) = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to the end of its iteration range, just behind
|
||||
* the last code unit or code point. This can be used to begin a backward
|
||||
* iteration with previous() or previous32().
|
||||
* @return the end position of the iteration range
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t setToEnd();
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the "position"-th code unit
|
||||
* in the text-storage object the iterator refers to, and
|
||||
* returns that code unit.
|
||||
* @param position the "position"-th code unit in the text-storage object
|
||||
* @return the "position"-th code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar setIndex(int32_t position) = 0;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the beginning of the code point
|
||||
* that contains the "position"-th code unit
|
||||
* in the text-storage object the iterator refers to, and
|
||||
* returns that code point.
|
||||
* The current position is adjusted to the beginning of the code point
|
||||
* (its first code unit).
|
||||
* @param position the "position"-th code unit in the text-storage object
|
||||
* @return the "position"-th code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 setIndex32(int32_t position) = 0;
|
||||
|
||||
/**
|
||||
* Returns the code unit the iterator currently refers to.
|
||||
* @return the current code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar current(void) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the code point the iterator currently refers to.
|
||||
* @return the current code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 current32(void) const = 0;
|
||||
|
||||
/**
|
||||
* Advances to the next code unit in the iteration range
|
||||
* (toward endIndex()), and returns that code unit. If there are
|
||||
* no more code units to return, returns DONE.
|
||||
* @return the next code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar next(void) = 0;
|
||||
|
||||
/**
|
||||
* Advances to the next code point in the iteration range
|
||||
* (toward endIndex()), and returns that code point. If there are
|
||||
* no more code points to return, returns DONE.
|
||||
* Note that iteration with "pre-increment" semantics is less
|
||||
* efficient than iteration with "post-increment" semantics
|
||||
* that is provided by next32PostInc().
|
||||
* @return the next code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 next32(void) = 0;
|
||||
|
||||
/**
|
||||
* Advances to the previous code unit in the iteration range
|
||||
* (toward startIndex()), and returns that code unit. If there are
|
||||
* no more code units to return, returns DONE.
|
||||
* @return the previous code unit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar previous(void) = 0;
|
||||
|
||||
/**
|
||||
* Advances to the previous code point in the iteration range
|
||||
* (toward startIndex()), and returns that code point. If there are
|
||||
* no more code points to return, returns DONE.
|
||||
* @return the previous code point.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UChar32 previous32(void) = 0;
|
||||
|
||||
/**
|
||||
* Returns FALSE if there are no more code units or code points
|
||||
* before the current position in the iteration range.
|
||||
* This is used with previous() or previous32() in backward
|
||||
* iteration.
|
||||
* @return FALSE if there are no more code units or code points
|
||||
* before the current position in the iteration range, return TRUE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool hasPrevious() = 0;
|
||||
|
||||
/**
|
||||
* Returns the numeric index in the underlying text-storage
|
||||
* object of the character returned by first(). Since it's
|
||||
* possible to create an iterator that iterates across only
|
||||
* part of a text-storage object, this number isn't
|
||||
* necessarily 0.
|
||||
* @returns the numeric index in the underlying text-storage
|
||||
* object of the character returned by first().
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t startIndex(void) const;
|
||||
|
||||
/**
|
||||
* Returns the numeric index in the underlying text-storage
|
||||
* object of the position immediately BEYOND the character
|
||||
* returned by last().
|
||||
* @return the numeric index in the underlying text-storage
|
||||
* object of the position immediately BEYOND the character
|
||||
* returned by last().
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t endIndex(void) const;
|
||||
|
||||
/**
|
||||
* Returns the numeric index in the underlying text-storage
|
||||
* object of the character the iterator currently refers to
|
||||
* (i.e., the character returned by current()).
|
||||
* @return the numberic index in the text-storage object of
|
||||
* the character the iterator currently refers to
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t getIndex(void) const;
|
||||
|
||||
/**
|
||||
* Returns the length of the entire text in the underlying
|
||||
* text-storage object.
|
||||
* @return the length of the entire text in the text-storage object
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline int32_t getLength() const;
|
||||
|
||||
/**
|
||||
* Moves the current position relative to the start or end of the
|
||||
* iteration range, or relative to the current position itself.
|
||||
* The movement is expressed in numbers of code units forward
|
||||
* or backward by specifying a positive or negative delta.
|
||||
* @param delta the position relative to origin. A positive delta means forward;
|
||||
* a negative delta means backward.
|
||||
* @param origin Origin enumeration {kStart, kCurrent, kEnd}
|
||||
* @return the new position
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t move(int32_t delta, EOrigin origin) = 0;
|
||||
|
||||
/**
|
||||
* Moves the current position relative to the start or end of the
|
||||
* iteration range, or relative to the current position itself.
|
||||
* The movement is expressed in numbers of code points forward
|
||||
* or backward by specifying a positive or negative delta.
|
||||
* @param delta the position relative to origin. A positive delta means forward;
|
||||
* a negative delta means backward.
|
||||
* @param origin Origin enumeration {kStart, kCurrent, kEnd}
|
||||
* @return the new position
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t move32(int32_t delta, EOrigin origin) = 0;
|
||||
|
||||
/**
|
||||
* Copies the text under iteration into the UnicodeString
|
||||
* referred to by "result".
|
||||
* @param result Receives a copy of the text under iteration.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void getText(UnicodeString& result) = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Empty constructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator();
|
||||
|
||||
/**
|
||||
* Constructor, just setting the length field in this base class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator(int32_t length);
|
||||
|
||||
/**
|
||||
* Constructor, just setting the length and position fields in this base class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator(int32_t length, int32_t position);
|
||||
|
||||
/**
|
||||
* Constructor, just setting the length, start, end, and position fields in this base class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param that The CharacterIterator to be copied
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator(const CharacterIterator &that);
|
||||
|
||||
/**
|
||||
* Assignment operator. Sets this CharacterIterator to have the same behavior,
|
||||
* as the one passed in.
|
||||
* @param that The CharacterIterator passed in.
|
||||
* @return the newly set CharacterIterator.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CharacterIterator &operator=(const CharacterIterator &that);
|
||||
|
||||
/**
|
||||
* Base class text length field.
|
||||
* Necessary this for correct getText() and hashCode().
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t textLength;
|
||||
|
||||
/**
|
||||
* Base class field for the current position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t pos;
|
||||
|
||||
/**
|
||||
* Base class field for the start of the iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t begin;
|
||||
|
||||
/**
|
||||
* Base class field for the end of the iteration range.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t end;
|
||||
};
|
||||
|
||||
inline UBool
|
||||
ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const {
|
||||
return !operator==(that);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::setToStart() {
|
||||
return move(0, kStart);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::setToEnd() {
|
||||
return move(0, kEnd);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::startIndex(void) const {
|
||||
return begin;
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::endIndex(void) const {
|
||||
return end;
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::getIndex(void) const {
|
||||
return pos;
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
CharacterIterator::getLength(void) const {
|
||||
return textLength;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,594 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File CHOICFMT.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 03/20/97 helena Finished first cut of implementation and got rid
|
||||
* of nextDouble/previousDouble and replaced with
|
||||
* boolean array.
|
||||
* 4/10/97 aliu Clean up. Modified to work on AIX.
|
||||
* 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
|
||||
* 07/22/98 stephen Removed operator!= (implemented in Format)
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CHOICFMT_H
|
||||
#define CHOICFMT_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Choice Format.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
|
||||
#include "unicode/fieldpos.h"
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/messagepattern.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class MessageFormat;
|
||||
|
||||
/**
|
||||
* ChoiceFormat converts between ranges of numeric values and strings for those ranges.
|
||||
* The strings must conform to the MessageFormat pattern syntax.
|
||||
*
|
||||
* <p><em><code>ChoiceFormat</code> is probably not what you need.
|
||||
* Please use <code>MessageFormat</code>
|
||||
* with <code>plural</code> arguments for proper plural selection,
|
||||
* and <code>select</code> arguments for simple selection among a fixed set of choices!</em></p>
|
||||
*
|
||||
* <p>A <code>ChoiceFormat</code> splits
|
||||
* the real number line \htmlonly<code>-∞</code> to
|
||||
* <code>+∞</code>\endhtmlonly into two
|
||||
* or more contiguous ranges. Each range is mapped to a
|
||||
* string.</p>
|
||||
*
|
||||
* <p><code>ChoiceFormat</code> was originally intended
|
||||
* for displaying grammatically correct
|
||||
* plurals such as "There is one file." vs. "There are 2 files."
|
||||
* <em>However,</em> plural rules for many languages
|
||||
* are too complex for the capabilities of ChoiceFormat,
|
||||
* and its requirement of specifying the precise rules for each message
|
||||
* is unmanageable for translators.</p>
|
||||
*
|
||||
* <p>There are two methods of defining a <code>ChoiceFormat</code>; both
|
||||
* are equivalent. The first is by using a string pattern. This is the
|
||||
* preferred method in most cases. The second method is through direct
|
||||
* specification of the arrays that logically make up the
|
||||
* <code>ChoiceFormat</code>.</p>
|
||||
*
|
||||
* <p>Note: Typically, choice formatting is done (if done at all) via <code>MessageFormat</code>
|
||||
* with a <code>choice</code> argument type,
|
||||
* rather than using a stand-alone <code>ChoiceFormat</code>.</p>
|
||||
*
|
||||
* <h5>Patterns and Their Interpretation</h5>
|
||||
*
|
||||
* <p>The pattern string defines the range boundaries and the strings for each number range.
|
||||
* Syntax:
|
||||
* <pre>
|
||||
* choiceStyle = number separator message ('|' number separator message)*
|
||||
* number = normal_number | ['-'] \htmlonly∞\endhtmlonly (U+221E, infinity)
|
||||
* normal_number = double value (unlocalized ASCII string)
|
||||
* separator = less_than | less_than_or_equal
|
||||
* less_than = '<'
|
||||
* less_than_or_equal = '#' | \htmlonly≤\endhtmlonly (U+2264)
|
||||
* message: see {@link MessageFormat}
|
||||
* </pre>
|
||||
* Pattern_White_Space between syntax elements is ignored, except
|
||||
* around each range's sub-message.</p>
|
||||
*
|
||||
* <p>Each numeric sub-range extends from the current range's number
|
||||
* to the next range's number.
|
||||
* The number itself is included in its range if a <code>less_than_or_equal</code> sign is used,
|
||||
* and excluded from its range (and instead included in the previous range)
|
||||
* if a <code>less_than</code> sign is used.</p>
|
||||
*
|
||||
* <p>When a <code>ChoiceFormat</code> is constructed from
|
||||
* arrays of numbers, closure flags and strings,
|
||||
* they are interpreted just like
|
||||
* the sequence of <code>(number separator string)</code> in an equivalent pattern string.
|
||||
* <code>closure[i]==TRUE</code> corresponds to a <code>less_than</code> separator sign.
|
||||
* The equivalent pattern string will be constructed automatically.</p>
|
||||
*
|
||||
* <p>During formatting, a number is mapped to the first range
|
||||
* where the number is not greater than the range's upper limit.
|
||||
* That range's message string is returned. A NaN maps to the very first range.</p>
|
||||
*
|
||||
* <p>During parsing, a range is selected for the longest match of
|
||||
* any range's message. That range's number is returned, ignoring the separator/closure.
|
||||
* Only a simple string match is performed, without parsing of arguments that
|
||||
* might be specified in the message strings.</p>
|
||||
*
|
||||
* <p>Note that the first range's number is ignored in formatting
|
||||
* but may be returned from parsing.</p>
|
||||
*
|
||||
* <h5>Examples</h5>
|
||||
*
|
||||
* <p>Here is an example of two arrays that map the number
|
||||
* <code>1..7</code> to the English day of the week abbreviations
|
||||
* <code>Sun..Sat</code>. No closures array is given; this is the same as
|
||||
* specifying all closures to be <code>FALSE</code>.</p>
|
||||
*
|
||||
* <pre> {1,2,3,4,5,6,7},
|
||||
* {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}</pre>
|
||||
*
|
||||
* <p>Here is an example that maps the ranges [-Inf, 1), [1, 1], and (1,
|
||||
* +Inf] to three strings. That is, the number line is split into three
|
||||
* ranges: x < 1.0, x = 1.0, and x > 1.0.
|
||||
* (The round parentheses in the notation above indicate an exclusive boundary,
|
||||
* like the turned bracket in European notation: [-Inf, 1) == [-Inf, 1[ )</p>
|
||||
*
|
||||
* <pre> {0, 1, 1},
|
||||
* {FALSE, FALSE, TRUE},
|
||||
* {"no files", "one file", "many files"}</pre>
|
||||
*
|
||||
* <p>Here is an example that shows formatting and parsing: </p>
|
||||
*
|
||||
* \code
|
||||
* #include <unicode/choicfmt.h>
|
||||
* #include <unicode/unistr.h>
|
||||
* #include <iostream.h>
|
||||
*
|
||||
* int main(int argc, char *argv[]) {
|
||||
* double limits[] = {1,2,3,4,5,6,7};
|
||||
* UnicodeString monthNames[] = {
|
||||
* "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
|
||||
* ChoiceFormat fmt(limits, monthNames, 7);
|
||||
* UnicodeString str;
|
||||
* char buf[256];
|
||||
* for (double x = 1.0; x <= 8.0; x += 1.0) {
|
||||
* fmt.format(x, str);
|
||||
* str.extract(0, str.length(), buf, 256, "");
|
||||
* str.truncate(0);
|
||||
* cout << x << " -> "
|
||||
* << buf << endl;
|
||||
* }
|
||||
* cout << endl;
|
||||
* return 0;
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* <p><em>User subclasses are not supported.</em> While clients may write
|
||||
* subclasses, such code will not necessarily work and will not be
|
||||
* guaranteed to work stably from release to release.
|
||||
*
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
class U_I18N_API ChoiceFormat: public NumberFormat {
|
||||
public:
|
||||
/**
|
||||
* Constructs a new ChoiceFormat from the pattern string.
|
||||
*
|
||||
* @param pattern Pattern used to construct object.
|
||||
* @param status Output param to receive success code. If the
|
||||
* pattern cannot be parsed, set to failure code.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
ChoiceFormat(const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new ChoiceFormat with the given limits and message strings.
|
||||
* All closure flags default to <code>FALSE</code>,
|
||||
* equivalent to <code>less_than_or_equal</code> separators.
|
||||
*
|
||||
* Copies the limits and formats instead of adopting them.
|
||||
*
|
||||
* @param limits Array of limit values.
|
||||
* @param formats Array of formats.
|
||||
* @param count Size of 'limits' and 'formats' arrays.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
ChoiceFormat(const double* limits,
|
||||
const UnicodeString* formats,
|
||||
int32_t count );
|
||||
|
||||
/**
|
||||
* Constructs a new ChoiceFormat with the given limits, closure flags and message strings.
|
||||
*
|
||||
* Copies the limits and formats instead of adopting them.
|
||||
*
|
||||
* @param limits Array of limit values
|
||||
* @param closures Array of booleans specifying whether each
|
||||
* element of 'limits' is open or closed. If FALSE, then the
|
||||
* corresponding limit number is a member of its range.
|
||||
* If TRUE, then the limit number belongs to the previous range it.
|
||||
* @param formats Array of formats
|
||||
* @param count Size of 'limits', 'closures', and 'formats' arrays
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
ChoiceFormat(const double* limits,
|
||||
const UBool* closures,
|
||||
const UnicodeString* formats,
|
||||
int32_t count);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param that ChoiceFormat object to be copied from
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
ChoiceFormat(const ChoiceFormat& that);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*
|
||||
* @param that ChoiceFormat object to be copied
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
const ChoiceFormat& operator=(const ChoiceFormat& that);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual ~ChoiceFormat();
|
||||
|
||||
/**
|
||||
* Clones this Format object. The caller owns the
|
||||
* result and must delete it when done.
|
||||
*
|
||||
* @return a copy of this object
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual Format* clone(void) const;
|
||||
|
||||
/**
|
||||
* Returns true if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
*
|
||||
* @param other ChoiceFormat object to be compared
|
||||
* @return true if other is the same as this.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Sets the pattern.
|
||||
* @param pattern The pattern to be applied.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual void applyPattern(const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Sets the pattern.
|
||||
* @param pattern The pattern to be applied.
|
||||
* @param parseError Struct to receive information on position
|
||||
* of error if an error is encountered
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual void applyPattern(const UnicodeString& pattern,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
/**
|
||||
* Gets the pattern.
|
||||
*
|
||||
* @param pattern Output param which will receive the pattern
|
||||
* Previous contents are deleted.
|
||||
* @return A reference to 'pattern'
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UnicodeString& toPattern(UnicodeString &pattern) const;
|
||||
|
||||
/**
|
||||
* Sets the choices to be used in formatting.
|
||||
* For details see the constructor with the same parameter list.
|
||||
*
|
||||
* @param limitsToCopy Contains the top value that you want
|
||||
* parsed with that format,and should be in
|
||||
* ascending sorted order. When formatting X,
|
||||
* the choice will be the i, where limit[i]
|
||||
* <= X < limit[i+1].
|
||||
* @param formatsToCopy The format strings you want to use for each limit.
|
||||
* @param count The size of the above arrays.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual void setChoices(const double* limitsToCopy,
|
||||
const UnicodeString* formatsToCopy,
|
||||
int32_t count );
|
||||
|
||||
/**
|
||||
* Sets the choices to be used in formatting.
|
||||
* For details see the constructor with the same parameter list.
|
||||
*
|
||||
* @param limits Array of limits
|
||||
* @param closures Array of limit booleans
|
||||
* @param formats Array of format string
|
||||
* @param count The size of the above arrays
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual void setChoices(const double* limits,
|
||||
const UBool* closures,
|
||||
const UnicodeString* formats,
|
||||
int32_t count);
|
||||
|
||||
/**
|
||||
* Returns NULL and 0.
|
||||
* Before ICU 4.8, this used to return the choice limits array.
|
||||
*
|
||||
* @param count Will be set to 0.
|
||||
* @return NULL
|
||||
* @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
|
||||
*/
|
||||
virtual const double* getLimits(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Returns NULL and 0.
|
||||
* Before ICU 4.8, this used to return the limit booleans array.
|
||||
*
|
||||
* @param count Will be set to 0.
|
||||
* @return NULL
|
||||
* @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
|
||||
*/
|
||||
virtual const UBool* getClosures(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Returns NULL and 0.
|
||||
* Before ICU 4.8, this used to return the array of choice strings.
|
||||
*
|
||||
* @param count Will be set to 0.
|
||||
* @return NULL
|
||||
* @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
|
||||
*/
|
||||
virtual const UnicodeString* getFormats(int32_t& count) const;
|
||||
|
||||
|
||||
using NumberFormat::format;
|
||||
|
||||
/**
|
||||
* Formats a double number using this object's choices.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
/**
|
||||
* Formats an int32_t number using this object's choices.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UnicodeString& format(int32_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Formats an int64_t number using this object's choices.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UnicodeString& format(int64_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Formats an array of objects using this object's choices.
|
||||
*
|
||||
* @param objs The array of objects to be formatted.
|
||||
* @param cnt The size of objs.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param success Output param set to success/failure code on
|
||||
* exit.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable* objs,
|
||||
int32_t cnt,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& success) const;
|
||||
|
||||
using NumberFormat::parse;
|
||||
|
||||
/**
|
||||
* Looks for the longest match of any message string on the input text and,
|
||||
* if there is a match, sets the result object to the corresponding range's number.
|
||||
*
|
||||
* If no string matches, then the parsePosition is unchanged.
|
||||
*
|
||||
* @param text The text to be parsed.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parsePosition The position to start parsing at on input.
|
||||
* On output, moved to after the last successfully
|
||||
* parse character. On parse failure, does not change.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const;
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Part of ICU's "poor man's RTTI".
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Returns the class ID for this class. This is useful only for
|
||||
* comparing to a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . Derived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Converts a double value to a string.
|
||||
* @param value the double number to be converted.
|
||||
* @param string the result string.
|
||||
* @return the converted string.
|
||||
*/
|
||||
static UnicodeString& dtos(double value, UnicodeString& string);
|
||||
|
||||
ChoiceFormat(); // default constructor not implemented
|
||||
|
||||
/**
|
||||
* Construct a new ChoiceFormat with the limits and the corresponding formats
|
||||
* based on the pattern.
|
||||
*
|
||||
* @param newPattern Pattern used to construct object.
|
||||
* @param parseError Struct to receive information on position
|
||||
* of error if an error is encountered.
|
||||
* @param status Output param to receive success code. If the
|
||||
* pattern cannot be parsed, set to failure code.
|
||||
*/
|
||||
ChoiceFormat(const UnicodeString& newPattern,
|
||||
UParseError& parseError,
|
||||
UErrorCode& status);
|
||||
|
||||
friend class MessageFormat;
|
||||
|
||||
virtual void setChoices(const double* limits,
|
||||
const UBool* closures,
|
||||
const UnicodeString* formats,
|
||||
int32_t count,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Finds the ChoiceFormat sub-message for the given number.
|
||||
* @param pattern A MessagePattern.
|
||||
* @param partIndex the index of the first ChoiceFormat argument style part.
|
||||
* @param number a number to be mapped to one of the ChoiceFormat argument's intervals
|
||||
* @return the sub-message start part index.
|
||||
*/
|
||||
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
|
||||
|
||||
static double parseArgument(
|
||||
const MessagePattern &pattern, int32_t partIndex,
|
||||
const UnicodeString &source, ParsePosition &pos);
|
||||
|
||||
/**
|
||||
* Matches the pattern string from the end of the partIndex to
|
||||
* the beginning of the limitPartIndex,
|
||||
* including all syntax except SKIP_SYNTAX,
|
||||
* against the source string starting at sourceOffset.
|
||||
* If they match, returns the length of the source string match.
|
||||
* Otherwise returns -1.
|
||||
*/
|
||||
static int32_t matchStringUntilLimitPart(
|
||||
const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
|
||||
const UnicodeString &source, int32_t sourceOffset);
|
||||
|
||||
/**
|
||||
* Some of the ChoiceFormat constructors do not have a UErrorCode paramater.
|
||||
* We need _some_ way to provide one for the MessagePattern constructor.
|
||||
* Alternatively, the MessagePattern could be a pointer field, but that is
|
||||
* not nice either.
|
||||
*/
|
||||
UErrorCode constructorErrorCode;
|
||||
|
||||
/**
|
||||
* The MessagePattern which contains the parsed structure of the pattern string.
|
||||
*
|
||||
* Starting with ICU 4.8, the MessagePattern contains a sequence of
|
||||
* numeric/selector/message parts corresponding to the parsed pattern.
|
||||
* For details see the MessagePattern class API docs.
|
||||
*/
|
||||
MessagePattern msgPattern;
|
||||
|
||||
/**
|
||||
* Docs & fields from before ICU 4.8, before MessagePattern was used.
|
||||
* Commented out, and left only for explanation of semantics.
|
||||
* --------
|
||||
* Each ChoiceFormat divides the range -Inf..+Inf into fCount
|
||||
* intervals. The intervals are:
|
||||
*
|
||||
* 0: fChoiceLimits[0]..fChoiceLimits[1]
|
||||
* 1: fChoiceLimits[1]..fChoiceLimits[2]
|
||||
* ...
|
||||
* fCount-2: fChoiceLimits[fCount-2]..fChoiceLimits[fCount-1]
|
||||
* fCount-1: fChoiceLimits[fCount-1]..+Inf
|
||||
*
|
||||
* Interval 0 is special; during formatting (mapping numbers to
|
||||
* strings), it also contains all numbers less than
|
||||
* fChoiceLimits[0], as well as NaN values.
|
||||
*
|
||||
* Interval i maps to and from string fChoiceFormats[i]. When
|
||||
* parsing (mapping strings to numbers), then intervals map to
|
||||
* their lower limit, that is, interval i maps to fChoiceLimit[i].
|
||||
*
|
||||
* The intervals may be closed, half open, or open. This affects
|
||||
* formatting but does not affect parsing. Interval i is affected
|
||||
* by fClosures[i] and fClosures[i+1]. If fClosures[i]
|
||||
* is FALSE, then the value fChoiceLimits[i] is in interval i.
|
||||
* That is, intervals i and i are:
|
||||
*
|
||||
* i-1: ... x < fChoiceLimits[i]
|
||||
* i: fChoiceLimits[i] <= x ...
|
||||
*
|
||||
* If fClosures[i] is TRUE, then the value fChoiceLimits[i] is
|
||||
* in interval i-1. That is, intervals i-1 and i are:
|
||||
*
|
||||
* i-1: ... x <= fChoiceLimits[i]
|
||||
* i: fChoiceLimits[i] < x ...
|
||||
*
|
||||
* Because of the nature of interval 0, fClosures[0] has no
|
||||
* effect.
|
||||
*/
|
||||
// double* fChoiceLimits;
|
||||
// UBool* fClosures;
|
||||
// UnicodeString* fChoiceFormats;
|
||||
// int32_t fCount;
|
||||
};
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // U_HIDE_DEPRECATED_API
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // CHOICFMT_H
|
||||
//eof
|
||||
@@ -1,384 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Collation Element Iterator.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File coleitr.h
|
||||
*
|
||||
*
|
||||
*
|
||||
* Created by: Helena Shih
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
*
|
||||
* 8/18/97 helena Added internal API documentation.
|
||||
* 08/03/98 erm Synched with 1.2 version CollationElementIterator.java
|
||||
* 12/10/99 aliu Ported Thai collation support from Java.
|
||||
* 01/25/01 swquek Modified into a C++ wrapper calling C APIs (ucoliter.h)
|
||||
* 02/19/01 swquek Removed CollationElementsIterator() since it is
|
||||
* private constructor and no calls are made to it
|
||||
*/
|
||||
|
||||
#ifndef COLEITR_H
|
||||
#define COLEITR_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/tblcoll.h"
|
||||
#include "unicode/ucoleitr.h"
|
||||
|
||||
/**
|
||||
* The UCollationElements struct.
|
||||
* For usage in C programs.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
typedef struct UCollationElements UCollationElements;
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* The CollationElementIterator class is used as an iterator to walk through
|
||||
* each character of an international string. Use the iterator to return the
|
||||
* ordering priority of the positioned character. The ordering priority of a
|
||||
* character, which we refer to as a key, defines how a character is collated in
|
||||
* the given collation object.
|
||||
* For example, consider the following in Spanish:
|
||||
* <pre>
|
||||
* "ca" -> the first key is key('c') and second key is key('a').
|
||||
* "cha" -> the first key is key('ch') and second key is key('a').</pre>
|
||||
* And in German,
|
||||
* <pre> \htmlonly "æb"-> the first key is key('a'), the second key is key('e'), and
|
||||
* the third key is key('b'). \endhtmlonly </pre>
|
||||
* The key of a character, is an integer composed of primary order(short),
|
||||
* secondary order(char), and tertiary order(char). Java strictly defines the
|
||||
* size and signedness of its primitive data types. Therefore, the static
|
||||
* functions primaryOrder(), secondaryOrder(), and tertiaryOrder() return
|
||||
* int32_t to ensure the correctness of the key value.
|
||||
* <p>Example of the iterator usage: (without error checking)
|
||||
* <pre>
|
||||
* \code
|
||||
* void CollationElementIterator_Example()
|
||||
* {
|
||||
* UnicodeString str = "This is a test";
|
||||
* UErrorCode success = U_ZERO_ERROR;
|
||||
* RuleBasedCollator* rbc =
|
||||
* (RuleBasedCollator*) RuleBasedCollator::createInstance(success);
|
||||
* CollationElementIterator* c =
|
||||
* rbc->createCollationElementIterator( str );
|
||||
* int32_t order = c->next(success);
|
||||
* c->reset();
|
||||
* order = c->previous(success);
|
||||
* delete c;
|
||||
* delete rbc;
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* <p>
|
||||
* The method next() returns the collation order of the next character based on
|
||||
* the comparison level of the collator. The method previous() returns the
|
||||
* collation order of the previous character based on the comparison level of
|
||||
* the collator. The Collation Element Iterator moves only in one direction
|
||||
* between calls to reset(), setOffset(), or setText(). That is, next()
|
||||
* and previous() can not be inter-used. Whenever previous() is to be called after
|
||||
* next() or vice versa, reset(), setOffset() or setText() has to be called first
|
||||
* to reset the status, shifting pointers to either the end or the start of
|
||||
* the string (reset() or setText()), or the specified position (setOffset()).
|
||||
* Hence at the next call of next() or previous(), the first or last collation order,
|
||||
* or collation order at the spefcifieid position will be returned. If a change of
|
||||
* direction is done without one of these calls, the result is undefined.
|
||||
* <p>
|
||||
* The result of a forward iterate (next()) and reversed result of the backward
|
||||
* iterate (previous()) on the same string are equivalent, if collation orders
|
||||
* with the value UCOL_IGNORABLE are ignored.
|
||||
* Character based on the comparison level of the collator. A collation order
|
||||
* consists of primary order, secondary order and tertiary order. The data
|
||||
* type of the collation order is <strong>t_int32</strong>.
|
||||
*
|
||||
* Note, CollationElementIterator should not be subclassed.
|
||||
* @see Collator
|
||||
* @see RuleBasedCollator
|
||||
* @version 1.8 Jan 16 2001
|
||||
*/
|
||||
class U_I18N_API CollationElementIterator : public UObject {
|
||||
public:
|
||||
|
||||
// CollationElementIterator public data member ------------------------------
|
||||
|
||||
enum {
|
||||
/**
|
||||
* NULLORDER indicates that an error has occured while processing
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
NULLORDER = (int32_t)0xffffffff
|
||||
};
|
||||
|
||||
// CollationElementIterator public constructor/destructor -------------------
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param other the object to be copied from
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
CollationElementIterator(const CollationElementIterator& other);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~CollationElementIterator();
|
||||
|
||||
// CollationElementIterator public methods ----------------------------------
|
||||
|
||||
/**
|
||||
* Returns true if "other" is the same as "this"
|
||||
*
|
||||
* @param other the object to be compared
|
||||
* @return true if "other" is the same as "this"
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const CollationElementIterator& other) const;
|
||||
|
||||
/**
|
||||
* Returns true if "other" is not the same as "this".
|
||||
*
|
||||
* @param other the object to be compared
|
||||
* @return true if "other" is not the same as "this"
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const CollationElementIterator& other) const;
|
||||
|
||||
/**
|
||||
* Resets the cursor to the beginning of the string.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void reset(void);
|
||||
|
||||
/**
|
||||
* Gets the ordering priority of the next character in the string.
|
||||
* @param status the error code status.
|
||||
* @return the next character's ordering. otherwise returns NULLORDER if an
|
||||
* error has occured or if the end of string has been reached
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t next(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Get the ordering priority of the previous collation element in the string.
|
||||
* @param status the error code status.
|
||||
* @return the previous element's ordering. otherwise returns NULLORDER if an
|
||||
* error has occured or if the start of string has been reached
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t previous(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Gets the primary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the primary order of a collation order.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static inline int32_t primaryOrder(int32_t order);
|
||||
|
||||
/**
|
||||
* Gets the secondary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the secondary order of a collation order.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static inline int32_t secondaryOrder(int32_t order);
|
||||
|
||||
/**
|
||||
* Gets the tertiary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the tertiary order of a collation order.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static inline int32_t tertiaryOrder(int32_t order);
|
||||
|
||||
/**
|
||||
* Return the maximum length of any expansion sequences that end with the
|
||||
* specified comparison order.
|
||||
* @param order a collation order returned by previous or next.
|
||||
* @return maximum size of the expansion sequences ending with the collation
|
||||
* element or 1 if collation element does not occur at the end of any
|
||||
* expansion sequence
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getMaxExpansion(int32_t order) const;
|
||||
|
||||
/**
|
||||
* Gets the comparison order in the desired strength. Ignore the other
|
||||
* differences.
|
||||
* @param order The order value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t strengthOrder(int32_t order) const;
|
||||
|
||||
/**
|
||||
* Sets the source string.
|
||||
* @param str the source string.
|
||||
* @param status the error code status.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const UnicodeString& str, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Sets the source string.
|
||||
* @param str the source character iterator.
|
||||
* @param status the error code status.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(CharacterIterator& str, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Checks if a comparison order is ignorable.
|
||||
* @param order the collation order.
|
||||
* @return TRUE if a character is ignorable, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static inline UBool isIgnorable(int32_t order);
|
||||
|
||||
/**
|
||||
* Gets the offset of the currently processed character in the source string.
|
||||
* @return the offset of the character.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getOffset(void) const;
|
||||
|
||||
/**
|
||||
* Sets the offset of the currently processed character in the source string.
|
||||
* @param newOffset the new offset.
|
||||
* @param status the error code status.
|
||||
* @return the offset of the character.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setOffset(int32_t newOffset, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
friend class RuleBasedCollator;
|
||||
|
||||
/**
|
||||
* CollationElementIterator constructor. This takes the source string and the
|
||||
* collation object. The cursor will walk thru the source string based on the
|
||||
* predefined collation rules. If the source string is empty, NULLORDER will
|
||||
* be returned on the calls to next().
|
||||
* @param sourceText the source string.
|
||||
* @param order the collation object.
|
||||
* @param status the error code status.
|
||||
*/
|
||||
CollationElementIterator(const UnicodeString& sourceText,
|
||||
const RuleBasedCollator* order, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* CollationElementIterator constructor. This takes the source string and the
|
||||
* collation object. The cursor will walk thru the source string based on the
|
||||
* predefined collation rules. If the source string is empty, NULLORDER will
|
||||
* be returned on the calls to next().
|
||||
* @param sourceText the source string.
|
||||
* @param order the collation object.
|
||||
* @param status the error code status.
|
||||
*/
|
||||
CollationElementIterator(const CharacterIterator& sourceText,
|
||||
const RuleBasedCollator* order, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*
|
||||
* @param other the object to be copied
|
||||
*/
|
||||
const CollationElementIterator&
|
||||
operator=(const CollationElementIterator& other);
|
||||
|
||||
CollationElementIterator(); // default constructor not implemented
|
||||
|
||||
// CollationElementIterator private data members ----------------------------
|
||||
|
||||
/**
|
||||
* Data wrapper for collation elements
|
||||
*/
|
||||
UCollationElements *m_data_;
|
||||
|
||||
/**
|
||||
* Indicates if m_data_ belongs to this object.
|
||||
*/
|
||||
UBool isDataOwned_;
|
||||
};
|
||||
|
||||
// CollationElementIterator inline method defination --------------------------
|
||||
|
||||
/**
|
||||
* Get the primary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the primary order of a collation order.
|
||||
*/
|
||||
inline int32_t CollationElementIterator::primaryOrder(int32_t order)
|
||||
{
|
||||
order &= RuleBasedCollator::PRIMARYORDERMASK;
|
||||
return (order >> RuleBasedCollator::PRIMARYORDERSHIFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the secondary order of a collation order.
|
||||
*/
|
||||
inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
|
||||
{
|
||||
order = order & RuleBasedCollator::SECONDARYORDERMASK;
|
||||
return (order >> RuleBasedCollator::SECONDARYORDERSHIFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tertiary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the tertiary order of a collation order.
|
||||
*/
|
||||
inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
|
||||
{
|
||||
return (order &= RuleBasedCollator::TERTIARYORDERMASK);
|
||||
}
|
||||
|
||||
inline int32_t CollationElementIterator::getMaxExpansion(int32_t order) const
|
||||
{
|
||||
return ucol_getMaxExpansion(m_data_, (uint32_t)order);
|
||||
}
|
||||
|
||||
inline UBool CollationElementIterator::isIgnorable(int32_t order)
|
||||
{
|
||||
return (primaryOrder(order) == RuleBasedCollator::PRIMIGNORABLE);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_COLLATION */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,333 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 2012-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File COMPACTDECIMALFORMAT.H
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __COMPACT_DECIMAL_FORMAT_H__
|
||||
#define __COMPACT_DECIMAL_FORMAT_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Formats decimal numbers in compact form.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
#include "unicode/decimfmt.h"
|
||||
|
||||
struct UHashtable;
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class PluralRules;
|
||||
|
||||
/**
|
||||
* The CompactDecimalFormat produces abbreviated numbers, suitable for display in
|
||||
* environments will limited real estate. For example, 'Hits: 1.2B' instead of
|
||||
* 'Hits: 1,200,000,000'. The format will be appropriate for the given language,
|
||||
* such as "1,2 Mrd." for German.
|
||||
* <p>
|
||||
* For numbers under 1000 trillion (under 10^15, such as 123,456,789,012,345),
|
||||
* the result will be short for supported languages. However, the result may
|
||||
* sometimes exceed 7 characters, such as when there are combining marks or thin
|
||||
* characters. In such cases, the visual width in fonts should still be short.
|
||||
* <p>
|
||||
* By default, there are 3 significant digits. After creation, if more than
|
||||
* three significant digits are set (with setMaximumSignificantDigits), or if a
|
||||
* fixed number of digits are set (with setMaximumIntegerDigits or
|
||||
* setMaximumFractionDigits), then result may be wider.
|
||||
* <p>
|
||||
* At this time, parsing is not supported, and will produce a U_UNSUPPORTED_ERROR.
|
||||
* Resetting the pattern prefixes or suffixes is not supported; the method calls
|
||||
* are ignored.
|
||||
* <p>
|
||||
* @draft ICU 51
|
||||
*/
|
||||
class U_I18N_API CompactDecimalFormat : public DecimalFormat {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns a compact decimal instance for specified locale.
|
||||
* @param inLocale the given locale.
|
||||
* @param style whether to use short or long style.
|
||||
* @param status error code returned here.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static CompactDecimalFormat* U_EXPORT2 createInstance(
|
||||
const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param source the DecimalFormat object to be copied from.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
CompactDecimalFormat(const CompactDecimalFormat& source);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual ~CompactDecimalFormat();
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*
|
||||
* @param rhs the DecimalFormat object to be copied.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
CompactDecimalFormat& operator=(const CompactDecimalFormat& rhs);
|
||||
|
||||
/**
|
||||
* Clone this Format object polymorphically. The caller owns the
|
||||
* result and should delete it when done.
|
||||
*
|
||||
* @return a polymorphic copy of this CompactDecimalFormat.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual Format* clone() const;
|
||||
|
||||
/**
|
||||
* Return TRUE if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
*
|
||||
* @param other the object to be compared with.
|
||||
* @return TRUE if the given Format objects are semantically equal.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const;
|
||||
|
||||
|
||||
using DecimalFormat::format;
|
||||
|
||||
/**
|
||||
* Format a double or long number using base-10 representation.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Format a double or long number using base-10 representation.
|
||||
* Currently sets status to U_UNSUPPORTED_ERROR.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call.
|
||||
* Can be NULL.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format an int64 number using base-10 representation.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual UnicodeString& format(int64_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Format an int64 number using base-10 representation.
|
||||
* Currently sets status to U_UNSUPPORTED_ERROR
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call.
|
||||
* Can be NULL.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString& format(int64_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format a decimal number. Currently sets status to U_UNSUPPORTED_ERROR
|
||||
* The syntax of the unformatted number is a "numeric string"
|
||||
* as defined in the Decimal Arithmetic Specification, available at
|
||||
* http://speleotrove.com/decimal
|
||||
*
|
||||
* @param number The unformatted number, as a string.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call.
|
||||
* Can be NULL.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString& format(const StringPiece &number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format a decimal number. Currently sets status to U_UNSUPPORTED_ERROR
|
||||
* The number is a DigitList wrapper onto a floating point decimal number.
|
||||
* The default implementation in NumberFormat converts the decimal number
|
||||
* to a double and formats that.
|
||||
*
|
||||
* @param number The number, a DigitList format Decimal Floating Point.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString& format(const DigitList &number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format a decimal number. Currently sets status to U_UNSUPPORTED_ERROR.
|
||||
* The number is a DigitList wrapper onto a floating point decimal number.
|
||||
* The default implementation in NumberFormat converts the decimal number
|
||||
* to a double and formats that.
|
||||
*
|
||||
* @param number The number, a DigitList format Decimal Floating Point.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString& format(const DigitList &number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* CompactDecimalFormat does not support parsing. This implementation
|
||||
* does nothing.
|
||||
* @param text Unused.
|
||||
* @param result Does not change.
|
||||
* @param parsePosition Does not change.
|
||||
* @see Formattable
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const;
|
||||
|
||||
/**
|
||||
* CompactDecimalFormat does not support parsing. This implementation
|
||||
* sets status to U_UNSUPPORTED_ERROR
|
||||
*
|
||||
* @param text Unused.
|
||||
* @param result Does not change.
|
||||
* @param status Always set to U_UNSUPPORTED_ERROR.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual */
|
||||
/**
|
||||
* Parses text from the given string as a currency amount. Unlike
|
||||
* the parse() method, this method will attempt to parse a generic
|
||||
* currency name, searching for a match of this object's locale's
|
||||
* currency display names, or for a 3-letter ISO currency code.
|
||||
* This method will fail if this format is not a currency format,
|
||||
* that is, if it does not contain the currency pattern symbol
|
||||
* (U+00A4) in its prefix or suffix. This implementation always returns
|
||||
* NULL.
|
||||
*
|
||||
* @param text the string to parse
|
||||
* @param pos input-output position; on input, the position within text
|
||||
* to match; must have 0 <= pos.getIndex() < text.length();
|
||||
* on output, the position after the last matched character.
|
||||
* If the parse fails, the position in unchanged upon output.
|
||||
* @return if parse succeeds, a pointer to a newly-created CurrencyAmount
|
||||
* object (owned by the caller) containing information about
|
||||
* the parsed currency; if parse fails, this is NULL.
|
||||
* @internal
|
||||
*/
|
||||
virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
|
||||
ParsePosition& pos) const;
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for
|
||||
* comparing to a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . Derived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
|
||||
* This method is to implement a simple version of RTTI, since not all
|
||||
* C++ compilers support genuine RTTI. Polymorphic operator==() and
|
||||
* clone() methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
private:
|
||||
|
||||
const UHashtable* _unitsByVariant;
|
||||
const double* _divisors;
|
||||
PluralRules* _pluralRules;
|
||||
|
||||
// Default constructor not implemented.
|
||||
CompactDecimalFormat(const DecimalFormat &, const UHashtable* unitsByVariant, const double* divisors, PluralRules* pluralRules);
|
||||
|
||||
UBool eqHelper(const CompactDecimalFormat& that) const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // __COMPACT_DECIMAL_FORMAT_H__
|
||||
//eof
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: April 26, 2004
|
||||
* Since: ICU 3.0
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef __CURRENCYAMOUNT_H__
|
||||
#define __CURRENCYAMOUNT_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/measure.h"
|
||||
#include "unicode/currunit.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Currency Amount Object.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
*
|
||||
* A currency together with a numeric amount, such as 200 USD.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_I18N_API CurrencyAmount: public Measure {
|
||||
public:
|
||||
/**
|
||||
* Construct an object with the given numeric amount and the given
|
||||
* ISO currency code.
|
||||
* @param amount a numeric object; amount.isNumeric() must be TRUE
|
||||
* @param isoCode the 3-letter ISO 4217 currency code; must not be
|
||||
* NULL and must have length 3
|
||||
* @param ec input-output error code. If the amount or the isoCode
|
||||
* is invalid, then this will be set to a failing value.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyAmount(const Formattable& amount, const UChar* isoCode,
|
||||
UErrorCode &ec);
|
||||
|
||||
/**
|
||||
* Construct an object with the given numeric amount and the given
|
||||
* ISO currency code.
|
||||
* @param amount the amount of the given currency
|
||||
* @param isoCode the 3-letter ISO 4217 currency code; must not be
|
||||
* NULL and must have length 3
|
||||
* @param ec input-output error code. If the isoCode is invalid,
|
||||
* then this will be set to a failing value.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyAmount(double amount, const UChar* isoCode,
|
||||
UErrorCode &ec);
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyAmount(const CurrencyAmount& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyAmount& operator=(const CurrencyAmount& other);
|
||||
|
||||
/**
|
||||
* Return a polymorphic clone of this object. The result will
|
||||
* have the same class as returned by getDynamicClassID().
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UObject* clone() const;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual ~CurrencyAmount();
|
||||
|
||||
/**
|
||||
* Returns a unique class ID for this object POLYMORPHICALLY.
|
||||
* This method implements a simple form of RTTI used by ICU.
|
||||
* @return The class ID for this object. All objects of a given
|
||||
* class have the same class ID. Objects of other classes have
|
||||
* different class IDs.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* Returns the class ID for this class. This is used to compare to
|
||||
* the return value of getDynamicClassID().
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* Return the currency unit object of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline const CurrencyUnit& getCurrency() const;
|
||||
|
||||
/**
|
||||
* Return the ISO currency code of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline const UChar* getISOCurrency() const;
|
||||
};
|
||||
|
||||
inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
|
||||
return (const CurrencyUnit&) getUnit();
|
||||
}
|
||||
|
||||
inline const UChar* CurrencyAmount::getISOCurrency() const {
|
||||
return getCurrency().getISOCurrency();
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // !UCONFIG_NO_FORMATTING
|
||||
#endif // __CURRENCYAMOUNT_H__
|
||||
@@ -1,258 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef CURRPINF_H
|
||||
#define CURRPINF_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Currency Plural Information used by Decimal Format
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class Locale;
|
||||
class PluralRules;
|
||||
class Hashtable;
|
||||
|
||||
/**
|
||||
* This class represents the information needed by
|
||||
* DecimalFormat to format currency plural,
|
||||
* such as "3.00 US dollars" or "1.00 US dollar".
|
||||
* DecimalFormat creates for itself an instance of
|
||||
* CurrencyPluralInfo from its locale data.
|
||||
* If you need to change any of these symbols, you can get the
|
||||
* CurrencyPluralInfo object from your
|
||||
* DecimalFormat and modify it.
|
||||
*
|
||||
* Following are the information needed for currency plural format and parse:
|
||||
* locale information,
|
||||
* plural rule of the locale,
|
||||
* currency plural pattern of the locale.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
class U_I18N_API CurrencyPluralInfo : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a CurrencyPluralInfo object for the default locale.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CurrencyPluralInfo(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a CurrencyPluralInfo object for the given locale.
|
||||
* @param locale the locale
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CurrencyPluralInfo(const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CurrencyPluralInfo(const CurrencyPluralInfo& info);
|
||||
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CurrencyPluralInfo& operator=(const CurrencyPluralInfo& info);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual ~CurrencyPluralInfo();
|
||||
|
||||
|
||||
/**
|
||||
* Equal operator.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UBool operator==(const CurrencyPluralInfo& info) const;
|
||||
|
||||
|
||||
/**
|
||||
* Not equal operator
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UBool operator!=(const CurrencyPluralInfo& info) const;
|
||||
|
||||
|
||||
/**
|
||||
* Clone
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
CurrencyPluralInfo* clone() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets plural rules of this locale, used for currency plural format
|
||||
*
|
||||
* @return plural rule
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
const PluralRules* getPluralRules() const;
|
||||
|
||||
/**
|
||||
* Given a plural count, gets currency plural pattern of this locale,
|
||||
* used for currency plural format
|
||||
*
|
||||
* @param pluralCount currency plural count
|
||||
* @param result output param to receive the pattern
|
||||
* @return a currency plural pattern based on plural count
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UnicodeString& getCurrencyPluralPattern(const UnicodeString& pluralCount,
|
||||
UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Get locale
|
||||
*
|
||||
* @return locale
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
const Locale& getLocale() const;
|
||||
|
||||
/**
|
||||
* Set plural rules.
|
||||
* The plural rule is set when CurrencyPluralInfo
|
||||
* instance is created.
|
||||
* You can call this method to reset plural rules only if you want
|
||||
* to modify the default plural rule of the locale.
|
||||
*
|
||||
* @param ruleDescription new plural rule description
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
void setPluralRules(const UnicodeString& ruleDescription,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Set currency plural pattern.
|
||||
* The currency plural pattern is set when CurrencyPluralInfo
|
||||
* instance is created.
|
||||
* You can call this method to reset currency plural pattern only if
|
||||
* you want to modify the default currency plural pattern of the locale.
|
||||
*
|
||||
* @param pluralCount the plural count for which the currency pattern will
|
||||
* be overridden.
|
||||
* @param pattern the new currency plural pattern
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
void setCurrencyPluralPattern(const UnicodeString& pluralCount,
|
||||
const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Set locale
|
||||
*
|
||||
* @param loc the new locale to set
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
void setLocale(const Locale& loc, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
friend class DecimalFormat;
|
||||
|
||||
void initialize(const Locale& loc, UErrorCode& status);
|
||||
|
||||
void setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status);
|
||||
|
||||
/*
|
||||
* delete hash table
|
||||
*
|
||||
* @param hTable hash table to be deleted
|
||||
*/
|
||||
void deleteHash(Hashtable* hTable);
|
||||
|
||||
|
||||
/*
|
||||
* initialize hash table
|
||||
*
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return hash table initialized
|
||||
*/
|
||||
Hashtable* initHash(UErrorCode& status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* copy hash table
|
||||
*
|
||||
* @param source the source to copy from
|
||||
* @param target the target to copy to
|
||||
* @param status error code
|
||||
*/
|
||||
void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
|
||||
|
||||
//-------------------- private data member ---------------------
|
||||
// map from plural count to currency plural pattern, for example
|
||||
// a plural pattern defined in "CurrencyUnitPatterns" is
|
||||
// "one{{0} {1}}", in which "one" is a plural count
|
||||
// and "{0} {1}" is a currency plural pattern".
|
||||
// The currency plural pattern saved in this mapping is the pattern
|
||||
// defined in "CurrencyUnitPattern" by replacing
|
||||
// {0} with the number format pattern,
|
||||
// and {1} with 3 currency sign.
|
||||
Hashtable* fPluralCountToCurrencyUnitPattern;
|
||||
|
||||
/*
|
||||
* The plural rule is used to format currency plural name,
|
||||
* for example: "3.00 US Dollars".
|
||||
* If there are 3 currency signs in the currency patttern,
|
||||
* the 3 currency signs will be replaced by currency plural name.
|
||||
*/
|
||||
PluralRules* fPluralRules;
|
||||
|
||||
// locale
|
||||
Locale* fLocale;
|
||||
};
|
||||
|
||||
|
||||
inline UBool
|
||||
CurrencyPluralInfo::operator!=(const CurrencyPluralInfo& info) const { return !operator==(info); }
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _CURRPINFO
|
||||
//eof
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: April 26, 2004
|
||||
* Since: ICU 3.0
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef __CURRENCYUNIT_H__
|
||||
#define __CURRENCYUNIT_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/measunit.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Currency Unit Information.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A unit of currency, such as USD (U.S. dollars) or JPY (Japanese
|
||||
* yen). This class is a thin wrapper over a UChar string that
|
||||
* subclasses MeasureUnit, for use with Measure and MeasureFormat.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_I18N_API CurrencyUnit: public MeasureUnit {
|
||||
public:
|
||||
/**
|
||||
* Construct an object with the given ISO currency code.
|
||||
* @param isoCode the 3-letter ISO 4217 currency code; must not be
|
||||
* NULL and must have length 3
|
||||
* @param ec input-output error code. If the isoCode is invalid,
|
||||
* then this will be set to a failing value.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyUnit(const UChar* isoCode, UErrorCode &ec);
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyUnit(const CurrencyUnit& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
CurrencyUnit& operator=(const CurrencyUnit& other);
|
||||
|
||||
/**
|
||||
* Return a polymorphic clone of this object. The result will
|
||||
* have the same class as returned by getDynamicClassID().
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UObject* clone() const;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual ~CurrencyUnit();
|
||||
|
||||
/**
|
||||
* Equality operator. Return true if this object is equal
|
||||
* to the given object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UBool operator==(const UObject& other) const;
|
||||
|
||||
/**
|
||||
* Returns a unique class ID for this object POLYMORPHICALLY.
|
||||
* This method implements a simple form of RTTI used by ICU.
|
||||
* @return The class ID for this object. All objects of a given
|
||||
* class have the same class ID. Objects of other classes have
|
||||
* different class IDs.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* Returns the class ID for this class. This is used to compare to
|
||||
* the return value of getDynamicClassID().
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* Return the ISO currency code of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline const UChar* getISOCurrency() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The ISO 4217 code of this object.
|
||||
*/
|
||||
UChar isoCode[4];
|
||||
};
|
||||
|
||||
inline const UChar* CurrencyUnit::getISOCurrency() const {
|
||||
return isoCode;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // !UCONFIG_NO_FORMATTING
|
||||
#endif // __CURRENCYUNIT_H__
|
||||
@@ -1,820 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File DATEFMT.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 04/01/97 aliu Added support for centuries.
|
||||
* 07/23/98 stephen JDK 1.2 sync
|
||||
* 11/15/99 weiv Added support for week of year/day of week formatting
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef DATEFMT_H
|
||||
#define DATEFMT_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/calendar.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/enumset.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Abstract class for converting dates.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class TimeZone;
|
||||
class DateTimePatternGenerator;
|
||||
|
||||
// explicit template instantiation. see digitlst.h
|
||||
#if defined (_MSC_VER)
|
||||
template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
|
||||
0,
|
||||
UDAT_BOOLEAN_ATTRIBUTE_COUNT>;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* DateFormat is an abstract class for a family of classes that convert dates and
|
||||
* times from their internal representations to textual form and back again in a
|
||||
* language-independent manner. Converting from the internal representation (milliseconds
|
||||
* since midnight, January 1, 1970) to text is known as "formatting," and converting
|
||||
* from text to millis is known as "parsing." We currently define only one concrete
|
||||
* subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal
|
||||
* date formatting and parsing actions.
|
||||
* <P>
|
||||
* DateFormat helps you to format and parse dates for any locale. Your code can
|
||||
* be completely independent of the locale conventions for months, days of the
|
||||
* week, or even the calendar format: lunar vs. solar.
|
||||
* <P>
|
||||
* To format a date for the current Locale, use one of the static factory
|
||||
* methods:
|
||||
* <pre>
|
||||
* \code
|
||||
* DateFormat* dfmt = DateFormat::createDateInstance();
|
||||
* UDate myDate = Calendar::getNow();
|
||||
* UnicodeString myString;
|
||||
* myString = dfmt->format( myDate, myString );
|
||||
* \endcode
|
||||
* </pre>
|
||||
* If you are formatting multiple numbers, it is more efficient to get the
|
||||
* format and use it multiple times so that the system doesn't have to fetch the
|
||||
* information about the local language and country conventions multiple times.
|
||||
* <pre>
|
||||
* \code
|
||||
* DateFormat* df = DateFormat::createDateInstance();
|
||||
* UnicodeString myString;
|
||||
* UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
|
||||
* for (int32_t i = 0; i < 3; ++i) {
|
||||
* myString.remove();
|
||||
* cout << df->format( myDateArr[i], myString ) << endl;
|
||||
* }
|
||||
* \endcode
|
||||
* </pre>
|
||||
* To get specific fields of a date, you can use UFieldPosition to
|
||||
* get specific fields.
|
||||
* <pre>
|
||||
* \code
|
||||
* DateFormat* dfmt = DateFormat::createDateInstance();
|
||||
* FieldPosition pos(DateFormat::YEAR_FIELD);
|
||||
* UnicodeString myString;
|
||||
* myString = dfmt->format( myDate, myString );
|
||||
* cout << myString << endl;
|
||||
* cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
|
||||
* \endcode
|
||||
* </pre>
|
||||
* To format a date for a different Locale, specify it in the call to
|
||||
* createDateInstance().
|
||||
* <pre>
|
||||
* \code
|
||||
* DateFormat* df =
|
||||
* DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
|
||||
* \endcode
|
||||
* </pre>
|
||||
* You can use a DateFormat to parse also.
|
||||
* <pre>
|
||||
* \code
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* UDate myDate = df->parse(myString, status);
|
||||
* \endcode
|
||||
* </pre>
|
||||
* Use createDateInstance() to produce the normal date format for that country.
|
||||
* There are other static factory methods available. Use createTimeInstance()
|
||||
* to produce the normal time format for that country. Use createDateTimeInstance()
|
||||
* to produce a DateFormat that formats both date and time. You can pass in
|
||||
* different options to these factory methods to control the length of the
|
||||
* result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the
|
||||
* locale, but generally:
|
||||
* <ul type=round>
|
||||
* <li> SHORT is completely numeric, such as 12/13/52 or 3:30pm
|
||||
* <li> MEDIUM is longer, such as Jan 12, 1952
|
||||
* <li> LONG is longer, such as January 12, 1952 or 3:30:32pm
|
||||
* <li> FULL is pretty completely specified, such as
|
||||
* Tuesday, April 12, 1952 AD or 3:30:42pm PST.
|
||||
* </ul>
|
||||
* You can also set the time zone on the format if you wish. If you want even
|
||||
* more control over the format or parsing, (or want to give your users more
|
||||
* control), you can try casting the DateFormat you get from the factory methods
|
||||
* to a SimpleDateFormat. This will work for the majority of countries; just
|
||||
* remember to chck getDynamicClassID() before carrying out the cast.
|
||||
* <P>
|
||||
* You can also use forms of the parse and format methods with ParsePosition and
|
||||
* FieldPosition to allow you to
|
||||
* <ul type=round>
|
||||
* <li> Progressively parse through pieces of a string.
|
||||
* <li> Align any particular field, or find out where it is for selection
|
||||
* on the screen.
|
||||
* </ul>
|
||||
*
|
||||
* <p><em>User subclasses are not supported.</em> While clients may write
|
||||
* subclasses, such code will not necessarily work and will not be
|
||||
* guaranteed to work stably from release to release.
|
||||
*/
|
||||
class U_I18N_API DateFormat : public Format {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constants for various style patterns. These reflect the order of items in
|
||||
* the DateTimePatterns resource. There are 4 time patterns, 4 date patterns,
|
||||
* the default date-time pattern, and 4 date-time patterns. Each block of 4 values
|
||||
* in the resource occurs in the order full, long, medium, short.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
enum EStyle
|
||||
{
|
||||
kNone = -1,
|
||||
|
||||
kFull = 0,
|
||||
kLong = 1,
|
||||
kMedium = 2,
|
||||
kShort = 3,
|
||||
|
||||
kDateOffset = kShort + 1,
|
||||
// kFull + kDateOffset = 4
|
||||
// kLong + kDateOffset = 5
|
||||
// kMedium + kDateOffset = 6
|
||||
// kShort + kDateOffset = 7
|
||||
|
||||
kDateTime = 8,
|
||||
// Default DateTime
|
||||
|
||||
kDateTimeOffset = kDateTime + 1,
|
||||
// kFull + kDateTimeOffset = 9
|
||||
// kLong + kDateTimeOffset = 10
|
||||
// kMedium + kDateTimeOffset = 11
|
||||
// kShort + kDateTimeOffset = 12
|
||||
|
||||
// relative dates
|
||||
kRelative = (1 << 7),
|
||||
|
||||
kFullRelative = (kFull | kRelative),
|
||||
|
||||
kLongRelative = kLong | kRelative,
|
||||
|
||||
kMediumRelative = kMedium | kRelative,
|
||||
|
||||
kShortRelative = kShort | kRelative,
|
||||
|
||||
|
||||
kDefault = kMedium,
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* These constants are provided for backwards compatibility only.
|
||||
* Please use the C++ style constants defined above.
|
||||
*/
|
||||
FULL = kFull,
|
||||
LONG = kLong,
|
||||
MEDIUM = kMedium,
|
||||
SHORT = kShort,
|
||||
DEFAULT = kDefault,
|
||||
DATE_OFFSET = kDateOffset,
|
||||
NONE = kNone,
|
||||
DATE_TIME = kDateTime
|
||||
};
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~DateFormat();
|
||||
|
||||
/**
|
||||
* Equality operator. Returns true if the two formats have the same behavior.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const Format&) const;
|
||||
|
||||
|
||||
using Format::format;
|
||||
|
||||
/**
|
||||
* Format an object to produce a string. This method handles Formattable
|
||||
* objects with a UDate type. If a the Formattable object type is not a Date,
|
||||
* then it returns a failing UErrorCode.
|
||||
*
|
||||
* @param obj The object to format. Must be a Date.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format an object to produce a string. This method handles Formattable
|
||||
* objects with a UDate type. If a the Formattable object type is not a Date,
|
||||
* then it returns a failing UErrorCode.
|
||||
*
|
||||
* @param obj The object to format. Must be a Date.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call. Field values
|
||||
* are defined in UDateFormatField. Can be NULL.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Formats a date into a date/time string. This is an abstract method which
|
||||
* concrete subclasses must implement.
|
||||
* <P>
|
||||
* On input, the FieldPosition parameter may have its "field" member filled with
|
||||
* an enum value specifying a field. On output, the FieldPosition will be filled
|
||||
* in with the text offsets for that field.
|
||||
* <P> For example, given a time text
|
||||
* "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
|
||||
* UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
|
||||
* statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
|
||||
* <P> Notice
|
||||
* that if the same time field appears more than once in a pattern, the status will
|
||||
* be set for the first occurence of that time field. For instance,
|
||||
* formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
|
||||
* using the pattern "h a z (zzzz)" and the alignment field
|
||||
* DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
|
||||
* fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
|
||||
* occurence of the timezone pattern character 'z'.
|
||||
*
|
||||
* @param cal Calendar set to the date and time to be formatted
|
||||
* into a date/time string. When the calendar type is
|
||||
* different from the internal calendar held by this
|
||||
* DateFormat instance, the date and the time zone will
|
||||
* be inherited from the input calendar, but other calendar
|
||||
* field values will be calculated by the internal calendar.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param fieldPosition On input: an alignment field, if desired (see examples above)
|
||||
* On output: the offsets of the alignment field (see examples above)
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
virtual UnicodeString& format( Calendar& cal,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& fieldPosition) const = 0;
|
||||
|
||||
/**
|
||||
* Formats a date into a date/time string. Subclasses should implement this method.
|
||||
*
|
||||
* @param cal Calendar set to the date and time to be formatted
|
||||
* into a date/time string. When the calendar type is
|
||||
* different from the internal calendar held by this
|
||||
* DateFormat instance, the date and the time zone will
|
||||
* be inherited from the input calendar, but other calendar
|
||||
* field values will be calculated by the internal calendar.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call. Field values
|
||||
* are defined in UDateFormatField. Can be NULL.
|
||||
* @param status error status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& format(Calendar& cal,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Formats a UDate into a date/time string.
|
||||
* <P>
|
||||
* On input, the FieldPosition parameter may have its "field" member filled with
|
||||
* an enum value specifying a field. On output, the FieldPosition will be filled
|
||||
* in with the text offsets for that field.
|
||||
* <P> For example, given a time text
|
||||
* "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
|
||||
* UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
|
||||
* statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
|
||||
* <P> Notice
|
||||
* that if the same time field appears more than once in a pattern, the status will
|
||||
* be set for the first occurence of that time field. For instance,
|
||||
* formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
|
||||
* using the pattern "h a z (zzzz)" and the alignment field
|
||||
* DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
|
||||
* fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
|
||||
* occurence of the timezone pattern character 'z'.
|
||||
*
|
||||
* @param date UDate to be formatted into a date/time string.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param fieldPosition On input: an alignment field, if desired (see examples above)
|
||||
* On output: the offsets of the alignment field (see examples above)
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& format( UDate date,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& fieldPosition) const;
|
||||
|
||||
/**
|
||||
* Formats a UDate into a date/time string.
|
||||
*
|
||||
* @param date UDate to be formatted into a date/time string.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call. Field values
|
||||
* are defined in UDateFormatField. Can be NULL.
|
||||
* @param status error status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UnicodeString& format(UDate date,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Formats a UDate into a date/time string. If there is a problem, you won't
|
||||
* know, using this method. Use the overloaded format() method which takes a
|
||||
* FieldPosition& to detect formatting problems.
|
||||
*
|
||||
* @param date The UDate value to be formatted into a string.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& format(UDate date, UnicodeString& appendTo) const;
|
||||
|
||||
/**
|
||||
* Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
|
||||
* will be parsed into a UDate that is equivalent to Date(837039928046).
|
||||
* Parsing begins at the beginning of the string and proceeds as far as
|
||||
* possible. Assuming no parse errors were encountered, this function
|
||||
* doesn't return any information about how much of the string was consumed
|
||||
* by the parsing. If you need that information, use the version of
|
||||
* parse() that takes a ParsePosition.
|
||||
* <P>
|
||||
* By default, parsing is lenient: If the input is not in the form used by
|
||||
* this object's format method but can still be parsed as a date, then the
|
||||
* parse succeeds. Clients may insist on strict adherence to the format by
|
||||
* calling setLenient(false).
|
||||
* @see DateFormat::setLenient(boolean)
|
||||
* <P>
|
||||
* Note that the normal date formats associated with some calendars - such
|
||||
* as the Chinese lunar calendar - do not specify enough fields to enable
|
||||
* dates to be parsed unambiguously. In the case of the Chinese lunar
|
||||
* calendar, while the year within the current 60-year cycle is specified,
|
||||
* the number of such cycles since the start date of the calendar (in the
|
||||
* ERA field of the Calendar object) is not normally part of the format,
|
||||
* and parsing may assume the wrong era. For cases such as this it is
|
||||
* recommended that clients parse using the method
|
||||
* parse(const UnicodeString&, Calendar& cal, ParsePosition&)
|
||||
* with the Calendar passed in set to the current date, or to a date
|
||||
* within the era/cycle that should be assumed if absent in the format.
|
||||
*
|
||||
* @param text The date/time string to be parsed into a UDate value.
|
||||
* @param status Output param to be set to success/failure code. If
|
||||
* 'text' cannot be parsed, it will be set to a failure
|
||||
* code.
|
||||
* @return The parsed UDate value, if successful.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UDate parse( const UnicodeString& text,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Parse a date/time string beginning at the given parse position. For
|
||||
* example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
|
||||
* that is equivalent to Date(837039928046).
|
||||
* <P>
|
||||
* By default, parsing is lenient: If the input is not in the form used by
|
||||
* this object's format method but can still be parsed as a date, then the
|
||||
* parse succeeds. Clients may insist on strict adherence to the format by
|
||||
* calling setLenient(false).
|
||||
* @see DateFormat::setLenient(boolean)
|
||||
*
|
||||
* @param text The date/time string to be parsed.
|
||||
* @param cal A Calendar set on input to the date and time to be used for
|
||||
* missing values in the date/time string being parsed, and set
|
||||
* on output to the parsed date/time. When the calendar type is
|
||||
* different from the internal calendar held by this DateFormat
|
||||
* instance, the internal calendar will be cloned to a work
|
||||
* calendar set to the same milliseconds and time zone as the
|
||||
* cal parameter, field values will be parsed based on the work
|
||||
* calendar, then the result (milliseconds and time zone) will
|
||||
* be set in this calendar.
|
||||
* @param pos On input, the position at which to start parsing; on
|
||||
* output, the position at which parsing terminated, or the
|
||||
* start position if the parse failed.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
virtual void parse( const UnicodeString& text,
|
||||
Calendar& cal,
|
||||
ParsePosition& pos) const = 0;
|
||||
|
||||
/**
|
||||
* Parse a date/time string beginning at the given parse position. For
|
||||
* example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
|
||||
* that is equivalent to Date(837039928046).
|
||||
* <P>
|
||||
* By default, parsing is lenient: If the input is not in the form used by
|
||||
* this object's format method but can still be parsed as a date, then the
|
||||
* parse succeeds. Clients may insist on strict adherence to the format by
|
||||
* calling setLenient(false).
|
||||
* @see DateFormat::setLenient(boolean)
|
||||
* <P>
|
||||
* Note that the normal date formats associated with some calendars - such
|
||||
* as the Chinese lunar calendar - do not specify enough fields to enable
|
||||
* dates to be parsed unambiguously. In the case of the Chinese lunar
|
||||
* calendar, while the year within the current 60-year cycle is specified,
|
||||
* the number of such cycles since the start date of the calendar (in the
|
||||
* ERA field of the Calendar object) is not normally part of the format,
|
||||
* and parsing may assume the wrong era. For cases such as this it is
|
||||
* recommended that clients parse using the method
|
||||
* parse(const UnicodeString&, Calendar& cal, ParsePosition&)
|
||||
* with the Calendar passed in set to the current date, or to a date
|
||||
* within the era/cycle that should be assumed if absent in the format.
|
||||
*
|
||||
* @param text The date/time string to be parsed into a UDate value.
|
||||
* @param pos On input, the position at which to start parsing; on
|
||||
* output, the position at which parsing terminated, or the
|
||||
* start position if the parse failed.
|
||||
* @return A valid UDate if the input could be parsed.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UDate parse( const UnicodeString& text,
|
||||
ParsePosition& pos) const;
|
||||
|
||||
/**
|
||||
* Parse a string to produce an object. This methods handles parsing of
|
||||
* date/time strings into Formattable objects with UDate types.
|
||||
* <P>
|
||||
* Before calling, set parse_pos.index to the offset you want to start
|
||||
* parsing at in the source. After calling, parse_pos.index is the end of
|
||||
* the text you parsed. If error occurs, index is unchanged.
|
||||
* <P>
|
||||
* When parsing, leading whitespace is discarded (with a successful parse),
|
||||
* while trailing whitespace is left as is.
|
||||
* <P>
|
||||
* See Format::parseObject() for more.
|
||||
*
|
||||
* @param source The string to be parsed into an object.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parse_pos The position to start parsing at. Upon return
|
||||
* this param is set to the position after the
|
||||
* last character successfully parsed. If the
|
||||
* source is not parsed successfully, this param
|
||||
* will remain unchanged.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void parseObject(const UnicodeString& source,
|
||||
Formattable& result,
|
||||
ParsePosition& parse_pos) const;
|
||||
|
||||
/**
|
||||
* Create a default date/time formatter that uses the SHORT style for both
|
||||
* the date and the time.
|
||||
*
|
||||
* @return A date/time formatter which the caller owns.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static DateFormat* U_EXPORT2 createInstance(void);
|
||||
|
||||
/**
|
||||
* Creates a time formatter with the given formatting style for the given
|
||||
* locale.
|
||||
*
|
||||
* @param style The given formatting style. For example,
|
||||
* SHORT for "h:mm a" in the US locale. Relative
|
||||
* time styles are not currently supported.
|
||||
* @param aLocale The given locale.
|
||||
* @return A time formatter which the caller owns.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
|
||||
const Locale& aLocale = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Creates a date formatter with the given formatting style for the given
|
||||
* const locale.
|
||||
*
|
||||
* @param style The given formatting style. For example, SHORT for "M/d/yy" in the
|
||||
* US locale. As currently implemented, relative date formatting only
|
||||
* affects a limited range of calendar days before or after the
|
||||
* current date, based on the CLDR <field type="day">/<relative> data:
|
||||
* For example, in English, "Yesterday", "Today", and "Tomorrow".
|
||||
* Outside of this range, dates are formatted using the corresponding
|
||||
* non-relative style.
|
||||
* @param aLocale The given locale.
|
||||
* @return A date formatter which the caller owns.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
|
||||
const Locale& aLocale = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Creates a date/time formatter with the given formatting styles for the
|
||||
* given locale.
|
||||
*
|
||||
* @param dateStyle The given formatting style for the date portion of the result.
|
||||
* For example, SHORT for "M/d/yy" in the US locale. As currently
|
||||
* implemented, relative date formatting only affects a limited range
|
||||
* of calendar days before or after the current date, based on the
|
||||
* CLDR <field type="day">/<relative> data: For example, in English,
|
||||
* "Yesterday", "Today", and "Tomorrow". Outside of this range, dates
|
||||
* are formatted using the corresponding non-relative style.
|
||||
* @param timeStyle The given formatting style for the time portion of the result.
|
||||
* For example, SHORT for "h:mm a" in the US locale. Relative
|
||||
* time styles are not currently supported.
|
||||
* @param aLocale The given locale.
|
||||
* @return A date/time formatter which the caller owns.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
|
||||
EStyle timeStyle = kDefault,
|
||||
const Locale& aLocale = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Gets the set of locales for which DateFormats are installed.
|
||||
* @param count Filled in with the number of locales in the list that is returned.
|
||||
* @return the set of locales for which DateFormats are installed. The caller
|
||||
* does NOT own this list and must not delete it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
|
||||
|
||||
/**
|
||||
* Returns true if the encapsulated Calendar object is set for lenient parsing.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool isLenient(void) const;
|
||||
|
||||
/**
|
||||
* Specify whether or not date/time parsing is to be lenient. With lenient
|
||||
* parsing, the parser may use heuristics to interpret inputs that do not
|
||||
* precisely match this object's format. With strict parsing, inputs must
|
||||
* match this object's format.
|
||||
*
|
||||
* Note: This method is specific to the encapsulated Calendar object. DateFormat
|
||||
* leniency aspects are controlled by setBooleanAttribute.
|
||||
*
|
||||
* @param lenient True specifies date/time interpretation to be lenient.
|
||||
* @see Calendar::setLenient
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setLenient(UBool lenient);
|
||||
|
||||
/**
|
||||
* Gets the calendar associated with this date/time formatter.
|
||||
* @return the calendar associated with this date/time formatter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual const Calendar* getCalendar(void) const;
|
||||
|
||||
/**
|
||||
* Set the calendar to be used by this date format. Initially, the default
|
||||
* calendar for the specified or default locale is used. The caller should
|
||||
* not delete the Calendar object after it is adopted by this call.
|
||||
* Adopting a new calendar will change to the default symbols.
|
||||
*
|
||||
* @param calendarToAdopt Calendar object to be adopted.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptCalendar(Calendar* calendarToAdopt);
|
||||
|
||||
/**
|
||||
* Set the calendar to be used by this date format. Initially, the default
|
||||
* calendar for the specified or default locale is used.
|
||||
*
|
||||
* @param newCalendar Calendar object to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setCalendar(const Calendar& newCalendar);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number formatter which this date/time formatter uses to format
|
||||
* and parse the numeric portions of the pattern.
|
||||
* @return the number formatter which this date/time formatter uses.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual const NumberFormat* getNumberFormat(void) const;
|
||||
|
||||
/**
|
||||
* Allows you to set the number formatter. The caller should
|
||||
* not delete the NumberFormat object after it is adopted by this call.
|
||||
* @param formatToAdopt NumberFormat object to be adopted.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
|
||||
|
||||
/**
|
||||
* Allows you to set the number formatter.
|
||||
* @param newNumberFormat NumberFormat object to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setNumberFormat(const NumberFormat& newNumberFormat);
|
||||
|
||||
/**
|
||||
* Returns a reference to the TimeZone used by this DateFormat's calendar.
|
||||
* @return the time zone associated with the calendar of DateFormat.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual const TimeZone& getTimeZone(void) const;
|
||||
|
||||
/**
|
||||
* Sets the time zone for the calendar of this DateFormat object. The caller
|
||||
* no longer owns the TimeZone object and should not delete it after this call.
|
||||
* @param zoneToAdopt the TimeZone to be adopted.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptTimeZone(TimeZone* zoneToAdopt);
|
||||
|
||||
/**
|
||||
* Sets the time zone for the calendar of this DateFormat object.
|
||||
* @param zone the new time zone.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setTimeZone(const TimeZone& zone);
|
||||
|
||||
/**
|
||||
* Set an boolean attribute on this DateFormat.
|
||||
* May return U_UNSUPPORTED_ERROR if this instance does not support
|
||||
* the specified attribute.
|
||||
* @param attr the attribute to set
|
||||
* @param newvalue new value
|
||||
* @param status the error type
|
||||
* @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
|
||||
* @internal ICU technology preview
|
||||
*/
|
||||
|
||||
virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr,
|
||||
UBool newvalue,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Get an boolean from this DateFormat
|
||||
* May return U_UNSUPPORTED_ERROR if this instance does not support
|
||||
* the specified attribute.
|
||||
* @param attr the attribute to set
|
||||
* @param status the error type
|
||||
* @return the attribute value. Undefined if there is an error.
|
||||
* @internal ICU technology preview
|
||||
*/
|
||||
virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor. Creates a DateFormat with no Calendar or NumberFormat
|
||||
* associated with it. This constructor depends on the subclasses to fill in
|
||||
* the calendar and numberFormat fields.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormat();
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormat(const DateFormat&);
|
||||
|
||||
/**
|
||||
* Default assignment operator.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormat& operator=(const DateFormat&);
|
||||
|
||||
/**
|
||||
* The calendar that DateFormat uses to produce the time field values needed
|
||||
* to implement date/time formatting. Subclasses should generally initialize
|
||||
* this to the default calendar for the locale associated with this DateFormat.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
Calendar* fCalendar;
|
||||
|
||||
/**
|
||||
* The number formatter that DateFormat uses to format numbers in dates and
|
||||
* times. Subclasses should generally initialize this to the default number
|
||||
* format for the locale associated with this DateFormat.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
NumberFormat* fNumberFormat;
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Gets the date/time formatter with the given formatting styles for the
|
||||
* given locale.
|
||||
* @param dateStyle the given date formatting style.
|
||||
* @param timeStyle the given time formatting style.
|
||||
* @param inLocale the given locale.
|
||||
* @return a date/time formatter, or 0 on failure.
|
||||
*/
|
||||
static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale);
|
||||
|
||||
|
||||
/**
|
||||
* enum set of active boolean attributes for this instance
|
||||
*/
|
||||
EnumSet<UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT> fBoolFlags;
|
||||
|
||||
|
||||
public:
|
||||
#ifndef U_HIDE_OBSOLETE_API
|
||||
/**
|
||||
* Field selector for FieldPosition for DateFormat fields.
|
||||
* @obsolete ICU 3.4 use UDateFormatField instead, since this API will be
|
||||
* removed in that release
|
||||
*/
|
||||
enum EField
|
||||
{
|
||||
// Obsolete; use UDateFormatField instead
|
||||
kEraField = UDAT_ERA_FIELD,
|
||||
kYearField = UDAT_YEAR_FIELD,
|
||||
kMonthField = UDAT_MONTH_FIELD,
|
||||
kDateField = UDAT_DATE_FIELD,
|
||||
kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
|
||||
kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
|
||||
kMinuteField = UDAT_MINUTE_FIELD,
|
||||
kSecondField = UDAT_SECOND_FIELD,
|
||||
kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
|
||||
kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
|
||||
kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
|
||||
kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
|
||||
kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
|
||||
kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
|
||||
kAmPmField = UDAT_AM_PM_FIELD,
|
||||
kHour1Field = UDAT_HOUR1_FIELD,
|
||||
kHour0Field = UDAT_HOUR0_FIELD,
|
||||
kTimezoneField = UDAT_TIMEZONE_FIELD,
|
||||
kYearWOYField = UDAT_YEAR_WOY_FIELD,
|
||||
kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
|
||||
kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
|
||||
kJulianDayField = UDAT_JULIAN_DAY_FIELD,
|
||||
kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
|
||||
|
||||
// Obsolete; use UDateFormatField instead
|
||||
ERA_FIELD = UDAT_ERA_FIELD,
|
||||
YEAR_FIELD = UDAT_YEAR_FIELD,
|
||||
MONTH_FIELD = UDAT_MONTH_FIELD,
|
||||
DATE_FIELD = UDAT_DATE_FIELD,
|
||||
HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
|
||||
HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
|
||||
MINUTE_FIELD = UDAT_MINUTE_FIELD,
|
||||
SECOND_FIELD = UDAT_SECOND_FIELD,
|
||||
MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
|
||||
DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
|
||||
DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
|
||||
DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
|
||||
WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
|
||||
WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
|
||||
AM_PM_FIELD = UDAT_AM_PM_FIELD,
|
||||
HOUR1_FIELD = UDAT_HOUR1_FIELD,
|
||||
HOUR0_FIELD = UDAT_HOUR0_FIELD,
|
||||
TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
|
||||
};
|
||||
#endif /* U_HIDE_OBSOLETE_API */
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _DATEFMT
|
||||
//eof
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1999-2006,2013 IBM Corp. All rights reserved.
|
||||
**********************************************************************
|
||||
* Date Name Description
|
||||
* 12/1/99 rgillam Complete port from Java.
|
||||
* 01/13/2000 helena Added UErrorCode to ctors.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef DBBI_H
|
||||
#define DBBI_H
|
||||
|
||||
#include "unicode/rbbi.h"
|
||||
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Dictionary Based Break Iterator
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* An obsolete subclass of RuleBasedBreakIterator. Handling of dictionary-
|
||||
* based break iteration has been folded into the base class. This class
|
||||
* is deprecated as of ICU 3.6.
|
||||
* @deprecated ICU 3.6
|
||||
*/
|
||||
typedef RuleBasedBreakIterator DictionaryBasedBreakIterator;
|
||||
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
||||
|
||||
#endif
|
||||
@@ -1,479 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File DCFMTSYM.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 03/18/97 clhuang Updated per C++ implementation.
|
||||
* 03/27/97 helena Updated to pass the simple test after code review.
|
||||
* 08/26/97 aliu Added currency/intl currency symbol support.
|
||||
* 07/22/98 stephen Changed to match C++ style
|
||||
* currencySymbol -> fCurrencySymbol
|
||||
* Constants changed from CAPS to kCaps
|
||||
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
|
||||
* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
|
||||
* functions.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef DCFMTSYM_H
|
||||
#define DCFMTSYM_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uchar.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/unum.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Symbols for formatting numbers.
|
||||
*/
|
||||
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class represents the set of symbols needed by DecimalFormat
|
||||
* to format numbers. DecimalFormat creates for itself an instance of
|
||||
* DecimalFormatSymbols from its locale data. If you need to change any
|
||||
* of these symbols, you can get the DecimalFormatSymbols object from
|
||||
* your DecimalFormat and modify it.
|
||||
* <P>
|
||||
* Here are the special characters used in the parts of the
|
||||
* subpattern, with notes on their usage.
|
||||
* <pre>
|
||||
* \code
|
||||
* Symbol Meaning
|
||||
* 0 a digit
|
||||
* # a digit, zero shows as absent
|
||||
* . placeholder for decimal separator
|
||||
* , placeholder for grouping separator.
|
||||
* ; separates formats.
|
||||
* - default negative prefix.
|
||||
* % divide by 100 and show as percentage
|
||||
* X any other characters can be used in the prefix or suffix
|
||||
* ' used to quote special characters in a prefix or suffix.
|
||||
* \endcode
|
||||
* </pre>
|
||||
* [Notes]
|
||||
* <P>
|
||||
* If there is no explicit negative subpattern, - is prefixed to the
|
||||
* positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
|
||||
* <P>
|
||||
* The grouping separator is commonly used for thousands, but in some
|
||||
* countries for ten-thousands. The interval is a constant number of
|
||||
* digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
|
||||
* If you supply a pattern with multiple grouping characters, the interval
|
||||
* between the last one and the end of the integer is the one that is
|
||||
* used. So "#,##,###,####" == "######,####" == "##,####,####".
|
||||
* <P>
|
||||
* This class only handles localized digits where the 10 digits are
|
||||
* contiguous in Unicode, from 0 to 9. Other digits sets (such as
|
||||
* superscripts) would need a different subclass.
|
||||
*/
|
||||
class U_I18N_API DecimalFormatSymbols : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Constants for specifying a number format symbol.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum ENumberFormatSymbol {
|
||||
/** The decimal separator */
|
||||
kDecimalSeparatorSymbol,
|
||||
/** The grouping separator */
|
||||
kGroupingSeparatorSymbol,
|
||||
/** The pattern separator */
|
||||
kPatternSeparatorSymbol,
|
||||
/** The percent sign */
|
||||
kPercentSymbol,
|
||||
/** Zero*/
|
||||
kZeroDigitSymbol,
|
||||
/** Character representing a digit in the pattern */
|
||||
kDigitSymbol,
|
||||
/** The minus sign */
|
||||
kMinusSignSymbol,
|
||||
/** The plus sign */
|
||||
kPlusSignSymbol,
|
||||
/** The currency symbol */
|
||||
kCurrencySymbol,
|
||||
/** The international currency symbol */
|
||||
kIntlCurrencySymbol,
|
||||
/** The monetary separator */
|
||||
kMonetarySeparatorSymbol,
|
||||
/** The exponential symbol */
|
||||
kExponentialSymbol,
|
||||
/** Per mill symbol - replaces kPermillSymbol */
|
||||
kPerMillSymbol,
|
||||
/** Escape padding character */
|
||||
kPadEscapeSymbol,
|
||||
/** Infinity symbol */
|
||||
kInfinitySymbol,
|
||||
/** Nan symbol */
|
||||
kNaNSymbol,
|
||||
/** Significant digit symbol
|
||||
* @stable ICU 3.0 */
|
||||
kSignificantDigitSymbol,
|
||||
/** The monetary grouping separator
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
kMonetaryGroupingSeparatorSymbol,
|
||||
/** One
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kOneDigitSymbol,
|
||||
/** Two
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kTwoDigitSymbol,
|
||||
/** Three
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kThreeDigitSymbol,
|
||||
/** Four
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kFourDigitSymbol,
|
||||
/** Five
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kFiveDigitSymbol,
|
||||
/** Six
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kSixDigitSymbol,
|
||||
/** Seven
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kSevenDigitSymbol,
|
||||
/** Eight
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kEightDigitSymbol,
|
||||
/** Nine
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
kNineDigitSymbol,
|
||||
/** count symbol constants */
|
||||
kFormatSymbolCount
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a DecimalFormatSymbols object for the given locale.
|
||||
*
|
||||
* @param locale The locale to get symbols for.
|
||||
* @param status Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a DecimalFormatSymbols object for the default locale.
|
||||
* This constructor will not fail. If the resource file data is
|
||||
* not available, it will use hard-coded last-resort data and
|
||||
* set status to U_USING_FALLBACK_ERROR.
|
||||
*
|
||||
* @param status Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DecimalFormatSymbols(UErrorCode& status);
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Creates a DecimalFormatSymbols object with last-resort data.
|
||||
* Intended for callers who cache the symbols data and
|
||||
* set all symbols on the resulting object.
|
||||
*
|
||||
* The last-resort symbols are similar to those for the root data,
|
||||
* except that the grouping separators are empty,
|
||||
* the NaN symbol is U+FFFD rather than "NaN",
|
||||
* and the CurrencySpacing patterns are empty.
|
||||
*
|
||||
* @param status Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @return last-resort symbols
|
||||
* @draft ICU 52
|
||||
*/
|
||||
static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DecimalFormatSymbols(const DecimalFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~DecimalFormatSymbols();
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*
|
||||
* @param other the object to be compared with.
|
||||
* @return true if another object is semantically equal to this one.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const DecimalFormatSymbols& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*
|
||||
* @param other the object to be compared with.
|
||||
* @return true if another object is semantically unequal to this one.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Get one of the format symbols by its enum constant.
|
||||
* Each symbol is stored as a string so that graphemes
|
||||
* (characters with modifier letters) can be used.
|
||||
*
|
||||
* @param symbol Constant to indicate a number format symbol.
|
||||
* @return the format symbols by the param 'symbol'
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
|
||||
|
||||
/**
|
||||
* Set one of the format symbols by its enum constant.
|
||||
* Each symbol is stored as a string so that graphemes
|
||||
* (characters with modifier letters) can be used.
|
||||
*
|
||||
* @param symbol Constant to indicate a number format symbol.
|
||||
* @param value value of the format symbol
|
||||
* @param propogateDigits If false, setting the zero digit will not automatically set 1-9.
|
||||
* The default behavior is to automatically set 1-9 if zero is being set and the value
|
||||
* it is being set to corresponds to a known Unicode zero digit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
|
||||
|
||||
/**
|
||||
* Returns the locale for which this object was constructed.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
inline Locale getLocale() const;
|
||||
|
||||
/**
|
||||
* Returns the locale for this object. Two flavors are available:
|
||||
* valid and actual locale.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Get pattern string for 'CurrencySpacing' that can be applied to
|
||||
* currency format.
|
||||
* This API gets the CurrencySpacing data from ResourceBundle. The pattern can
|
||||
* be empty if there is no data from current locale and its parent locales.
|
||||
*
|
||||
* @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
|
||||
* @param beforeCurrency : true if the pattern is for before currency symbol.
|
||||
* false if the pattern is for after currency symbol.
|
||||
* @param status: Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @return pattern string for currencyMatch, surroundingMatch or spaceInsert.
|
||||
* Return empty string if there is no data for this locale and its parent
|
||||
* locales.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
|
||||
UBool beforeCurrency,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Set pattern string for 'CurrencySpacing' that can be applied to
|
||||
* currency format.
|
||||
*
|
||||
* @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
|
||||
* @param beforeCurrency : true if the pattern is for before currency symbol.
|
||||
* false if the pattern is for after currency symbol.
|
||||
* @param pattern : pattern string to override current setting.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
void setPatternForCurrencySpacing(UCurrencySpacing type,
|
||||
UBool beforeCurrency,
|
||||
const UnicodeString& pattern);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
DecimalFormatSymbols();
|
||||
|
||||
/**
|
||||
* Initializes the symbols from the LocaleElements resource bundle.
|
||||
* Note: The organization of LocaleElements badly needs to be
|
||||
* cleaned up.
|
||||
*
|
||||
* @param locale The locale to get symbols for.
|
||||
* @param success Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @param useLastResortData determine if use last resort data
|
||||
*/
|
||||
void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
|
||||
|
||||
/**
|
||||
* Initialize the symbols with default values.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
void setCurrencyForSymbols();
|
||||
|
||||
public:
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* _Internal_ function - more efficient version of getSymbol,
|
||||
* returning a const reference to one of the symbol strings.
|
||||
* The returned reference becomes invalid when the symbol is changed
|
||||
* or when the DecimalFormatSymbols are destroyed.
|
||||
* ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
|
||||
*
|
||||
* @param symbol Constant to indicate a number format symbol.
|
||||
* @return the format symbol by the param 'symbol'
|
||||
* @internal
|
||||
*/
|
||||
inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
|
||||
|
||||
/**
|
||||
* Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
|
||||
* @internal
|
||||
*/
|
||||
inline const UChar* getCurrencyPattern(void) const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
/**
|
||||
* Private symbol strings.
|
||||
* They are either loaded from a resource bundle or otherwise owned.
|
||||
* setSymbol() clones the symbol string.
|
||||
* Readonly aliases can only come from a resource bundle, so that we can always
|
||||
* use fastCopyFrom() with them.
|
||||
*
|
||||
* If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
|
||||
* from private to protected,
|
||||
* or when fSymbols can be set any other way that allows them to be readonly aliases
|
||||
* to non-resource bundle strings,
|
||||
* then regular UnicodeString copies must be used instead of fastCopyFrom().
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
UnicodeString fSymbols[kFormatSymbolCount];
|
||||
|
||||
/**
|
||||
* Non-symbol variable for getConstSymbol(). Always empty.
|
||||
* @internal
|
||||
*/
|
||||
UnicodeString fNoSymbol;
|
||||
|
||||
Locale locale;
|
||||
|
||||
char actualLocale[ULOC_FULLNAME_CAPACITY];
|
||||
char validLocale[ULOC_FULLNAME_CAPACITY];
|
||||
const UChar* currPattern;
|
||||
|
||||
UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
|
||||
UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
inline UnicodeString
|
||||
DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
|
||||
const UnicodeString *strPtr;
|
||||
if(symbol < kFormatSymbolCount) {
|
||||
strPtr = &fSymbols[symbol];
|
||||
} else {
|
||||
strPtr = &fNoSymbol;
|
||||
}
|
||||
return *strPtr;
|
||||
}
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
||||
inline const UnicodeString &
|
||||
DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
|
||||
const UnicodeString *strPtr;
|
||||
if(symbol < kFormatSymbolCount) {
|
||||
strPtr = &fSymbols[symbol];
|
||||
} else {
|
||||
strPtr = &fNoSymbol;
|
||||
}
|
||||
return *strPtr;
|
||||
}
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
inline void
|
||||
DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
|
||||
if(symbol<kFormatSymbolCount) {
|
||||
fSymbols[symbol]=value;
|
||||
}
|
||||
|
||||
// If the zero digit is being set to a known zero digit according to Unicode,
|
||||
// then we automatically set the corresponding 1-9 digits
|
||||
if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
|
||||
UChar32 sym = value.char32At(0);
|
||||
if ( u_charDigitValue(sym) == 0 ) {
|
||||
for ( int8_t i = 1 ; i<= 9 ; i++ ) {
|
||||
sym++;
|
||||
fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
inline Locale
|
||||
DecimalFormatSymbols::getLocale() const {
|
||||
return locale;
|
||||
}
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
inline const UChar*
|
||||
DecimalFormatSymbols::getCurrencyPattern() const {
|
||||
return currPattern;
|
||||
}
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _DCFMTSYM
|
||||
//eof
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,215 +0,0 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*
|
||||
* FILE NAME: DOCMAIN.h
|
||||
*
|
||||
* Date Name Description
|
||||
* 12/11/2000 Ram Creation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief (Non API- contains Doxygen definitions)
|
||||
*
|
||||
* This file contains documentation for Doxygen and doesnot have
|
||||
* any significance with respect to C or C++ API
|
||||
*/
|
||||
|
||||
/*! \mainpage
|
||||
*
|
||||
* \section API API Reference Usage
|
||||
*
|
||||
* <h3>C++ Programmers:</h3>
|
||||
* <p>Use <a href="hierarchy.html">Class Hierarchy</a> or <a href="classes.html"> Alphabetical List </a>
|
||||
* or <a href="annotated.html"> Compound List</a>
|
||||
* to find the class you are interested in. For example, to find BreakIterator,
|
||||
* you can go to the <a href="classes.html"> Alphabetical List</a>, then click on
|
||||
* "BreakIterator". Once you are at the class, you will find an inheritance
|
||||
* chart, a list of the public members, a detailed description of the class,
|
||||
* then detailed member descriptions.</p>
|
||||
*
|
||||
* <h3>C Programmers:</h3>
|
||||
* <p>Use <a href="#Module">Module List</a> or <a href="globals.html">File Members</a>
|
||||
* to find a list of all the functions and constants.
|
||||
* For example, to find BreakIterator functions you would click on
|
||||
* <a href="files.html"> File List</a>,
|
||||
* then find "ubrk.h" and click on it. You will find descriptions of Defines,
|
||||
* Typedefs, Enumerations, and Functions, with detailed descriptions below.
|
||||
* If you want to find a specific function, such as ubrk_next(), then click
|
||||
* first on <a href="globals.html"> File Members</a>, then use your browser
|
||||
* Find dialog to search for "ubrk_next()".</p>
|
||||
*
|
||||
*
|
||||
* <h3>API References for Previous Releases</h3>
|
||||
* <p>The API References for each release of ICU are also available as
|
||||
* a zip file from the ICU
|
||||
* <a href="http://site.icu-project.org/download">download page</a>.</p>
|
||||
*
|
||||
* <hr>
|
||||
*
|
||||
* <h2>Architecture (User's Guide)</h2>
|
||||
* <ul>
|
||||
* <li><a href="http://userguide.icu-project.org/">Introduction</a></li>
|
||||
* <li><a href="http://userguide.icu-project.org/i18n">Internationalization</a></li>
|
||||
* <li><a href="http://userguide.icu-project.org/design">Locale Model, Multithreading, Error Handling, etc.</a></li>
|
||||
* <li><a href="http://userguide.icu-project.org/conversion">Conversion</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <hr>
|
||||
*\htmlonly <h2><a NAME="Module">Module List</a></h2> \endhtmlonly
|
||||
* <table border="1" cols="3" align="center">
|
||||
* <tr>
|
||||
* <td><strong>Module Name</strong></td>
|
||||
* <td><strong>C</strong></td>
|
||||
* <td><strong>C++</strong></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Basic Types and Constants</td>
|
||||
* <td>utypes.h</td>
|
||||
* <td>utypes.h</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Strings and Character Iteration</td>
|
||||
* <td>ustring.h, utf8.h, utf16.h, UText, UCharIterator</td>
|
||||
* <td>icu::UnicodeString, icu::CharacterIterator, icu::Appendable, icu::StringPiece,icu::ByteSink</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Unicode Character<br/>Properties and Names</td>
|
||||
* <td>uchar.h, uscript.h</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Sets of Unicode Code Points and Strings</td>
|
||||
* <td>uset.h</td>
|
||||
* <td>icu::UnicodeSet</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Maps from Strings to Integer Values</td>
|
||||
* <td>(no C API)</td>
|
||||
* <td>icu::BytesTrie, icu::UCharsTrie</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Codepage Conversion</td>
|
||||
* <td>ucnv.h, ucnvsel.hb</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Unicode Text Compression</td>
|
||||
* <td>ucnv.h<br/>(encoding name "SCSU" or "BOCU-1")</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Locales </td>
|
||||
* <td>uloc.h</a></td>
|
||||
* <td>icu::Locale</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Resource Bundles</td>
|
||||
* <td>ures.h</td>
|
||||
* <td>icu::ResourceBundle</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Normalization</td>
|
||||
* <td>unorm2.h</td>
|
||||
* <td>icu::Normalizer2</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Calendars</td>
|
||||
* <td>ucal.h</td>
|
||||
* <td>icu::Calendar</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Date and Time Formatting</td>
|
||||
* <td>udat.h</td>
|
||||
* <td>icu::DateFormat</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Message Formatting</td>
|
||||
* <td>umsg.h</td>
|
||||
* <td>icu::MessageFormat</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Number Formatting</td>
|
||||
* <td>unum.h</td>
|
||||
* <td>icu::NumberFormat</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Number Spellout<br/>(Rule Based Number Formatting)</td>
|
||||
* <td>unum.h<br/>(use UNUM_SPELLOUT)</td>
|
||||
* <td>icu::RuleBasedNumberFormat</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Text Transformation<br/>(Transliteration)</td>
|
||||
* <td>utrans.h</td>
|
||||
* <td>icu::Transliterator</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Bidirectional Algorithm</td>
|
||||
* <td>ubidi.h</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Arabic Shaping</td>
|
||||
* <td>ushape.h</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Collation</td>
|
||||
* <td>ucol.h</td>
|
||||
* <td>icu::Collator</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>String Searching</td>
|
||||
* <td>usearch.h</td>
|
||||
* <td>icu::StringSearch</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Index Characters/<br/>Bucketing for Sorted Lists</td>
|
||||
* <td>(no C API)</td>
|
||||
* <td>icu::AlphabeticIndex</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Text Boundary Analysis<br/>(Break Iteration)</td>
|
||||
* <td>ubrk.h</td>
|
||||
* <td>icu::BreakIterator</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Regular Expressions</td>
|
||||
* <td>uregex.h</td>
|
||||
* <td>icu::RegexPattern, icu::RegexMatcher</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>StringPrep</td>
|
||||
* <td>usprep.h</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>International Domain Names in Applications:<br/>
|
||||
* UTS #46 in C/C++, IDNA2003 only via C API</td>
|
||||
* <td>uidna.h</td>
|
||||
* <td>idna.h</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Identifier Spoofing & Confusability</td>
|
||||
* <td>uspoof.h</td>
|
||||
* <td>C API</td>
|
||||
* <tr>
|
||||
* <td>Universal Time Scale</td>
|
||||
* <td>utmscale.h</td>
|
||||
* <td>C API</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Layout Engine/Complex Text Layout</td>
|
||||
* <td>loengine.h</td>
|
||||
* <td>icu::LayoutEngine,icu::ParagraphLayout</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ICU I/O</td>
|
||||
* <td>ustdio.h</td>
|
||||
* <td>ustream.h</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <i>This main page is generated from docmain.h</i>
|
||||
*/
|
||||
@@ -1,847 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File DTFMTSYM.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 07/21/98 stephen Added getZoneIndex()
|
||||
* Changed to match C++ conventions
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef DTFMTSYM_H
|
||||
#define DTFMTSYM_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/calendar.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/ures.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Symbols for formatting dates.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/* forward declaration */
|
||||
class SimpleDateFormat;
|
||||
class Hashtable;
|
||||
|
||||
/**
|
||||
* DateFormatSymbols is a public class for encapsulating localizable date-time
|
||||
* formatting data -- including timezone data. DateFormatSymbols is used by
|
||||
* DateFormat and SimpleDateFormat.
|
||||
* <P>
|
||||
* Rather than first creating a DateFormatSymbols to get a date-time formatter
|
||||
* by using a SimpleDateFormat constructor, clients are encouraged to create a
|
||||
* date-time formatter using the getTimeInstance(), getDateInstance(), or
|
||||
* getDateTimeInstance() method in DateFormat. Each of these methods can return a
|
||||
* date/time formatter initialized with a default format pattern along with the
|
||||
* date-time formatting data for a given or default locale. After a formatter is
|
||||
* created, clients may modify the format pattern using the setPattern function
|
||||
* as so desired. For more information on using these formatter factory
|
||||
* functions, see DateFormat.
|
||||
* <P>
|
||||
* If clients decide to create a date-time formatter with a particular format
|
||||
* pattern and locale, they can do so with new SimpleDateFormat(aPattern,
|
||||
* new DateFormatSymbols(aLocale)). This will load the appropriate date-time
|
||||
* formatting data from the locale.
|
||||
* <P>
|
||||
* DateFormatSymbols objects are clonable. When clients obtain a
|
||||
* DateFormatSymbols object, they can feel free to modify the date-time
|
||||
* formatting data as necessary. For instance, clients can
|
||||
* replace the localized date-time format pattern characters with the ones that
|
||||
* they feel easy to remember. Or they can change the representative cities
|
||||
* originally picked by default to using their favorite ones.
|
||||
* <P>
|
||||
* DateFormatSymbols are not expected to be subclassed. Data for a calendar is
|
||||
* loaded out of resource bundles. The 'type' parameter indicates the type of
|
||||
* calendar, for example, "gregorian" or "japanese". If the type is not gregorian
|
||||
* (or NULL, or an empty string) then the type is appended to the resource name,
|
||||
* for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did
|
||||
* not exist (even in root), then this class will fall back to just 'Eras', that is,
|
||||
* Gregorian data. Therefore, the calendar implementor MUST ensure that the root
|
||||
* locale at least contains any resources that are to be particularized for the
|
||||
* calendar type.
|
||||
*/
|
||||
class U_I18N_API DateFormatSymbols : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the default locale, in the default calendar (Gregorian).
|
||||
* <P>
|
||||
* NOTE: This constructor will never fail; if it cannot get resource
|
||||
* data for the default locale, it will return a last-resort object
|
||||
* based on hard-coded strings.
|
||||
*
|
||||
* @param status Status code. Failure
|
||||
* results if the resources for the default cannot be
|
||||
* found or cannot be loaded
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormatSymbols(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the given locale, in the default calendar (Gregorian).
|
||||
*
|
||||
* @param locale Locale to load format data from.
|
||||
* @param status Status code. Failure
|
||||
* results if the resources for the locale cannot be
|
||||
* found or cannot be loaded
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormatSymbols(const Locale& locale,
|
||||
UErrorCode& status);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the default locale, in the default calendar (Gregorian).
|
||||
* <P>
|
||||
* NOTE: This constructor will never fail; if it cannot get resource
|
||||
* data for the default locale, it will return a last-resort object
|
||||
* based on hard-coded strings.
|
||||
*
|
||||
* @param type Type of calendar (as returned by Calendar::getType).
|
||||
* Will be used to access the correct set of strings.
|
||||
* (NULL or empty string defaults to "gregorian".)
|
||||
* @param status Status code. Failure
|
||||
* results if the resources for the default cannot be
|
||||
* found or cannot be loaded
|
||||
* @internal
|
||||
*/
|
||||
DateFormatSymbols(const char *type, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the given locale, in the default calendar (Gregorian).
|
||||
*
|
||||
* @param locale Locale to load format data from.
|
||||
* @param type Type of calendar (as returned by Calendar::getType).
|
||||
* Will be used to access the correct set of strings.
|
||||
* (NULL or empty string defaults to "gregorian".)
|
||||
* @param status Status code. Failure
|
||||
* results if the resources for the locale cannot be
|
||||
* found or cannot be loaded
|
||||
* @internal
|
||||
*/
|
||||
DateFormatSymbols(const Locale& locale,
|
||||
const char *type,
|
||||
UErrorCode& status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormatSymbols(const DateFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
DateFormatSymbols& operator=(const DateFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Destructor. This is nonvirtual because this class is not designed to be
|
||||
* subclassed.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~DateFormatSymbols();
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*
|
||||
* @param other the DateFormatSymbols object to be compared with.
|
||||
* @return true if other is semantically equal to this.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const DateFormatSymbols& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*
|
||||
* @param other the DateFormatSymbols object to be compared with.
|
||||
* @return true if other is semantically unequal to this.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Gets abbreviated era strings. For example: "AD" and "BC".
|
||||
*
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the era strings.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getEras(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets abbreviated era strings. For example: "AD" and "BC".
|
||||
* @param eras Array of era strings (DateFormatSymbols retains ownership.)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setEras(const UnicodeString* eras, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets era name strings. For example: "Anno Domini" and "Before Christ".
|
||||
*
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the era name strings.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
const UnicodeString* getEraNames(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets era name strings. For example: "Anno Domini" and "Before Christ".
|
||||
* @param eraNames Array of era name strings (DateFormatSymbols retains ownership.)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void setEraNames(const UnicodeString* eraNames, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets narrow era strings. For example: "A" and "B".
|
||||
*
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the narrow era strings.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
const UnicodeString* getNarrowEras(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets narrow era strings. For example: "A" and "B".
|
||||
* @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets month strings. For example: "January", "February", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the month strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getMonths(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets month strings. For example: "January", "February", etc.
|
||||
*
|
||||
* @param months the new month strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setMonths(const UnicodeString* months, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets short month strings. For example: "Jan", "Feb", etc.
|
||||
*
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the short month strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getShortMonths(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets short month strings. For example: "Jan", "Feb", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @param shortMonths the new short month strings. (not adopted; caller retains ownership)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setShortMonths(const UnicodeString* shortMonths, int32_t count);
|
||||
|
||||
/**
|
||||
* Selector for date formatting context
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
enum DtContextType {
|
||||
FORMAT,
|
||||
STANDALONE,
|
||||
DT_CONTEXT_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* Selector for date formatting width
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
enum DtWidthType {
|
||||
ABBREVIATED,
|
||||
WIDE,
|
||||
NARROW,
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Short width is currently only supported for weekday names.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
SHORT,
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
/**
|
||||
*/
|
||||
DT_WIDTH_COUNT = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets month strings by width and context. For example: "January", "February", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
|
||||
* @return the month strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
|
||||
|
||||
/**
|
||||
* Sets month strings by width and context. For example: "January", "February", etc.
|
||||
*
|
||||
* @param months The new month strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
|
||||
|
||||
/**
|
||||
* Gets wide weekday strings. For example: "Sunday", "Monday", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the weekday strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getWeekdays(int32_t& count) const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets wide weekday strings. For example: "Sunday", "Monday", etc.
|
||||
* @param weekdays the new weekday strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setWeekdays(const UnicodeString* weekdays, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
|
||||
* misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getShortWeekdays(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
|
||||
* misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
|
||||
* @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
|
||||
|
||||
/**
|
||||
* Gets weekday strings by width and context. For example: "Sunday", "Monday", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
|
||||
* @return the month strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
|
||||
|
||||
/**
|
||||
* Sets weekday strings by width and context. For example: "Sunday", "Monday", etc.
|
||||
* @param weekdays The new weekday strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
|
||||
|
||||
/**
|
||||
* Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE or ABBREVIATED. There
|
||||
* are no NARROW quarters.
|
||||
* @return the quarter strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
|
||||
|
||||
/**
|
||||
* Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
|
||||
*
|
||||
* @param quarters The new quarter strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE or ABBREVIATED. There
|
||||
* are no NARROW quarters.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
|
||||
|
||||
/**
|
||||
* Gets AM/PM strings. For example: "AM" and "PM".
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the weekday strings. (DateFormatSymbols retains ownership.)
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const UnicodeString* getAmPmStrings(int32_t& count) const;
|
||||
|
||||
/**
|
||||
* Sets ampm strings. For example: "AM" and "PM".
|
||||
* @param ampms the new ampm strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setAmPmStrings(const UnicodeString* ampms, int32_t count);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Somewhat temporary constants for leap month pattern types, adequate for supporting
|
||||
* just leap month patterns as needed for Chinese lunar calendar.
|
||||
* Eventually we will add full support for different month pattern types (needed for
|
||||
* other calendars such as Hindu) at which point this approach will be replaced by a
|
||||
* more complete approach.
|
||||
* @internal
|
||||
*/
|
||||
enum EMonthPatternType
|
||||
{
|
||||
kLeapMonthPatternFormatWide,
|
||||
kLeapMonthPatternFormatAbbrev,
|
||||
kLeapMonthPatternFormatNarrow,
|
||||
kLeapMonthPatternStandaloneWide,
|
||||
kLeapMonthPatternStandaloneAbbrev,
|
||||
kLeapMonthPatternStandaloneNarrow,
|
||||
kLeapMonthPatternNumeric,
|
||||
kMonthPatternsCount
|
||||
};
|
||||
|
||||
/**
|
||||
* Somewhat temporary function for getting complete set of leap month patterns for all
|
||||
* contexts & widths, indexed by EMonthPatternType values. Returns NULL if calendar
|
||||
* does not have leap month patterns. Note, there is currently no setter for this.
|
||||
* Eventually we will add full support for different month pattern types (needed for
|
||||
* other calendars such as Hindu) at which point this approach will be replaced by a
|
||||
* more complete approach.
|
||||
* @param count Filled in with length of the array (may be 0).
|
||||
* @return The leap month patterns (DateFormatSymbols retains ownership).
|
||||
* May be NULL if there are no leap month patterns for this calendar.
|
||||
* @internal
|
||||
*/
|
||||
const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Gets timezone strings. These strings are stored in a 2-dimensional array.
|
||||
* @param rowCount Output param to receive number of rows.
|
||||
* @param columnCount Output param to receive number of columns.
|
||||
* @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.)
|
||||
* @deprecated ICU 3.6
|
||||
*/
|
||||
const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Sets timezone strings. These strings are stored in a 2-dimensional array.
|
||||
* <p><b>Note:</b> SimpleDateFormat no longer use the zone strings stored in
|
||||
* a DateFormatSymbols. Therefore, the time zone strings set by this mthod
|
||||
* have no effects in an instance of SimpleDateFormat for formatting time
|
||||
* zones.
|
||||
* @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership)
|
||||
* @param rowCount The number of rows (count of first index).
|
||||
* @param columnCount The number of columns (count of second index).
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount);
|
||||
|
||||
/**
|
||||
* Get the non-localized date-time pattern characters.
|
||||
* @return the non-localized date-time pattern characters
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const UChar * U_EXPORT2 getPatternUChars(void);
|
||||
|
||||
/**
|
||||
* Gets localized date-time pattern characters. For example: 'u', 't', etc.
|
||||
* <p>
|
||||
* Note: ICU no longer provides localized date-time pattern characters for a locale
|
||||
* starting ICU 3.8. This method returns the non-localized date-time pattern
|
||||
* characters unless user defined localized data is set by setLocalPatternChars.
|
||||
* @param result Output param which will receive the localized date-time pattern characters.
|
||||
* @return A reference to 'result'.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getLocalPatternChars(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Sets localized date-time pattern characters. For example: 'u', 't', etc.
|
||||
* @param newLocalPatternChars the new localized date-time
|
||||
* pattern characters.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
|
||||
|
||||
/**
|
||||
* Returns the locale for this object. Two flavors are available:
|
||||
* valid and actual locale.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Constants for capitalization context usage types.
|
||||
* @internal
|
||||
*/
|
||||
enum ECapitalizationContextUsageType
|
||||
{
|
||||
kCapContextUsageOther,
|
||||
kCapContextUsageMonthFormat, /* except narrow */
|
||||
kCapContextUsageMonthStandalone, /* except narrow */
|
||||
kCapContextUsageMonthNarrow,
|
||||
kCapContextUsageDayFormat, /* except narrow */
|
||||
kCapContextUsageDayStandalone, /* except narrow */
|
||||
kCapContextUsageDayNarrow,
|
||||
kCapContextUsageEraWide,
|
||||
kCapContextUsageEraAbbrev,
|
||||
kCapContextUsageEraNarrow,
|
||||
kCapContextUsageZoneLong,
|
||||
kCapContextUsageZoneShort,
|
||||
kCapContextUsageMetazoneLong,
|
||||
kCapContextUsageMetazoneShort,
|
||||
kCapContextUsageTypeCount
|
||||
};
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
|
||||
friend class SimpleDateFormat;
|
||||
friend class DateFormatSymbolsSingleSetter; // see udat.cpp
|
||||
|
||||
/**
|
||||
* Abbreviated era strings. For example: "AD" and "BC".
|
||||
*/
|
||||
UnicodeString* fEras;
|
||||
int32_t fErasCount;
|
||||
|
||||
/**
|
||||
* Era name strings. For example: "Anno Domini" and "Before Christ".
|
||||
*/
|
||||
UnicodeString* fEraNames;
|
||||
int32_t fEraNamesCount;
|
||||
|
||||
/**
|
||||
* Narrow era strings. For example: "A" and "B".
|
||||
*/
|
||||
UnicodeString* fNarrowEras;
|
||||
int32_t fNarrowErasCount;
|
||||
|
||||
/**
|
||||
* Month strings. For example: "January", "February", etc.
|
||||
*/
|
||||
UnicodeString* fMonths;
|
||||
int32_t fMonthsCount;
|
||||
|
||||
/**
|
||||
* Short month strings. For example: "Jan", "Feb", etc.
|
||||
*/
|
||||
UnicodeString* fShortMonths;
|
||||
int32_t fShortMonthsCount;
|
||||
|
||||
/**
|
||||
* Narrow month strings. For example: "J", "F", etc.
|
||||
*/
|
||||
UnicodeString* fNarrowMonths;
|
||||
int32_t fNarrowMonthsCount;
|
||||
|
||||
/**
|
||||
* Standalone Month strings. For example: "January", "February", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneMonths;
|
||||
int32_t fStandaloneMonthsCount;
|
||||
|
||||
/**
|
||||
* Standalone Short month strings. For example: "Jan", "Feb", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneShortMonths;
|
||||
int32_t fStandaloneShortMonthsCount;
|
||||
|
||||
/**
|
||||
* Standalone Narrow month strings. For example: "J", "F", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneNarrowMonths;
|
||||
int32_t fStandaloneNarrowMonthsCount;
|
||||
|
||||
/**
|
||||
* CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc.
|
||||
*/
|
||||
UnicodeString* fWeekdays;
|
||||
int32_t fWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
|
||||
*/
|
||||
UnicodeString* fShortWeekdays;
|
||||
int32_t fShortWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style format short weekday strings. For example: "Su", "Mo", etc.
|
||||
*/
|
||||
UnicodeString* fShorterWeekdays;
|
||||
int32_t fShorterWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style format narrow weekday strings. For example: "S", "M", etc.
|
||||
*/
|
||||
UnicodeString* fNarrowWeekdays;
|
||||
int32_t fNarrowWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneWeekdays;
|
||||
int32_t fStandaloneWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneShortWeekdays;
|
||||
int32_t fStandaloneShortWeekdaysCount;
|
||||
|
||||
/**
|
||||
* CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneShorterWeekdays;
|
||||
int32_t fStandaloneShorterWeekdaysCount;
|
||||
|
||||
/**
|
||||
* Standalone Narrow weekday strings. For example: "Sun", "Mon", etc.
|
||||
*/
|
||||
UnicodeString* fStandaloneNarrowWeekdays;
|
||||
int32_t fStandaloneNarrowWeekdaysCount;
|
||||
|
||||
/**
|
||||
* Ampm strings. For example: "AM" and "PM".
|
||||
*/
|
||||
UnicodeString* fAmPms;
|
||||
int32_t fAmPmsCount;
|
||||
|
||||
/**
|
||||
* Quarter strings. For example: "1st quarter", "2nd quarter", etc.
|
||||
*/
|
||||
UnicodeString *fQuarters;
|
||||
int32_t fQuartersCount;
|
||||
|
||||
/**
|
||||
* Short quarters. For example: "Q1", "Q2", etc.
|
||||
*/
|
||||
UnicodeString *fShortQuarters;
|
||||
int32_t fShortQuartersCount;
|
||||
|
||||
/**
|
||||
* Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc.
|
||||
*/
|
||||
UnicodeString *fStandaloneQuarters;
|
||||
int32_t fStandaloneQuartersCount;
|
||||
|
||||
/**
|
||||
* Standalone short quarter strings. For example: "Q1", "Q2", etc.
|
||||
*/
|
||||
UnicodeString *fStandaloneShortQuarters;
|
||||
int32_t fStandaloneShortQuartersCount;
|
||||
|
||||
/**
|
||||
* All leap month patterns, for example "{0}bis".
|
||||
*/
|
||||
UnicodeString *fLeapMonthPatterns;
|
||||
int32_t fLeapMonthPatternsCount;
|
||||
|
||||
/**
|
||||
* (Format) Short cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai"
|
||||
*/
|
||||
UnicodeString* fShortYearNames;
|
||||
int32_t fShortYearNamesCount;
|
||||
|
||||
/**
|
||||
* Localized names of time zones in this locale. This is a
|
||||
* two-dimensional array of strings of size n by m,
|
||||
* where m is at least 5 and up to 7. Each of the n rows is an
|
||||
* entry containing the localized names for a single TimeZone.
|
||||
*
|
||||
* Each such row contains (with i ranging from 0..n-1):
|
||||
*
|
||||
* zoneStrings[i][0] - time zone ID
|
||||
* example: America/Los_Angeles
|
||||
* zoneStrings[i][1] - long name of zone in standard time
|
||||
* example: Pacific Standard Time
|
||||
* zoneStrings[i][2] - short name of zone in standard time
|
||||
* example: PST
|
||||
* zoneStrings[i][3] - long name of zone in daylight savings time
|
||||
* example: Pacific Daylight Time
|
||||
* zoneStrings[i][4] - short name of zone in daylight savings time
|
||||
* example: PDT
|
||||
* zoneStrings[i][5] - location name of zone
|
||||
* example: United States (Los Angeles)
|
||||
* zoneStrings[i][6] - long generic name of zone
|
||||
* example: Pacific Time
|
||||
* zoneStrings[i][7] - short generic of zone
|
||||
* example: PT
|
||||
*
|
||||
* The zone ID is not localized; it corresponds to the ID
|
||||
* value associated with a system time zone object. All other entries
|
||||
* are localized names. If a zone does not implement daylight savings
|
||||
* time, the daylight savings time names are ignored.
|
||||
*
|
||||
* Note:CLDR 1.5 introduced metazone and its historical mappings.
|
||||
* This simple two-dimensional array is no longer sufficient to represent
|
||||
* localized names and its historic changes. Since ICU 3.8.1, localized
|
||||
* zone names extracted from ICU locale data is stored in a ZoneStringFormat
|
||||
* instance. But we still need to support the old way of customizing
|
||||
* localized zone names, so we keep this field for the purpose.
|
||||
*/
|
||||
UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
|
||||
UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
|
||||
int32_t fZoneStringsRowCount;
|
||||
int32_t fZoneStringsColCount;
|
||||
|
||||
Locale fZSFLocale; // Locale used for getting ZoneStringFormat
|
||||
|
||||
/**
|
||||
* Localized date-time pattern characters. For example: use 'u' as 'y'.
|
||||
*/
|
||||
UnicodeString fLocalPatternChars;
|
||||
|
||||
/**
|
||||
* Capitalization transforms. For each usage type, the first array element indicates
|
||||
* whether to titlecase for uiListOrMenu context, the second indicates whether to
|
||||
* titlecase for stand-alone context.
|
||||
*/
|
||||
UBool fCapitalization[kCapContextUsageTypeCount][2];
|
||||
|
||||
private:
|
||||
/** valid/actual locale information
|
||||
* these are always ICU locales, so the length should not be a problem
|
||||
*/
|
||||
char validLocale[ULOC_FULLNAME_CAPACITY];
|
||||
char actualLocale[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
DateFormatSymbols(); // default constructor not implemented
|
||||
|
||||
/**
|
||||
* Called by the constructors to actually load data from the resources
|
||||
*
|
||||
* @param locale The locale to get symbols for.
|
||||
* @param type Calendar Type (as from Calendar::getType())
|
||||
* @param status Input/output parameter, set to success or
|
||||
* failure code upon return.
|
||||
* @param useLastResortData determine if use last resort data
|
||||
*/
|
||||
void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE);
|
||||
|
||||
/**
|
||||
* Copy or alias an array in another object, as appropriate.
|
||||
*
|
||||
* @param dstArray the copy destination array.
|
||||
* @param dstCount fill in with the lenth of 'dstArray'.
|
||||
* @param srcArray the source array to be copied.
|
||||
* @param srcCount the length of items to be copied from the 'srcArray'.
|
||||
*/
|
||||
static void assignArray(UnicodeString*& dstArray,
|
||||
int32_t& dstCount,
|
||||
const UnicodeString* srcArray,
|
||||
int32_t srcCount);
|
||||
|
||||
/**
|
||||
* Return true if the given arrays' contents are equal, or if the arrays are
|
||||
* identical (pointers are equal).
|
||||
*
|
||||
* @param array1 one array to be compared with.
|
||||
* @param array2 another array to be compared with.
|
||||
* @param count the length of items to be copied.
|
||||
* @return true if the given arrays' contents are equal, or if the arrays are
|
||||
* identical (pointers are equal).
|
||||
*/
|
||||
static UBool arrayCompare(const UnicodeString* array1,
|
||||
const UnicodeString* array2,
|
||||
int32_t count);
|
||||
|
||||
/**
|
||||
* Create a copy, in fZoneStrings, of the given zone strings array. The
|
||||
* member variables fZoneStringsRowCount and fZoneStringsColCount should be
|
||||
* set already by the caller.
|
||||
*/
|
||||
void createZoneStrings(const UnicodeString *const * otherStrings);
|
||||
|
||||
/**
|
||||
* Delete all the storage owned by this object.
|
||||
*/
|
||||
void dispose(void);
|
||||
|
||||
/**
|
||||
* Copy all of the other's data to this.
|
||||
* @param other the object to be copied.
|
||||
*/
|
||||
void copyData(const DateFormatSymbols& other);
|
||||
|
||||
/**
|
||||
* Create zone strings array by locale if not yet available
|
||||
*/
|
||||
void initZoneStringsArray(void);
|
||||
|
||||
/**
|
||||
* Delete just the zone strings.
|
||||
*/
|
||||
void disposeZoneStrings(void);
|
||||
|
||||
/**
|
||||
* Returns the date format field index of the pattern character c,
|
||||
* or UDAT_FIELD_COUNT if c is not a pattern character.
|
||||
*/
|
||||
static UDateFormatField U_EXPORT2 getPatternCharIndex(UChar c);
|
||||
|
||||
/**
|
||||
* Returns TRUE if f (with its pattern character repeated count times) is a numeric field.
|
||||
*/
|
||||
static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
|
||||
|
||||
/**
|
||||
* Returns TRUE if c (repeated count times) is the pattern character for a numeric field.
|
||||
*/
|
||||
static UBool U_EXPORT2 isNumericPatternChar(UChar c, int32_t count);
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _DTFMTSYM
|
||||
//eof
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008-2009, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
* File DTINTRV.H
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __DTINTRV_H__
|
||||
#define __DTINTRV_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Date Interval data type
|
||||
*/
|
||||
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a date interval.
|
||||
* It is a pair of UDate representing from UDate 1 to UDate 2.
|
||||
* @stable ICU 4.0
|
||||
**/
|
||||
class U_COMMON_API DateInterval : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct a DateInterval given a from date and a to date.
|
||||
* @param fromDate The from date in date interval.
|
||||
* @param toDate The to date in date interval.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateInterval(UDate fromDate, UDate toDate);
|
||||
|
||||
/**
|
||||
* destructor
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual ~DateInterval();
|
||||
|
||||
/**
|
||||
* Get the from date.
|
||||
* @return the from date in dateInterval.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UDate getFromDate() const;
|
||||
|
||||
/**
|
||||
* Get the to date.
|
||||
* @return the to date in dateInterval.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UDate getToDate() const;
|
||||
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to
|
||||
* a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . erived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
||||
* method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
||||
* methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateInterval(const DateInterval& other);
|
||||
|
||||
/**
|
||||
* Default assignment operator
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateInterval& operator=(const DateInterval&);
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @return TRUE if the two DateIntervals are the same
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator==(const DateInterval& other) const;
|
||||
|
||||
/**
|
||||
* Non-equality operator
|
||||
* @return TRUE if the two DateIntervals are not the same
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool operator!=(const DateInterval& other) const;
|
||||
|
||||
|
||||
/**
|
||||
* clone this object.
|
||||
* The caller owns the result and should delete it when done.
|
||||
* @return a cloned DateInterval
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual DateInterval* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor, not implemented.
|
||||
*/
|
||||
DateInterval();
|
||||
|
||||
UDate fromDate;
|
||||
UDate toDate;
|
||||
|
||||
} ;// end class DateInterval
|
||||
|
||||
|
||||
inline UDate
|
||||
DateInterval::getFromDate() const {
|
||||
return fromDate;
|
||||
}
|
||||
|
||||
|
||||
inline UDate
|
||||
DateInterval::getToDate() const {
|
||||
return toDate;
|
||||
}
|
||||
|
||||
|
||||
inline UBool
|
||||
DateInterval::operator!=(const DateInterval& other) const {
|
||||
return ( !operator==(other) );
|
||||
}
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,985 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2008-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
* File DTITVFMT.H
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __DTITVFMT_H__
|
||||
#define __DTITVFMT_H__
|
||||
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Format and parse date interval in a language-independent manner.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/ucal.h"
|
||||
#include "unicode/smpdtfmt.h"
|
||||
#include "unicode/dtintrv.h"
|
||||
#include "unicode/dtitvinf.h"
|
||||
#include "unicode/dtptngen.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DateIntervalFormat is a class for formatting and parsing date
|
||||
* intervals in a language-independent manner.
|
||||
* Only formatting is supported, parsing is not supported.
|
||||
*
|
||||
* <P>
|
||||
* Date interval means from one date to another date,
|
||||
* for example, from "Jan 11, 2008" to "Jan 18, 2008".
|
||||
* We introduced class DateInterval to represent it.
|
||||
* DateInterval is a pair of UDate, which is
|
||||
* the standard milliseconds since 24:00 GMT, Jan 1, 1970.
|
||||
*
|
||||
* <P>
|
||||
* DateIntervalFormat formats a DateInterval into
|
||||
* text as compactly as possible.
|
||||
* For example, the date interval format from "Jan 11, 2008" to "Jan 18,. 2008"
|
||||
* is "Jan 11-18, 2008" for English.
|
||||
* And it parses text into DateInterval,
|
||||
* although initially, parsing is not supported.
|
||||
*
|
||||
* <P>
|
||||
* There is no structural information in date time patterns.
|
||||
* For any punctuations and string literals inside a date time pattern,
|
||||
* we do not know whether it is just a separator, or a prefix, or a suffix.
|
||||
* Without such information, so, it is difficult to generate a sub-pattern
|
||||
* (or super-pattern) by algorithm.
|
||||
* So, formatting a DateInterval is pattern-driven. It is very
|
||||
* similar to formatting in SimpleDateFormat.
|
||||
* We introduce class DateIntervalInfo to save date interval
|
||||
* patterns, similar to date time pattern in SimpleDateFormat.
|
||||
*
|
||||
* <P>
|
||||
* Logically, the interval patterns are mappings
|
||||
* from (skeleton, the_largest_different_calendar_field)
|
||||
* to (date_interval_pattern).
|
||||
*
|
||||
* <P>
|
||||
* A skeleton
|
||||
* <ol>
|
||||
* <li>
|
||||
* only keeps the field pattern letter and ignores all other parts
|
||||
* in a pattern, such as space, punctuations, and string literals.
|
||||
* </li>
|
||||
* <li>
|
||||
* hides the order of fields.
|
||||
* </li>
|
||||
* <li>
|
||||
* might hide a field's pattern letter length.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
* For those non-digit calendar fields, the pattern letter length is
|
||||
* important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
|
||||
* and the field's pattern letter length is honored.
|
||||
*
|
||||
* For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
|
||||
* the field pattern length is ignored and the best match, which is defined
|
||||
* in date time patterns, will be returned without honor the field pattern
|
||||
* letter length in skeleton.
|
||||
*
|
||||
* <P>
|
||||
* The calendar fields we support for interval formatting are:
|
||||
* year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
|
||||
* Those calendar fields can be defined in the following order:
|
||||
* year > month > date > hour (in day) > minute
|
||||
*
|
||||
* The largest different calendar fields between 2 calendars is the
|
||||
* first different calendar field in above order.
|
||||
*
|
||||
* For example: the largest different calendar fields between "Jan 10, 2007"
|
||||
* and "Feb 20, 2008" is year.
|
||||
*
|
||||
* <P>
|
||||
* For other calendar fields, the compact interval formatting is not
|
||||
* supported. And the interval format will be fall back to fall-back
|
||||
* patterns, which is mostly "{date0} - {date1}".
|
||||
*
|
||||
* <P>
|
||||
* There is a set of pre-defined static skeleton strings.
|
||||
* There are pre-defined interval patterns for those pre-defined skeletons
|
||||
* in locales' resource files.
|
||||
* For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd",
|
||||
* in en_US, if the largest different calendar field between date1 and date2
|
||||
* is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy",
|
||||
* such as "Jan 10, 2007 - Jan 10, 2008".
|
||||
* If the largest different calendar field between date1 and date2 is "month",
|
||||
* the date interval pattern is "MMM d - MMM d, yyyy",
|
||||
* such as "Jan 10 - Feb 10, 2007".
|
||||
* If the largest different calendar field between date1 and date2 is "day",
|
||||
* the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007".
|
||||
*
|
||||
* For date skeleton, the interval patterns when year, or month, or date is
|
||||
* different are defined in resource files.
|
||||
* For time skeleton, the interval patterns when am/pm, or hour, or minute is
|
||||
* different are defined in resource files.
|
||||
*
|
||||
* <P>
|
||||
* If a skeleton is not found in a locale's DateIntervalInfo, which means
|
||||
* the interval patterns for the skeleton is not defined in resource file,
|
||||
* the interval pattern will falls back to the interval "fallback" pattern
|
||||
* defined in resource file.
|
||||
* If the interval "fallback" pattern is not defined, the default fall-back
|
||||
* is "{date0} - {data1}".
|
||||
*
|
||||
* <P>
|
||||
* For the combination of date and time,
|
||||
* The rule to generate interval patterns are:
|
||||
* <ol>
|
||||
* <li>
|
||||
* when the year, month, or day differs, falls back to fall-back
|
||||
* interval pattern, which mostly is the concatenate the two original
|
||||
* expressions with a separator between,
|
||||
* For example, interval pattern from "Jan 10, 2007 10:10 am"
|
||||
* to "Jan 11, 2007 10:10am" is
|
||||
* "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
|
||||
* </li>
|
||||
* <li>
|
||||
* otherwise, present the date followed by the range expression
|
||||
* for the time.
|
||||
* For example, interval pattern from "Jan 10, 2007 10:10 am"
|
||||
* to "Jan 10, 2007 11:10am" is "Jan 10, 2007 10:10 am - 11:10am"
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
*
|
||||
* <P>
|
||||
* If two dates are the same, the interval pattern is the single date pattern.
|
||||
* For example, interval pattern from "Jan 10, 2007" to "Jan 10, 2007" is
|
||||
* "Jan 10, 2007".
|
||||
*
|
||||
* Or if the presenting fields between 2 dates have the exact same values,
|
||||
* the interval pattern is the single date pattern.
|
||||
* For example, if user only requests year and month,
|
||||
* the interval pattern from "Jan 10, 2007" to "Jan 20, 2007" is "Jan 2007".
|
||||
*
|
||||
* <P>
|
||||
* DateIntervalFormat needs the following information for correct
|
||||
* formatting: time zone, calendar type, pattern, date format symbols,
|
||||
* and date interval patterns.
|
||||
* It can be instantiated in 2 ways:
|
||||
* <ol>
|
||||
* <li>
|
||||
* create an instance using default or given locale plus given skeleton.
|
||||
* Users are encouraged to created date interval formatter this way and
|
||||
* to use the pre-defined skeleton macros, such as
|
||||
* UDAT_YEAR_NUM_MONTH, which consists the calendar fields and
|
||||
* the format style.
|
||||
* </li>
|
||||
* <li>
|
||||
* create an instance using default or given locale plus given skeleton
|
||||
* plus a given DateIntervalInfo.
|
||||
* This factory method is for powerful users who want to provide their own
|
||||
* interval patterns.
|
||||
* Locale provides the timezone, calendar, and format symbols information.
|
||||
* Local plus skeleton provides full pattern information.
|
||||
* DateIntervalInfo provides the date interval patterns.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
* <P>
|
||||
* For the calendar field pattern letter, such as G, y, M, d, a, h, H, m, s etc.
|
||||
* DateIntervalFormat uses the same syntax as that of
|
||||
* DateTime format.
|
||||
*
|
||||
* <P>
|
||||
* Code Sample: general usage
|
||||
* <pre>
|
||||
* \code
|
||||
* // the date interval object which the DateIntervalFormat formats on
|
||||
* // and parses into
|
||||
* DateInterval* dtInterval = new DateInterval(1000*3600*24, 1000*3600*24*2);
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* DateIntervalFormat* dtIntervalFmt = DateIntervalFormat::createInstance(
|
||||
* UDAT_YEAR_MONTH_DAY,
|
||||
* Locale("en", "GB", ""), status);
|
||||
* UnicodeUnicodeString dateIntervalString;
|
||||
* FieldPosition pos = 0;
|
||||
* // formatting
|
||||
* dtIntervalFmt->format(dtInterval, dateIntervalUnicodeString, pos, status);
|
||||
* delete dtIntervalFmt;
|
||||
* \endcode
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
class U_I18N_API DateIntervalFormat : public Format {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from skeleton and the default locale.
|
||||
*
|
||||
* This is a convenient override of
|
||||
* createInstance(const UnicodeString& skeleton, const Locale& locale,
|
||||
* UErrorCode&)
|
||||
* with the value of locale as default locale.
|
||||
*
|
||||
* @param skeleton the skeleton on which interval format based.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return a date time interval formatter which the caller owns.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static DateIntervalFormat* U_EXPORT2 createInstance(
|
||||
const UnicodeString& skeleton,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from skeleton and a given locale.
|
||||
* <P>
|
||||
* In this factory method,
|
||||
* the date interval pattern information is load from resource files.
|
||||
* Users are encouraged to created date interval formatter this way and
|
||||
* to use the pre-defined skeleton macros.
|
||||
*
|
||||
* <P>
|
||||
* There are pre-defined skeletons (defined in udate.h) having predefined
|
||||
* interval patterns in resource files.
|
||||
* Users are encouraged to use those macros.
|
||||
* For example:
|
||||
* DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
|
||||
*
|
||||
* The given Locale provides the interval patterns.
|
||||
* For example, for en_GB, if skeleton is UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY,
|
||||
* which is "yMMMEEEd",
|
||||
* the interval patterns defined in resource file to above skeleton are:
|
||||
* "EEE, d MMM, yyyy - EEE, d MMM, yyyy" for year differs,
|
||||
* "EEE, d MMM - EEE, d MMM, yyyy" for month differs,
|
||||
* "EEE, d - EEE, d MMM, yyyy" for day differs,
|
||||
* @param skeleton the skeleton on which the interval format is based.
|
||||
* @param locale the given locale
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return a date time interval formatter which the caller owns.
|
||||
* @stable ICU 4.0
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1
|
||||
* \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined
|
||||
* <p>
|
||||
*/
|
||||
|
||||
static DateIntervalFormat* U_EXPORT2 createInstance(
|
||||
const UnicodeString& skeleton,
|
||||
const Locale& locale,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from skeleton
|
||||
* DateIntervalInfo, and default locale.
|
||||
*
|
||||
* This is a convenient override of
|
||||
* createInstance(const UnicodeString& skeleton, const Locale& locale,
|
||||
* const DateIntervalInfo& dtitvinf, UErrorCode&)
|
||||
* with the locale value as default locale.
|
||||
*
|
||||
* @param skeleton the skeleton on which interval format based.
|
||||
* @param dtitvinf the DateIntervalInfo object.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return a date time interval formatter which the caller owns.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static DateIntervalFormat* U_EXPORT2 createInstance(
|
||||
const UnicodeString& skeleton,
|
||||
const DateIntervalInfo& dtitvinf,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from skeleton
|
||||
* a DateIntervalInfo, and the given locale.
|
||||
*
|
||||
* <P>
|
||||
* In this factory method, user provides its own date interval pattern
|
||||
* information, instead of using those pre-defined data in resource file.
|
||||
* This factory method is for powerful users who want to provide their own
|
||||
* interval patterns.
|
||||
* <P>
|
||||
* There are pre-defined skeletons (defined in udate.h) having predefined
|
||||
* interval patterns in resource files.
|
||||
* Users are encouraged to use those macros.
|
||||
* For example:
|
||||
* DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
|
||||
*
|
||||
* The DateIntervalInfo provides the interval patterns.
|
||||
* and the DateIntervalInfo ownership remains to the caller.
|
||||
*
|
||||
* User are encouraged to set default interval pattern in DateIntervalInfo
|
||||
* as well, if they want to set other interval patterns ( instead of
|
||||
* reading the interval patterns from resource files).
|
||||
* When the corresponding interval pattern for a largest calendar different
|
||||
* field is not found ( if user not set it ), interval format fallback to
|
||||
* the default interval pattern.
|
||||
* If user does not provide default interval pattern, it fallback to
|
||||
* "{date0} - {date1}"
|
||||
*
|
||||
* @param skeleton the skeleton on which interval format based.
|
||||
* @param locale the given locale
|
||||
* @param dtitvinf the DateIntervalInfo object.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return a date time interval formatter which the caller owns.
|
||||
* @stable ICU 4.0
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1
|
||||
* \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtCustomized
|
||||
* <p>
|
||||
*/
|
||||
static DateIntervalFormat* U_EXPORT2 createInstance(
|
||||
const UnicodeString& skeleton,
|
||||
const Locale& locale,
|
||||
const DateIntervalInfo& dtitvinf,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual ~DateIntervalFormat();
|
||||
|
||||
/**
|
||||
* Clone this Format object polymorphically. The caller owns the result and
|
||||
* should delete it when done.
|
||||
* @return A copy of the object.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual Format* clone(void) const;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are semantically equal. Objects
|
||||
* of different subclasses are considered unequal.
|
||||
* @param other the object to be compared with.
|
||||
* @return true if the given Format objects are semantically equal.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are not semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
* @param other the object to be compared with.
|
||||
* @return true if the given Format objects are not semantically equal.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool operator!=(const Format& other) const;
|
||||
|
||||
|
||||
using Format::format;
|
||||
|
||||
/**
|
||||
* Format an object to produce a string. This method handles Formattable
|
||||
* objects with a DateInterval type.
|
||||
* If a the Formattable object type is not a DateInterval,
|
||||
* then it returns a failing UErrorCode.
|
||||
*
|
||||
* @param obj The object to format.
|
||||
* Must be a DateInterval.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param fieldPosition On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& fieldPosition,
|
||||
UErrorCode& status) const ;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Format a DateInterval to produce a string.
|
||||
*
|
||||
* @param dtInterval DateInterval to be formatted.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param fieldPosition On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& format(const DateInterval* dtInterval,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& fieldPosition,
|
||||
UErrorCode& status) const ;
|
||||
|
||||
|
||||
/**
|
||||
* Format 2 Calendars to produce a string.
|
||||
*
|
||||
* Note: "fromCalendar" and "toCalendar" are not const,
|
||||
* since calendar is not const in SimpleDateFormat::format(Calendar&),
|
||||
*
|
||||
* @param fromCalendar calendar set to the from date in date interval
|
||||
* to be formatted into date interval string
|
||||
* @param toCalendar calendar set to the to date in date interval
|
||||
* to be formatted into date interval string
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param fieldPosition On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* Caller needs to make sure it is SUCCESS
|
||||
* at the function entrance
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& format(Calendar& fromCalendar,
|
||||
Calendar& toCalendar,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& fieldPosition,
|
||||
UErrorCode& status) const ;
|
||||
|
||||
/**
|
||||
* Date interval parsing is not supported. Please do not use.
|
||||
* <P>
|
||||
* This method should handle parsing of
|
||||
* date time interval strings into Formattable objects with
|
||||
* DateInterval type, which is a pair of UDate.
|
||||
* <P>
|
||||
* Before calling, set parse_pos.index to the offset you want to start
|
||||
* parsing at in the source. After calling, parse_pos.index is the end of
|
||||
* the text you parsed. If error occurs, index is unchanged.
|
||||
* <P>
|
||||
* When parsing, leading whitespace is discarded (with a successful parse),
|
||||
* while trailing whitespace is left as is.
|
||||
* <P>
|
||||
* See Format::parseObject() for more.
|
||||
*
|
||||
* @param source The string to be parsed into an object.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parse_pos The position to start parsing at. Since no parsing
|
||||
* is supported, upon return this param is unchanged.
|
||||
* @return A newly created Formattable* object, or NULL
|
||||
* on failure. The caller owns this and should
|
||||
* delete it when done.
|
||||
* @internal ICU 4.0
|
||||
*/
|
||||
virtual void parseObject(const UnicodeString& source,
|
||||
Formattable& result,
|
||||
ParsePosition& parse_pos) const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the date time interval patterns.
|
||||
* @return the date time interval patterns associated with
|
||||
* this date interval formatter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
const DateIntervalInfo* getDateIntervalInfo(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Set the date time interval patterns.
|
||||
* @param newIntervalPatterns the given interval patterns to copy.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the date formatter
|
||||
* @return the date formatter associated with this date interval formatter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
const DateFormat* getDateFormat(void) const;
|
||||
|
||||
/**
|
||||
* Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
|
||||
* @return the time zone associated with the calendar of DateIntervalFormat.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const TimeZone& getTimeZone(void) const;
|
||||
|
||||
/**
|
||||
* Sets the time zone for the calendar used by this DateIntervalFormat object. The
|
||||
* caller no longer owns the TimeZone object and should not delete it after this call.
|
||||
* @param zoneToAdopt the TimeZone to be adopted.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual void adoptTimeZone(TimeZone* zoneToAdopt);
|
||||
|
||||
/**
|
||||
* Sets the time zone for the calendar used by this DateIntervalFormat object.
|
||||
* @param zone the new time zone.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual void setTimeZone(const TimeZone& zone);
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to
|
||||
* a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . erived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
||||
* method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
||||
* methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateIntervalFormat(const DateIntervalFormat&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateIntervalFormat& operator=(const DateIntervalFormat&);
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
* This is for ICU internal use only. Please do not use.
|
||||
* Save the interval pattern information.
|
||||
* Interval pattern consists of 2 single date patterns and the separator.
|
||||
* For example, interval pattern "MMM d - MMM d, yyyy" consists
|
||||
* a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
|
||||
* and a separator "-".
|
||||
* The pattern is divided into 2 parts. For above example,
|
||||
* the first part is "MMM d - ", and the second part is "MMM d, yyyy".
|
||||
* Also, the first date appears in an interval pattern could be
|
||||
* the earlier date or the later date.
|
||||
* And such information is saved in the interval pattern as well.
|
||||
*/
|
||||
struct PatternInfo {
|
||||
UnicodeString firstPart;
|
||||
UnicodeString secondPart;
|
||||
/**
|
||||
* Whether the first date in interval pattern is later date or not.
|
||||
* Fallback format set the default ordering.
|
||||
* And for a particular interval pattern, the order can be
|
||||
* overriden by prefixing the interval pattern with "latestFirst:" or
|
||||
* "earliestFirst:"
|
||||
* For example, given 2 date, Jan 10, 2007 to Feb 10, 2007.
|
||||
* if the fallback format is "{0} - {1}",
|
||||
* and the pattern is "d MMM - d MMM yyyy", the interval format is
|
||||
* "10 Jan - 10 Feb, 2007".
|
||||
* If the pattern is "latestFirst:d MMM - d MMM yyyy",
|
||||
* the interval format is "10 Feb - 10 Jan, 2007"
|
||||
*/
|
||||
UBool laterDateFirst;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
* @internal ICU 4.0
|
||||
*/
|
||||
DateIntervalFormat();
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from DateFormat,
|
||||
* a DateIntervalInfo, and skeleton.
|
||||
* DateFormat provides the timezone, calendar,
|
||||
* full pattern, and date format symbols information.
|
||||
* It should be a SimpleDateFormat object which
|
||||
* has a pattern in it.
|
||||
* the DateIntervalInfo provides the interval patterns.
|
||||
*
|
||||
* Note: the DateIntervalFormat takes ownership of both
|
||||
* DateFormat and DateIntervalInfo objects.
|
||||
* Caller should not delete them.
|
||||
*
|
||||
* @param locale the locale of this date interval formatter.
|
||||
* @param dtItvInfo the DateIntervalInfo object to be adopted.
|
||||
* @param skeleton the skeleton of the date formatter
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
|
||||
const UnicodeString* skeleton, UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Construct a DateIntervalFormat from DateFormat
|
||||
* and a DateIntervalInfo.
|
||||
*
|
||||
* It is a wrapper of the constructor.
|
||||
*
|
||||
* @param locale the locale of this date interval formatter.
|
||||
* @param dtitvinf the DateIntervalInfo object to be adopted.
|
||||
* @param skeleton the skeleton of this formatter.
|
||||
* @param status Output param set to success/failure code.
|
||||
* @return a date time interval formatter which the caller owns.
|
||||
*/
|
||||
static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
|
||||
DateIntervalInfo* dtitvinf,
|
||||
const UnicodeString* skeleton,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a simple date/time formatter from skeleton, given locale,
|
||||
* and date time pattern generator.
|
||||
*
|
||||
* @param skeleton the skeleton on which date format based.
|
||||
* @param locale the given locale.
|
||||
* @param dtpng the date time pattern generator.
|
||||
* @param status Output param to be set to success/failure code.
|
||||
* If it is failure, the returned date formatter will
|
||||
* be NULL.
|
||||
* @return a simple date formatter which the caller owns.
|
||||
*/
|
||||
static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance(
|
||||
const UnicodeString& skeleton,
|
||||
const Locale& locale,
|
||||
DateTimePatternGenerator* dtpng,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Below are for generating interval patterns local to the formatter
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Format 2 Calendars using fall-back interval pattern
|
||||
*
|
||||
* The full pattern used in this fall-back format is the
|
||||
* full pattern of the date formatter.
|
||||
*
|
||||
* @param fromCalendar calendar set to the from date in date interval
|
||||
* to be formatted into date interval string
|
||||
* @param toCalendar calendar set to the to date in date interval
|
||||
* to be formatted into date interval string
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
*/
|
||||
UnicodeString& fallbackFormat(Calendar& fromCalendar,
|
||||
Calendar& toCalendar,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize interval patterns locale to this formatter
|
||||
*
|
||||
* This code is a bit complicated since
|
||||
* 1. the interval patterns saved in resource bundle files are interval
|
||||
* patterns based on date or time only.
|
||||
* It does not have interval patterns based on both date and time.
|
||||
* Interval patterns on both date and time are algorithm generated.
|
||||
*
|
||||
* For example, it has interval patterns on skeleton "dMy" and "hm",
|
||||
* but it does not have interval patterns on skeleton "dMyhm".
|
||||
*
|
||||
* The rule to generate interval patterns for both date and time skeleton are
|
||||
* 1) when the year, month, or day differs, concatenate the two original
|
||||
* expressions with a separator between,
|
||||
* For example, interval pattern from "Jan 10, 2007 10:10 am"
|
||||
* to "Jan 11, 2007 10:10am" is
|
||||
* "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
|
||||
*
|
||||
* 2) otherwise, present the date followed by the range expression
|
||||
* for the time.
|
||||
* For example, interval pattern from "Jan 10, 2007 10:10 am"
|
||||
* to "Jan 10, 2007 11:10am" is
|
||||
* "Jan 10, 2007 10:10 am - 11:10am"
|
||||
*
|
||||
* 2. even a pattern does not request a certain calendar field,
|
||||
* the interval pattern needs to include such field if such fields are
|
||||
* different between 2 dates.
|
||||
* For example, a pattern/skeleton is "hm", but the interval pattern
|
||||
* includes year, month, and date when year, month, and date differs.
|
||||
*
|
||||
*
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void initializePattern(UErrorCode& status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set fall back interval pattern given a calendar field,
|
||||
* a skeleton, and a date time pattern generator.
|
||||
* @param field the largest different calendar field
|
||||
* @param skeleton a skeleton
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void setFallbackPattern(UCalendarDateFields field,
|
||||
const UnicodeString& skeleton,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get separated date and time skeleton from a combined skeleton.
|
||||
*
|
||||
* The difference between date skeleton and normalizedDateSkeleton are:
|
||||
* 1. both 'y' and 'd' are appeared only once in normalizeDateSkeleton
|
||||
* 2. 'E' and 'EE' are normalized into 'EEE'
|
||||
* 3. 'MM' is normalized into 'M'
|
||||
*
|
||||
** the difference between time skeleton and normalizedTimeSkeleton are:
|
||||
* 1. both 'H' and 'h' are normalized as 'h' in normalized time skeleton,
|
||||
* 2. 'a' is omitted in normalized time skeleton.
|
||||
* 3. there is only one appearance for 'h', 'm','v', 'z' in normalized time
|
||||
* skeleton
|
||||
*
|
||||
*
|
||||
* @param skeleton given combined skeleton.
|
||||
* @param date Output parameter for date only skeleton.
|
||||
* @param normalizedDate Output parameter for normalized date only
|
||||
*
|
||||
* @param time Output parameter for time only skeleton.
|
||||
* @param normalizedTime Output parameter for normalized time only
|
||||
* skeleton.
|
||||
*
|
||||
*/
|
||||
static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
|
||||
UnicodeString& date,
|
||||
UnicodeString& normalizedDate,
|
||||
UnicodeString& time,
|
||||
UnicodeString& normalizedTime);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate date or time interval pattern from resource,
|
||||
* and set them into the interval pattern locale to this formatter.
|
||||
*
|
||||
* It needs to handle the following:
|
||||
* 1. need to adjust field width.
|
||||
* For example, the interval patterns saved in DateIntervalInfo
|
||||
* includes "dMMMy", but not "dMMMMy".
|
||||
* Need to get interval patterns for dMMMMy from dMMMy.
|
||||
* Another example, the interval patterns saved in DateIntervalInfo
|
||||
* includes "hmv", but not "hmz".
|
||||
* Need to get interval patterns for "hmz' from 'hmv'
|
||||
*
|
||||
* 2. there might be no pattern for 'y' differ for skeleton "Md",
|
||||
* in order to get interval patterns for 'y' differ,
|
||||
* need to look for it from skeleton 'yMd'
|
||||
*
|
||||
* @param dateSkeleton normalized date skeleton
|
||||
* @param timeSkeleton normalized time skeleton
|
||||
* @return whether the resource is found for the skeleton.
|
||||
* TRUE if interval pattern found for the skeleton,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
|
||||
const UnicodeString& timeSkeleton);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate interval pattern from existing resource
|
||||
*
|
||||
* It not only save the interval patterns,
|
||||
* but also return the extended skeleton and its best match skeleton.
|
||||
*
|
||||
* @param field largest different calendar field
|
||||
* @param skeleton skeleton
|
||||
* @param bestSkeleton the best match skeleton which has interval pattern
|
||||
* defined in resource
|
||||
* @param differenceInfo the difference between skeleton and best skeleton
|
||||
* 0 means the best matched skeleton is the same as input skeleton
|
||||
* 1 means the fields are the same, but field width are different
|
||||
* 2 means the only difference between fields are v/z,
|
||||
* -1 means there are other fields difference
|
||||
*
|
||||
* @param extendedSkeleton extended skeleton
|
||||
* @param extendedBestSkeleton extended best match skeleton
|
||||
* @return whether the interval pattern is found
|
||||
* through extending skeleton or not.
|
||||
* TRUE if interval pattern is found by
|
||||
* extending skeleton, FALSE otherwise.
|
||||
*/
|
||||
UBool setIntervalPattern(UCalendarDateFields field,
|
||||
const UnicodeString* skeleton,
|
||||
const UnicodeString* bestSkeleton,
|
||||
int8_t differenceInfo,
|
||||
UnicodeString* extendedSkeleton = NULL,
|
||||
UnicodeString* extendedBestSkeleton = NULL);
|
||||
|
||||
/**
|
||||
* Adjust field width in best match interval pattern to match
|
||||
* the field width in input skeleton.
|
||||
*
|
||||
* TODO (xji) make a general solution
|
||||
* The adjusting rule can be:
|
||||
* 1. always adjust
|
||||
* 2. never adjust
|
||||
* 3. default adjust, which means adjust according to the following rules
|
||||
* 3.1 always adjust string, such as MMM and MMMM
|
||||
* 3.2 never adjust between string and numeric, such as MM and MMM
|
||||
* 3.3 always adjust year
|
||||
* 3.4 do not adjust 'd', 'h', or 'm' if h presents
|
||||
* 3.5 do not adjust 'M' if it is numeric(?)
|
||||
*
|
||||
* Since date interval format is well-formed format,
|
||||
* date and time skeletons are normalized previously,
|
||||
* till this stage, the adjust here is only "adjust strings, such as MMM
|
||||
* and MMMM, EEE and EEEE.
|
||||
*
|
||||
* @param inputSkeleton the input skeleton
|
||||
* @param bestMatchSkeleton the best match skeleton
|
||||
* @param bestMatchIntervalPattern the best match interval pattern
|
||||
* @param differenceInfo the difference between 2 skeletons
|
||||
* 1 means only field width differs
|
||||
* 2 means v/z exchange
|
||||
* @param adjustedIntervalPattern adjusted interval pattern
|
||||
*/
|
||||
static void U_EXPORT2 adjustFieldWidth(
|
||||
const UnicodeString& inputSkeleton,
|
||||
const UnicodeString& bestMatchSkeleton,
|
||||
const UnicodeString& bestMatchIntervalPattern,
|
||||
int8_t differenceInfo,
|
||||
UnicodeString& adjustedIntervalPattern);
|
||||
|
||||
/**
|
||||
* Concat a single date pattern with a time interval pattern,
|
||||
* set it into the intervalPatterns, while field is time field.
|
||||
* This is used to handle time interval patterns on skeleton with
|
||||
* both time and date. Present the date followed by
|
||||
* the range expression for the time.
|
||||
* @param format date and time format
|
||||
* @param formatLen format string length
|
||||
* @param datePattern date pattern
|
||||
* @param field time calendar field: AM_PM, HOUR, MINUTE
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void concatSingleDate2TimeInterval(const UChar* format,
|
||||
int32_t formatLen,
|
||||
const UnicodeString& datePattern,
|
||||
UCalendarDateFields field,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* check whether a calendar field present in a skeleton.
|
||||
* @param field calendar field need to check
|
||||
* @param skeleton given skeleton on which to check the calendar field
|
||||
* @return true if field present in a skeleton.
|
||||
*/
|
||||
static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
|
||||
const UnicodeString& skeleton);
|
||||
|
||||
|
||||
/**
|
||||
* Split interval patterns into 2 part.
|
||||
* @param intervalPattern interval pattern
|
||||
* @return the index in interval pattern which split the pattern into 2 part
|
||||
*/
|
||||
static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
|
||||
|
||||
|
||||
/**
|
||||
* Break interval patterns as 2 part and save them into pattern info.
|
||||
* @param field calendar field
|
||||
* @param intervalPattern interval pattern
|
||||
*/
|
||||
void setIntervalPattern(UCalendarDateFields field,
|
||||
const UnicodeString& intervalPattern);
|
||||
|
||||
|
||||
/**
|
||||
* Break interval patterns as 2 part and save them into pattern info.
|
||||
* @param field calendar field
|
||||
* @param intervalPattern interval pattern
|
||||
* @param laterDateFirst whether later date appear first in interval pattern
|
||||
*/
|
||||
void setIntervalPattern(UCalendarDateFields field,
|
||||
const UnicodeString& intervalPattern,
|
||||
UBool laterDateFirst);
|
||||
|
||||
|
||||
/**
|
||||
* Set pattern information.
|
||||
*
|
||||
* @param field calendar field
|
||||
* @param firstPart the first part in interval pattern
|
||||
* @param secondPart the second part in interval pattern
|
||||
* @param laterDateFirst whether the first date in intervalPattern
|
||||
* is earlier date or later date
|
||||
*/
|
||||
void setPatternInfo(UCalendarDateFields field,
|
||||
const UnicodeString* firstPart,
|
||||
const UnicodeString* secondPart,
|
||||
UBool laterDateFirst);
|
||||
|
||||
|
||||
// from calendar field to pattern letter
|
||||
static const UChar fgCalendarFieldToPatternLetter[];
|
||||
|
||||
|
||||
/**
|
||||
* The interval patterns for this locale.
|
||||
*/
|
||||
DateIntervalInfo* fInfo;
|
||||
|
||||
/**
|
||||
* The DateFormat object used to format single pattern
|
||||
*/
|
||||
SimpleDateFormat* fDateFormat;
|
||||
|
||||
/**
|
||||
* The 2 calendars with the from and to date.
|
||||
* could re-use the calendar in fDateFormat,
|
||||
* but keeping 2 calendars make it clear and clean.
|
||||
*/
|
||||
Calendar* fFromCalendar;
|
||||
Calendar* fToCalendar;
|
||||
|
||||
/**
|
||||
* Date time pattern generator
|
||||
*/
|
||||
DateTimePatternGenerator* fDtpng;
|
||||
|
||||
/**
|
||||
* Following are interval information relavent (locale) to this formatter.
|
||||
*/
|
||||
UnicodeString fSkeleton;
|
||||
PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
|
||||
};
|
||||
|
||||
inline UBool
|
||||
DateIntervalFormat::operator!=(const Format& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _DTITVFMT_H__
|
||||
//eof
|
||||
@@ -1,514 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008-2011,2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
* File DTITVINF.H
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __DTITVINF_H__
|
||||
#define __DTITVINF_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Date/Time interval patterns for formatting date/time interval
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/ucal.h"
|
||||
#include "unicode/dtptngen.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* DateIntervalInfo is a public class for encapsulating localizable
|
||||
* date time interval patterns. It is used by DateIntervalFormat.
|
||||
*
|
||||
* <P>
|
||||
* For most users, ordinary use of DateIntervalFormat does not need to create
|
||||
* DateIntervalInfo object directly.
|
||||
* DateIntervalFormat will take care of it when creating a date interval
|
||||
* formatter when user pass in skeleton and locale.
|
||||
*
|
||||
* <P>
|
||||
* For power users, who want to create their own date interval patterns,
|
||||
* or want to re-set date interval patterns, they could do so by
|
||||
* directly creating DateIntervalInfo and manupulating it.
|
||||
*
|
||||
* <P>
|
||||
* Logically, the interval patterns are mappings
|
||||
* from (skeleton, the_largest_different_calendar_field)
|
||||
* to (date_interval_pattern).
|
||||
*
|
||||
* <P>
|
||||
* A skeleton
|
||||
* <ol>
|
||||
* <li>
|
||||
* only keeps the field pattern letter and ignores all other parts
|
||||
* in a pattern, such as space, punctuations, and string literals.
|
||||
* <li>
|
||||
* hides the order of fields.
|
||||
* <li>
|
||||
* might hide a field's pattern letter length.
|
||||
*
|
||||
* For those non-digit calendar fields, the pattern letter length is
|
||||
* important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
|
||||
* and the field's pattern letter length is honored.
|
||||
*
|
||||
* For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
|
||||
* the field pattern length is ignored and the best match, which is defined
|
||||
* in date time patterns, will be returned without honor the field pattern
|
||||
* letter length in skeleton.
|
||||
* </ol>
|
||||
*
|
||||
* <P>
|
||||
* The calendar fields we support for interval formatting are:
|
||||
* year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
|
||||
* Those calendar fields can be defined in the following order:
|
||||
* year > month > date > am-pm > hour > minute
|
||||
*
|
||||
* The largest different calendar fields between 2 calendars is the
|
||||
* first different calendar field in above order.
|
||||
*
|
||||
* For example: the largest different calendar fields between "Jan 10, 2007"
|
||||
* and "Feb 20, 2008" is year.
|
||||
*
|
||||
* <P>
|
||||
* There is a set of pre-defined static skeleton strings.
|
||||
* There are pre-defined interval patterns for those pre-defined skeletons
|
||||
* in locales' resource files.
|
||||
* For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd",
|
||||
* in en_US, if the largest different calendar field between date1 and date2
|
||||
* is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy",
|
||||
* such as "Jan 10, 2007 - Jan 10, 2008".
|
||||
* If the largest different calendar field between date1 and date2 is "month",
|
||||
* the date interval pattern is "MMM d - MMM d, yyyy",
|
||||
* such as "Jan 10 - Feb 10, 2007".
|
||||
* If the largest different calendar field between date1 and date2 is "day",
|
||||
* the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007".
|
||||
*
|
||||
* For date skeleton, the interval patterns when year, or month, or date is
|
||||
* different are defined in resource files.
|
||||
* For time skeleton, the interval patterns when am/pm, or hour, or minute is
|
||||
* different are defined in resource files.
|
||||
*
|
||||
*
|
||||
* <P>
|
||||
* There are 2 dates in interval pattern. For most locales, the first date
|
||||
* in an interval pattern is the earlier date. There might be a locale in which
|
||||
* the first date in an interval pattern is the later date.
|
||||
* We use fallback format for the default order for the locale.
|
||||
* For example, if the fallback format is "{0} - {1}", it means
|
||||
* the first date in the interval pattern for this locale is earlier date.
|
||||
* If the fallback format is "{1} - {0}", it means the first date is the
|
||||
* later date.
|
||||
* For a particular interval pattern, the default order can be overriden
|
||||
* by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern.
|
||||
* For example, if the fallback format is "{0}-{1}",
|
||||
* but for skeleton "yMMMd", the interval pattern when day is different is
|
||||
* "latestFirst:d-d MMM yy", it means by default, the first date in interval
|
||||
* pattern is the earlier date. But for skeleton "yMMMd", when day is different,
|
||||
* the first date in "d-d MMM yy" is the later date.
|
||||
*
|
||||
* <P>
|
||||
* The recommended way to create a DateIntervalFormat object is to pass in
|
||||
* the locale.
|
||||
* By using a Locale parameter, the DateIntervalFormat object is
|
||||
* initialized with the pre-defined interval patterns for a given or
|
||||
* default locale.
|
||||
* <P>
|
||||
* Users can also create DateIntervalFormat object
|
||||
* by supplying their own interval patterns.
|
||||
* It provides flexibility for power users.
|
||||
*
|
||||
* <P>
|
||||
* After a DateIntervalInfo object is created, clients may modify
|
||||
* the interval patterns using setIntervalPattern function as so desired.
|
||||
* Currently, users can only set interval patterns when the following
|
||||
* calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
|
||||
* DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
|
||||
* Interval patterns when other calendar fields are different is not supported.
|
||||
* <P>
|
||||
* DateIntervalInfo objects are cloneable.
|
||||
* When clients obtain a DateIntervalInfo object,
|
||||
* they can feel free to modify it as necessary.
|
||||
* <P>
|
||||
* DateIntervalInfo are not expected to be subclassed.
|
||||
* Data for a calendar is loaded out of resource bundles.
|
||||
* Through ICU 4.4, date interval patterns are only supported in the Gregorian
|
||||
* calendar; non-Gregorian calendars are supported from ICU 4.4.1.
|
||||
* @stable ICU 4.0
|
||||
**/
|
||||
|
||||
class U_I18N_API DateIntervalInfo : public UObject {
|
||||
public:
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Default constructor.
|
||||
* It does not initialize any interval patterns except
|
||||
* that it initialize default fall-back pattern as "{0} - {1}",
|
||||
* which can be reset by setFallbackIntervalPattern().
|
||||
* It should be followed by setFallbackIntervalPattern() and
|
||||
* setIntervalPattern(),
|
||||
* and is recommended to be used only for power users who
|
||||
* wants to create their own interval patterns and use them to create
|
||||
* date interval formatter.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @internal ICU 4.0
|
||||
*/
|
||||
DateIntervalInfo(UErrorCode& status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
|
||||
/**
|
||||
* Construct DateIntervalInfo for the given locale,
|
||||
* @param locale the interval patterns are loaded from the appropriate calendar
|
||||
* data (specified calendar or default calendar) in this locale.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateIntervalInfo(const Locale& locale, UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateIntervalInfo(const DateIntervalInfo&);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
DateIntervalInfo& operator=(const DateIntervalInfo&);
|
||||
|
||||
/**
|
||||
* Clone this object polymorphically.
|
||||
* The caller owns the result and should delete it when done.
|
||||
* @return a copy of the object
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual DateIntervalInfo* clone(void) const;
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* It is virtual to be safe, but it is not designed to be subclassed.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual ~DateIntervalInfo();
|
||||
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*
|
||||
* @param other the DateIntervalInfo object to be compared with.
|
||||
* @return true if other is semantically equal to this.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator==(const DateIntervalInfo& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*
|
||||
* @param other the DateIntervalInfo object to be compared with.
|
||||
* @return true if other is semantically unequal to this.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool operator!=(const DateIntervalInfo& other) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides a way for client to build interval patterns.
|
||||
* User could construct DateIntervalInfo by providing a list of skeletons
|
||||
* and their patterns.
|
||||
* <P>
|
||||
* For example:
|
||||
* <pre>
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
|
||||
* dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}");
|
||||
* dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status);
|
||||
* dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status);
|
||||
* dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status);
|
||||
* </pre>
|
||||
*
|
||||
* Restriction:
|
||||
* Currently, users can only set interval patterns when the following
|
||||
* calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
|
||||
* DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
|
||||
* Interval patterns when other calendar fields are different are
|
||||
* not supported.
|
||||
*
|
||||
* @param skeleton the skeleton on which interval pattern based
|
||||
* @param lrgDiffCalUnit the largest different calendar unit.
|
||||
* @param intervalPattern the interval pattern on the largest different
|
||||
* calendar unit.
|
||||
* For example, if lrgDiffCalUnit is
|
||||
* "year", the interval pattern for en_US when year
|
||||
* is different could be "'from' yyyy 'to' yyyy".
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
void setIntervalPattern(const UnicodeString& skeleton,
|
||||
UCalendarDateFields lrgDiffCalUnit,
|
||||
const UnicodeString& intervalPattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Get the interval pattern given skeleton and
|
||||
* the largest different calendar field.
|
||||
* @param skeleton the skeleton
|
||||
* @param field the largest different calendar field
|
||||
* @param result output param to receive the pattern
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return a reference to 'result'
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& getIntervalPattern(const UnicodeString& skeleton,
|
||||
UCalendarDateFields field,
|
||||
UnicodeString& result,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Get the fallback interval pattern.
|
||||
* @param result output param to receive the pattern
|
||||
* @return a reference to 'result'
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& getFallbackIntervalPattern(UnicodeString& result) const;
|
||||
|
||||
|
||||
/**
|
||||
* Re-set the fallback interval pattern.
|
||||
*
|
||||
* In construction, default fallback pattern is set as "{0} - {1}".
|
||||
* And constructor taking locale as parameter will set the
|
||||
* fallback pattern as what defined in the locale resource file.
|
||||
*
|
||||
* This method provides a way for user to replace the fallback pattern.
|
||||
*
|
||||
* @param fallbackPattern fall-back interval pattern.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
void setFallbackIntervalPattern(const UnicodeString& fallbackPattern,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/** Get default order -- whether the first date in pattern is later date
|
||||
or not.
|
||||
* return default date ordering in interval pattern. TRUE if the first date
|
||||
* in pattern is later date, FALSE otherwise.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool getDefaultOrder() const;
|
||||
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* DateIntervalFormat will need access to
|
||||
* getBestSkeleton(), parseSkeleton(), enum IntervalPatternIndex,
|
||||
* and calendarFieldToPatternIndex().
|
||||
*
|
||||
* Instead of making above public,
|
||||
* make DateIntervalFormat a friend of DateIntervalInfo.
|
||||
*/
|
||||
friend class DateIntervalFormat;
|
||||
|
||||
/**
|
||||
* Following is for saving the interval patterns.
|
||||
* We only support interval patterns on
|
||||
* ERA, YEAR, MONTH, DAY, AM_PM, HOUR, and MINUTE
|
||||
*/
|
||||
enum IntervalPatternIndex
|
||||
{
|
||||
kIPI_ERA,
|
||||
kIPI_YEAR,
|
||||
kIPI_MONTH,
|
||||
kIPI_DATE,
|
||||
kIPI_AM_PM,
|
||||
kIPI_HOUR,
|
||||
kIPI_MINUTE,
|
||||
kIPI_MAX_INDEX
|
||||
};
|
||||
public:
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Max index for stored interval patterns
|
||||
* @internal ICU 4.4
|
||||
*/
|
||||
enum {
|
||||
kMaxIntervalPatternIndex = kIPI_MAX_INDEX
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the DateIntervalInfo from locale
|
||||
* @param locale the given locale.
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void initializeData(const Locale& locale, UErrorCode& status);
|
||||
|
||||
|
||||
/* Set Interval pattern.
|
||||
*
|
||||
* It sets interval pattern into the hash map.
|
||||
*
|
||||
* @param skeleton skeleton on which the interval pattern based
|
||||
* @param lrgDiffCalUnit the largest different calendar unit.
|
||||
* @param intervalPattern the interval pattern on the largest different
|
||||
* calendar unit.
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void setIntervalPatternInternally(const UnicodeString& skeleton,
|
||||
UCalendarDateFields lrgDiffCalUnit,
|
||||
const UnicodeString& intervalPattern,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**given an input skeleton, get the best match skeleton
|
||||
* which has pre-defined interval pattern in resource file.
|
||||
* Also return the difference between the input skeleton
|
||||
* and the best match skeleton.
|
||||
*
|
||||
* TODO (xji): set field weight or
|
||||
* isolate the funtionality in DateTimePatternGenerator
|
||||
* @param skeleton input skeleton
|
||||
* @param bestMatchDistanceInfo the difference between input skeleton
|
||||
* and best match skeleton.
|
||||
* 0, if there is exact match for input skeleton
|
||||
* 1, if there is only field width difference between
|
||||
* the best match and the input skeleton
|
||||
* 2, the only field difference is 'v' and 'z'
|
||||
* -1, if there is calendar field difference between
|
||||
* the best match and the input skeleton
|
||||
* @return best match skeleton
|
||||
*/
|
||||
const UnicodeString* getBestSkeleton(const UnicodeString& skeleton,
|
||||
int8_t& bestMatchDistanceInfo) const;
|
||||
|
||||
|
||||
/**
|
||||
* Parse skeleton, save each field's width.
|
||||
* It is used for looking for best match skeleton,
|
||||
* and adjust pattern field width.
|
||||
* @param skeleton skeleton to be parsed
|
||||
* @param skeletonFieldWidth parsed skeleton field width
|
||||
*/
|
||||
static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton,
|
||||
int32_t* skeletonFieldWidth);
|
||||
|
||||
|
||||
/**
|
||||
* Check whether one field width is numeric while the other is string.
|
||||
*
|
||||
* TODO (xji): make it general
|
||||
*
|
||||
* @param fieldWidth one field width
|
||||
* @param anotherFieldWidth another field width
|
||||
* @param patternLetter pattern letter char
|
||||
* @return true if one field width is numeric and the other is string,
|
||||
* false otherwise.
|
||||
*/
|
||||
static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth,
|
||||
int32_t anotherFieldWidth,
|
||||
char patternLetter);
|
||||
|
||||
|
||||
/**
|
||||
* Convert calendar field to the interval pattern index in
|
||||
* hash table.
|
||||
*
|
||||
* Since we only support the following calendar fields:
|
||||
* ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK,
|
||||
* AM_PM, HOUR, HOUR_OF_DAY, and MINUTE,
|
||||
* We reserve only 4 interval patterns for a skeleton.
|
||||
*
|
||||
* @param field calendar field
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return interval pattern index in hash table
|
||||
*/
|
||||
static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex(
|
||||
UCalendarDateFields field,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* delete hash table (of type fIntervalPatterns).
|
||||
*
|
||||
* @param hTable hash table to be deleted
|
||||
*/
|
||||
void deleteHash(Hashtable* hTable);
|
||||
|
||||
|
||||
/**
|
||||
* initialize hash table (of type fIntervalPatterns).
|
||||
*
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @return hash table initialized
|
||||
*/
|
||||
Hashtable* initHash(UErrorCode& status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* copy hash table (of type fIntervalPatterns).
|
||||
*
|
||||
* @param source the source to copy from
|
||||
* @param target the target to copy to
|
||||
* @param status output param set to success/failure code on exit
|
||||
*/
|
||||
void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
|
||||
|
||||
|
||||
// data members
|
||||
// fallback interval pattern
|
||||
UnicodeString fFallbackIntervalPattern;
|
||||
// default order
|
||||
UBool fFirstDateInPtnIsLaterDate;
|
||||
|
||||
// HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]>
|
||||
// HashMap( skeleton, pattern[largest_different_field] )
|
||||
Hashtable* fIntervalPatterns;
|
||||
|
||||
};// end class DateIntervalInfo
|
||||
|
||||
|
||||
inline UBool
|
||||
DateIntervalInfo::operator!=(const DateIntervalInfo& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,498 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
* File DTPTNGEN.H
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __DTPTNGEN_H__
|
||||
#define __DTPTNGEN_H__
|
||||
|
||||
#include "unicode/datefmt.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/udatpg.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Date/Time Pattern Generator
|
||||
*/
|
||||
|
||||
|
||||
class Hashtable;
|
||||
class FormatParser;
|
||||
class DateTimeMatcher;
|
||||
class DistanceInfo;
|
||||
class PatternMap;
|
||||
class PtnSkeleton;
|
||||
|
||||
/**
|
||||
* This class provides flexible generation of date format patterns, like "yy-MM-dd".
|
||||
* The user can build up the generator by adding successive patterns. Once that
|
||||
* is done, a query can be made using a "skeleton", which is a pattern which just
|
||||
* includes the desired fields and lengths. The generator will return the "best fit"
|
||||
* pattern corresponding to that skeleton.
|
||||
* <p>The main method people will use is getBestPattern(String skeleton),
|
||||
* since normally this class is pre-built with data from a particular locale.
|
||||
* However, generators can be built directly from other data as well.
|
||||
* <p><i>Issue: may be useful to also have a function that returns the list of
|
||||
* fields in a pattern, in order, since we have that internally.
|
||||
* That would be useful for getting the UI order of field elements.</i>
|
||||
* @stable ICU 3.8
|
||||
**/
|
||||
class U_I18N_API DateTimePatternGenerator : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Construct a flexible generator according to default locale.
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a flexible generator according to data for a given locale.
|
||||
* @param uLocale
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create an empty generator, to be constructed with addPattern(...) etc.
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual ~DateTimePatternGenerator();
|
||||
|
||||
/**
|
||||
* Clone DateTimePatternGenerator object. Clients are responsible for
|
||||
* deleting the DateTimePatternGenerator object cloned.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimePatternGenerator* clone() const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*
|
||||
* @param other the DateTimePatternGenerator object to be compared with.
|
||||
* @return true if other is semantically equal to this.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UBool operator==(const DateTimePatternGenerator& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*
|
||||
* @param other the DateTimePatternGenerator object to be compared with.
|
||||
* @return true if other is semantically unequal to this.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UBool operator!=(const DateTimePatternGenerator& other) const;
|
||||
|
||||
/**
|
||||
* Utility to return a unique skeleton from a given pattern. For example,
|
||||
* both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
|
||||
*
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return skeleton such as "MMMdd"
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Utility to return a unique base skeleton from a given pattern. This is
|
||||
* the same as the skeleton, except that differences in length are minimized
|
||||
* so as to only preserve the difference between string and numeric form. So
|
||||
* for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
|
||||
* (notice the single d).
|
||||
*
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return base skeleton, such as "Md"
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Adds a pattern to the generator. If the pattern has the same skeleton as
|
||||
* an existing pattern, and the override parameter is set, then the previous
|
||||
* value is overriden. Otherwise, the previous value is retained. In either
|
||||
* case, the conflicting status is set and previous vale is stored in
|
||||
* conflicting pattern.
|
||||
* <p>
|
||||
* Note that single-field patterns (like "MMM") are automatically added, and
|
||||
* don't need to be added explicitly!
|
||||
*
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param override When existing values are to be overridden use true,
|
||||
* otherwise use false.
|
||||
* @param conflictingPattern Previous pattern with the same skeleton.
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return conflicting status. The value could be UDATPG_NO_CONFLICT,
|
||||
* UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
|
||||
* @stable ICU 3.8
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp addPatternExample
|
||||
* <p>
|
||||
*/
|
||||
UDateTimePatternConflict addPattern(const UnicodeString& pattern,
|
||||
UBool override,
|
||||
UnicodeString& conflictingPattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* An AppendItem format is a pattern used to append a field if there is no
|
||||
* good match. For example, suppose that the input skeleton is "GyyyyMMMd",
|
||||
* and there is no matching pattern internally, but there is a pattern
|
||||
* matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
|
||||
* G. The way these two are conjoined is by using the AppendItemFormat for G
|
||||
* (era). So if that value is, say "{0}, {1}" then the final resulting
|
||||
* pattern is "d-MM-yyyy, G".
|
||||
* <p>
|
||||
* There are actually three available variables: {0} is the pattern so far,
|
||||
* {1} is the element we are adding, and {2} is the name of the element.
|
||||
* <p>
|
||||
* This reflects the way that the CLDR data is organized.
|
||||
*
|
||||
* @param field such as UDATPG_ERA_FIELD.
|
||||
* @param value pattern, such as "{0}, {1}"
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
|
||||
|
||||
/**
|
||||
* Getter corresponding to setAppendItemFormat. Values below 0 or at or
|
||||
* above UDATPG_FIELD_COUNT are illegal arguments.
|
||||
*
|
||||
* @param field such as UDATPG_ERA_FIELD.
|
||||
* @return append pattern for field
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
|
||||
|
||||
/**
|
||||
* Sets the names of field, eg "era" in English for ERA. These are only
|
||||
* used if the corresponding AppendItemFormat is used, and if it contains a
|
||||
* {2} variable.
|
||||
* <p>
|
||||
* This reflects the way that the CLDR data is organized.
|
||||
*
|
||||
* @param field such as UDATPG_ERA_FIELD.
|
||||
* @param value name of the field
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
|
||||
|
||||
/**
|
||||
* Getter corresponding to setAppendItemNames. Values below 0 or at or above
|
||||
* UDATPG_FIELD_COUNT are illegal arguments.
|
||||
*
|
||||
* @param field such as UDATPG_ERA_FIELD.
|
||||
* @return name for field
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
|
||||
|
||||
/**
|
||||
* The date time format is a message format pattern used to compose date and
|
||||
* time patterns. The default value is "{0} {1}", where {0} will be replaced
|
||||
* by the date pattern and {1} will be replaced by the time pattern.
|
||||
* <p>
|
||||
* This is used when the input skeleton contains both date and time fields,
|
||||
* but there is not a close match among the added patterns. For example,
|
||||
* suppose that this object was created by adding "dd-MMM" and "hh:mm", and
|
||||
* its datetimeFormat is the default "{0} {1}". Then if the input skeleton
|
||||
* is "MMMdhmm", there is not an exact match, so the input skeleton is
|
||||
* broken up into two components "MMMd" and "hmm". There are close matches
|
||||
* for those two skeletons, so the result is put together with this pattern,
|
||||
* resulting in "d-MMM h:mm".
|
||||
*
|
||||
* @param dateTimeFormat
|
||||
* message format pattern, here {0} will be replaced by the date
|
||||
* pattern and {1} will be replaced by the time pattern.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void setDateTimeFormat(const UnicodeString& dateTimeFormat);
|
||||
|
||||
/**
|
||||
* Getter corresponding to setDateTimeFormat.
|
||||
* @return DateTimeFormat.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
const UnicodeString& getDateTimeFormat() const;
|
||||
|
||||
/**
|
||||
* Return the best pattern matching the input skeleton. It is guaranteed to
|
||||
* have all of the fields in the skeleton.
|
||||
*
|
||||
* @param skeleton
|
||||
* The skeleton is a pattern containing only the variable fields.
|
||||
* For example, "MMMdd" and "mmhh" are skeletons.
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return bestPattern
|
||||
* The best pattern found from the given skeleton.
|
||||
* @stable ICU 3.8
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample
|
||||
* <p>
|
||||
*/
|
||||
UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Return the best pattern matching the input skeleton. It is guaranteed to
|
||||
* have all of the fields in the skeleton.
|
||||
*
|
||||
* @param skeleton
|
||||
* The skeleton is a pattern containing only the variable fields.
|
||||
* For example, "MMMdd" and "mmhh" are skeletons.
|
||||
* @param options
|
||||
* Options for forcing the length of specified fields in the
|
||||
* returned pattern to match those in the skeleton (when this
|
||||
* would not happen otherwise). For default behavior, use
|
||||
* UDATPG_MATCH_NO_OPTIONS.
|
||||
* @param status
|
||||
* Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return bestPattern
|
||||
* The best pattern found from the given skeleton.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UnicodeString getBestPattern(const UnicodeString& skeleton,
|
||||
UDateTimePatternMatchOptions options,
|
||||
UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Adjusts the field types (width and subtype) of a pattern to match what is
|
||||
* in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
|
||||
* skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
|
||||
* "dd-MMMM hh:mm". This is used internally to get the best match for the
|
||||
* input skeleton, but can also be used externally.
|
||||
*
|
||||
* @param pattern Input pattern
|
||||
* @param skeleton
|
||||
* The skeleton is a pattern containing only the variable fields.
|
||||
* For example, "MMMdd" and "mmhh" are skeletons.
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return pattern adjusted to match the skeleton fields widths and subtypes.
|
||||
* @stable ICU 3.8
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
|
||||
* \snippet samples/dtptngsample/dtptngsample.cpp replaceFieldTypesExample
|
||||
* <p>
|
||||
*/
|
||||
UnicodeString replaceFieldTypes(const UnicodeString& pattern,
|
||||
const UnicodeString& skeleton,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Adjusts the field types (width and subtype) of a pattern to match what is
|
||||
* in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
|
||||
* skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
|
||||
* "dd-MMMM hh:mm". This is used internally to get the best match for the
|
||||
* input skeleton, but can also be used externally.
|
||||
*
|
||||
* @param pattern Input pattern
|
||||
* @param skeleton
|
||||
* The skeleton is a pattern containing only the variable fields.
|
||||
* For example, "MMMdd" and "mmhh" are skeletons.
|
||||
* @param options
|
||||
* Options controlling whether the length of specified fields in the
|
||||
* pattern are adjusted to match those in the skeleton (when this
|
||||
* would not happen otherwise). For default behavior, use
|
||||
* UDATPG_MATCH_NO_OPTIONS.
|
||||
* @param status
|
||||
* Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return pattern adjusted to match the skeleton fields widths and subtypes.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UnicodeString replaceFieldTypes(const UnicodeString& pattern,
|
||||
const UnicodeString& skeleton,
|
||||
UDateTimePatternMatchOptions options,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Return a list of all the skeletons (in canonical form) from this class.
|
||||
*
|
||||
* Call getPatternForSkeleton() to get the corresponding pattern.
|
||||
*
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return StringEnumeration with the skeletons.
|
||||
* The caller must delete the object.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
StringEnumeration* getSkeletons(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Get the pattern corresponding to a given skeleton.
|
||||
* @param skeleton
|
||||
* @return pattern corresponding to a given skeleton.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
|
||||
|
||||
/**
|
||||
* Return a list of all the base skeletons (in canonical form) from this class.
|
||||
*
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return a StringEnumeration with the base skeletons.
|
||||
* The caller must delete the object.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Return a list of redundant patterns are those which if removed, make no
|
||||
* difference in the resulting getBestPattern values. This method returns a
|
||||
* list of them, to help check the consistency of the patterns used to build
|
||||
* this generator.
|
||||
*
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return a StringEnumeration with the redundant pattern.
|
||||
* The caller must delete the object.
|
||||
* @internal ICU 3.8
|
||||
*/
|
||||
StringEnumeration* getRedundants(UErrorCode& status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* The decimal value is used in formatting fractions of seconds. If the
|
||||
* skeleton contains fractional seconds, then this is used with the
|
||||
* fractional seconds. For example, suppose that the input pattern is
|
||||
* "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
|
||||
* the decimal string is ",". Then the resulting pattern is modified to be
|
||||
* "H:mm:ss,SSSS"
|
||||
*
|
||||
* @param decimal
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void setDecimal(const UnicodeString& decimal);
|
||||
|
||||
/**
|
||||
* Getter corresponding to setDecimal.
|
||||
* @return UnicodeString corresponding to the decimal point
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
const UnicodeString& getDecimal() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Constructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimePatternGenerator(UErrorCode & status);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other DateTimePatternGenerator to copy
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimePatternGenerator(const DateTimePatternGenerator& other);
|
||||
|
||||
/**
|
||||
* Default assignment operator.
|
||||
* @param other DateTimePatternGenerator to copy
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
|
||||
|
||||
Locale pLocale; // pattern locale
|
||||
FormatParser *fp;
|
||||
DateTimeMatcher* dtMatcher;
|
||||
DistanceInfo *distanceInfo;
|
||||
PatternMap *patternMap;
|
||||
UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
|
||||
UnicodeString appendItemNames[UDATPG_FIELD_COUNT];
|
||||
UnicodeString dateTimeFormat;
|
||||
UnicodeString decimal;
|
||||
DateTimeMatcher *skipMatcher;
|
||||
Hashtable *fAvailableFormatKeyHash;
|
||||
UnicodeString hackPattern;
|
||||
UnicodeString emptyString;
|
||||
UChar fDefaultHourFormatChar;
|
||||
|
||||
/* internal flags masks for adjustFieldTypes etc. */
|
||||
enum {
|
||||
kDTPGNoFlags = 0,
|
||||
kDTPGFixFractionalSeconds = 1,
|
||||
kDTPGSkeletonUsesCapJ = 2
|
||||
};
|
||||
|
||||
void initData(const Locale &locale, UErrorCode &status);
|
||||
void addCanonicalItems();
|
||||
void addICUPatterns(const Locale& locale, UErrorCode& status);
|
||||
void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
|
||||
void addCLDRData(const Locale& locale, UErrorCode& status);
|
||||
UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
|
||||
void initHashtable(UErrorCode& status);
|
||||
void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
|
||||
void setDecimalSymbols(const Locale& locale, UErrorCode& status);
|
||||
UDateTimePatternField getAppendFormatNumber(const char* field) const;
|
||||
UDateTimePatternField getAppendNameNumber(const char* field) const;
|
||||
void getAppendName(UDateTimePatternField field, UnicodeString& value);
|
||||
int32_t getCanonicalIndex(const UnicodeString& field);
|
||||
const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, const PtnSkeleton** specifiedSkeletonPtr = 0);
|
||||
UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
|
||||
UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
|
||||
int32_t getTopBitNumber(int32_t foundMask);
|
||||
void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
|
||||
UBool isAvailableFormatSet(const UnicodeString &key) const;
|
||||
void copyHashtable(Hashtable *other, UErrorCode &status);
|
||||
UBool isCanonicalItem(const UnicodeString& item) const;
|
||||
} ;// end class DateTimePatternGenerator
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef DTRULE_H
|
||||
#define DTRULE_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Rule for specifying date and time in an year
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
/**
|
||||
* <code>DateTimeRule</code> is a class representing a time in a year by
|
||||
* a rule specified by month, day of month, day of week and
|
||||
* time in the day.
|
||||
*
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
class U_I18N_API DateTimeRule : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Date rule type constants.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
enum DateRuleType {
|
||||
DOM = 0, /**< The exact day of month,
|
||||
for example, March 11. */
|
||||
DOW, /**< The Nth occurence of the day of week,
|
||||
for example, 2nd Sunday in March. */
|
||||
DOW_GEQ_DOM, /**< The first occurence of the day of week on or after the day of monnth,
|
||||
for example, first Sunday on or after March 8. */
|
||||
DOW_LEQ_DOM /**< The last occurence of the day of week on or before the day of month,
|
||||
for example, first Sunday on or before March 14. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Time rule type constants.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
enum TimeRuleType {
|
||||
WALL_TIME = 0, /**< The local wall clock time */
|
||||
STANDARD_TIME, /**< The local standard time */
|
||||
UTC_TIME /**< The UTC time */
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a <code>DateTimeRule</code> by the day of month and
|
||||
* the time rule. The date rule type for an instance created by
|
||||
* this constructor is <code>DOM</code>.
|
||||
*
|
||||
* @param month The rule month, for example, <code>Calendar::JANUARY</code>
|
||||
* @param dayOfMonth The day of month, 1-based.
|
||||
* @param millisInDay The milliseconds in the rule date.
|
||||
* @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
|
||||
* or <code>UTC_TIME</code>.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule(int32_t month, int32_t dayOfMonth,
|
||||
int32_t millisInDay, TimeRuleType timeType);
|
||||
|
||||
/**
|
||||
* Constructs a <code>DateTimeRule</code> by the day of week and its oridinal
|
||||
* number and the time rule. The date rule type for an instance created
|
||||
* by this constructor is <code>DOW</code>.
|
||||
*
|
||||
* @param month The rule month, for example, <code>Calendar::JANUARY</code>.
|
||||
* @param weekInMonth The ordinal number of the day of week. Negative number
|
||||
* may be used for specifying a rule date counted from the
|
||||
* end of the rule month.
|
||||
* @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
|
||||
* @param millisInDay The milliseconds in the rule date.
|
||||
* @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
|
||||
* or <code>UTC_TIME</code>.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek,
|
||||
int32_t millisInDay, TimeRuleType timeType);
|
||||
|
||||
/**
|
||||
* Constructs a <code>DateTimeRule</code> by the first/last day of week
|
||||
* on or after/before the day of month and the time rule. The date rule
|
||||
* type for an instance created by this constructor is either
|
||||
* <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>.
|
||||
*
|
||||
* @param month The rule month, for example, <code>Calendar::JANUARY</code>
|
||||
* @param dayOfMonth The day of month, 1-based.
|
||||
* @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
|
||||
* @param after true if the rule date is on or after the day of month.
|
||||
* @param millisInDay The milliseconds in the rule date.
|
||||
* @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
|
||||
* or <code>UTC_TIME</code>.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after,
|
||||
int32_t millisInDay, TimeRuleType timeType);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param source The DateTimeRule object to be copied.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule(const DateTimeRule& source);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
~DateTimeRule();
|
||||
|
||||
/**
|
||||
* Clone this DateTimeRule object polymorphically. The caller owns the result and
|
||||
* should delete it when done.
|
||||
* @return A copy of the object.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule* clone(void) const;
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @param right The object to be copied.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateTimeRule& operator=(const DateTimeRule& right);
|
||||
|
||||
/**
|
||||
* Return true if the given DateTimeRule objects are semantically equal. Objects
|
||||
* of different subclasses are considered unequal.
|
||||
* @param that The object to be compared with.
|
||||
* @return true if the given DateTimeRule objects are semantically equal.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UBool operator==(const DateTimeRule& that) const;
|
||||
|
||||
/**
|
||||
* Return true if the given DateTimeRule objects are semantically unequal. Objects
|
||||
* of different subclasses are considered unequal.
|
||||
* @param that The object to be compared with.
|
||||
* @return true if the given DateTimeRule objects are semantically unequal.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UBool operator!=(const DateTimeRule& that) const;
|
||||
|
||||
/**
|
||||
* Gets the date rule type, such as <code>DOM</code>
|
||||
* @return The date rule type.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
DateRuleType getDateRuleType(void) const;
|
||||
|
||||
/**
|
||||
* Gets the time rule type
|
||||
* @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
|
||||
* or <code>UTC_TIME</code>.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
TimeRuleType getTimeRuleType(void) const;
|
||||
|
||||
/**
|
||||
* Gets the rule month.
|
||||
* @return The rule month.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
int32_t getRuleMonth(void) const;
|
||||
|
||||
/**
|
||||
* Gets the rule day of month. When the date rule type
|
||||
* is <code>DOW</code>, the value is always 0.
|
||||
* @return The rule day of month
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
int32_t getRuleDayOfMonth(void) const;
|
||||
|
||||
/**
|
||||
* Gets the rule day of week. When the date rule type
|
||||
* is <code>DOM</code>, the value is always 0.
|
||||
* @return The rule day of week.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
int32_t getRuleDayOfWeek(void) const;
|
||||
|
||||
/**
|
||||
* Gets the ordinal number of the occurence of the day of week
|
||||
* in the month. When the date rule type is not <code>DOW</code>,
|
||||
* the value is always 0.
|
||||
* @return The rule day of week ordinal number in the month.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
int32_t getRuleWeekInMonth(void) const;
|
||||
|
||||
/**
|
||||
* Gets the rule time in the rule day.
|
||||
* @return The time in the rule day in milliseconds.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
int32_t getRuleMillisInDay(void) const;
|
||||
|
||||
private:
|
||||
int32_t fMonth;
|
||||
int32_t fDayOfMonth;
|
||||
int32_t fDayOfWeek;
|
||||
int32_t fWeekInMonth;
|
||||
int32_t fMillisInDay;
|
||||
DateRuleType fDateRuleType;
|
||||
TimeRuleType fTimeRuleType;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to
|
||||
* a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . erived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
||||
* method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
||||
* methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // DTRULE_H
|
||||
//eof
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++: internal template EnumSet<>
|
||||
*/
|
||||
|
||||
#ifndef ENUMSET_H
|
||||
#define ENUMSET_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if U_SHOW_CPLUSPLUS_API
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* enum bitset for boolean fields. Similar to Java EnumSet<>.
|
||||
* Needs to range check.
|
||||
* @internal
|
||||
*/
|
||||
template<typename T, uint32_t minValue, uint32_t limitValue>
|
||||
class EnumSet {
|
||||
public:
|
||||
inline EnumSet() : fBools(0) {}
|
||||
inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
|
||||
inline ~EnumSet() {}
|
||||
inline void clear() { fBools=0; }
|
||||
inline void add(T toAdd) { set(toAdd, 1); }
|
||||
inline void remove(T toRemove) { set(toRemove, 0); }
|
||||
inline int32_t contains(T toCheck) const { return get(toCheck); }
|
||||
inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
|
||||
inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
|
||||
inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }
|
||||
inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
|
||||
inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
|
||||
fBools = other.fBools;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline uint32_t getAll() const {
|
||||
return fBools;
|
||||
}
|
||||
|
||||
private:
|
||||
inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
|
||||
private:
|
||||
uint32_t fBools;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_SHOW_CPLUSPLUS_API */
|
||||
#endif /* ENUMSET_H */
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: errorcode.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2009mar10
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __ERRORCODE_H__
|
||||
#define __ERRORCODE_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: ErrorCode class intended to make it easier to use
|
||||
* ICU C and C++ APIs from C++ user code.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Wrapper class for UErrorCode, with conversion operators for direct use
|
||||
* in ICU C and C++ APIs.
|
||||
* Intended to be used as a base class, where a subclass overrides
|
||||
* the handleFailure() function so that it throws an exception,
|
||||
* does an assert(), logs an error, etc.
|
||||
* This is not an abstract base class. This class can be used and instantiated
|
||||
* by itself, although it will be more useful when subclassed.
|
||||
*
|
||||
* Features:
|
||||
* - The constructor initializes the internal UErrorCode to U_ZERO_ERROR,
|
||||
* removing one common source of errors.
|
||||
* - Same use in C APIs taking a UErrorCode * (pointer)
|
||||
* and C++ taking UErrorCode & (reference) via conversion operators.
|
||||
* - Possible automatic checking for success when it goes out of scope.
|
||||
*
|
||||
* Note: For automatic checking for success in the destructor, a subclass
|
||||
* must implement such logic in its own destructor because the base class
|
||||
* destructor cannot call a subclass function (like handleFailure()).
|
||||
* The ErrorCode base class destructor does nothing.
|
||||
*
|
||||
* Note also: While it is possible for a destructor to throw an exception,
|
||||
* it is generally unsafe to do so. This means that in a subclass the destructor
|
||||
* and the handleFailure() function may need to take different actions.
|
||||
*
|
||||
* Sample code:
|
||||
* \code
|
||||
* class IcuErrorCode: public icu::ErrorCode {
|
||||
* public:
|
||||
* virtual ~IcuErrorCode() { // should be defined in .cpp as "key function"
|
||||
* // Safe because our handleFailure() does not throw exceptions.
|
||||
* if(isFailure()) { handleFailure(); }
|
||||
* }
|
||||
* protected:
|
||||
* virtual void handleFailure() const {
|
||||
* log_failure(u_errorName(errorCode));
|
||||
* exit(errorCode);
|
||||
* }
|
||||
* };
|
||||
* IcuErrorCode error_code;
|
||||
* UConverter *cnv = ucnv_open("Shift-JIS", error_code);
|
||||
* length = ucnv_fromUChars(dest, capacity, src, length, error_code);
|
||||
* ucnv_close(cnv);
|
||||
* // IcuErrorCode destructor checks for success.
|
||||
* \endcode
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
class U_COMMON_API ErrorCode: public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Default constructor. Initializes its UErrorCode to U_ZERO_ERROR.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
ErrorCode() : errorCode(U_ZERO_ERROR) {}
|
||||
/** Destructor, does nothing. See class documentation for details. @stable ICU 4.2 */
|
||||
virtual ~ErrorCode();
|
||||
/** Conversion operator, returns a reference. @stable ICU 4.2 */
|
||||
operator UErrorCode & () { return errorCode; }
|
||||
/** Conversion operator, returns a pointer. @stable ICU 4.2 */
|
||||
operator UErrorCode * () { return &errorCode; }
|
||||
/** Tests for U_SUCCESS(). @stable ICU 4.2 */
|
||||
UBool isSuccess() const { return U_SUCCESS(errorCode); }
|
||||
/** Tests for U_FAILURE(). @stable ICU 4.2 */
|
||||
UBool isFailure() const { return U_FAILURE(errorCode); }
|
||||
/** Returns the UErrorCode value. @stable ICU 4.2 */
|
||||
UErrorCode get() const { return errorCode; }
|
||||
/** Sets the UErrorCode value. @stable ICU 4.2 */
|
||||
void set(UErrorCode value) { errorCode=value; }
|
||||
/** Returns the UErrorCode value and resets it to U_ZERO_ERROR. @stable ICU 4.2 */
|
||||
UErrorCode reset();
|
||||
/**
|
||||
* Asserts isSuccess().
|
||||
* In other words, this method checks for a failure code,
|
||||
* and the base class handles it like this:
|
||||
* \code
|
||||
* if(isFailure()) { handleFailure(); }
|
||||
* \endcode
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
void assertSuccess() const;
|
||||
/**
|
||||
* Return a string for the UErrorCode value.
|
||||
* The string will be the same as the name of the error code constant
|
||||
* in the UErrorCode enum.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
const char* errorName() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Internal UErrorCode, accessible to subclasses.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UErrorCode errorCode;
|
||||
/**
|
||||
* Called by assertSuccess() if isFailure() is true.
|
||||
* A subclass should override this function to deal with a failure code:
|
||||
* Throw an exception, log an error, terminate the program, or similar.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual void handleFailure() const {}
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // __ERRORCODE_H__
|
||||
@@ -1,291 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File FIELDPOS.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/25/97 aliu Converted from java.
|
||||
* 03/17/97 clhuang Updated per Format implementation.
|
||||
* 07/17/98 stephen Added default/copy ctors, and operators =, ==, !=
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
// *****************************************************************************
|
||||
// This file was generated from the java source file FieldPosition.java
|
||||
// *****************************************************************************
|
||||
|
||||
#ifndef FIELDPOS_H
|
||||
#define FIELDPOS_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: FieldPosition identifies the fields in a formatted output.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* <code>FieldPosition</code> is a simple class used by <code>Format</code>
|
||||
* and its subclasses to identify fields in formatted output. Fields are
|
||||
* identified by constants, whose names typically end with <code>_FIELD</code>,
|
||||
* defined in the various subclasses of <code>Format</code>. See
|
||||
* <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
|
||||
* an example.
|
||||
*
|
||||
* <p>
|
||||
* <code>FieldPosition</code> keeps track of the position of the
|
||||
* field within the formatted output with two indices: the index
|
||||
* of the first character of the field and the index of the last
|
||||
* character of the field.
|
||||
*
|
||||
* <p>
|
||||
* One version of the <code>format</code> method in the various
|
||||
* <code>Format</code> classes requires a <code>FieldPosition</code>
|
||||
* object as an argument. You use this <code>format</code> method
|
||||
* to perform partial formatting or to get information about the
|
||||
* formatted output (such as the position of a field).
|
||||
*
|
||||
* The FieldPosition class is not suitable for subclassing.
|
||||
*
|
||||
* <p>
|
||||
* Below is an example of using <code>FieldPosition</code> to aid
|
||||
* alignment of an array of formatted floating-point numbers on
|
||||
* their decimal points:
|
||||
* <pre>
|
||||
* \code
|
||||
* double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
|
||||
* 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
|
||||
* int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
|
||||
*
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
|
||||
* fmt->setDecimalSeparatorAlwaysShown(true);
|
||||
*
|
||||
* const int tempLen = 20;
|
||||
* char temp[tempLen];
|
||||
*
|
||||
* for (int i=0; i<dNumSize; i++) {
|
||||
* FieldPosition pos(NumberFormat::INTEGER_FIELD);
|
||||
* UnicodeString buf;
|
||||
* char fmtText[tempLen];
|
||||
* ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
|
||||
* for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
|
||||
* temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
|
||||
* cout << temp << fmtText << endl;
|
||||
* }
|
||||
* delete fmt;
|
||||
* \endcode
|
||||
* </pre>
|
||||
* <p>
|
||||
* The code will generate the following output:
|
||||
* <pre>
|
||||
* \code
|
||||
* 123,456,789.000
|
||||
* -12,345,678.900
|
||||
* 1,234,567.880
|
||||
* -123,456.789
|
||||
* 12,345.678
|
||||
* -1,234.567
|
||||
* 123.456
|
||||
* -12.345
|
||||
* 1.234
|
||||
* \endcode
|
||||
* </pre>
|
||||
*/
|
||||
class U_I18N_API FieldPosition : public UObject {
|
||||
public:
|
||||
/**
|
||||
* DONT_CARE may be specified as the field to indicate that the
|
||||
* caller doesn't need to specify a field. Do not subclass.
|
||||
*/
|
||||
enum { DONT_CARE = -1 };
|
||||
|
||||
/**
|
||||
* Creates a FieldPosition object with a non-specified field.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
FieldPosition()
|
||||
: UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {}
|
||||
|
||||
/**
|
||||
* Creates a FieldPosition object for the given field. Fields are
|
||||
* identified by constants, whose names typically end with _FIELD,
|
||||
* in the various subclasses of Format.
|
||||
*
|
||||
* @see NumberFormat#INTEGER_FIELD
|
||||
* @see NumberFormat#FRACTION_FIELD
|
||||
* @see DateFormat#YEAR_FIELD
|
||||
* @see DateFormat#MONTH_FIELD
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
FieldPosition(int32_t field)
|
||||
: UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param copy the object to be copied from.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
FieldPosition(const FieldPosition& copy)
|
||||
: UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~FieldPosition();
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @param copy the object to be copied from.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
FieldPosition& operator=(const FieldPosition& copy);
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @param that the object to be compared with.
|
||||
* @return TRUE if the two field positions are equal, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const FieldPosition& that) const;
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @param that the object to be compared with.
|
||||
* @return TRUE if the two field positions are not equal, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const FieldPosition& that) const;
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If an error occurs, then NULL is returned.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
FieldPosition *clone() const;
|
||||
|
||||
/**
|
||||
* Retrieve the field identifier.
|
||||
* @return the field identifier.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getField(void) const { return fField; }
|
||||
|
||||
/**
|
||||
* Retrieve the index of the first character in the requested field.
|
||||
* @return the index of the first character in the requested field.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getBeginIndex(void) const { return fBeginIndex; }
|
||||
|
||||
/**
|
||||
* Retrieve the index of the character following the last character in the
|
||||
* requested field.
|
||||
* @return the index of the character following the last character in the
|
||||
* requested field.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getEndIndex(void) const { return fEndIndex; }
|
||||
|
||||
/**
|
||||
* Set the field.
|
||||
* @param f the new value of the field.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setField(int32_t f) { fField = f; }
|
||||
|
||||
/**
|
||||
* Set the begin index. For use by subclasses of Format.
|
||||
* @param bi the new value of the begin index
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setBeginIndex(int32_t bi) { fBeginIndex = bi; }
|
||||
|
||||
/**
|
||||
* Set the end index. For use by subclasses of Format.
|
||||
* @param ei the new value of the end index
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setEndIndex(int32_t ei) { fEndIndex = ei; }
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Input: Desired field to determine start and end offsets for.
|
||||
* The meaning depends on the subclass of Format.
|
||||
*/
|
||||
int32_t fField;
|
||||
|
||||
/**
|
||||
* Output: Start offset of field in text.
|
||||
* If the field does not occur in the text, 0 is returned.
|
||||
*/
|
||||
int32_t fBeginIndex;
|
||||
|
||||
/**
|
||||
* Output: End offset of field in text.
|
||||
* If the field does not occur in the text, 0 is returned.
|
||||
*/
|
||||
int32_t fEndIndex;
|
||||
};
|
||||
|
||||
inline FieldPosition&
|
||||
FieldPosition::operator=(const FieldPosition& copy)
|
||||
{
|
||||
fField = copy.fField;
|
||||
fEndIndex = copy.fEndIndex;
|
||||
fBeginIndex = copy.fBeginIndex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline UBool
|
||||
FieldPosition::operator==(const FieldPosition& copy) const
|
||||
{
|
||||
return (fField == copy.fField &&
|
||||
fEndIndex == copy.fEndIndex &&
|
||||
fBeginIndex == copy.fBeginIndex);
|
||||
}
|
||||
|
||||
inline UBool
|
||||
FieldPosition::operator!=(const FieldPosition& copy) const
|
||||
{
|
||||
return !operator==(copy);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _FIELDPOS
|
||||
//eof
|
||||
@@ -1,764 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File FMTABLE.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/29/97 aliu Creation.
|
||||
********************************************************************************
|
||||
*/
|
||||
#ifndef FMTABLE_H
|
||||
#define FMTABLE_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uformattable.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class CharString;
|
||||
class DigitList;
|
||||
|
||||
/**
|
||||
* \def UNUM_INTERNAL_STACKARRAY_SIZE
|
||||
* @internal
|
||||
*/
|
||||
#if U_PLATFORM == U_PF_OS400
|
||||
#define UNUM_INTERNAL_STACKARRAY_SIZE 144
|
||||
#else
|
||||
#define UNUM_INTERNAL_STACKARRAY_SIZE 128
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Formattable objects can be passed to the Format class or
|
||||
* its subclasses for formatting. Formattable is a thin wrapper
|
||||
* class which interconverts between the primitive numeric types
|
||||
* (double, long, etc.) as well as UDate and UnicodeString.
|
||||
*
|
||||
* <p>Internally, a Formattable object is a union of primitive types.
|
||||
* As such, it can only store one flavor of data at a time. To
|
||||
* determine what flavor of data it contains, use the getType method.
|
||||
*
|
||||
* <p>As of ICU 3.0, Formattable may also wrap a UObject pointer,
|
||||
* which it owns. This allows an instance of any ICU class to be
|
||||
* encapsulated in a Formattable. For legacy reasons and for
|
||||
* efficiency, primitive numeric types are still stored directly
|
||||
* within a Formattable.
|
||||
*
|
||||
* <p>The Formattable class is not suitable for subclassing.
|
||||
*
|
||||
* <p>See UFormattable for a C wrapper.
|
||||
*/
|
||||
class U_I18N_API Formattable : public UObject {
|
||||
public:
|
||||
/**
|
||||
* This enum is only used to let callers distinguish between
|
||||
* the Formattable(UDate) constructor and the Formattable(double)
|
||||
* constructor; the compiler cannot distinguish the signatures,
|
||||
* since UDate is currently typedefed to be either double or long.
|
||||
* If UDate is changed later to be a bonafide class
|
||||
* or struct, then we no longer need this enum.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
enum ISDATE { kIsDate };
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
Formattable(); // Type kLong, value 0
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with a UDate instance.
|
||||
* @param d the UDate instance.
|
||||
* @param flag the flag to indicate this is a date. Always set it to kIsDate
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(UDate d, ISDATE flag);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with a double number.
|
||||
* @param d the double number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(double d);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with a long number.
|
||||
* @param l the long number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(int32_t l);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with an int64_t number
|
||||
* @param ll the int64_t number.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Formattable(int64_t ll);
|
||||
|
||||
#if !UCONFIG_NO_CONVERSION
|
||||
/**
|
||||
* Creates a Formattable object with a char string pointer.
|
||||
* Assumes that the char string is null terminated.
|
||||
* @param strToCopy the char string.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(const char* strToCopy);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a Formattable object of an appropriate numeric type from a
|
||||
* a decimal number in string form. The Formattable will retain the
|
||||
* full precision of the input in decimal format, even when it exceeds
|
||||
* what can be represented by a double or int64_t.
|
||||
*
|
||||
* @param number the unformatted (not localized) string representation
|
||||
* of the Decimal number.
|
||||
* @param status the error code. Possible errors include U_INVALID_FORMAT_ERROR
|
||||
* if the format of the string does not conform to that of a
|
||||
* decimal number.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
Formattable(const StringPiece &number, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with a UnicodeString object to copy from.
|
||||
* @param strToCopy the UnicodeString string.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(const UnicodeString& strToCopy);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with a UnicodeString object to adopt from.
|
||||
* @param strToAdopt the UnicodeString string.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(UnicodeString* strToAdopt);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object with an array of Formattable objects.
|
||||
* @param arrayToCopy the Formattable object array.
|
||||
* @param count the array count.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(const Formattable* arrayToCopy, int32_t count);
|
||||
|
||||
/**
|
||||
* Creates a Formattable object that adopts the given UObject.
|
||||
* @param objectToAdopt the UObject to set this object to
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
Formattable(UObject* objectToAdopt);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable(const Formattable&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @param rhs The Formattable object to copy into this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable& operator=(const Formattable &rhs);
|
||||
|
||||
/**
|
||||
* Equality comparison.
|
||||
* @param other the object to be compared with.
|
||||
* @return TRUE if other are equal to this, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const Formattable &other) const;
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @param other the object to be compared with.
|
||||
* @return TRUE if other are unequal to this, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const Formattable& other) const
|
||||
{ return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~Formattable();
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If an error occurs, then NULL is returned.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Formattable *clone() const;
|
||||
|
||||
/**
|
||||
* Selector for flavor of data type contained within a
|
||||
* Formattable object. Formattable is a union of several
|
||||
* different types, and at any time contains exactly one type.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
enum Type {
|
||||
/**
|
||||
* Selector indicating a UDate value. Use getDate to retrieve
|
||||
* the value.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
kDate,
|
||||
|
||||
/**
|
||||
* Selector indicating a double value. Use getDouble to
|
||||
* retrieve the value.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
kDouble,
|
||||
|
||||
/**
|
||||
* Selector indicating a 32-bit integer value. Use getLong to
|
||||
* retrieve the value.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
kLong,
|
||||
|
||||
/**
|
||||
* Selector indicating a UnicodeString value. Use getString
|
||||
* to retrieve the value.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
kString,
|
||||
|
||||
/**
|
||||
* Selector indicating an array of Formattables. Use getArray
|
||||
* to retrieve the value.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
kArray,
|
||||
|
||||
/**
|
||||
* Selector indicating a 64-bit integer value. Use getInt64
|
||||
* to retrieve the value.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
kInt64,
|
||||
|
||||
/**
|
||||
* Selector indicating a UObject value. Use getObject to
|
||||
* retrieve the value.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
kObject
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the data type of this Formattable object.
|
||||
* @return the data type of this Formattable object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Type getType(void) const;
|
||||
|
||||
/**
|
||||
* Returns TRUE if the data type of this Formattable object
|
||||
* is kDouble, kLong, or kInt64
|
||||
* @return TRUE if this is a pure numeric object
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UBool isNumeric() const;
|
||||
|
||||
/**
|
||||
* Gets the double value of this object. If this object is not of type
|
||||
* kDouble then the result is undefined.
|
||||
* @return the double value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
double getDouble(void) const { return fValue.fDouble; }
|
||||
|
||||
/**
|
||||
* Gets the double value of this object. If this object is of type
|
||||
* long, int64 or Decimal Number then a conversion is peformed, with
|
||||
* possible loss of precision. If the type is kObject and the
|
||||
* object is a Measure, then the result of
|
||||
* getNumber().getDouble(status) is returned. If this object is
|
||||
* neither a numeric type nor a Measure, then 0 is returned and
|
||||
* the status is set to U_INVALID_FORMAT_ERROR.
|
||||
* @param status the error code
|
||||
* @return the double value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
double getDouble(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the long value of this object. If this object is not of type
|
||||
* kLong then the result is undefined.
|
||||
* @return the long value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
|
||||
|
||||
/**
|
||||
* Gets the long value of this object. If the magnitude is too
|
||||
* large to fit in a long, then the maximum or minimum long value,
|
||||
* as appropriate, is returned and the status is set to
|
||||
* U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and
|
||||
* it fits within a long, then no precision is lost. If it is of
|
||||
* type kDouble, then a conversion is peformed, with
|
||||
* truncation of any fractional part. If the type is kObject and
|
||||
* the object is a Measure, then the result of
|
||||
* getNumber().getLong(status) is returned. If this object is
|
||||
* neither a numeric type nor a Measure, then 0 is returned and
|
||||
* the status is set to U_INVALID_FORMAT_ERROR.
|
||||
* @param status the error code
|
||||
* @return the long value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
int32_t getLong(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the int64 value of this object. If this object is not of type
|
||||
* kInt64 then the result is undefined.
|
||||
* @return the int64 value of this object.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
int64_t getInt64(void) const { return fValue.fInt64; }
|
||||
|
||||
/**
|
||||
* Gets the int64 value of this object. If this object is of a numeric
|
||||
* type and the magnitude is too large to fit in an int64, then
|
||||
* the maximum or minimum int64 value, as appropriate, is returned
|
||||
* and the status is set to U_INVALID_FORMAT_ERROR. If the
|
||||
* magnitude fits in an int64, then a casting conversion is
|
||||
* peformed, with truncation of any fractional part. If the type
|
||||
* is kObject and the object is a Measure, then the result of
|
||||
* getNumber().getDouble(status) is returned. If this object is
|
||||
* neither a numeric type nor a Measure, then 0 is returned and
|
||||
* the status is set to U_INVALID_FORMAT_ERROR.
|
||||
* @param status the error code
|
||||
* @return the int64 value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
int64_t getInt64(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the Date value of this object. If this object is not of type
|
||||
* kDate then the result is undefined.
|
||||
* @return the Date value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UDate getDate() const { return fValue.fDate; }
|
||||
|
||||
/**
|
||||
* Gets the Date value of this object. If the type is not a date,
|
||||
* status is set to U_INVALID_FORMAT_ERROR and the return value is
|
||||
* undefined.
|
||||
* @param status the error code.
|
||||
* @return the Date value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UDate getDate(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the string value of this object. If this object is not of type
|
||||
* kString then the result is undefined.
|
||||
* @param result Output param to receive the Date value of this object.
|
||||
* @return A reference to 'result'.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getString(UnicodeString& result) const
|
||||
{ result=*fValue.fString; return result; }
|
||||
|
||||
/**
|
||||
* Gets the string value of this object. If the type is not a
|
||||
* string, status is set to U_INVALID_FORMAT_ERROR and a bogus
|
||||
* string is returned.
|
||||
* @param result Output param to receive the Date value of this object.
|
||||
* @param status the error code.
|
||||
* @return A reference to 'result'.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets a const reference to the string value of this object. If
|
||||
* this object is not of type kString then the result is
|
||||
* undefined.
|
||||
* @return a const reference to the string value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline const UnicodeString& getString(void) const;
|
||||
|
||||
/**
|
||||
* Gets a const reference to the string value of this object. If
|
||||
* the type is not a string, status is set to
|
||||
* U_INVALID_FORMAT_ERROR and the result is a bogus string.
|
||||
* @param status the error code.
|
||||
* @return a const reference to the string value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
const UnicodeString& getString(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets a reference to the string value of this object. If this
|
||||
* object is not of type kString then the result is undefined.
|
||||
* @return a reference to the string value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline UnicodeString& getString(void);
|
||||
|
||||
/**
|
||||
* Gets a reference to the string value of this object. If the
|
||||
* type is not a string, status is set to U_INVALID_FORMAT_ERROR
|
||||
* and the result is a bogus string.
|
||||
* @param status the error code.
|
||||
* @return a reference to the string value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UnicodeString& getString(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Gets the array value and count of this object. If this object
|
||||
* is not of type kArray then the result is undefined.
|
||||
* @param count fill-in with the count of this object.
|
||||
* @return the array value of this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const Formattable* getArray(int32_t& count) const
|
||||
{ count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
|
||||
|
||||
/**
|
||||
* Gets the array value and count of this object. If the type is
|
||||
* not an array, status is set to U_INVALID_FORMAT_ERROR, count is
|
||||
* set to 0, and the result is NULL.
|
||||
* @param count fill-in with the count of this object.
|
||||
* @param status the error code.
|
||||
* @return the array value of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
const Formattable* getArray(int32_t& count, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Accesses the specified element in the array value of this
|
||||
* Formattable object. If this object is not of type kArray then
|
||||
* the result is undefined.
|
||||
* @param index the specified index.
|
||||
* @return the accessed element in the array.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the UObject contained within this
|
||||
* formattable, or NULL if this object does not contain a UObject.
|
||||
* @return a UObject pointer, or NULL
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
const UObject* getObject() const;
|
||||
|
||||
/**
|
||||
* Returns a numeric string representation of the number contained within this
|
||||
* formattable, or NULL if this object does not contain numeric type.
|
||||
* For values obtained by parsing, the returned decimal number retains
|
||||
* the full precision and range of the original input, unconstrained by
|
||||
* the limits of a double floating point or a 64 bit int.
|
||||
*
|
||||
* This function is not thread safe, and therfore is not declared const,
|
||||
* even though it is logically const.
|
||||
*
|
||||
* Possible errors include U_MEMORY_ALLOCATION_ERROR, and
|
||||
* U_INVALID_STATE if the formattable object has not been set to
|
||||
* a numeric type.
|
||||
*
|
||||
* @param status the error code.
|
||||
* @return the unformatted string representation of a number.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
StringPiece getDecimalNumber(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Sets the double value of this object and changes the type to
|
||||
* kDouble.
|
||||
* @param d the new double value to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setDouble(double d);
|
||||
|
||||
/**
|
||||
* Sets the long value of this object and changes the type to
|
||||
* kLong.
|
||||
* @param l the new long value to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setLong(int32_t l);
|
||||
|
||||
/**
|
||||
* Sets the int64 value of this object and changes the type to
|
||||
* kInt64.
|
||||
* @param ll the new int64 value to be set.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
void setInt64(int64_t ll);
|
||||
|
||||
/**
|
||||
* Sets the Date value of this object and changes the type to
|
||||
* kDate.
|
||||
* @param d the new Date value to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setDate(UDate d);
|
||||
|
||||
/**
|
||||
* Sets the string value of this object and changes the type to
|
||||
* kString.
|
||||
* @param stringToCopy the new string value to be set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setString(const UnicodeString& stringToCopy);
|
||||
|
||||
/**
|
||||
* Sets the array value and count of this object and changes the
|
||||
* type to kArray.
|
||||
* @param array the array value.
|
||||
* @param count the number of array elements to be copied.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setArray(const Formattable* array, int32_t count);
|
||||
|
||||
/**
|
||||
* Sets and adopts the string value and count of this object and
|
||||
* changes the type to kArray.
|
||||
* @param stringToAdopt the new string value to be adopted.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void adoptString(UnicodeString* stringToAdopt);
|
||||
|
||||
/**
|
||||
* Sets and adopts the array value and count of this object and
|
||||
* changes the type to kArray.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void adoptArray(Formattable* array, int32_t count);
|
||||
|
||||
/**
|
||||
* Sets and adopts the UObject value of this object and changes
|
||||
* the type to kObject. After this call, the caller must not
|
||||
* delete the given object.
|
||||
* @param objectToAdopt the UObject value to be adopted
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
void adoptObject(UObject* objectToAdopt);
|
||||
|
||||
/**
|
||||
* Sets the the numeric value from a decimal number string, and changes
|
||||
* the type to to a numeric type appropriate for the number.
|
||||
* The syntax of the number is a "numeric string"
|
||||
* as defined in the Decimal Arithmetic Specification, available at
|
||||
* http://speleotrove.com/decimal
|
||||
* The full precision and range of the input number will be retained,
|
||||
* even when it exceeds what can be represented by a double or an int64.
|
||||
*
|
||||
* @param numberString a string representation of the unformatted decimal number.
|
||||
* @param status the error code. Set to U_INVALID_FORMAT_ERROR if the
|
||||
* incoming string is not a valid decimal number.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
void setDecimalNumber(const StringPiece &numberString,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast.
|
||||
* @param fmt a valid UFormattable
|
||||
* @return the UFormattable as a Formattable object pointer. This is an alias to the original
|
||||
* UFormattable, and so is only valid while the original argument remains in scope.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
static inline Formattable *fromUFormattable(UFormattable *fmt);
|
||||
|
||||
/**
|
||||
* Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast.
|
||||
* @param fmt a valid UFormattable
|
||||
* @return the UFormattable as a Formattable object pointer. This is an alias to the original
|
||||
* UFormattable, and so is only valid while the original argument remains in scope.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
static inline const Formattable *fromUFormattable(const UFormattable *fmt);
|
||||
|
||||
/**
|
||||
* Convert this object pointer to a UFormattable.
|
||||
* @return this object as a UFormattable pointer. This is an alias to this object,
|
||||
* and so is only valid while this object remains in scope.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
inline UFormattable *toUFormattable();
|
||||
|
||||
/**
|
||||
* Convert this object pointer to a UFormattable.
|
||||
* @return this object as a UFormattable pointer. This is an alias to this object,
|
||||
* and so is only valid while this object remains in scope.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
inline const UFormattable *toUFormattable() const;
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Deprecated variant of getLong(UErrorCode&).
|
||||
* @param status the error code
|
||||
* @return the long value of this object.
|
||||
* @deprecated ICU 3.0 use getLong(UErrorCode&) instead
|
||||
*/
|
||||
inline int32_t getLong(UErrorCode* status) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Internal function, do not use.
|
||||
* TODO: figure out how to make this be non-public.
|
||||
* NumberFormat::format(Formattable, ...
|
||||
* needs to get at the DigitList, if it exists, for
|
||||
* big decimal formatting.
|
||||
* @internal
|
||||
*/
|
||||
DigitList *getDigitList() const { return fDecimalNum;}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
DigitList *getInternalDigitList();
|
||||
|
||||
/**
|
||||
* Adopt, and set value from, a DigitList
|
||||
* Internal Function, do not use.
|
||||
* @param dl the Digit List to be adopted
|
||||
* @internal
|
||||
*/
|
||||
void adoptDigitList(DigitList *dl);
|
||||
|
||||
/**
|
||||
* Internal function to return the CharString pointer.
|
||||
* @param status error code
|
||||
* @return pointer to the CharString - may become invalid if the object is modified
|
||||
* @internal
|
||||
*/
|
||||
CharString *internalGetCharString(UErrorCode &status);
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
/**
|
||||
* Cleans up the memory for unwanted values. For example, the adopted
|
||||
* string or array objects.
|
||||
*/
|
||||
void dispose(void);
|
||||
|
||||
/**
|
||||
* Common initialization, for use by constructors.
|
||||
*/
|
||||
void init();
|
||||
|
||||
UnicodeString* getBogus() const;
|
||||
|
||||
union {
|
||||
UObject* fObject;
|
||||
UnicodeString* fString;
|
||||
double fDouble;
|
||||
int64_t fInt64;
|
||||
UDate fDate;
|
||||
struct {
|
||||
Formattable* fArray;
|
||||
int32_t fCount;
|
||||
} fArrayAndCount;
|
||||
} fValue;
|
||||
|
||||
CharString *fDecimalStr;
|
||||
|
||||
DigitList *fDecimalNum;
|
||||
|
||||
char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList
|
||||
|
||||
Type fType;
|
||||
UnicodeString fBogus; // Bogus string when it's needed.
|
||||
};
|
||||
|
||||
inline UDate Formattable::getDate(UErrorCode& status) const {
|
||||
if (fType != kDate) {
|
||||
if (U_SUCCESS(status)) {
|
||||
status = U_INVALID_FORMAT_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return fValue.fDate;
|
||||
}
|
||||
|
||||
inline const UnicodeString& Formattable::getString(void) const {
|
||||
return *fValue.fString;
|
||||
}
|
||||
|
||||
inline UnicodeString& Formattable::getString(void) {
|
||||
return *fValue.fString;
|
||||
}
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
inline int32_t Formattable::getLong(UErrorCode* status) const {
|
||||
return getLong(*status);
|
||||
}
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
inline UFormattable* Formattable::toUFormattable() {
|
||||
return reinterpret_cast<UFormattable*>(this);
|
||||
}
|
||||
|
||||
inline const UFormattable* Formattable::toUFormattable() const {
|
||||
return reinterpret_cast<const UFormattable*>(this);
|
||||
}
|
||||
|
||||
inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) {
|
||||
return reinterpret_cast<Formattable *>(fmt);
|
||||
}
|
||||
|
||||
inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) {
|
||||
return reinterpret_cast<const Formattable *>(fmt);
|
||||
}
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif //_FMTABLE
|
||||
//eof
|
||||
@@ -1,305 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 1997-2011, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File FORMAT.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 03/17/97 clhuang Updated per C++ implementation.
|
||||
* 03/27/97 helena Updated to pass the simple test after code review.
|
||||
********************************************************************************
|
||||
*/
|
||||
// *****************************************************************************
|
||||
// This file was generated from the java source file Format.java
|
||||
// *****************************************************************************
|
||||
|
||||
#ifndef FORMAT_H
|
||||
#define FORMAT_H
|
||||
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Base class for all formats.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/fmtable.h"
|
||||
#include "unicode/fieldpos.h"
|
||||
#include "unicode/fpositer.h"
|
||||
#include "unicode/parsepos.h"
|
||||
#include "unicode/parseerr.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Base class for all formats. This is an abstract base class which
|
||||
* specifies the protocol for classes which convert other objects or
|
||||
* values, such as numeric values and dates, and their string
|
||||
* representations. In some cases these representations may be
|
||||
* localized or contain localized characters or strings. For example,
|
||||
* a numeric formatter such as DecimalFormat may convert a numeric
|
||||
* value such as 12345 to the string "$12,345". It may also parse
|
||||
* the string back into a numeric value. A date and time formatter
|
||||
* like SimpleDateFormat may represent a specific date, encoded
|
||||
* numerically, as a string such as "Wednesday, February 26, 1997 AD".
|
||||
* <P>
|
||||
* Many of the concrete subclasses of Format employ the notion of
|
||||
* a pattern. A pattern is a string representation of the rules which
|
||||
* govern the interconversion between values and strings. For example,
|
||||
* a DecimalFormat object may be associated with the pattern
|
||||
* "$#,##0.00;($#,##0.00)", which is a common US English format for
|
||||
* currency values, yielding strings such as "$1,234.45" for 1234.45,
|
||||
* and "($987.65)" for 987.6543. The specific syntax of a pattern
|
||||
* is defined by each subclass.
|
||||
* <P>
|
||||
* Even though many subclasses use patterns, the notion of a pattern
|
||||
* is not inherent to Format classes in general, and is not part of
|
||||
* the explicit base class protocol.
|
||||
* <P>
|
||||
* Two complex formatting classes bear mentioning. These are
|
||||
* MessageFormat and ChoiceFormat. ChoiceFormat is a subclass of
|
||||
* NumberFormat which allows the user to format different number ranges
|
||||
* as strings. For instance, 0 may be represented as "no files", 1 as
|
||||
* "one file", and any number greater than 1 as "many files".
|
||||
* MessageFormat is a formatter which utilizes other Format objects to
|
||||
* format a string containing with multiple values. For instance,
|
||||
* A MessageFormat object might produce the string "There are no files
|
||||
* on the disk MyDisk on February 27, 1997." given the arguments 0,
|
||||
* "MyDisk", and the date value of 2/27/97. See the ChoiceFormat
|
||||
* and MessageFormat headers for further information.
|
||||
* <P>
|
||||
* If formatting is unsuccessful, a failing UErrorCode is returned when
|
||||
* the Format cannot format the type of object, otherwise if there is
|
||||
* something illformed about the the Unicode replacement character
|
||||
* 0xFFFD is returned.
|
||||
* <P>
|
||||
* If there is no match when parsing, a parse failure UErrorCode is
|
||||
* retured for methods which take no ParsePosition. For the method
|
||||
* that takes a ParsePosition, the index parameter is left unchanged.
|
||||
* <P>
|
||||
* <em>User subclasses are not supported.</em> While clients may write
|
||||
* subclasses, such code will not necessarily work and will not be
|
||||
* guaranteed to work stably from release to release.
|
||||
*/
|
||||
class U_I18N_API Format : public UObject {
|
||||
public:
|
||||
|
||||
/** Destructor
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual ~Format();
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
* @param other the object to be compared with.
|
||||
* @return Return true if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const = 0;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are not semantically
|
||||
* equal.
|
||||
* @param other the object to be compared with.
|
||||
* @return Return true if the given Format objects are not semantically.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const Format& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Clone this object polymorphically. The caller is responsible
|
||||
* for deleting the result when done.
|
||||
* @return A copy of the object
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual Format* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Formats an object to produce a string.
|
||||
*
|
||||
* @param obj The object to format.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param status Output parameter filled in with success or failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Format an object to produce a string. This is a pure virtual method which
|
||||
* subclasses must implement. This method allows polymorphic formatting
|
||||
* of Formattable objects. If a subclass of Format receives a Formattable
|
||||
* object type it doesn't handle (e.g., if a numeric Formattable is passed
|
||||
* to a DateFormat object) then it returns a failing UErrorCode.
|
||||
*
|
||||
* @param obj The object to format.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const = 0;
|
||||
/**
|
||||
* Format an object to produce a string. Subclasses should override this
|
||||
* method. This method allows polymorphic formatting of Formattable objects.
|
||||
* If a subclass of Format receives a Formattable object type it doesn't
|
||||
* handle (e.g., if a numeric Formattable is passed to a DateFormat object)
|
||||
* then it returns a failing UErrorCode.
|
||||
*
|
||||
* @param obj The object to format.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param posIter On return, can be used to iterate over positions
|
||||
* of fields generated by this format call.
|
||||
* @param status Output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Parse a string to produce an object. This is a pure virtual
|
||||
* method which subclasses must implement. This method allows
|
||||
* polymorphic parsing of strings into Formattable objects.
|
||||
* <P>
|
||||
* Before calling, set parse_pos.index to the offset you want to
|
||||
* start parsing at in the source. After calling, parse_pos.index
|
||||
* is the end of the text you parsed. If error occurs, index is
|
||||
* unchanged.
|
||||
* <P>
|
||||
* When parsing, leading whitespace is discarded (with successful
|
||||
* parse), while trailing whitespace is left as is.
|
||||
* <P>
|
||||
* Example:
|
||||
* <P>
|
||||
* Parsing "_12_xy" (where _ represents a space) for a number,
|
||||
* with index == 0 will result in the number 12, with
|
||||
* parse_pos.index updated to 3 (just before the second space).
|
||||
* Parsing a second time will result in a failing UErrorCode since
|
||||
* "xy" is not a number, and leave index at 3.
|
||||
* <P>
|
||||
* Subclasses will typically supply specific parse methods that
|
||||
* return different types of values. Since methods can't overload
|
||||
* on return types, these will typically be named "parse", while
|
||||
* this polymorphic method will always be called parseObject. Any
|
||||
* parse method that does not take a parse_pos should set status
|
||||
* to an error value when no text in the required format is at the
|
||||
* start position.
|
||||
*
|
||||
* @param source The string to be parsed into an object.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parse_pos The position to start parsing at. Upon return
|
||||
* this param is set to the position after the
|
||||
* last character successfully parsed. If the
|
||||
* source is not parsed successfully, this param
|
||||
* will remain unchanged.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void parseObject(const UnicodeString& source,
|
||||
Formattable& result,
|
||||
ParsePosition& parse_pos) const = 0;
|
||||
|
||||
/**
|
||||
* Parses a string to produce an object. This is a convenience method
|
||||
* which calls the pure virtual parseObject() method, and returns a
|
||||
* failure UErrorCode if the ParsePosition indicates failure.
|
||||
*
|
||||
* @param source The string to be parsed into an object.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param status Output param to be filled with success/failure
|
||||
* result code.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void parseObject(const UnicodeString& source,
|
||||
Formattable& result,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/** Get the locale for this format object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @param status error code for the operation
|
||||
* @return the locale
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/** Get the locale for this format object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @param status error code for the operation
|
||||
* @return the locale
|
||||
* @internal
|
||||
*/
|
||||
const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
protected:
|
||||
/** @stable ICU 2.8 */
|
||||
void setLocaleIDs(const char* valid, const char* actual);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor for subclass use only. Does nothing.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Format();
|
||||
|
||||
/**
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Format(const Format&); // Does nothing; for subclasses only
|
||||
|
||||
/**
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Format& operator=(const Format&); // Does nothing; for subclasses
|
||||
|
||||
|
||||
/**
|
||||
* Simple function for initializing a UParseError from a UnicodeString.
|
||||
*
|
||||
* @param pattern The pattern to copy into the parseError
|
||||
* @param pos The position in pattern where the error occured
|
||||
* @param parseError The UParseError object to fill in
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
static void syntaxError(const UnicodeString& pattern,
|
||||
int32_t pos,
|
||||
UParseError& parseError);
|
||||
|
||||
private:
|
||||
char actualLocale[ULOC_FULLNAME_CAPACITY];
|
||||
char validLocale[ULOC_FULLNAME_CAPACITY];
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _FORMAT
|
||||
//eof
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
* Copyright (C) 2010-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File attiter.h
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 12/15/2009 dougfelt Created
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef FPOSITER_H
|
||||
#define FPOSITER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: FieldPosition Iterator.
|
||||
*/
|
||||
|
||||
#if UCONFIG_NO_FORMATTING
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/*
|
||||
* Allow the declaration of APIs with pointers to FieldPositionIterator
|
||||
* even when formatting is removed from the build.
|
||||
*/
|
||||
class FieldPositionIterator;
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#else
|
||||
|
||||
#include "unicode/fieldpos.h"
|
||||
#include "unicode/umisc.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class UVector32;
|
||||
|
||||
/**
|
||||
* FieldPositionIterator returns the field ids and their start/limit positions generated
|
||||
* by a call to Format::format. See Format, NumberFormat, DecimalFormat.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
class U_I18N_API FieldPositionIterator : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~FieldPositionIterator();
|
||||
|
||||
/**
|
||||
* Constructs a new, empty iterator.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
FieldPositionIterator(void);
|
||||
|
||||
/**
|
||||
* Copy constructor. If the copy failed for some reason, the new iterator will
|
||||
* be empty.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
FieldPositionIterator(const FieldPositionIterator&);
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this
|
||||
* one.
|
||||
* <p>
|
||||
* Return true if this FieldPositionIterator is at the same position in an
|
||||
* equal array of run values.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UBool operator==(const FieldPositionIterator&) const;
|
||||
|
||||
/**
|
||||
* Returns the complement of the result of operator==
|
||||
* @param rhs The FieldPositionIterator to be compared for inequality
|
||||
* @return the complement of the result of operator==
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UBool operator!=(const FieldPositionIterator& rhs) const { return !operator==(rhs); }
|
||||
|
||||
/**
|
||||
* If the current position is valid, updates the FieldPosition values, advances the iterator,
|
||||
* and returns TRUE, otherwise returns FALSE.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UBool next(FieldPosition& fp);
|
||||
|
||||
private:
|
||||
friend class FieldPositionIteratorHandler;
|
||||
|
||||
/**
|
||||
* Sets the data used by the iterator, and resets the position.
|
||||
* Returns U_ILLEGAL_ARGUMENT_ERROR in status if the data is not valid
|
||||
* (length is not a multiple of 3, or start >= limit for any run).
|
||||
*/
|
||||
void setData(UVector32 *adopt, UErrorCode& status);
|
||||
|
||||
UVector32 *data;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // FPOSITER_H
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
*
|
||||
* File GENDER.H
|
||||
*
|
||||
* Modification History:*
|
||||
* Date Name Description
|
||||
*
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _GENDER
|
||||
#define _GENDER
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/ugender.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
class GenderInfoTest;
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// Forward Declaration
|
||||
void GenderInfo_initCache(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* GenderInfo computes the gender of a list as a whole given the gender of
|
||||
* each element.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
class U_I18N_API GenderInfo : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Provides access to the predefined GenderInfo object for a given
|
||||
* locale.
|
||||
*
|
||||
* @param locale The locale for which a <code>GenderInfo</code> object is
|
||||
* returned.
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return The predefined <code>GenderInfo</code> object pointer for
|
||||
* this locale. The returned object is immutable, so it is
|
||||
* declared as const. Caller does not own the returned
|
||||
* pointer, so it must not attempt to free it.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
static const GenderInfo* U_EXPORT2 getInstance(const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Determines the gender of a list as a whole given the gender of each
|
||||
* of the elements.
|
||||
*
|
||||
* @param genders the gender of each element in the list.
|
||||
* @param length the length of gender array.
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return the gender of the whole list.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
UGender getListGender(const UGender* genders, int32_t length, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
* @stable ICU 50
|
||||
*/
|
||||
virtual ~GenderInfo();
|
||||
|
||||
private:
|
||||
int32_t _style;
|
||||
|
||||
/**
|
||||
* Copy constructor. One object per locale invariant. Clients
|
||||
* must never copy GenderInfo objects.
|
||||
*/
|
||||
GenderInfo(const GenderInfo& other);
|
||||
|
||||
/**
|
||||
* Assignment operator. Not applicable to immutable objects.
|
||||
*/
|
||||
GenderInfo& operator=(const GenderInfo&);
|
||||
|
||||
GenderInfo();
|
||||
|
||||
static const GenderInfo* getNeutralInstance();
|
||||
|
||||
static const GenderInfo* getMixedNeutralInstance();
|
||||
|
||||
static const GenderInfo* getMaleTaintsInstance();
|
||||
|
||||
static const GenderInfo* loadInstance(const Locale& locale, UErrorCode& status);
|
||||
|
||||
friend class ::GenderInfoTest;
|
||||
friend void GenderInfo_initCache(UErrorCode &status);
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _GENDER
|
||||
//eof
|
||||
@@ -1,777 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 1997-2013, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************
|
||||
*
|
||||
* File GREGOCAL.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 04/22/97 aliu Overhauled header.
|
||||
* 07/28/98 stephen Sync with JDK 1.2
|
||||
* 09/04/98 stephen Re-sync with JDK 8/31 putback
|
||||
* 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
|
||||
* Fixed bug in roll()
|
||||
* 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
|
||||
* Added documentation of WEEK_OF_YEAR computation.
|
||||
* 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
|
||||
* {JDK bug 4210209 4209272}
|
||||
* 11/07/2003 srl Update, clean up documentation.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef GREGOCAL_H
|
||||
#define GREGOCAL_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/calendar.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Concrete class which provides the standard calendar.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Concrete class which provides the standard calendar used by most of the world.
|
||||
* <P>
|
||||
* The standard (Gregorian) calendar has 2 eras, BC and AD.
|
||||
* <P>
|
||||
* This implementation handles a single discontinuity, which corresponds by default to
|
||||
* the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
|
||||
* countries adopted the Gregorian calendar then, so this cutover date may be changed by
|
||||
* the caller.
|
||||
* <P>
|
||||
* Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
|
||||
* avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
|
||||
* if desired for dates that are prior to the Gregorian changeover and which fall
|
||||
* between January 1 and March 24.
|
||||
*
|
||||
* <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
|
||||
* 53. Week 1 for a year is the first week that contains at least
|
||||
* <code>getMinimalDaysInFirstWeek()</code> days from that year. It thus
|
||||
* depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
|
||||
* <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
|
||||
* Weeks between week 1 of one year and week 1 of the following year are
|
||||
* numbered sequentially from 2 to 52 or 53 (as needed).
|
||||
*
|
||||
* <p>For example, January 1, 1998 was a Thursday. If
|
||||
* <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
|
||||
* <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
|
||||
* reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
|
||||
* on December 29, 1997, and ends on January 4, 1998. If, however,
|
||||
* <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
|
||||
* starts on January 4, 1998, and ends on January 10, 1998; the first three days
|
||||
* of 1998 then are part of week 53 of 1997.
|
||||
*
|
||||
* <p>Example for using GregorianCalendar:
|
||||
* <pre>
|
||||
* \code
|
||||
* // get the supported ids for GMT-08:00 (Pacific Standard Time)
|
||||
* UErrorCode success = U_ZERO_ERROR;
|
||||
* const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
|
||||
* // if no ids were returned, something is wrong. get out.
|
||||
* if (ids == 0 || ids->count(success) == 0) {
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* // begin output
|
||||
* cout << "Current Time" << endl;
|
||||
*
|
||||
* // create a Pacific Standard Time time zone
|
||||
* SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));
|
||||
*
|
||||
* // set up rules for daylight savings time
|
||||
* pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
|
||||
* pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
|
||||
*
|
||||
* // create a GregorianCalendar with the Pacific Daylight time zone
|
||||
* // and the current date and time
|
||||
* Calendar* calendar = new GregorianCalendar( pdt, success );
|
||||
*
|
||||
* // print out a bunch of interesting things
|
||||
* cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
|
||||
* cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
|
||||
* cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
|
||||
* cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
|
||||
* cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
|
||||
* cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
|
||||
* cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
|
||||
* cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
|
||||
* cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
|
||||
* cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
|
||||
* cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
|
||||
* cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
|
||||
* cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
|
||||
* cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
|
||||
* cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
|
||||
* cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
|
||||
* cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
|
||||
* cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
|
||||
*
|
||||
* cout << "Current Time, with hour reset to 3" << endl;
|
||||
* calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
|
||||
* calendar->set(UCAL_HOUR, 3);
|
||||
* cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
|
||||
* cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
|
||||
* cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
|
||||
* cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
|
||||
* cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
|
||||
* cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
|
||||
* cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
|
||||
* cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
|
||||
* cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
|
||||
* cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
|
||||
* cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
|
||||
* cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
|
||||
* cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
|
||||
* cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
|
||||
* cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
|
||||
* cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
|
||||
* cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
|
||||
* cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
|
||||
*
|
||||
* if (U_FAILURE(success)) {
|
||||
* cout << "An error occured. success=" << u_errorName(success) << endl;
|
||||
* }
|
||||
*
|
||||
* delete ids;
|
||||
* delete calendar; // also deletes pdt
|
||||
* \endcode
|
||||
* </pre>
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_I18N_API GregorianCalendar: public Calendar {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Useful constants for GregorianCalendar and TimeZone.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum EEras {
|
||||
BC,
|
||||
AD
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a default GregorianCalendar using the current time in the default time
|
||||
* zone with the default locale.
|
||||
*
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar based on the current time in the given time zone
|
||||
* with the default locale. Clients are no longer responsible for deleting the given
|
||||
* time zone object after it's adopted.
|
||||
*
|
||||
* @param zoneToAdopt The given timezone.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar based on the current time in the given time zone
|
||||
* with the default locale.
|
||||
*
|
||||
* @param zone The given timezone.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(const TimeZone& zone, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar based on the current time in the default time zone
|
||||
* with the given locale.
|
||||
*
|
||||
* @param aLocale The given locale.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(const Locale& aLocale, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar based on the current time in the given time zone
|
||||
* with the given locale. Clients are no longer responsible for deleting the given
|
||||
* time zone object after it's adopted.
|
||||
*
|
||||
* @param zoneToAdopt The given timezone.
|
||||
* @param aLocale The given locale.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar based on the current time in the given time zone
|
||||
* with the given locale.
|
||||
*
|
||||
* @param zone The given timezone.
|
||||
* @param aLocale The given locale.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar with the given AD date set in the default time
|
||||
* zone with the default locale.
|
||||
*
|
||||
* @param year The value used to set the YEAR time field in the calendar.
|
||||
* @param month The value used to set the MONTH time field in the calendar. Month
|
||||
* value is 0-based. e.g., 0 for January.
|
||||
* @param date The value used to set the DATE time field in the calendar.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar with the given AD date and time set for the
|
||||
* default time zone with the default locale.
|
||||
*
|
||||
* @param year The value used to set the YEAR time field in the calendar.
|
||||
* @param month The value used to set the MONTH time field in the calendar. Month
|
||||
* value is 0-based. e.g., 0 for January.
|
||||
* @param date The value used to set the DATE time field in the calendar.
|
||||
* @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
|
||||
* @param minute The value used to set the MINUTE time field in the calendar.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Constructs a GregorianCalendar with the given AD date and time set for the
|
||||
* default time zone with the default locale.
|
||||
*
|
||||
* @param year The value used to set the YEAR time field in the calendar.
|
||||
* @param month The value used to set the MONTH time field in the calendar. Month
|
||||
* value is 0-based. e.g., 0 for January.
|
||||
* @param date The value used to set the DATE time field in the calendar.
|
||||
* @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
|
||||
* @param minute The value used to set the MINUTE time field in the calendar.
|
||||
* @param second The value used to set the SECOND time field in the calendar.
|
||||
* @param success Indicates the status of GregorianCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~GregorianCalendar();
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param source the object to be copied.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar(const GregorianCalendar& source);
|
||||
|
||||
/**
|
||||
* Default assignment operator
|
||||
* @param right the object to be copied.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
GregorianCalendar& operator=(const GregorianCalendar& right);
|
||||
|
||||
/**
|
||||
* Create and return a polymorphic copy of this calendar.
|
||||
* @return return a polymorphic copy of this calendar.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual Calendar* clone(void) const;
|
||||
|
||||
/**
|
||||
* Sets the GregorianCalendar change date. This is the point when the switch from
|
||||
* Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
|
||||
* 15, 1582. Previous to this time and date will be Julian dates.
|
||||
*
|
||||
* @param date The given Gregorian cutover date.
|
||||
* @param success Output param set to success/failure code on exit.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setGregorianChange(UDate date, UErrorCode& success);
|
||||
|
||||
/**
|
||||
* Gets the Gregorian Calendar change date. This is the point when the switch from
|
||||
* Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
|
||||
* 15, 1582. Previous to this time and date will be Julian dates.
|
||||
*
|
||||
* @return The Gregorian cutover time for this calendar.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UDate getGregorianChange(void) const;
|
||||
|
||||
/**
|
||||
* Return true if the given year is a leap year. Determination of whether a year is
|
||||
* a leap year is actually very complicated. We do something crude and mostly
|
||||
* correct here, but for a real determination you need a lot of contextual
|
||||
* information. For example, in Sweden, the change from Julian to Gregorian happened
|
||||
* in a complex way resulting in missed leap years and double leap years between
|
||||
* 1700 and 1753. Another example is that after the start of the Julian calendar in
|
||||
* 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
|
||||
* quirks, and pays attention only to the Julian onset date and the Gregorian
|
||||
* cutover (which can be changed).
|
||||
*
|
||||
* @param year The given year.
|
||||
* @return True if the given year is a leap year; false otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool isLeapYear(int32_t year) const;
|
||||
|
||||
/**
|
||||
* Returns TRUE if the given Calendar object is equivalent to this
|
||||
* one. Calendar override.
|
||||
*
|
||||
* @param other the Calendar to be compared with this Calendar
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual UBool isEquivalentTo(const Calendar& other) const;
|
||||
|
||||
/**
|
||||
* (Overrides Calendar) Rolls up or down by the given amount in the specified field.
|
||||
* For more information, see the documentation for Calendar::roll().
|
||||
*
|
||||
* @param field The time field.
|
||||
* @param amount Indicates amount to roll.
|
||||
* @param status Output param set to success/failure code on exit. If any value
|
||||
* previously set in the time field is invalid, this will be set to
|
||||
* an error status.
|
||||
* @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
|
||||
*/
|
||||
virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* (Overrides Calendar) Rolls up or down by the given amount in the specified field.
|
||||
* For more information, see the documentation for Calendar::roll().
|
||||
*
|
||||
* @param field The time field.
|
||||
* @param amount Indicates amount to roll.
|
||||
* @param status Output param set to success/failure code on exit. If any value
|
||||
* previously set in the time field is invalid, this will be set to
|
||||
* an error status.
|
||||
* @stable ICU 2.6.
|
||||
*/
|
||||
virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Return the minimum value that this field could have, given the current date.
|
||||
* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
|
||||
* @param field the time field.
|
||||
* @return the minimum value that this field could have, given the current date.
|
||||
* @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
|
||||
*/
|
||||
int32_t getActualMinimum(EDateFields field) const;
|
||||
|
||||
/**
|
||||
* Return the minimum value that this field could have, given the current date.
|
||||
* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
|
||||
* @param field the time field.
|
||||
* @param status
|
||||
* @return the minimum value that this field could have, given the current date.
|
||||
* @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
|
||||
*/
|
||||
int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Return the minimum value that this field could have, given the current date.
|
||||
* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
|
||||
* @param field the time field.
|
||||
* @param status error result.
|
||||
* @return the minimum value that this field could have, given the current date.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Return the maximum value that this field could have, given the current date.
|
||||
* For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
|
||||
* maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
|
||||
* for some years the actual maximum for MONTH is 12, and for others 13.
|
||||
* @param field the time field.
|
||||
* @return the maximum value that this field could have, given the current date.
|
||||
* @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
|
||||
*/
|
||||
int32_t getActualMaximum(EDateFields field) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Return the maximum value that this field could have, given the current date.
|
||||
* For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
|
||||
* maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
|
||||
* for some years the actual maximum for MONTH is 12, and for others 13.
|
||||
* @param field the time field.
|
||||
* @param status returns any errors that may result from this function call.
|
||||
* @return the maximum value that this field could have, given the current date.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* (Overrides Calendar) Return true if the current date for this Calendar is in
|
||||
* Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
|
||||
*
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @return True if the current date for this Calendar is in Daylight Savings Time,
|
||||
* false, otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool inDaylightTime(UErrorCode& status) const;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
|
||||
* override. This method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
|
||||
* this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a given class have the
|
||||
* same class ID. Objects of other classes have different class IDs.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to a return
|
||||
* value from getDynamicClassID(). For example:
|
||||
*
|
||||
* Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* Derived::getStaticClassID()) ...
|
||||
*
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Returns the calendar type name string for this Calendar object.
|
||||
* The returned string is the legacy ICU calendar attribute value,
|
||||
* for example, "gregorian" or "japanese".
|
||||
*
|
||||
* For more details see the Calendar::getType() documentation.
|
||||
*
|
||||
* @return legacy calendar type name string
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual const char * getType() const;
|
||||
|
||||
private:
|
||||
GregorianCalendar(); // default constructor not implemented
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Return the ERA. We need a special method for this because the
|
||||
* default ERA is AD, but a zero (unset) ERA is BC.
|
||||
* @return the ERA.
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t internalGetEra() const;
|
||||
|
||||
/**
|
||||
* Return the Julian day number of day before the first day of the
|
||||
* given month in the given extended year. Subclasses should override
|
||||
* this method to implement their calendar system.
|
||||
* @param eyear the extended year
|
||||
* @param month the zero-based month, or 0 if useMonth is false
|
||||
* @param useMonth if false, compute the day before the first day of
|
||||
* the given year, otherwise, compute the day before the first day of
|
||||
* the given month
|
||||
* @return the Julian day number of the day before the first
|
||||
* day of the given month and year
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
|
||||
UBool useMonth) const;
|
||||
|
||||
/**
|
||||
* Subclasses may override this. This method calls
|
||||
* handleGetMonthLength() to obtain the calendar-specific month
|
||||
* length.
|
||||
* @param bestField which field to use to calculate the date
|
||||
* @return julian day specified by calendar fields.
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
|
||||
|
||||
/**
|
||||
* Return the number of days in the given month of the given extended
|
||||
* year of this calendar system. Subclasses should override this
|
||||
* method if they can provide a more correct or more efficient
|
||||
* implementation than the default implementation in Calendar.
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
|
||||
|
||||
/**
|
||||
* Return the number of days in the given extended year of this
|
||||
* calendar system. Subclasses should override this method if they can
|
||||
* provide a more correct or more efficient implementation than the
|
||||
* default implementation in Calendar.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t handleGetYearLength(int32_t eyear) const;
|
||||
|
||||
/**
|
||||
* return the length of the given month.
|
||||
* @param month the given month.
|
||||
* @return the length of the given month.
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t monthLength(int32_t month) const;
|
||||
|
||||
/**
|
||||
* return the length of the month according to the given year.
|
||||
* @param month the given month.
|
||||
* @param year the given year.
|
||||
* @return the length of the month
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t monthLength(int32_t month, int32_t year) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* return the length of the given year.
|
||||
* @param year the given year.
|
||||
* @return the length of the given year.
|
||||
* @internal
|
||||
*/
|
||||
int32_t yearLength(int32_t year) const;
|
||||
|
||||
/**
|
||||
* return the length of the year field.
|
||||
* @return the length of the year field
|
||||
* @internal
|
||||
*/
|
||||
int32_t yearLength(void) const;
|
||||
|
||||
/**
|
||||
* After adjustments such as add(MONTH), add(YEAR), we don't want the
|
||||
* month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar
|
||||
* 3, we want it to go to Feb 28. Adjustments which might run into this
|
||||
* problem call this method to retain the proper month.
|
||||
* @internal
|
||||
*/
|
||||
void pinDayOfMonth(void);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Return the day number with respect to the epoch. January 1, 1970 (Gregorian)
|
||||
* is day zero.
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @return the day number with respect to the epoch.
|
||||
* @internal
|
||||
*/
|
||||
virtual UDate getEpochDay(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Subclass API for defining limits of different types.
|
||||
* Subclasses must implement this method to return limits for the
|
||||
* following fields:
|
||||
*
|
||||
* <pre>UCAL_ERA
|
||||
* UCAL_YEAR
|
||||
* UCAL_MONTH
|
||||
* UCAL_WEEK_OF_YEAR
|
||||
* UCAL_WEEK_OF_MONTH
|
||||
* UCAL_DATE (DAY_OF_MONTH on Java)
|
||||
* UCAL_DAY_OF_YEAR
|
||||
* UCAL_DAY_OF_WEEK_IN_MONTH
|
||||
* UCAL_YEAR_WOY
|
||||
* UCAL_EXTENDED_YEAR</pre>
|
||||
*
|
||||
* @param field one of the above field numbers
|
||||
* @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
|
||||
* <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
|
||||
|
||||
/**
|
||||
* Return the extended year defined by the current fields. This will
|
||||
* use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
|
||||
* as UCAL_ERA) specific to the calendar system, depending on which set of
|
||||
* fields is newer.
|
||||
* @return the extended year
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetExtendedYear();
|
||||
|
||||
/**
|
||||
* Subclasses may override this to convert from week fields
|
||||
* (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
|
||||
* where YEAR, EXTENDED_YEAR are not set.
|
||||
* The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
|
||||
* @return the extended year, UCAL_EXTENDED_YEAR
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses may override this method to compute several fields
|
||||
* specific to each calendar system. These are:
|
||||
*
|
||||
* <ul><li>ERA
|
||||
* <li>YEAR
|
||||
* <li>MONTH
|
||||
* <li>DAY_OF_MONTH
|
||||
* <li>DAY_OF_YEAR
|
||||
* <li>EXTENDED_YEAR</ul>
|
||||
*
|
||||
* <p>The GregorianCalendar implementation implements
|
||||
* a calendar with the specified Julian/Gregorian cutover date.
|
||||
* @internal
|
||||
*/
|
||||
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Compute the julian day number of the given year.
|
||||
* @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar
|
||||
* @param year the given year.
|
||||
* @param isLeap true if the year is a leap year.
|
||||
* @return
|
||||
*/
|
||||
static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
|
||||
UBool& isLeap);
|
||||
|
||||
/**
|
||||
* Validates the values of the set time fields. True if they're all valid.
|
||||
* @return True if the set time fields are all valid.
|
||||
*/
|
||||
UBool validateFields(void) const;
|
||||
|
||||
/**
|
||||
* Validates the value of the given time field. True if it's valid.
|
||||
*/
|
||||
UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
|
||||
|
||||
/**
|
||||
* Return the pseudo-time-stamp for two fields, given their
|
||||
* individual pseudo-time-stamps. If either of the fields
|
||||
* is unset, then the aggregate is unset. Otherwise, the
|
||||
* aggregate is the later of the two stamps.
|
||||
* @param stamp_a One given field.
|
||||
* @param stamp_b Another given field.
|
||||
* @return the pseudo-time-stamp for two fields
|
||||
*/
|
||||
int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
|
||||
|
||||
/**
|
||||
* The point at which the Gregorian calendar rules are used, measured in
|
||||
* milliseconds from the standard epoch. Default is October 15, 1582
|
||||
* (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
|
||||
* by October 15, 1582 (Gregorian). This corresponds to Julian day number
|
||||
* 2299161. This is measured from the standard epoch, not in Julian Days.
|
||||
*/
|
||||
UDate fGregorianCutover;
|
||||
|
||||
/**
|
||||
* Julian day number of the Gregorian cutover
|
||||
*/
|
||||
int32_t fCutoverJulianDay;
|
||||
|
||||
/**
|
||||
* Midnight, local time (using this Calendar's TimeZone) at or before the
|
||||
* gregorianCutover. This is a pure date value with no time of day or
|
||||
* timezone component.
|
||||
*/
|
||||
UDate fNormalizedGregorianCutover;// = gregorianCutover;
|
||||
|
||||
/**
|
||||
* The year of the gregorianCutover, with 0 representing
|
||||
* 1 BC, -1 representing 2 BC, etc.
|
||||
*/
|
||||
int32_t fGregorianCutoverYear;// = 1582;
|
||||
|
||||
/**
|
||||
* The year of the gregorianCutover, with 0 representing
|
||||
* 1 BC, -1 representing 2 BC, etc.
|
||||
*/
|
||||
int32_t fGregorianCutoverJulianDay;// = 2299161;
|
||||
|
||||
/**
|
||||
* Converts time as milliseconds to Julian date. The Julian date used here is not a
|
||||
* true Julian date, since it is measured from midnight, not noon.
|
||||
*
|
||||
* @param millis The given milliseconds.
|
||||
* @return The Julian date number.
|
||||
*/
|
||||
static double millisToJulianDay(UDate millis);
|
||||
|
||||
/**
|
||||
* Converts Julian date to time as milliseconds. The Julian date used here is not a
|
||||
* true Julian date, since it is measured from midnight, not noon.
|
||||
*
|
||||
* @param julian The given Julian date number.
|
||||
* @return Time as milliseconds.
|
||||
*/
|
||||
static UDate julianDayToMillis(double julian);
|
||||
|
||||
/**
|
||||
* Used by handleComputeJulianDay() and handleComputeMonthStart().
|
||||
* Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
|
||||
*/
|
||||
UBool fIsGregorian;
|
||||
|
||||
/**
|
||||
* Used by handleComputeJulianDay() and handleComputeMonthStart().
|
||||
* Temporary field indicating that the sense of the gregorian cutover should be inverted
|
||||
* to handle certain calculations on and around the cutover date.
|
||||
*/
|
||||
UBool fInvertGregorian;
|
||||
|
||||
|
||||
public: // internal implementation
|
||||
|
||||
/**
|
||||
* @return TRUE if this calendar has the notion of a default century
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool haveDefaultCentury() const;
|
||||
|
||||
/**
|
||||
* @return the start of the default century
|
||||
* @internal
|
||||
*/
|
||||
virtual UDate defaultCenturyStart() const;
|
||||
|
||||
/**
|
||||
* @return the beginning year of the default century
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t defaultCenturyStartYear() const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _GREGOCAL
|
||||
//eof
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: access to ICU Data Version number
|
||||
*/
|
||||
|
||||
#ifndef __ICU_DATA_VER_H__
|
||||
#define __ICU_DATA_VER_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* @stable ICU 49
|
||||
*/
|
||||
#define U_ICU_VERSION_BUNDLE "icuver"
|
||||
|
||||
/**
|
||||
* @stable ICU 49
|
||||
*/
|
||||
#define U_ICU_DATA_KEY "DataVersion"
|
||||
|
||||
/**
|
||||
* Retrieves the data version from icuver and stores it in dataVersionFillin.
|
||||
*
|
||||
* @param dataVersionFillin icuver data version information to be filled in if not-null
|
||||
* @param status stores the error code from the calls to resource bundle
|
||||
*
|
||||
* @stable ICU 49
|
||||
*/
|
||||
U_STABLE void U_EXPORT2 u_getDataVersion(UVersionInfo dataVersionFillin, UErrorCode *status);
|
||||
|
||||
#endif
|
||||
@@ -1,371 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* FILE NAME : icuplug.h
|
||||
*
|
||||
* Date Name Description
|
||||
* 10/29/2009 sl New.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: ICU Plugin API
|
||||
*
|
||||
* <h2>C API: ICU Plugin API</h2>
|
||||
*
|
||||
* <p>C API allowing run-time loadable modules that extend or modify ICU functionality.</p>
|
||||
*
|
||||
* <h3>Loading and Configuration</h3>
|
||||
*
|
||||
* <p>At ICU startup time, the environment variable "ICU_PLUGINS" will be
|
||||
* queried for a directory name. If it is not set, the preprocessor symbol
|
||||
* "DEFAULT_ICU_PLUGINS" will be checked for a default value.</p>
|
||||
*
|
||||
* <p>Within the above-named directory, the file "icuplugins##.txt" will be
|
||||
* opened, if present, where ## is the major+minor number of the currently
|
||||
* running ICU (such as, 44 for ICU 4.4, thus icuplugins44.txt)</p>
|
||||
*
|
||||
* <p>The configuration file has this format:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>Hash (#) begins a comment line</li>
|
||||
*
|
||||
* <li>Non-comment lines have two or three components:
|
||||
* LIBRARYNAME ENTRYPOINT [ CONFIGURATION .. ]</li>
|
||||
*
|
||||
* <li>Tabs or spaces separate the three items.</li>
|
||||
*
|
||||
* <li>LIBRARYNAME is the name of a shared library, either a short name if
|
||||
* it is on the loader path, or a full pathname.</li>
|
||||
*
|
||||
* <li>ENTRYPOINT is the short (undecorated) symbol name of the plugin's
|
||||
* entrypoint, as above.</li>
|
||||
*
|
||||
* <li>CONFIGURATION is the entire rest of the line . It's passed as-is to
|
||||
* the plugin.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>An example configuration file is, in its entirety:</p>
|
||||
*
|
||||
* \code
|
||||
* # this is icuplugins44.txt
|
||||
* testplug.dll myPlugin hello=world
|
||||
* \endcode
|
||||
* <p>Plugins are categorized as "high" or "low" level. Low level are those
|
||||
* which must be run BEFORE high level plugins, and before any operations
|
||||
* which cause ICU to be 'initialized'. If a plugin is low level but
|
||||
* causes ICU to allocate memory or become initialized, that plugin is said
|
||||
* to cause a 'level change'. </p>
|
||||
*
|
||||
* <p>At load time, ICU first queries all plugins to determine their level,
|
||||
* then loads all 'low' plugins first, and then loads all 'high' plugins.
|
||||
* Plugins are otherwise loaded in the order listed in the configuration file.</p>
|
||||
*
|
||||
* <h3>Implementing a Plugin</h3>
|
||||
* \code
|
||||
* U_CAPI UPlugTokenReturn U_EXPORT2
|
||||
* myPlugin (UPlugData *plug, UPlugReason reason, UErrorCode *status) {
|
||||
* if(reason==UPLUG_REASON_QUERY) {
|
||||
* uplug_setPlugName(plug, "Simple Plugin");
|
||||
* uplug_setPlugLevel(plug, UPLUG_LEVEL_HIGH);
|
||||
* } else if(reason==UPLUG_REASON_LOAD) {
|
||||
* ... Set up some ICU things here....
|
||||
* } else if(reason==UPLUG_REASON_UNLOAD) {
|
||||
* ... unload, clean up ...
|
||||
* }
|
||||
* return UPLUG_TOKEN;
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* <p>The UPlugData* is an opaque pointer to the plugin-specific data, and is
|
||||
* used in all other API calls.</p>
|
||||
*
|
||||
* <p>The API contract is:</p>
|
||||
* <ol><li>The plugin MUST always return UPLUG_TOKEN as a return value- to
|
||||
* indicate that it is a valid plugin.</li>
|
||||
*
|
||||
* <li>When the 'reason' parameter is set to UPLUG_REASON_QUERY, the
|
||||
* plugin MUST call uplug_setPlugLevel() to indicate whether it is a high
|
||||
* level or low level plugin.</li>
|
||||
*
|
||||
* <li>When the 'reason' parameter is UPLUG_REASON_QUERY, the plugin
|
||||
* SHOULD call uplug_setPlugName to indicate a human readable plugin name.</li></ol>
|
||||
*
|
||||
*
|
||||
* \internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ICUPLUG_H
|
||||
#define ICUPLUG_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
|
||||
/* === Basic types === */
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* @{
|
||||
* Opaque structure passed to/from a plugin.
|
||||
* use the APIs to access it.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
|
||||
struct UPlugData;
|
||||
typedef struct UPlugData UPlugData;
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Random Token to identify a valid ICU plugin. Plugins must return this
|
||||
* from the entrypoint.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
#define UPLUG_TOKEN 0x54762486
|
||||
|
||||
/**
|
||||
* Max width of names, symbols, and configuration strings
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
#define UPLUG_NAME_MAX 100
|
||||
|
||||
|
||||
/**
|
||||
* Return value from a plugin entrypoint.
|
||||
* Must always be set to UPLUG_TOKEN
|
||||
* @see UPLUG_TOKEN
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
typedef uint32_t UPlugTokenReturn;
|
||||
|
||||
/**
|
||||
* Reason code for the entrypoint's call
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
typedef enum {
|
||||
UPLUG_REASON_QUERY = 0, /**< The plugin is being queried for info. **/
|
||||
UPLUG_REASON_LOAD = 1, /**< The plugin is being loaded. **/
|
||||
UPLUG_REASON_UNLOAD = 2, /**< The plugin is being unloaded. **/
|
||||
UPLUG_REASON_COUNT /**< count of known reasons **/
|
||||
} UPlugReason;
|
||||
|
||||
|
||||
/**
|
||||
* Level of plugin loading
|
||||
* INITIAL: UNKNOWN
|
||||
* QUERY: INVALID -> { LOW | HIGH }
|
||||
* ERR -> INVALID
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
typedef enum {
|
||||
UPLUG_LEVEL_INVALID = 0, /**< The plugin is invalid, hasn't called uplug_setLevel, or can't load. **/
|
||||
UPLUG_LEVEL_UNKNOWN = 1, /**< The plugin is waiting to be installed. **/
|
||||
UPLUG_LEVEL_LOW = 2, /**< The plugin must be called before u_init completes **/
|
||||
UPLUG_LEVEL_HIGH = 3, /**< The plugin can run at any time. **/
|
||||
UPLUG_LEVEL_COUNT /**< count of known reasons **/
|
||||
} UPlugLevel;
|
||||
|
||||
/**
|
||||
* Entrypoint for an ICU plugin.
|
||||
* @param plug the UPlugData handle.
|
||||
* @param status the plugin's extended status code.
|
||||
* @return A valid plugin must return UPLUG_TOKEN
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
typedef UPlugTokenReturn (U_EXPORT2 UPlugEntrypoint) (
|
||||
UPlugData *plug,
|
||||
UPlugReason reason,
|
||||
UErrorCode *status);
|
||||
|
||||
/* === Needed for Implementing === */
|
||||
|
||||
/**
|
||||
* Request that this plugin not be unloaded at cleanup time.
|
||||
* This is appropriate for plugins which cannot be cleaned up.
|
||||
* @see u_cleanup()
|
||||
* @param plug plugin
|
||||
* @param dontUnload set true if this plugin can't be unloaded
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload);
|
||||
|
||||
/**
|
||||
* Set the level of this plugin.
|
||||
* @param plug plugin data handle
|
||||
* @param level the level of this plugin
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
uplug_setPlugLevel(UPlugData *plug, UPlugLevel level);
|
||||
|
||||
/**
|
||||
* Get the level of this plugin.
|
||||
* @param plug plugin data handle
|
||||
* @return the level of this plugin
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UPlugLevel U_EXPORT2
|
||||
uplug_getPlugLevel(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Get the lowest level of plug which can currently load.
|
||||
* For example, if UPLUG_LEVEL_LOW is returned, then low level plugins may load
|
||||
* if UPLUG_LEVEL_HIGH is returned, then only high level plugins may load.
|
||||
* @return the lowest level of plug which can currently load
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UPlugLevel U_EXPORT2
|
||||
uplug_getCurrentLevel(void);
|
||||
|
||||
|
||||
/**
|
||||
* Get plug load status
|
||||
* @return The error code of this plugin's load attempt.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UErrorCode U_EXPORT2
|
||||
uplug_getPlugLoadStatus(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Set the human-readable name of this plugin.
|
||||
* @param plug plugin data handle
|
||||
* @param name the name of this plugin. The first UPLUG_NAME_MAX characters willi be copied into a new buffer.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
uplug_setPlugName(UPlugData *plug, const char *name);
|
||||
|
||||
/**
|
||||
* Get the human-readable name of this plugin.
|
||||
* @param plug plugin data handle
|
||||
* @return the name of this plugin
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL const char * U_EXPORT2
|
||||
uplug_getPlugName(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Return the symbol name for this plugin, if known.
|
||||
* @param plug plugin data handle
|
||||
* @return the symbol name, or NULL
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL const char * U_EXPORT2
|
||||
uplug_getSymbolName(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Return the library name for this plugin, if known.
|
||||
* @param plug plugin data handle
|
||||
* @param status error code
|
||||
* @return the library name, or NULL
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL const char * U_EXPORT2
|
||||
uplug_getLibraryName(UPlugData *plug, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Return the library used for this plugin, if known.
|
||||
* Plugins could use this to load data out of their
|
||||
* @param plug plugin data handle
|
||||
* @return the library, or NULL
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void * U_EXPORT2
|
||||
uplug_getLibrary(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Return the plugin-specific context data.
|
||||
* @param plug plugin data handle
|
||||
* @return the context, or NULL if not set
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void * U_EXPORT2
|
||||
uplug_getContext(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Set the plugin-specific context data.
|
||||
* @param plug plugin data handle
|
||||
* @param context new context to set
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
uplug_setContext(UPlugData *plug, void *context);
|
||||
|
||||
|
||||
/**
|
||||
* Get the configuration string, if available.
|
||||
* The string is in the platform default codepage.
|
||||
* @param plug plugin data handle
|
||||
* @return configuration string, or else null.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL const char * U_EXPORT2
|
||||
uplug_getConfiguration(UPlugData *plug);
|
||||
|
||||
/**
|
||||
* Return all currently installed plugins, from newest to oldest
|
||||
* Usage Example:
|
||||
* \code
|
||||
* UPlugData *plug = NULL;
|
||||
* while(plug=uplug_nextPlug(plug)) {
|
||||
* ... do something with 'plug' ...
|
||||
* }
|
||||
* \endcode
|
||||
* Not thread safe- do not call while plugs are added or removed.
|
||||
* @param prior pass in 'NULL' to get the first (most recent) plug,
|
||||
* otherwise pass the value returned on a prior call to uplug_nextPlug
|
||||
* @return the next oldest plugin, or NULL if no more.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UPlugData* U_EXPORT2
|
||||
uplug_nextPlug(UPlugData *prior);
|
||||
|
||||
/**
|
||||
* Inject a plugin as if it were loaded from a library.
|
||||
* This is useful for testing plugins.
|
||||
* Note that it will have a 'NULL' library pointer associated
|
||||
* with it, and therefore no llibrary will be closed at cleanup time.
|
||||
* Low level plugins may not be able to load, as ordering can't be enforced.
|
||||
* @param entrypoint entrypoint to install
|
||||
* @param config user specified configuration string, if available, or NULL.
|
||||
* @param status error result
|
||||
* @return the new UPlugData associated with this plugin, or NULL if error.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UPlugData* U_EXPORT2
|
||||
uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UErrorCode *status);
|
||||
|
||||
|
||||
/**
|
||||
* Inject a plugin from a library, as if the information came from a config file.
|
||||
* Low level plugins may not be able to load, and ordering can't be enforced.
|
||||
* @param libName DLL name to load
|
||||
* @param sym symbol of plugin (UPlugEntrypoint function)
|
||||
* @param config configuration string, or NULL
|
||||
* @param status error result
|
||||
* @return the new UPlugData associated with this plugin, or NULL if error.
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL UPlugData* U_EXPORT2
|
||||
uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *config, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Remove a plugin.
|
||||
* Will request the plugin to be unloaded, and close the library if needed
|
||||
* @param plug plugin handle to close
|
||||
* @param status error result
|
||||
* @internal ICU 4.4 Technology Preview
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2
|
||||
uplug_removePlug(UPlugData *plug, UErrorCode *status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#endif
|
||||
@@ -1,323 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: idna.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010mar05
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __IDNA_H__
|
||||
#define __IDNA_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Internationalizing Domain Names in Applications (IDNA)
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_IDNA
|
||||
|
||||
#include "unicode/bytestream.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uidna.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class IDNAInfo;
|
||||
|
||||
/**
|
||||
* Abstract base class for IDNA processing.
|
||||
* See http://www.unicode.org/reports/tr46/
|
||||
* and http://www.ietf.org/rfc/rfc3490.txt
|
||||
*
|
||||
* The IDNA class is not intended for public subclassing.
|
||||
*
|
||||
* This C++ API currently only implements UTS #46.
|
||||
* The uidna.h C API implements both UTS #46 (functions using UIDNA service object)
|
||||
* and IDNA2003 (functions that do not use a service object).
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
class U_COMMON_API IDNA : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
~IDNA();
|
||||
|
||||
/**
|
||||
* Returns an IDNA instance which implements UTS #46.
|
||||
* Returns an unmodifiable instance, owned by the caller.
|
||||
* Cache it for multiple operations, and delete it when done.
|
||||
* The instance is thread-safe, that is, it can be used concurrently.
|
||||
*
|
||||
* UTS #46 defines Unicode IDNA Compatibility Processing,
|
||||
* updated to the latest version of Unicode and compatible with both
|
||||
* IDNA2003 and IDNA2008.
|
||||
*
|
||||
* The worker functions use transitional processing, including deviation mappings,
|
||||
* unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE
|
||||
* is used in which case the deviation characters are passed through without change.
|
||||
*
|
||||
* Disallowed characters are mapped to U+FFFD.
|
||||
*
|
||||
* For available options see the uidna.h header.
|
||||
* Operations with the UTS #46 instance do not support the
|
||||
* UIDNA_ALLOW_UNASSIGNED option.
|
||||
*
|
||||
* By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped).
|
||||
* When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than
|
||||
* letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD.
|
||||
*
|
||||
* @param options Bit set to modify the processing and error checking.
|
||||
* See option bit set values in uidna.h.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the UTS #46 IDNA instance, if successful
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
static IDNA *
|
||||
createUTS46Instance(uint32_t options, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE and
|
||||
* the result might not be an ASCII string.
|
||||
* The label might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
labelToASCII(const UnicodeString &label, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE.
|
||||
* The label might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
labelToUnicode(const UnicodeString &label, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE and
|
||||
* the result might not be an ASCII string.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
nameToASCII(const UnicodeString &name, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
nameToUnicode(const UnicodeString &name, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
// UTF-8 versions of the processing methods ---------------------------- ***
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of labelToASCII(), same behavior.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
labelToASCII_UTF8(const StringPiece &label, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* UTF-8 version of labelToUnicode(), same behavior.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
labelToUnicodeUTF8(const StringPiece &label, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of nameToASCII(), same behavior.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
nameToASCII_UTF8(const StringPiece &name, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* UTF-8 version of nameToUnicode(), same behavior.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
nameToUnicodeUTF8(const StringPiece &name, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
};
|
||||
|
||||
class UTS46;
|
||||
|
||||
/**
|
||||
* Output container for IDNA processing errors.
|
||||
* The IDNAInfo class is not suitable for subclassing.
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
class U_COMMON_API IDNAInfo : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructor for stack allocation.
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE), isBiDi(FALSE), isOkBiDi(TRUE) {}
|
||||
/**
|
||||
* Were there IDNA processing errors?
|
||||
* @return TRUE if there were processing errors
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
UBool hasErrors() const { return errors!=0; }
|
||||
/**
|
||||
* Returns a bit set indicating IDNA processing errors.
|
||||
* See UIDNA_ERROR_... constants in uidna.h.
|
||||
* @return bit set of processing errors
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
uint32_t getErrors() const { return errors; }
|
||||
/**
|
||||
* Returns TRUE if transitional and nontransitional processing produce different results.
|
||||
* This is the case when the input label or domain name contains
|
||||
* one or more deviation characters outside a Punycode label (see UTS #46).
|
||||
* <ul>
|
||||
* <li>With nontransitional processing, such characters are
|
||||
* copied to the destination string.
|
||||
* <li>With transitional processing, such characters are
|
||||
* mapped (sharp s/sigma) or removed (joiner/nonjoiner).
|
||||
* </ul>
|
||||
* @return TRUE if transitional and nontransitional processing produce different results
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
UBool isTransitionalDifferent() const { return isTransDiff; }
|
||||
|
||||
private:
|
||||
friend class UTS46;
|
||||
|
||||
IDNAInfo(const IDNAInfo &other); // no copying
|
||||
IDNAInfo &operator=(const IDNAInfo &other); // no copying
|
||||
|
||||
void reset() {
|
||||
errors=labelErrors=0;
|
||||
isTransDiff=FALSE;
|
||||
isBiDi=FALSE;
|
||||
isOkBiDi=TRUE;
|
||||
}
|
||||
|
||||
uint32_t errors, labelErrors;
|
||||
UBool isTransDiff;
|
||||
UBool isBiDi;
|
||||
UBool isOkBiDi;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // UCONFIG_NO_IDNA
|
||||
#endif // __IDNA_H__
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: listformatter.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 20120426
|
||||
* created by: Umesh P. Nair
|
||||
*/
|
||||
|
||||
#ifndef __LISTFORMATTER_H__
|
||||
#define __LISTFORMATTER_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/** @internal */
|
||||
class Hashtable;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/** @internal */
|
||||
struct ListFormatData : public UMemory {
|
||||
UnicodeString twoPattern;
|
||||
UnicodeString startPattern;
|
||||
UnicodeString middlePattern;
|
||||
UnicodeString endPattern;
|
||||
|
||||
ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
|
||||
twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
|
||||
};
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: API for formatting a list.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* An immutable class for formatting a list, using data from CLDR (or supplied
|
||||
* separately).
|
||||
*
|
||||
* Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
|
||||
* as "Alice, Bob, Charlie and Delta" in English.
|
||||
*
|
||||
* The ListFormatter class is not intended for public subclassing.
|
||||
* @draft ICU 50
|
||||
*/
|
||||
class U_COMMON_API ListFormatter : public UObject{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
ListFormatter(const ListFormatter&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
ListFormatter& operator=(const ListFormatter& other);
|
||||
|
||||
/**
|
||||
* Creates a ListFormatter appropriate for the default locale.
|
||||
*
|
||||
* @param errorCode ICU error code, set if no data available for default locale.
|
||||
* @return Pointer to a ListFormatter object for the default locale,
|
||||
* created from internal data derived from CLDR data.
|
||||
* @draft ICU 50
|
||||
*/
|
||||
static ListFormatter* createInstance(UErrorCode& errorCode);
|
||||
|
||||
/**
|
||||
* Creates a ListFormatter appropriate for a locale.
|
||||
*
|
||||
* @param locale The locale.
|
||||
* @param errorCode ICU error code, set if no data available for the given locale.
|
||||
* @return A ListFormatter object created from internal data derived from
|
||||
* CLDR data.
|
||||
* @draft ICU 50
|
||||
*/
|
||||
static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Creates a ListFormatter appropriate for a locale and style.
|
||||
*
|
||||
* @param locale The locale.
|
||||
* @param style the style, either "standard", "duration", or "duration-short"
|
||||
* @param errorCode ICU error code, set if no data available for the given locale.
|
||||
* @return A ListFormatter object created from internal data derived from
|
||||
* CLDR data.
|
||||
* @internal
|
||||
*/
|
||||
static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
* @draft ICU 50
|
||||
*/
|
||||
virtual ~ListFormatter();
|
||||
|
||||
|
||||
/**
|
||||
* Formats a list of strings.
|
||||
*
|
||||
* @param items An array of strings to be combined and formatted.
|
||||
* @param n_items Length of the array items.
|
||||
* @param appendTo The string to which the result should be appended to.
|
||||
* @param errorCode ICU error code, set if there is an error.
|
||||
* @return Formatted string combining the elements of items, appended to appendTo.
|
||||
* @draft ICU 50
|
||||
*/
|
||||
UnicodeString& format(const UnicodeString items[], int32_t n_items,
|
||||
UnicodeString& appendTo, UErrorCode& errorCode) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* @internal constructor made public for testing.
|
||||
*/
|
||||
ListFormatter(const ListFormatData* listFormatterData);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
static void initializeHash(UErrorCode& errorCode);
|
||||
static const ListFormatData* getListFormatData(const Locale& locale, const char *style, UErrorCode& errorCode);
|
||||
|
||||
ListFormatter();
|
||||
void addNewString(const UnicodeString& pattern, UnicodeString& originalString,
|
||||
const UnicodeString& newString, UErrorCode& errorCode) const;
|
||||
|
||||
const ListFormatData* data;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
#endif
|
||||
@@ -1,304 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: localpointer.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2009nov13
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __LOCALPOINTER_H__
|
||||
#define __LOCALPOINTER_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: "Smart pointers" for use with and in ICU4C C++ code.
|
||||
*
|
||||
* These classes are inspired by
|
||||
* - std::auto_ptr
|
||||
* - boost::scoped_ptr & boost::scoped_array
|
||||
* - Taligent Safe Pointers (TOnlyPointerTo)
|
||||
*
|
||||
* but none of those provide for all of the goals for ICU smart pointers:
|
||||
* - Smart pointer owns the object and releases it when it goes out of scope.
|
||||
* - No transfer of ownership via copy/assignment to reduce misuse. Simpler & more robust.
|
||||
* - ICU-compatible: No exceptions.
|
||||
* - Need to be able to orphan/release the pointer and its ownership.
|
||||
* - Need variants for normal C++ object pointers, C++ arrays, and ICU C service objects.
|
||||
*
|
||||
* For details see http://site.icu-project.org/design/cpp/scoped_ptr
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if U_SHOW_CPLUSPLUS_API
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* "Smart pointer" base class; do not use directly: use LocalPointer etc.
|
||||
*
|
||||
* Base class for smart pointer classes that do not throw exceptions.
|
||||
*
|
||||
* Do not use this base class directly, since it does not delete its pointer.
|
||||
* A subclass must implement methods that delete the pointer:
|
||||
* Destructor and adoptInstead().
|
||||
*
|
||||
* There is no operator T *() provided because the programmer must decide
|
||||
* whether to use getAlias() (without transfer of ownership) or orpan()
|
||||
* (with transfer of ownership and NULLing of the pointer).
|
||||
*
|
||||
* @see LocalPointer
|
||||
* @see LocalArray
|
||||
* @see U_DEFINE_LOCAL_OPEN_POINTER
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalPointerBase {
|
||||
public:
|
||||
/**
|
||||
* Constructor takes ownership.
|
||||
* @param p simple pointer to an object that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
explicit LocalPointerBase(T *p=NULL) : ptr(p) {}
|
||||
/**
|
||||
* Destructor deletes the object it owns.
|
||||
* Subclass must override: Base class does nothing.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~LocalPointerBase() { /* delete ptr; */ }
|
||||
/**
|
||||
* NULL check.
|
||||
* @return TRUE if ==NULL
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UBool isNull() const { return ptr==NULL; }
|
||||
/**
|
||||
* NULL check.
|
||||
* @return TRUE if !=NULL
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UBool isValid() const { return ptr!=NULL; }
|
||||
/**
|
||||
* Comparison with a simple pointer, so that existing code
|
||||
* with ==NULL need not be changed.
|
||||
* @param other simple pointer for comparison
|
||||
* @return true if this pointer value equals other
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
bool operator==(const T *other) const { return ptr==other; }
|
||||
/**
|
||||
* Comparison with a simple pointer, so that existing code
|
||||
* with !=NULL need not be changed.
|
||||
* @param other simple pointer for comparison
|
||||
* @return true if this pointer value differs from other
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
bool operator!=(const T *other) const { return ptr!=other; }
|
||||
/**
|
||||
* Access without ownership change.
|
||||
* @return the pointer value
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
T *getAlias() const { return ptr; }
|
||||
/**
|
||||
* Access without ownership change.
|
||||
* @return the pointer value as a reference
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
T &operator*() const { return *ptr; }
|
||||
/**
|
||||
* Access without ownership change.
|
||||
* @return the pointer value
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
T *operator->() const { return ptr; }
|
||||
/**
|
||||
* Gives up ownership; the internal pointer becomes NULL.
|
||||
* @return the pointer value;
|
||||
* caller becomes responsible for deleting the object
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
T *orphan() {
|
||||
T *p=ptr;
|
||||
ptr=NULL;
|
||||
return p;
|
||||
}
|
||||
/**
|
||||
* Deletes the object it owns,
|
||||
* and adopts (takes ownership of) the one passed in.
|
||||
* Subclass must override: Base class does not delete the object.
|
||||
* @param p simple pointer to an object that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
void adoptInstead(T *p) {
|
||||
// delete ptr;
|
||||
ptr=p;
|
||||
}
|
||||
protected:
|
||||
/**
|
||||
* Actual pointer.
|
||||
* @internal
|
||||
*/
|
||||
T *ptr;
|
||||
private:
|
||||
// No comparison operators with other LocalPointerBases.
|
||||
bool operator==(const LocalPointerBase &other);
|
||||
bool operator!=(const LocalPointerBase &other);
|
||||
// No ownership transfer: No copy constructor, no assignment operator.
|
||||
LocalPointerBase(const LocalPointerBase &other);
|
||||
void operator=(const LocalPointerBase &other);
|
||||
// No heap allocation. Use only on the stack.
|
||||
static void * U_EXPORT2 operator new(size_t size);
|
||||
static void * U_EXPORT2 operator new[](size_t size);
|
||||
#if U_HAVE_PLACEMENT_NEW
|
||||
static void * U_EXPORT2 operator new(size_t, void *ptr);
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* "Smart pointer" class, deletes objects via the standard C++ delete operator.
|
||||
* For most methods see the LocalPointerBase base class.
|
||||
*
|
||||
* Usage example:
|
||||
* \code
|
||||
* LocalPointer<UnicodeString> s(new UnicodeString((UChar32)0x50005));
|
||||
* int32_t length=s->length(); // 2
|
||||
* UChar lead=s->charAt(0); // 0xd900
|
||||
* if(some condition) { return; } // no need to explicitly delete the pointer
|
||||
* s.adoptInstead(new UnicodeString((UChar)0xfffc));
|
||||
* length=s->length(); // 1
|
||||
* // no need to explicitly delete the pointer
|
||||
* \endcode
|
||||
*
|
||||
* @see LocalPointerBase
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalPointer : public LocalPointerBase<T> {
|
||||
public:
|
||||
/**
|
||||
* Constructor takes ownership.
|
||||
* @param p simple pointer to an object that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
explicit LocalPointer(T *p=NULL) : LocalPointerBase<T>(p) {}
|
||||
/**
|
||||
* Destructor deletes the object it owns.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~LocalPointer() {
|
||||
delete LocalPointerBase<T>::ptr;
|
||||
}
|
||||
/**
|
||||
* Deletes the object it owns,
|
||||
* and adopts (takes ownership of) the one passed in.
|
||||
* @param p simple pointer to an object that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
void adoptInstead(T *p) {
|
||||
delete LocalPointerBase<T>::ptr;
|
||||
LocalPointerBase<T>::ptr=p;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* "Smart pointer" class, deletes objects via the C++ array delete[] operator.
|
||||
* For most methods see the LocalPointerBase base class.
|
||||
* Adds operator[] for array item access.
|
||||
*
|
||||
* Usage example:
|
||||
* \code
|
||||
* LocalArray<UnicodeString> a(new UnicodeString[2]);
|
||||
* a[0].append((UChar)0x61);
|
||||
* if(some condition) { return; } // no need to explicitly delete the array
|
||||
* a.adoptInstead(new UnicodeString[4]);
|
||||
* a[3].append((UChar)0x62).append((UChar)0x63).reverse();
|
||||
* // no need to explicitly delete the array
|
||||
* \endcode
|
||||
*
|
||||
* @see LocalPointerBase
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalArray : public LocalPointerBase<T> {
|
||||
public:
|
||||
/**
|
||||
* Constructor takes ownership.
|
||||
* @param p simple pointer to an array of T objects that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
explicit LocalArray(T *p=NULL) : LocalPointerBase<T>(p) {}
|
||||
/**
|
||||
* Destructor deletes the array it owns.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~LocalArray() {
|
||||
delete[] LocalPointerBase<T>::ptr;
|
||||
}
|
||||
/**
|
||||
* Deletes the array it owns,
|
||||
* and adopts (takes ownership of) the one passed in.
|
||||
* @param p simple pointer to an array of T objects that is adopted
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
void adoptInstead(T *p) {
|
||||
delete[] LocalPointerBase<T>::ptr;
|
||||
LocalPointerBase<T>::ptr=p;
|
||||
}
|
||||
/**
|
||||
* Array item access (writable).
|
||||
* No index bounds check.
|
||||
* @param i array index
|
||||
* @return reference to the array item
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
T &operator[](ptrdiff_t i) const { return LocalPointerBase<T>::ptr[i]; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \def U_DEFINE_LOCAL_OPEN_POINTER
|
||||
* "Smart pointer" definition macro, deletes objects via the closeFunction.
|
||||
* Defines a subclass of LocalPointerBase which works just
|
||||
* like LocalPointer<Type> except that this subclass will use the closeFunction
|
||||
* rather than the C++ delete operator.
|
||||
*
|
||||
* Requirement: The closeFunction must tolerate a NULL pointer.
|
||||
* (We could add a NULL check here but it is normally redundant.)
|
||||
*
|
||||
* Usage example:
|
||||
* \code
|
||||
* LocalUCaseMapPointer csm(ucasemap_open(localeID, options, &errorCode));
|
||||
* utf8OutLength=ucasemap_utf8ToLower(csm.getAlias(),
|
||||
* utf8Out, (int32_t)sizeof(utf8Out),
|
||||
* utf8In, utf8InLength, &errorCode);
|
||||
* if(U_FAILURE(errorCode)) { return; } // no need to explicitly delete the UCaseMap
|
||||
* \endcode
|
||||
*
|
||||
* @see LocalPointerBase
|
||||
* @see LocalPointer
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
|
||||
class LocalPointerClassName : public LocalPointerBase<Type> { \
|
||||
public: \
|
||||
explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
|
||||
~LocalPointerClassName() { closeFunction(ptr); } \
|
||||
void adoptInstead(Type *p) { \
|
||||
closeFunction(ptr); \
|
||||
ptr=p; \
|
||||
} \
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_SHOW_CPLUSPLUS_API */
|
||||
#endif /* __LOCALPOINTER_H__ */
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 2010-2012, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef LOCDSPNM_H
|
||||
#define LOCDSPNM_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Provides display names of Locale and its components.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/uscript.h"
|
||||
#include "unicode/uldnames.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Returns display names of Locales and components of Locales. For
|
||||
* more information on language, script, region, variant, key, and
|
||||
* values, see Locale.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
class U_I18N_API LocaleDisplayNames : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual ~LocaleDisplayNames();
|
||||
|
||||
/**
|
||||
* Convenience overload of
|
||||
* {@link #createInstance(const Locale& locale, UDialectHandling dialectHandling)}
|
||||
* that specifies STANDARD dialect handling.
|
||||
* @param locale the display locale
|
||||
* @return a LocaleDisplayNames instance
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale);
|
||||
|
||||
/**
|
||||
* Returns an instance of LocaleDisplayNames that returns names
|
||||
* formatted for the provided locale, using the provided
|
||||
* dialectHandling.
|
||||
*
|
||||
* @param locale the display locale
|
||||
* @param dialectHandling how to select names for locales
|
||||
* @return a LocaleDisplayNames instance
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
|
||||
UDialectHandling dialectHandling);
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Returns an instance of LocaleDisplayNames that returns names formatted
|
||||
* for the provided locale, using the provided UDisplayContext settings.
|
||||
*
|
||||
* @param locale the display locale
|
||||
* @param contexts List of one or more context settings (e.g. for dialect
|
||||
* handling, capitalization, etc.
|
||||
* @param length Number of items in the contexts list
|
||||
* @return a LocaleDisplayNames instance
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
|
||||
UDisplayContext *contexts, int32_t length);
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
// getters for state
|
||||
/**
|
||||
* Returns the locale used to determine the display names. This is
|
||||
* not necessarily the same locale passed to {@link #createInstance}.
|
||||
* @return the display locale
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual const Locale& getLocale() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the dialect handling used in the display names.
|
||||
* @return the dialect handling enum
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UDialectHandling getDialectHandling() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the UDisplayContext value for the specified UDisplayContextType.
|
||||
* @param type the UDisplayContextType whose value to return
|
||||
* @return the UDisplayContext for the specified type.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual UDisplayContext getContext(UDisplayContextType type) const = 0;
|
||||
|
||||
// names for entire locales
|
||||
/**
|
||||
* Returns the display name of the provided locale.
|
||||
* @param locale the locale whose display name to return
|
||||
* @param result receives the locale's display name
|
||||
* @return the display name of the provided locale
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& localeDisplayName(const Locale& locale,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided locale id.
|
||||
* @param localeId the id of the locale whose display name to return
|
||||
* @param result receives the locale's display name
|
||||
* @return the display name of the provided locale
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& localeDisplayName(const char* localeId,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
// names for components of a locale id
|
||||
/**
|
||||
* Returns the display name of the provided language code.
|
||||
* @param lang the language code
|
||||
* @param result receives the language code's display name
|
||||
* @return the display name of the provided language code
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& languageDisplayName(const char* lang,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided script code.
|
||||
* @param script the script code
|
||||
* @param result receives the script code's display name
|
||||
* @return the display name of the provided script code
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& scriptDisplayName(const char* script,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided script code.
|
||||
* @param scriptCode the script code number
|
||||
* @param result receives the script code's display name
|
||||
* @return the display name of the provided script code
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided region code.
|
||||
* @param region the region code
|
||||
* @param result receives the region code's display name
|
||||
* @return the display name of the provided region code
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& regionDisplayName(const char* region,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided variant.
|
||||
* @param variant the variant string
|
||||
* @param result receives the variant's display name
|
||||
* @return the display name of the provided variant
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& variantDisplayName(const char* variant,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided locale key.
|
||||
* @param key the locale key name
|
||||
* @param result receives the locale key's display name
|
||||
* @return the display name of the provided locale key
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& keyDisplayName(const char* key,
|
||||
UnicodeString& result) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the display name of the provided value (used with the provided key).
|
||||
* @param key the locale key name
|
||||
* @param value the locale key's value
|
||||
* @param result receives the value's display name
|
||||
* @return the display name of the provided value
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString& keyValueDisplayName(const char* key, const char* value,
|
||||
UnicodeString& result) const = 0;
|
||||
};
|
||||
|
||||
inline LocaleDisplayNames* LocaleDisplayNames::createInstance(const Locale& locale) {
|
||||
return LocaleDisplayNames::createInstance(locale, ULDN_STANDARD_NAMES);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,798 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1996-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* File locid.h
|
||||
*
|
||||
* Created by: Helena Shih
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
|
||||
* get and set it.
|
||||
* 04/02/97 aliu Made operator!= inline; fixed return value of getName().
|
||||
* 04/15/97 aliu Cleanup for AIX/Win32.
|
||||
* 04/24/97 aliu Numerous changes per code review.
|
||||
* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
|
||||
* 09/08/98 stephen Moved definition of kEmptyString for Mac Port
|
||||
* 11/09/99 weiv Added const char * getName() const;
|
||||
* 04/12/00 srl removing unicodestring api's and cached hash code
|
||||
* 08/10/01 grhoten Change the static Locales to accessor functions
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef LOCID_H
|
||||
#define LOCID_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/putil.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/strenum.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Locale ID object.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// Forward Declarations
|
||||
void U_CALLCONV locale_available_init(); /**< @internal */
|
||||
|
||||
/**
|
||||
* A <code>Locale</code> object represents a specific geographical, political,
|
||||
* or cultural region. An operation that requires a <code>Locale</code> to perform
|
||||
* its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
|
||||
* to tailor information for the user. For example, displaying a number
|
||||
* is a locale-sensitive operation--the number should be formatted
|
||||
* according to the customs/conventions of the user's native country,
|
||||
* region, or culture.
|
||||
*
|
||||
* The Locale class is not suitable for subclassing.
|
||||
*
|
||||
* <P>
|
||||
* You can create a <code>Locale</code> object using the constructor in
|
||||
* this class:
|
||||
* \htmlonly<blockquote>\endhtmlonly
|
||||
* <pre>
|
||||
* Locale( const char* language,
|
||||
* const char* country,
|
||||
* const char* variant);
|
||||
* </pre>
|
||||
* \htmlonly</blockquote>\endhtmlonly
|
||||
* The first argument to the constructors is a valid <STRONG>ISO
|
||||
* Language Code.</STRONG> These codes are the lower-case two-letter
|
||||
* codes as defined by ISO-639.
|
||||
* You can find a full list of these codes at:
|
||||
* <BR><a href ="http://www.loc.gov/standards/iso639-2/">
|
||||
* http://www.loc.gov/standards/iso639-2/</a>
|
||||
*
|
||||
* <P>
|
||||
* The second argument to the constructors is a valid <STRONG>ISO Country
|
||||
* Code.</STRONG> These codes are the upper-case two-letter codes
|
||||
* as defined by ISO-3166.
|
||||
* You can find a full list of these codes at a number of sites, such as:
|
||||
* <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
|
||||
* http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
|
||||
*
|
||||
* <P>
|
||||
* The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
|
||||
* The Variant codes are vendor and browser-specific.
|
||||
* For example, use REVISED for a langauge's revised script orthography, and POSIX for POSIX.
|
||||
* Where there are two variants, separate them with an underscore, and
|
||||
* put the most important one first. For
|
||||
* example, a Traditional Spanish collation might be referenced, with
|
||||
* "ES", "ES", "Traditional_POSIX".
|
||||
*
|
||||
* <P>
|
||||
* Because a <code>Locale</code> object is just an identifier for a region,
|
||||
* no validity check is performed when you construct a <code>Locale</code>.
|
||||
* If you want to see whether particular resources are available for the
|
||||
* <code>Locale</code> you construct, you must query those resources. For
|
||||
* example, ask the <code>NumberFormat</code> for the locales it supports
|
||||
* using its <code>getAvailableLocales</code> method.
|
||||
* <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
|
||||
* locale, you get back the best available match, not necessarily
|
||||
* precisely what you asked for. For more information, look at
|
||||
* <code>ResourceBundle</code>.
|
||||
*
|
||||
* <P>
|
||||
* The <code>Locale</code> class provides a number of convenient constants
|
||||
* that you can use to create <code>Locale</code> objects for commonly used
|
||||
* locales. For example, the following refers to a <code>Locale</code> object
|
||||
* for the United States:
|
||||
* \htmlonly<blockquote>\endhtmlonly
|
||||
* <pre>
|
||||
* Locale::getUS()
|
||||
* </pre>
|
||||
* \htmlonly</blockquote>\endhtmlonly
|
||||
*
|
||||
* <P>
|
||||
* Once you've created a <code>Locale</code> you can query it for information about
|
||||
* itself. Use <code>getCountry</code> to get the ISO Country Code and
|
||||
* <code>getLanguage</code> to get the ISO Language Code. You can
|
||||
* use <code>getDisplayCountry</code> to get the
|
||||
* name of the country suitable for displaying to the user. Similarly,
|
||||
* you can use <code>getDisplayLanguage</code> to get the name of
|
||||
* the language suitable for displaying to the user. Interestingly,
|
||||
* the <code>getDisplayXXX</code> methods are themselves locale-sensitive
|
||||
* and have two versions: one that uses the default locale and one
|
||||
* that takes a locale as an argument and displays the name or country in
|
||||
* a language appropriate to that locale.
|
||||
*
|
||||
* <P>
|
||||
* ICU provides a number of classes that perform locale-sensitive
|
||||
* operations. For example, the <code>NumberFormat</code> class formats
|
||||
* numbers, currency, or percentages in a locale-sensitive manner. Classes
|
||||
* such as <code>NumberFormat</code> have a number of convenience methods
|
||||
* for creating a default object of that type. For example, the
|
||||
* <code>NumberFormat</code> class provides these three convenience methods
|
||||
* for creating a default <code>NumberFormat</code> object:
|
||||
* \htmlonly<blockquote>\endhtmlonly
|
||||
* <pre>
|
||||
* UErrorCode success = U_ZERO_ERROR;
|
||||
* Locale myLocale;
|
||||
* NumberFormat *nf;
|
||||
*
|
||||
* nf = NumberFormat::createInstance( success ); delete nf;
|
||||
* nf = NumberFormat::createCurrencyInstance( success ); delete nf;
|
||||
* nf = NumberFormat::createPercentInstance( success ); delete nf;
|
||||
* </pre>
|
||||
* \htmlonly</blockquote>\endhtmlonly
|
||||
* Each of these methods has two variants; one with an explicit locale
|
||||
* and one without; the latter using the default locale.
|
||||
* \htmlonly<blockquote>\endhtmlonly
|
||||
* <pre>
|
||||
* nf = NumberFormat::createInstance( myLocale, success ); delete nf;
|
||||
* nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;
|
||||
* nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;
|
||||
* </pre>
|
||||
* \htmlonly</blockquote>\endhtmlonly
|
||||
* A <code>Locale</code> is the mechanism for identifying the kind of object
|
||||
* (<code>NumberFormat</code>) that you would like to get. The locale is
|
||||
* <STRONG>just</STRONG> a mechanism for identifying objects,
|
||||
* <STRONG>not</STRONG> a container for the objects themselves.
|
||||
*
|
||||
* <P>
|
||||
* Each class that performs locale-sensitive operations allows you
|
||||
* to get all the available objects of that type. You can sift
|
||||
* through these objects by language, country, or variant,
|
||||
* and use the display names to present a menu to the user.
|
||||
* For example, you can create a menu of all the collation objects
|
||||
* suitable for a given language. Such classes implement these
|
||||
* three class methods:
|
||||
* \htmlonly<blockquote>\endhtmlonly
|
||||
* <pre>
|
||||
* static Locale* getAvailableLocales(int32_t& numLocales)
|
||||
* static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
* const Locale& displayLocale,
|
||||
* UnicodeString& displayName)
|
||||
* static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
* UnicodeString& displayName)
|
||||
* </pre>
|
||||
* \htmlonly</blockquote>\endhtmlonly
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
* @see ResourceBundle
|
||||
*/
|
||||
class U_COMMON_API Locale : public UObject {
|
||||
public:
|
||||
/** Useful constant for the Root locale. @stable ICU 4.4 */
|
||||
static const Locale &U_EXPORT2 getRoot(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getEnglish(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getFrench(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getGerman(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getItalian(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getJapanese(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getKorean(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getChinese(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getSimplifiedChinese(void);
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getTraditionalChinese(void);
|
||||
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getFrance(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getGermany(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getItaly(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getJapan(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getKorea(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getChina(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getPRC(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getTaiwan(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getUK(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getUS(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getCanada(void);
|
||||
/** Useful constant for this country/region. @stable ICU 2.0 */
|
||||
static const Locale &U_EXPORT2 getCanadaFrench(void);
|
||||
|
||||
|
||||
/**
|
||||
* Construct a default locale object, a Locale for the default locale ID.
|
||||
*
|
||||
* @see getDefault
|
||||
* @see uloc_getDefault
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Locale();
|
||||
|
||||
/**
|
||||
* Construct a locale from language, country, variant.
|
||||
* If an error occurs, then the constructed object will be "bogus"
|
||||
* (isBogus() will return TRUE).
|
||||
*
|
||||
* @param language Lowercase two-letter or three-letter ISO-639 code.
|
||||
* This parameter can instead be an ICU style C locale (e.g. "en_US"),
|
||||
* but the other parameters must not be used.
|
||||
* This parameter can be NULL; if so,
|
||||
* the locale is initialized to match the current default locale.
|
||||
* (This is the same as using the default constructor.)
|
||||
* Please note: The Java Locale class does NOT accept the form
|
||||
* 'new Locale("en_US")' but only 'new Locale("en","US")'
|
||||
*
|
||||
* @param country Uppercase two-letter ISO-3166 code. (optional)
|
||||
* @param variant Uppercase vendor and browser specific code. See class
|
||||
* description. (optional)
|
||||
* @param keywordsAndValues A string consisting of keyword/values pairs, such as
|
||||
* "collation=phonebook;currency=euro"
|
||||
*
|
||||
* @see getDefault
|
||||
* @see uloc_getDefault
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Locale( const char * language,
|
||||
const char * country = 0,
|
||||
const char * variant = 0,
|
||||
const char * keywordsAndValues = 0);
|
||||
|
||||
/**
|
||||
* Initializes a Locale object from another Locale object.
|
||||
*
|
||||
* @param other The Locale object being copied in.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Locale(const Locale& other);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~Locale() ;
|
||||
|
||||
/**
|
||||
* Replaces the entire contents of *this with the specified value.
|
||||
*
|
||||
* @param other The Locale object being copied in.
|
||||
* @return *this
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Locale& operator=(const Locale& other);
|
||||
|
||||
/**
|
||||
* Checks if two locale keys are the same.
|
||||
*
|
||||
* @param other The locale key object to be compared with this.
|
||||
* @return True if the two locale keys are the same, false otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const Locale& other) const;
|
||||
|
||||
/**
|
||||
* Checks if two locale keys are not the same.
|
||||
*
|
||||
* @param other The locale key object to be compared with this.
|
||||
* @return True if the two locale keys are not the same, false
|
||||
* otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const Locale& other) const;
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If an error occurs, then NULL is returned.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
Locale *clone() const;
|
||||
|
||||
#ifndef U_HIDE_SYSTEM_API
|
||||
/**
|
||||
* Common methods of getting the current default Locale. Used for the
|
||||
* presentation: menus, dialogs, etc. Generally set once when your applet or
|
||||
* application is initialized, then never reset. (If you do reset the
|
||||
* default locale, you probably want to reload your GUI, so that the change
|
||||
* is reflected in your interface.)
|
||||
*
|
||||
* More advanced programs will allow users to use different locales for
|
||||
* different fields, e.g. in a spreadsheet.
|
||||
*
|
||||
* Note that the initial setting will match the host system.
|
||||
* @return a reference to the Locale object for the default locale ID
|
||||
* @system
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const Locale& U_EXPORT2 getDefault(void);
|
||||
|
||||
/**
|
||||
* Sets the default. Normally set once at the beginning of a process,
|
||||
* then never reset.
|
||||
* setDefault() only changes ICU's default locale ID, <strong>not</strong>
|
||||
* the default locale ID of the runtime environment.
|
||||
*
|
||||
* @param newLocale Locale to set to. If NULL, set to the value obtained
|
||||
* from the runtime environement.
|
||||
* @param success The error code.
|
||||
* @system
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static void U_EXPORT2 setDefault(const Locale& newLocale,
|
||||
UErrorCode& success);
|
||||
#endif /* U_HIDE_SYSTEM_API */
|
||||
|
||||
/**
|
||||
* Creates a locale which has had minimal canonicalization
|
||||
* as per uloc_getName().
|
||||
* @param name The name to create from. If name is null,
|
||||
* the default Locale is used.
|
||||
* @return new locale object
|
||||
* @stable ICU 2.0
|
||||
* @see uloc_getName
|
||||
*/
|
||||
static Locale U_EXPORT2 createFromName(const char *name);
|
||||
|
||||
/**
|
||||
* Creates a locale from the given string after canonicalizing
|
||||
* the string by calling uloc_canonicalize().
|
||||
* @param name the locale ID to create from. Must not be NULL.
|
||||
* @return a new locale object corresponding to the given name
|
||||
* @stable ICU 3.0
|
||||
* @see uloc_canonicalize
|
||||
*/
|
||||
static Locale U_EXPORT2 createCanonical(const char* name);
|
||||
|
||||
/**
|
||||
* Returns the locale's ISO-639 language code.
|
||||
* @return An alias to the code
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline const char * getLanguage( ) const;
|
||||
|
||||
/**
|
||||
* Returns the locale's ISO-15924 abbreviation script code.
|
||||
* @return An alias to the code
|
||||
* @see uscript_getShortName
|
||||
* @see uscript_getCode
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
inline const char * getScript( ) const;
|
||||
|
||||
/**
|
||||
* Returns the locale's ISO-3166 country code.
|
||||
* @return An alias to the code
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline const char * getCountry( ) const;
|
||||
|
||||
/**
|
||||
* Returns the locale's variant code.
|
||||
* @return An alias to the code
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline const char * getVariant( ) const;
|
||||
|
||||
/**
|
||||
* Returns the programmatic name of the entire locale, with the language,
|
||||
* country and variant separated by underbars. If a field is missing, up
|
||||
* to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
|
||||
* "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
|
||||
* @return A pointer to "name".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline const char * getName() const;
|
||||
|
||||
/**
|
||||
* Returns the programmatic name of the entire locale as getName() would return,
|
||||
* but without keywords.
|
||||
* @return A pointer to "name".
|
||||
* @see getName
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
const char * getBaseName() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of keywords for the specified locale.
|
||||
*
|
||||
* @param status the status code
|
||||
* @return pointer to StringEnumeration class, or NULL if there are no keywords.
|
||||
* Client must dispose of it by calling delete.
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
StringEnumeration * createKeywords(UErrorCode &status) const;
|
||||
|
||||
/**
|
||||
* Gets the value for a keyword.
|
||||
*
|
||||
* @param keywordName name of the keyword for which we want the value. Case insensitive.
|
||||
* @param buffer The buffer to receive the keyword value.
|
||||
* @param bufferCapacity The capacity of receiving buffer
|
||||
* @param status Returns any error information while performing this operation.
|
||||
* @return the length of the keyword value
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
|
||||
|
||||
/**
|
||||
* Sets or removes the value for a keyword.
|
||||
*
|
||||
* For removing all keywords, use getBaseName(),
|
||||
* and construct a new Locale if it differs from getName().
|
||||
*
|
||||
* @param keywordName name of the keyword to be set. Case insensitive.
|
||||
* @param keywordValue value of the keyword to be set. If 0-length or
|
||||
* NULL, will result in the keyword being removed. No error is given if
|
||||
* that keyword does not exist.
|
||||
* @param status Returns any error information while performing this operation.
|
||||
*
|
||||
* @stable ICU 49
|
||||
*/
|
||||
void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* returns the locale's three-letter language code, as specified
|
||||
* in ISO draft standard ISO-639-2.
|
||||
* @return An alias to the code, or an empty string
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const char * getISO3Language() const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the locale's three-letter ISO-3166 country code.
|
||||
* @return An alias to the code, or an empty string
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const char * getISO3Country() const;
|
||||
|
||||
/**
|
||||
* Returns the Windows LCID value corresponding to this locale.
|
||||
* This value is stored in the resource data for the locale as a one-to-four-digit
|
||||
* hexadecimal number. If the resource is missing, in the wrong format, or
|
||||
* there is no Windows LCID value that corresponds to this locale, returns 0.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
uint32_t getLCID(void) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispLang" with the name of this locale's language in a format suitable for
|
||||
* user display in the default locale. For example, if the locale's language code is
|
||||
* "fr" and the default locale's language code is "en", this function would set
|
||||
* dispLang to "French".
|
||||
* @param dispLang Receives the language's display name.
|
||||
* @return A reference to "dispLang".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispLang" with the name of this locale's language in a format suitable for
|
||||
* user display in the locale specified by "displayLocale". For example, if the locale's
|
||||
* language code is "en" and displayLocale's language code is "fr", this function would set
|
||||
* dispLang to "Anglais".
|
||||
* @param displayLocale Specifies the locale to be used to display the name. In other words,
|
||||
* if the locale's language code is "en", passing Locale::getFrench() for
|
||||
* displayLocale would result in "Anglais", while passing Locale::getGerman()
|
||||
* for displayLocale would result in "Englisch".
|
||||
* @param dispLang Receives the language's display name.
|
||||
* @return A reference to "dispLang".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayLanguage( const Locale& displayLocale,
|
||||
UnicodeString& dispLang) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispScript" with the name of this locale's script in a format suitable
|
||||
* for user display in the default locale. For example, if the locale's script code
|
||||
* is "LATN" and the default locale's language code is "en", this function would set
|
||||
* dispScript to "Latin".
|
||||
* @param dispScript Receives the scripts's display name.
|
||||
* @return A reference to "dispScript".
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispScript" with the name of this locale's country in a format suitable
|
||||
* for user display in the locale specified by "displayLocale". For example, if the locale's
|
||||
* script code is "LATN" and displayLocale's language code is "en", this function would set
|
||||
* dispScript to "Latin".
|
||||
* @param displayLocale Specifies the locale to be used to display the name. In other
|
||||
* words, if the locale's script code is "LATN", passing
|
||||
* Locale::getFrench() for displayLocale would result in "", while
|
||||
* passing Locale::getGerman() for displayLocale would result in
|
||||
* "".
|
||||
* @param dispScript Receives the scripts's display name.
|
||||
* @return A reference to "dispScript".
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
UnicodeString& getDisplayScript( const Locale& displayLocale,
|
||||
UnicodeString& dispScript) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispCountry" with the name of this locale's country in a format suitable
|
||||
* for user display in the default locale. For example, if the locale's country code
|
||||
* is "FR" and the default locale's language code is "en", this function would set
|
||||
* dispCountry to "France".
|
||||
* @param dispCountry Receives the country's display name.
|
||||
* @return A reference to "dispCountry".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispCountry" with the name of this locale's country in a format suitable
|
||||
* for user display in the locale specified by "displayLocale". For example, if the locale's
|
||||
* country code is "US" and displayLocale's language code is "fr", this function would set
|
||||
* dispCountry to "États-Unis".
|
||||
* @param displayLocale Specifies the locale to be used to display the name. In other
|
||||
* words, if the locale's country code is "US", passing
|
||||
* Locale::getFrench() for displayLocale would result in "États-Unis", while
|
||||
* passing Locale::getGerman() for displayLocale would result in
|
||||
* "Vereinigte Staaten".
|
||||
* @param dispCountry Receives the country's display name.
|
||||
* @return A reference to "dispCountry".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayCountry( const Locale& displayLocale,
|
||||
UnicodeString& dispCountry) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispVar" with the name of this locale's variant code in a format suitable
|
||||
* for user display in the default locale.
|
||||
* @param dispVar Receives the variant's name.
|
||||
* @return A reference to "dispVar".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispVar" with the name of this locale's variant code in a format
|
||||
* suitable for user display in the locale specified by "displayLocale".
|
||||
* @param displayLocale Specifies the locale to be used to display the name.
|
||||
* @param dispVar Receives the variant's display name.
|
||||
* @return A reference to "dispVar".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayVariant( const Locale& displayLocale,
|
||||
UnicodeString& dispVar) const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the name of this locale in a format suitable for user display
|
||||
* in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),
|
||||
* and getDisplayVariant() to do its work, and outputs the display name in the format
|
||||
* "language (country[,variant])". For example, if the default locale is en_US, then
|
||||
* fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
|
||||
* would be "Spanish (Mexico,Traditional)".
|
||||
* @param name Receives the locale's display name.
|
||||
* @return A reference to "name".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayName( UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the name of this locale in a format suitable for user display
|
||||
* in the locale specfied by "displayLocale". This function uses getDisplayLanguage(),
|
||||
* getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
|
||||
* name in the format "language (country[,variant])". For example, if displayLocale is
|
||||
* fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
|
||||
* display name would be "norvégien (Norvège,NY)".
|
||||
* @param displayLocale Specifies the locale to be used to display the name.
|
||||
* @param name Receives the locale's display name.
|
||||
* @return A reference to "name".
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString& getDisplayName( const Locale& displayLocale,
|
||||
UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Generates a hash code for the locale.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t hashCode(void) const;
|
||||
|
||||
/**
|
||||
* Sets the locale to bogus
|
||||
* A bogus locale represents a non-existing locale associated
|
||||
* with services that can be instantiated from non-locale data
|
||||
* in addition to locale (for example, collation can be
|
||||
* instantiated from a locale and from a rule set).
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
void setToBogus();
|
||||
|
||||
/**
|
||||
* Gets the bogus state. Locale object can be bogus if it doesn't exist
|
||||
* @return FALSE if it is a real locale, TRUE if it is a bogus locale
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
UBool isBogus(void) const;
|
||||
|
||||
/**
|
||||
* Returns a list of all installed locales.
|
||||
* @param count Receives the number of locales in the list.
|
||||
* @return A pointer to an array of Locale objects. This array is the list
|
||||
* of all locales with installed resource files. The called does NOT
|
||||
* get ownership of this list, and must NOT delete it.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
|
||||
|
||||
/**
|
||||
* Gets a list of all available 2-letter country codes defined in ISO 3166. This is a
|
||||
* pointer to an array of pointers to arrays of char. All of these pointers are
|
||||
* owned by ICU-- do not delete them, and do not write through them. The array is
|
||||
* terminated with a null pointer.
|
||||
* @return a list of all available country codes
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const char* const* U_EXPORT2 getISOCountries();
|
||||
|
||||
/**
|
||||
* Gets a list of all available language codes defined in ISO 639. This is a pointer
|
||||
* to an array of pointers to arrays of char. All of these pointers are owned
|
||||
* by ICU-- do not delete them, and do not write through them. The array is
|
||||
* terminated with a null pointer.
|
||||
* @return a list of all available language codes
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static const char* const* U_EXPORT2 getISOLanguages();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
protected: /* only protected for testing purposes. DO NOT USE. */
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Set this from a single POSIX style locale string.
|
||||
* @internal
|
||||
*/
|
||||
void setFromPOSIXID(const char *posixID);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initialize the locale object with a new name.
|
||||
* Was deprecated - used in implementation - moved internal
|
||||
*
|
||||
* @param cLocaleID The new locale name.
|
||||
* @param canonicalize whether to call uloc_canonicalize on cLocaleID
|
||||
*/
|
||||
Locale& init(const char* cLocaleID, UBool canonicalize);
|
||||
|
||||
/*
|
||||
* Internal constructor to allow construction of a locale object with
|
||||
* NO side effects. (Default constructor tries to get
|
||||
* the default locale.)
|
||||
*/
|
||||
enum ELocaleType {
|
||||
eBOGUS
|
||||
};
|
||||
Locale(ELocaleType);
|
||||
|
||||
/**
|
||||
* Initialize the locale cache for commonly used locales
|
||||
*/
|
||||
static Locale *getLocaleCache(void);
|
||||
|
||||
char language[ULOC_LANG_CAPACITY];
|
||||
char script[ULOC_SCRIPT_CAPACITY];
|
||||
char country[ULOC_COUNTRY_CAPACITY];
|
||||
int32_t variantBegin;
|
||||
char* fullName;
|
||||
char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
|
||||
// name without keywords
|
||||
char* baseName;
|
||||
char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
UBool fIsBogus;
|
||||
|
||||
static const Locale &getLocale(int locid);
|
||||
|
||||
/**
|
||||
* A friend to allow the default locale to be set by either the C or C++ API.
|
||||
* @internal
|
||||
*/
|
||||
friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
friend void locale_available_init();
|
||||
};
|
||||
|
||||
inline UBool
|
||||
Locale::operator!=(const Locale& other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
inline const char *
|
||||
Locale::getCountry() const
|
||||
{
|
||||
return country;
|
||||
}
|
||||
|
||||
inline const char *
|
||||
Locale::getLanguage() const
|
||||
{
|
||||
return language;
|
||||
}
|
||||
|
||||
inline const char *
|
||||
Locale::getScript() const
|
||||
{
|
||||
return script;
|
||||
}
|
||||
|
||||
inline const char *
|
||||
Locale::getVariant() const
|
||||
{
|
||||
getBaseName(); // lazy init
|
||||
return &baseName[variantBegin];
|
||||
}
|
||||
|
||||
inline const char *
|
||||
Locale::getName() const
|
||||
{
|
||||
return fullName;
|
||||
}
|
||||
|
||||
inline UBool
|
||||
Locale::isBogus(void) const {
|
||||
return fIsBogus;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: April 20, 2004
|
||||
* Since: ICU 3.0
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef MEASUREFORMAT_H
|
||||
#define MEASUREFORMAT_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/format.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Formatter for measure objects.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
*
|
||||
* A formatter for measure objects. This is an abstract base class.
|
||||
*
|
||||
* <p>To format or parse a measure object, first create a formatter
|
||||
* object using a MeasureFormat factory method. Then use that
|
||||
* object's format and parse methods.
|
||||
*
|
||||
* <p>This is an abstract class.
|
||||
*
|
||||
* @see Format
|
||||
* @author Alan Liu
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_I18N_API MeasureFormat : public Format {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual ~MeasureFormat();
|
||||
|
||||
/**
|
||||
* Return a formatter for CurrencyAmount objects in the given
|
||||
* locale.
|
||||
* @param locale desired locale
|
||||
* @param ec input-output error code
|
||||
* @return a formatter object, or NULL upon error
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
|
||||
UErrorCode& ec);
|
||||
|
||||
/**
|
||||
* Return a formatter for CurrencyAmount objects in the default
|
||||
* locale.
|
||||
* @param ec input-output error code
|
||||
* @return a formatter object, or NULL upon error
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
MeasureFormat();
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // #if !UCONFIG_NO_FORMATTING
|
||||
#endif // #ifndef MEASUREFORMAT_H
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: April 26, 2004
|
||||
* Since: ICU 3.0
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef __MEASUREUNIT_H__
|
||||
#define __MEASUREUNIT_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/fmtable.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: A unit for measuring a quantity.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A unit such as length, mass, volume, currency, etc. A unit is
|
||||
* coupled with a numeric amount to produce a Measure.
|
||||
*
|
||||
* <p>This is an abstract class.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_I18N_API MeasureUnit: public UObject {
|
||||
public:
|
||||
/**
|
||||
* Return a polymorphic clone of this object. The result will
|
||||
* have the same class as returned by getDynamicClassID().
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UObject* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual ~MeasureUnit();
|
||||
|
||||
/**
|
||||
* Equality operator. Return true if this object is equal
|
||||
* to the given object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UBool operator==(const UObject& other) const = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
MeasureUnit();
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
// NOTE: There is no measunit.cpp. For implementation, see measure.cpp. [alan]
|
||||
|
||||
#endif // !UCONFIG_NO_FORMATTING
|
||||
#endif // __MEASUREUNIT_H__
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: April 26, 2004
|
||||
* Since: ICU 3.0
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef __MEASURE_H__
|
||||
#define __MEASURE_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: MeasureUnit object.
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/fmtable.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class MeasureUnit;
|
||||
|
||||
/**
|
||||
* An amount of a specified unit, consisting of a number and a Unit.
|
||||
* For example, a length measure consists of a number and a length
|
||||
* unit, such as feet or meters. This is an abstract class.
|
||||
* Subclasses specify a concrete Unit type.
|
||||
*
|
||||
* <p>Measure objects are parsed and formatted by subclasses of
|
||||
* MeasureFormat.
|
||||
*
|
||||
* <p>Measure objects are immutable.
|
||||
*
|
||||
* <p>This is an abstract class.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
class U_I18N_API Measure: public UObject {
|
||||
public:
|
||||
/**
|
||||
* Construct an object with the given numeric amount and the given
|
||||
* unit. After this call, the caller must not delete the given
|
||||
* unit object.
|
||||
* @param number a numeric object; amount.isNumeric() must be TRUE
|
||||
* @param adoptedUnit the unit object, which must not be NULL
|
||||
* @param ec input-output error code. If the amount or the unit
|
||||
* is invalid, then this will be set to a failing value.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
Measure(const Formattable& number, MeasureUnit* adoptedUnit,
|
||||
UErrorCode& ec);
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
Measure(const Measure& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
Measure& operator=(const Measure& other);
|
||||
|
||||
/**
|
||||
* Return a polymorphic clone of this object. The result will
|
||||
* have the same class as returned by getDynamicClassID().
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UObject* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual ~Measure();
|
||||
|
||||
/**
|
||||
* Equality operator. Return true if this object is equal
|
||||
* to the given object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
UBool operator==(const UObject& other) const;
|
||||
|
||||
/**
|
||||
* Return a reference to the numeric value of this object. The
|
||||
* numeric value may be of any numeric type supported by
|
||||
* Formattable.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline const Formattable& getNumber() const;
|
||||
|
||||
/**
|
||||
* Return a reference to the unit of this object.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
inline const MeasureUnit& getUnit() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
Measure();
|
||||
|
||||
private:
|
||||
/**
|
||||
* The numeric value of this object, e.g. 2.54 or 100.
|
||||
*/
|
||||
Formattable number;
|
||||
|
||||
/**
|
||||
* The unit of this object, e.g., "millimeter" or "JPY". This is
|
||||
* owned by this object.
|
||||
*/
|
||||
MeasureUnit* unit;
|
||||
};
|
||||
|
||||
inline const Formattable& Measure::getNumber() const {
|
||||
return number;
|
||||
}
|
||||
|
||||
inline const MeasureUnit& Measure::getUnit() const {
|
||||
return *unit;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // !UCONFIG_NO_FORMATTING
|
||||
#endif // __MEASURE_H__
|
||||
@@ -1,943 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: messagepattern.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2011mar14
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __MESSAGEPATTERN_H__
|
||||
#define __MESSAGEPATTERN_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/parseerr.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
/**
|
||||
* Mode for when an apostrophe starts quoted literal text for MessageFormat output.
|
||||
* The default is DOUBLE_OPTIONAL unless overridden via uconfig.h
|
||||
* (UCONFIG_MSGPAT_DEFAULT_APOSTROPHE_MODE).
|
||||
* <p>
|
||||
* A pair of adjacent apostrophes always results in a single apostrophe in the output,
|
||||
* even when the pair is between two single, text-quoting apostrophes.
|
||||
* <p>
|
||||
* The following table shows examples of desired MessageFormat.format() output
|
||||
* with the pattern strings that yield that output.
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <th>Desired output</th>
|
||||
* <th>DOUBLE_OPTIONAL</th>
|
||||
* <th>DOUBLE_REQUIRED</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>I see {many}</td>
|
||||
* <td>I see '{many}'</td>
|
||||
* <td>(same)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>I said {'Wow!'}</td>
|
||||
* <td>I said '{''Wow!''}'</td>
|
||||
* <td>(same)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>I don't know</td>
|
||||
* <td>I don't know OR<br> I don''t know</td>
|
||||
* <td>I don''t know</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* @stable ICU 4.8
|
||||
* @see UCONFIG_MSGPAT_DEFAULT_APOSTROPHE_MODE
|
||||
*/
|
||||
enum UMessagePatternApostropheMode {
|
||||
/**
|
||||
* A literal apostrophe is represented by
|
||||
* either a single or a double apostrophe pattern character.
|
||||
* Within a MessageFormat pattern, a single apostrophe only starts quoted literal text
|
||||
* if it immediately precedes a curly brace {},
|
||||
* or a pipe symbol | if inside a choice format,
|
||||
* or a pound symbol # if inside a plural format.
|
||||
* <p>
|
||||
* This is the default behavior starting with ICU 4.8.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_APOS_DOUBLE_OPTIONAL,
|
||||
/**
|
||||
* A literal apostrophe must be represented by
|
||||
* a double apostrophe pattern character.
|
||||
* A single apostrophe always starts quoted literal text.
|
||||
* <p>
|
||||
* This is the behavior of ICU 4.6 and earlier, and of the JDK.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_APOS_DOUBLE_REQUIRED
|
||||
};
|
||||
/**
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
typedef enum UMessagePatternApostropheMode UMessagePatternApostropheMode;
|
||||
|
||||
/**
|
||||
* MessagePattern::Part type constants.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
enum UMessagePatternPartType {
|
||||
/**
|
||||
* Start of a message pattern (main or nested).
|
||||
* The length is 0 for the top-level message
|
||||
* and for a choice argument sub-message, otherwise 1 for the '{'.
|
||||
* The value indicates the nesting level, starting with 0 for the main message.
|
||||
* <p>
|
||||
* There is always a later MSG_LIMIT part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_MSG_START,
|
||||
/**
|
||||
* End of a message pattern (main or nested).
|
||||
* The length is 0 for the top-level message and
|
||||
* the last sub-message of a choice argument,
|
||||
* otherwise 1 for the '}' or (in a choice argument style) the '|'.
|
||||
* The value indicates the nesting level, starting with 0 for the main message.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_MSG_LIMIT,
|
||||
/**
|
||||
* Indicates a substring of the pattern string which is to be skipped when formatting.
|
||||
* For example, an apostrophe that begins or ends quoted text
|
||||
* would be indicated with such a part.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_SKIP_SYNTAX,
|
||||
/**
|
||||
* Indicates that a syntax character needs to be inserted for auto-quoting.
|
||||
* The length is 0.
|
||||
* The value is the character code of the insertion character. (U+0027=APOSTROPHE)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_INSERT_CHAR,
|
||||
/**
|
||||
* Indicates a syntactic (non-escaped) # symbol in a plural variant.
|
||||
* When formatting, replace this part's substring with the
|
||||
* (value-offset) for the plural argument value.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_REPLACE_NUMBER,
|
||||
/**
|
||||
* Start of an argument.
|
||||
* The length is 1 for the '{'.
|
||||
* The value is the ordinal value of the ArgType. Use getArgType().
|
||||
* <p>
|
||||
* This part is followed by either an ARG_NUMBER or ARG_NAME,
|
||||
* followed by optional argument sub-parts (see UMessagePatternArgType constants)
|
||||
* and finally an ARG_LIMIT part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_START,
|
||||
/**
|
||||
* End of an argument.
|
||||
* The length is 1 for the '}'.
|
||||
* The value is the ordinal value of the ArgType. Use getArgType().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_LIMIT,
|
||||
/**
|
||||
* The argument number, provided by the value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_NUMBER,
|
||||
/**
|
||||
* The argument name.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_NAME,
|
||||
/**
|
||||
* The argument type.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_TYPE,
|
||||
/**
|
||||
* The argument style text.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_STYLE,
|
||||
/**
|
||||
* A selector substring in a "complex" argument style.
|
||||
* The value is undefined and currently always 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_SELECTOR,
|
||||
/**
|
||||
* An integer value, for example the offset or an explicit selector value
|
||||
* in a PluralFormat style.
|
||||
* The part value is the integer value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_INT,
|
||||
/**
|
||||
* A numeric value, for example the offset or an explicit selector value
|
||||
* in a PluralFormat style.
|
||||
* The part value is an index into an internal array of numeric values;
|
||||
* use getNumericValue().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_PART_TYPE_ARG_DOUBLE
|
||||
};
|
||||
/**
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
typedef enum UMessagePatternPartType UMessagePatternPartType;
|
||||
|
||||
/**
|
||||
* Argument type constants.
|
||||
* Returned by Part.getArgType() for ARG_START and ARG_LIMIT parts.
|
||||
*
|
||||
* Messages nested inside an argument are each delimited by MSG_START and MSG_LIMIT,
|
||||
* with a nesting level one greater than the surrounding message.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
enum UMessagePatternArgType {
|
||||
/**
|
||||
* The argument has no specified type.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_NONE,
|
||||
/**
|
||||
* The argument has a "simple" type which is provided by the ARG_TYPE part.
|
||||
* An ARG_STYLE part might follow that.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_SIMPLE,
|
||||
/**
|
||||
* The argument is a ChoiceFormat with one or more
|
||||
* ((ARG_INT | ARG_DOUBLE), ARG_SELECTOR, message) tuples.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_CHOICE,
|
||||
/**
|
||||
* The argument is a cardinal-number PluralFormat with an optional ARG_INT or ARG_DOUBLE offset
|
||||
* (e.g., offset:1)
|
||||
* and one or more (ARG_SELECTOR [explicit-value] message) tuples.
|
||||
* If the selector has an explicit value (e.g., =2), then
|
||||
* that value is provided by the ARG_INT or ARG_DOUBLE part preceding the message.
|
||||
* Otherwise the message immediately follows the ARG_SELECTOR.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_PLURAL,
|
||||
/**
|
||||
* The argument is a SelectFormat with one or more (ARG_SELECTOR, message) pairs.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_SELECT,
|
||||
/**
|
||||
* The argument is an ordinal-number PluralFormat
|
||||
* with the same style parts sequence and semantics as UMSGPAT_ARG_TYPE_PLURAL.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
UMSGPAT_ARG_TYPE_SELECTORDINAL
|
||||
};
|
||||
/**
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
typedef enum UMessagePatternArgType UMessagePatternArgType;
|
||||
|
||||
/**
|
||||
* \def UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE
|
||||
* Returns TRUE if the argument type has a plural style part sequence and semantics,
|
||||
* for example UMSGPAT_ARG_TYPE_PLURAL and UMSGPAT_ARG_TYPE_SELECTORDINAL.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
#define UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) \
|
||||
((argType)==UMSGPAT_ARG_TYPE_PLURAL || (argType)==UMSGPAT_ARG_TYPE_SELECTORDINAL)
|
||||
|
||||
enum {
|
||||
/**
|
||||
* Return value from MessagePattern.validateArgumentName() for when
|
||||
* the string is a valid "pattern identifier" but not a number.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_NAME_NOT_NUMBER=-1,
|
||||
|
||||
/**
|
||||
* Return value from MessagePattern.validateArgumentName() for when
|
||||
* the string is invalid.
|
||||
* It might not be a valid "pattern identifier",
|
||||
* or it have only ASCII digits but there is a leading zero or the number is too large.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMSGPAT_ARG_NAME_NOT_VALID=-2
|
||||
};
|
||||
|
||||
/**
|
||||
* Special value that is returned by getNumericValue(Part) when no
|
||||
* numeric value is defined for a part.
|
||||
* @see MessagePattern.getNumericValue()
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
#define UMSGPAT_NO_NUMERIC_VALUE ((double)(-123456789))
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class MessagePatternDoubleList;
|
||||
class MessagePatternPartsList;
|
||||
|
||||
/**
|
||||
* Parses and represents ICU MessageFormat patterns.
|
||||
* Also handles patterns for ChoiceFormat, PluralFormat and SelectFormat.
|
||||
* Used in the implementations of those classes as well as in tools
|
||||
* for message validation, translation and format conversion.
|
||||
* <p>
|
||||
* The parser handles all syntax relevant for identifying message arguments.
|
||||
* This includes "complex" arguments whose style strings contain
|
||||
* nested MessageFormat pattern substrings.
|
||||
* For "simple" arguments (with no nested MessageFormat pattern substrings),
|
||||
* the argument style is not parsed any further.
|
||||
* <p>
|
||||
* The parser handles named and numbered message arguments and allows both in one message.
|
||||
* <p>
|
||||
* Once a pattern has been parsed successfully, iterate through the parsed data
|
||||
* with countParts(), getPart() and related methods.
|
||||
* <p>
|
||||
* The data logically represents a parse tree, but is stored and accessed
|
||||
* as a list of "parts" for fast and simple parsing and to minimize object allocations.
|
||||
* Arguments and nested messages are best handled via recursion.
|
||||
* For every _START "part", MessagePattern.getLimitPartIndex() efficiently returns
|
||||
* the index of the corresponding _LIMIT "part".
|
||||
* <p>
|
||||
* List of "parts":
|
||||
* <pre>
|
||||
* message = MSG_START (SKIP_SYNTAX | INSERT_CHAR | REPLACE_NUMBER | argument)* MSG_LIMIT
|
||||
* argument = noneArg | simpleArg | complexArg
|
||||
* complexArg = choiceArg | pluralArg | selectArg
|
||||
*
|
||||
* noneArg = ARG_START.NONE (ARG_NAME | ARG_NUMBER) ARG_LIMIT.NONE
|
||||
* simpleArg = ARG_START.SIMPLE (ARG_NAME | ARG_NUMBER) ARG_TYPE [ARG_STYLE] ARG_LIMIT.SIMPLE
|
||||
* choiceArg = ARG_START.CHOICE (ARG_NAME | ARG_NUMBER) choiceStyle ARG_LIMIT.CHOICE
|
||||
* pluralArg = ARG_START.PLURAL (ARG_NAME | ARG_NUMBER) pluralStyle ARG_LIMIT.PLURAL
|
||||
* selectArg = ARG_START.SELECT (ARG_NAME | ARG_NUMBER) selectStyle ARG_LIMIT.SELECT
|
||||
*
|
||||
* choiceStyle = ((ARG_INT | ARG_DOUBLE) ARG_SELECTOR message)+
|
||||
* pluralStyle = [ARG_INT | ARG_DOUBLE] (ARG_SELECTOR [ARG_INT | ARG_DOUBLE] message)+
|
||||
* selectStyle = (ARG_SELECTOR message)+
|
||||
* </pre>
|
||||
* <ul>
|
||||
* <li>Literal output text is not represented directly by "parts" but accessed
|
||||
* between parts of a message, from one part's getLimit() to the next part's getIndex().
|
||||
* <li><code>ARG_START.CHOICE</code> stands for an ARG_START Part with ArgType CHOICE.
|
||||
* <li>In the choiceStyle, the ARG_SELECTOR has the '<', the '#' or
|
||||
* the less-than-or-equal-to sign (U+2264).
|
||||
* <li>In the pluralStyle, the first, optional numeric Part has the "offset:" value.
|
||||
* The optional numeric Part between each (ARG_SELECTOR, message) pair
|
||||
* is the value of an explicit-number selector like "=2",
|
||||
* otherwise the selector is a non-numeric identifier.
|
||||
* <li>The REPLACE_NUMBER Part can occur only in an immediate sub-message of the pluralStyle.
|
||||
* </ul>
|
||||
* <p>
|
||||
* This class is not intended for public subclassing.
|
||||
*
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API MessagePattern : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty MessagePattern with default UMessagePatternApostropheMode.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Constructs an empty MessagePattern.
|
||||
* @param mode Explicit UMessagePatternApostropheMode.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern(UMessagePatternApostropheMode mode, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Constructs a MessagePattern with default UMessagePatternApostropheMode and
|
||||
* parses the MessageFormat pattern string.
|
||||
* @param pattern a MessageFormat pattern string
|
||||
* @param parseError Struct to receive information on the position
|
||||
* of an error within the pattern.
|
||||
* Can be NULL.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* TODO: turn @throws into UErrorCode specifics?
|
||||
* @throws IllegalArgumentException for syntax errors in the pattern string
|
||||
* @throws IndexOutOfBoundsException if certain limits are exceeded
|
||||
* (e.g., argument number too high, argument name too long, etc.)
|
||||
* @throws NumberFormatException if a number could not be parsed
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other Object to copy.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern(const MessagePattern &other);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @param other Object to copy.
|
||||
* @return *this=other
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern &operator=(const MessagePattern &other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual ~MessagePattern();
|
||||
|
||||
/**
|
||||
* Parses a MessageFormat pattern string.
|
||||
* @param pattern a MessageFormat pattern string
|
||||
* @param parseError Struct to receive information on the position
|
||||
* of an error within the pattern.
|
||||
* Can be NULL.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @throws IllegalArgumentException for syntax errors in the pattern string
|
||||
* @throws IndexOutOfBoundsException if certain limits are exceeded
|
||||
* (e.g., argument number too high, argument name too long, etc.)
|
||||
* @throws NumberFormatException if a number could not be parsed
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern &parse(const UnicodeString &pattern,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Parses a ChoiceFormat pattern string.
|
||||
* @param pattern a ChoiceFormat pattern string
|
||||
* @param parseError Struct to receive information on the position
|
||||
* of an error within the pattern.
|
||||
* Can be NULL.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @throws IllegalArgumentException for syntax errors in the pattern string
|
||||
* @throws IndexOutOfBoundsException if certain limits are exceeded
|
||||
* (e.g., argument number too high, argument name too long, etc.)
|
||||
* @throws NumberFormatException if a number could not be parsed
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern &parseChoiceStyle(const UnicodeString &pattern,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Parses a PluralFormat pattern string.
|
||||
* @param pattern a PluralFormat pattern string
|
||||
* @param parseError Struct to receive information on the position
|
||||
* of an error within the pattern.
|
||||
* Can be NULL.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @throws IllegalArgumentException for syntax errors in the pattern string
|
||||
* @throws IndexOutOfBoundsException if certain limits are exceeded
|
||||
* (e.g., argument number too high, argument name too long, etc.)
|
||||
* @throws NumberFormatException if a number could not be parsed
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern &parsePluralStyle(const UnicodeString &pattern,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Parses a SelectFormat pattern string.
|
||||
* @param pattern a SelectFormat pattern string
|
||||
* @param parseError Struct to receive information on the position
|
||||
* of an error within the pattern.
|
||||
* Can be NULL.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @throws IllegalArgumentException for syntax errors in the pattern string
|
||||
* @throws IndexOutOfBoundsException if certain limits are exceeded
|
||||
* (e.g., argument number too high, argument name too long, etc.)
|
||||
* @throws NumberFormatException if a number could not be parsed
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
MessagePattern &parseSelectStyle(const UnicodeString &pattern,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Clears this MessagePattern.
|
||||
* countParts() will return 0.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Clears this MessagePattern and sets the UMessagePatternApostropheMode.
|
||||
* countParts() will return 0.
|
||||
* @param mode The new UMessagePatternApostropheMode.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
void clearPatternAndSetApostropheMode(UMessagePatternApostropheMode mode) {
|
||||
clear();
|
||||
aposMode=mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other another object to compare with.
|
||||
* @return TRUE if this object is equivalent to the other one.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool operator==(const MessagePattern &other) const;
|
||||
|
||||
/**
|
||||
* @param other another object to compare with.
|
||||
* @return FALSE if this object is equivalent to the other one.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
inline UBool operator!=(const MessagePattern &other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A hash code for this object.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t hashCode() const;
|
||||
|
||||
/**
|
||||
* @return this instance's UMessagePatternApostropheMode.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMessagePatternApostropheMode getApostropheMode() const {
|
||||
return aposMode;
|
||||
}
|
||||
|
||||
// Java has package-private jdkAposMode() here.
|
||||
// In C++, this is declared in the MessageImpl class.
|
||||
|
||||
/**
|
||||
* @return the parsed pattern string (null if none was parsed).
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const UnicodeString &getPatternString() const {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the parsed pattern have named arguments like {first_name}?
|
||||
* @return TRUE if the parsed pattern has at least one named argument.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool hasNamedArguments() const {
|
||||
return hasArgNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the parsed pattern have numbered arguments like {2}?
|
||||
* @return TRUE if the parsed pattern has at least one numbered argument.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool hasNumberedArguments() const {
|
||||
return hasArgNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and parses an argument name or argument number string.
|
||||
* An argument name must be a "pattern identifier", that is, it must contain
|
||||
* no Unicode Pattern_Syntax or Pattern_White_Space characters.
|
||||
* If it only contains ASCII digits, then it must be a small integer with no leading zero.
|
||||
* @param name Input string.
|
||||
* @return >=0 if the name is a valid number,
|
||||
* ARG_NAME_NOT_NUMBER (-1) if it is a "pattern identifier" but not all ASCII digits,
|
||||
* ARG_NAME_NOT_VALID (-2) if it is neither.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
static int32_t validateArgumentName(const UnicodeString &name);
|
||||
|
||||
/**
|
||||
* Returns a version of the parsed pattern string where each ASCII apostrophe
|
||||
* is doubled (escaped) if it is not already, and if it is not interpreted as quoting syntax.
|
||||
* <p>
|
||||
* For example, this turns "I don't '{know}' {gender,select,female{h''er}other{h'im}}."
|
||||
* into "I don''t '{know}' {gender,select,female{h''er}other{h''im}}."
|
||||
* @return the deep-auto-quoted version of the parsed pattern string.
|
||||
* @see MessageFormat.autoQuoteApostrophe()
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UnicodeString autoQuoteApostropheDeep() const;
|
||||
|
||||
class Part;
|
||||
|
||||
/**
|
||||
* Returns the number of "parts" created by parsing the pattern string.
|
||||
* Returns 0 if no pattern has been parsed or clear() was called.
|
||||
* @return the number of pattern parts.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t countParts() const {
|
||||
return partsLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the i-th pattern "part".
|
||||
* @param i The index of the Part data. (0..countParts()-1)
|
||||
* @return the i-th pattern "part".
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const Part &getPart(int32_t i) const {
|
||||
return parts[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UMessagePatternPartType of the i-th pattern "part".
|
||||
* Convenience method for getPart(i).getType().
|
||||
* @param i The index of the Part data. (0..countParts()-1)
|
||||
* @return The UMessagePatternPartType of the i-th Part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMessagePatternPartType getPartType(int32_t i) const {
|
||||
return getPart(i).type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern index of the specified pattern "part".
|
||||
* Convenience method for getPart(partIndex).getIndex().
|
||||
* @param partIndex The index of the Part data. (0..countParts()-1)
|
||||
* @return The pattern index of this Part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getPatternIndex(int32_t partIndex) const {
|
||||
return getPart(partIndex).index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the substring of the pattern string indicated by the Part.
|
||||
* Convenience method for getPatternString().substring(part.getIndex(), part.getLimit()).
|
||||
* @param part a part of this MessagePattern.
|
||||
* @return the substring associated with part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UnicodeString getSubstring(const Part &part) const {
|
||||
return msg.tempSubString(part.index, part.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the part's substring with the input string s.
|
||||
* @param part a part of this MessagePattern.
|
||||
* @param s a string.
|
||||
* @return TRUE if getSubstring(part).equals(s).
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool partSubstringMatches(const Part &part, const UnicodeString &s) const {
|
||||
return 0==msg.compare(part.index, part.length, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric value associated with an ARG_INT or ARG_DOUBLE.
|
||||
* @param part a part of this MessagePattern.
|
||||
* @return the part's numeric value, or UMSGPAT_NO_NUMERIC_VALUE if this is not a numeric part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
double getNumericValue(const Part &part) const;
|
||||
|
||||
/**
|
||||
* Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified.
|
||||
* @param pluralStart the index of the first PluralFormat argument style part. (0..countParts()-1)
|
||||
* @return the "offset:" value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
double getPluralOffset(int32_t pluralStart) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the ARG|MSG_LIMIT part corresponding to the ARG|MSG_START at start.
|
||||
* @param start The index of some Part data (0..countParts()-1);
|
||||
* this Part should be of Type ARG_START or MSG_START.
|
||||
* @return The first i>start where getPart(i).getType()==ARG|MSG_LIMIT at the same nesting level,
|
||||
* or start itself if getPartType(msgStart)!=ARG|MSG_START.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getLimitPartIndex(int32_t start) const {
|
||||
int32_t limit=getPart(start).limitPartIndex;
|
||||
if(limit<start) {
|
||||
return start;
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* A message pattern "part", representing a pattern parsing event.
|
||||
* There is a part for the start and end of a message or argument,
|
||||
* for quoting and escaping of and with ASCII apostrophes,
|
||||
* and for syntax elements of "complex" arguments.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
class Part : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Default constructor, do not use.
|
||||
* @internal
|
||||
*/
|
||||
Part() {}
|
||||
|
||||
/**
|
||||
* Returns the type of this part.
|
||||
* @return the part type.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMessagePatternPartType getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern string index associated with this Part.
|
||||
* @return this part's pattern string index.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getIndex() const {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the pattern substring associated with this Part.
|
||||
* This is 0 for some parts.
|
||||
* @return this part's pattern substring length.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getLength() const {
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern string limit (exclusive-end) index associated with this Part.
|
||||
* Convenience method for getIndex()+getLength().
|
||||
* @return this part's pattern string limit index, same as getIndex()+getLength().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getLimit() const {
|
||||
return index+length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value associated with this part.
|
||||
* See the documentation of each part type for details.
|
||||
* @return the part value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument type if this part is of type ARG_START or ARG_LIMIT,
|
||||
* otherwise UMSGPAT_ARG_TYPE_NONE.
|
||||
* @return the argument type for this part.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UMessagePatternArgType getArgType() const {
|
||||
UMessagePatternPartType type=getType();
|
||||
if(type==UMSGPAT_PART_TYPE_ARG_START || type==UMSGPAT_PART_TYPE_ARG_LIMIT) {
|
||||
return (UMessagePatternArgType)value;
|
||||
} else {
|
||||
return UMSGPAT_ARG_TYPE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the Part type has a numeric value.
|
||||
* If so, then that numeric value can be retrieved via MessagePattern.getNumericValue().
|
||||
* @param type The Part type to be tested.
|
||||
* @return TRUE if the Part type has a numeric value.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
static UBool hasNumericValue(UMessagePatternPartType type) {
|
||||
return type==UMSGPAT_PART_TYPE_ARG_INT || type==UMSGPAT_PART_TYPE_ARG_DOUBLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other another object to compare with.
|
||||
* @return TRUE if this object is equivalent to the other one.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
UBool operator==(const Part &other) const;
|
||||
|
||||
/**
|
||||
* @param other another object to compare with.
|
||||
* @return FALSE if this object is equivalent to the other one.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
inline UBool operator!=(const Part &other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A hash code for this object.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t hashCode() const {
|
||||
return ((type*37+index)*37+length)*37+value;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class MessagePattern;
|
||||
|
||||
static const int32_t MAX_LENGTH=0xffff;
|
||||
static const int32_t MAX_VALUE=0x7fff;
|
||||
|
||||
// Some fields are not final because they are modified during pattern parsing.
|
||||
// After pattern parsing, the parts are effectively immutable.
|
||||
UMessagePatternPartType type;
|
||||
int32_t index;
|
||||
uint16_t length;
|
||||
int16_t value;
|
||||
int32_t limitPartIndex;
|
||||
};
|
||||
|
||||
private:
|
||||
void preParse(const UnicodeString &pattern, UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
void postParse();
|
||||
|
||||
int32_t parseMessage(int32_t index, int32_t msgStartLength,
|
||||
int32_t nestingLevel, UMessagePatternArgType parentType,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
int32_t parseArg(int32_t index, int32_t argStartLength, int32_t nestingLevel,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
int32_t parseSimpleStyle(int32_t index, UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
int32_t parseChoiceStyle(int32_t index, int32_t nestingLevel,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
int32_t parsePluralOrSelectStyle(UMessagePatternArgType argType, int32_t index, int32_t nestingLevel,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Validates and parses an argument name or argument number string.
|
||||
* This internal method assumes that the input substring is a "pattern identifier".
|
||||
* @return >=0 if the name is a valid number,
|
||||
* ARG_NAME_NOT_NUMBER (-1) if it is a "pattern identifier" but not all ASCII digits,
|
||||
* ARG_NAME_NOT_VALID (-2) if it is neither.
|
||||
* @see #validateArgumentName(String)
|
||||
*/
|
||||
static int32_t parseArgNumber(const UnicodeString &s, int32_t start, int32_t limit);
|
||||
|
||||
int32_t parseArgNumber(int32_t start, int32_t limit) {
|
||||
return parseArgNumber(msg, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a number from the specified message substring.
|
||||
* @param start start index into the message string
|
||||
* @param limit limit index into the message string, must be start<limit
|
||||
* @param allowInfinity TRUE if U+221E is allowed (for ChoiceFormat)
|
||||
* @param parseError
|
||||
* @param errorCode
|
||||
*/
|
||||
void parseDouble(int32_t start, int32_t limit, UBool allowInfinity,
|
||||
UParseError *parseError, UErrorCode &errorCode);
|
||||
|
||||
// Java has package-private appendReducedApostrophes() here.
|
||||
// In C++, this is declared in the MessageImpl class.
|
||||
|
||||
int32_t skipWhiteSpace(int32_t index);
|
||||
|
||||
int32_t skipIdentifier(int32_t index);
|
||||
|
||||
/**
|
||||
* Skips a sequence of characters that could occur in a double value.
|
||||
* Does not fully parse or validate the value.
|
||||
*/
|
||||
int32_t skipDouble(int32_t index);
|
||||
|
||||
static UBool isArgTypeChar(UChar32 c);
|
||||
|
||||
UBool isChoice(int32_t index);
|
||||
|
||||
UBool isPlural(int32_t index);
|
||||
|
||||
UBool isSelect(int32_t index);
|
||||
|
||||
UBool isOrdinal(int32_t index);
|
||||
|
||||
/**
|
||||
* @return TRUE if we are inside a MessageFormat (sub-)pattern,
|
||||
* as opposed to inside a top-level choice/plural/select pattern.
|
||||
*/
|
||||
UBool inMessageFormatPattern(int32_t nestingLevel);
|
||||
|
||||
/**
|
||||
* @return TRUE if we are in a MessageFormat sub-pattern
|
||||
* of a top-level ChoiceFormat pattern.
|
||||
*/
|
||||
UBool inTopLevelChoiceMessage(int32_t nestingLevel, UMessagePatternArgType parentType);
|
||||
|
||||
void addPart(UMessagePatternPartType type, int32_t index, int32_t length,
|
||||
int32_t value, UErrorCode &errorCode);
|
||||
|
||||
void addLimitPart(int32_t start,
|
||||
UMessagePatternPartType type, int32_t index, int32_t length,
|
||||
int32_t value, UErrorCode &errorCode);
|
||||
|
||||
void addArgDoublePart(double numericValue, int32_t start, int32_t length, UErrorCode &errorCode);
|
||||
|
||||
void setParseError(UParseError *parseError, int32_t index);
|
||||
|
||||
UBool init(UErrorCode &errorCode);
|
||||
UBool copyStorage(const MessagePattern &other, UErrorCode &errorCode);
|
||||
|
||||
UMessagePatternApostropheMode aposMode;
|
||||
UnicodeString msg;
|
||||
// ArrayList<Part> parts=new ArrayList<Part>();
|
||||
MessagePatternPartsList *partsList;
|
||||
Part *parts;
|
||||
int32_t partsLength;
|
||||
// ArrayList<Double> numericValues;
|
||||
MessagePatternDoubleList *numericValuesList;
|
||||
double *numericValues;
|
||||
int32_t numericValuesLength;
|
||||
UBool hasArgNames;
|
||||
UBool hasArgNumbers;
|
||||
UBool needsAutoQuoting;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // !UCONFIG_NO_FORMATTING
|
||||
|
||||
#endif // __MESSAGEPATTERN_H__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,658 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: normalizer2.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2009nov22
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __NORMALIZER2_H__
|
||||
#define __NORMALIZER2_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: New API for Unicode Normalization.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
|
||||
#include "unicode/uniset.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/unorm2.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Unicode normalization functionality for standard Unicode normalization or
|
||||
* for using custom mapping tables.
|
||||
* All instances of this class are unmodifiable/immutable.
|
||||
* Instances returned by getInstance() are singletons that must not be deleted by the caller.
|
||||
* The Normalizer2 class is not intended for public subclassing.
|
||||
*
|
||||
* The primary functions are to produce a normalized string and to detect whether
|
||||
* a string is already normalized.
|
||||
* The most commonly used normalization forms are those defined in
|
||||
* http://www.unicode.org/unicode/reports/tr15/
|
||||
* However, this API supports additional normalization forms for specialized purposes.
|
||||
* For example, NFKC_Casefold is provided via getInstance("nfkc_cf", COMPOSE)
|
||||
* and can be used in implementations of UTS #46.
|
||||
*
|
||||
* Not only are the standard compose and decompose modes supplied,
|
||||
* but additional modes are provided as documented in the Mode enum.
|
||||
*
|
||||
* Some of the functions in this class identify normalization boundaries.
|
||||
* At a normalization boundary, the portions of the string
|
||||
* before it and starting from it do not interact and can be handled independently.
|
||||
*
|
||||
* The spanQuickCheckYes() stops at a normalization boundary.
|
||||
* When the goal is a normalized string, then the text before the boundary
|
||||
* can be copied, and the remainder can be processed with normalizeSecondAndAppend().
|
||||
*
|
||||
* The hasBoundaryBefore(), hasBoundaryAfter() and isInert() functions test whether
|
||||
* a character is guaranteed to be at a normalization boundary,
|
||||
* regardless of context.
|
||||
* This is used for moving from one normalization boundary to the next
|
||||
* or preceding boundary, and for performing iterative normalization.
|
||||
*
|
||||
* Iterative normalization is useful when only a small portion of a
|
||||
* longer string needs to be processed.
|
||||
* For example, in ICU, iterative normalization is used by the NormalizationTransliterator
|
||||
* (to avoid replacing already-normalized text) and ucol_nextSortKeyPart()
|
||||
* (to process only the substring for which sort key bytes are computed).
|
||||
*
|
||||
* The set of normalization boundaries returned by these functions may not be
|
||||
* complete: There may be more boundaries that could be returned.
|
||||
* Different functions may return different boundaries.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
class U_COMMON_API Normalizer2 : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~Normalizer2();
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance for Unicode NFC normalization.
|
||||
* Same as getInstance(NULL, "nfc", UNORM2_COMPOSE, errorCode).
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 49
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getNFCInstance(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance for Unicode NFD normalization.
|
||||
* Same as getInstance(NULL, "nfc", UNORM2_DECOMPOSE, errorCode).
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 49
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getNFDInstance(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance for Unicode NFKC normalization.
|
||||
* Same as getInstance(NULL, "nfkc", UNORM2_COMPOSE, errorCode).
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 49
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getNFKCInstance(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance for Unicode NFKD normalization.
|
||||
* Same as getInstance(NULL, "nfkc", UNORM2_DECOMPOSE, errorCode).
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 49
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getNFKDInstance(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance for Unicode NFKC_Casefold normalization.
|
||||
* Same as getInstance(NULL, "nfkc_cf", UNORM2_COMPOSE, errorCode).
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 49
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getNFKCCasefoldInstance(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns a Normalizer2 instance which uses the specified data file
|
||||
* (packageName/name similar to ucnv_openPackage() and ures_open()/ResourceBundle)
|
||||
* and which composes or decomposes text according to the specified mode.
|
||||
* Returns an unmodifiable singleton instance. Do not delete it.
|
||||
*
|
||||
* Use packageName=NULL for data files that are part of ICU's own data.
|
||||
* Use name="nfc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFC/NFD.
|
||||
* Use name="nfkc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFKC/NFKD.
|
||||
* Use name="nfkc_cf" and UNORM2_COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.
|
||||
*
|
||||
* @param packageName NULL for ICU built-in data, otherwise application data package name
|
||||
* @param name "nfc" or "nfkc" or "nfkc_cf" or name of custom data file
|
||||
* @param mode normalization mode (compose or decompose etc.)
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the requested Normalizer2, if successful
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
static const Normalizer2 *
|
||||
getInstance(const char *packageName,
|
||||
const char *name,
|
||||
UNormalization2Mode mode,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Returns the normalized form of the source string.
|
||||
* @param src source string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return normalized src
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
UnicodeString
|
||||
normalize(const UnicodeString &src, UErrorCode &errorCode) const {
|
||||
UnicodeString result;
|
||||
normalize(src, result, errorCode);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Writes the normalized form of the source string to the destination string
|
||||
* (replacing its contents) and returns the destination string.
|
||||
* The source and destination strings must be different objects.
|
||||
* @param src source string
|
||||
* @param dest destination string; its contents is replaced with normalized src
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
normalize(const UnicodeString &src,
|
||||
UnicodeString &dest,
|
||||
UErrorCode &errorCode) const = 0;
|
||||
/**
|
||||
* Appends the normalized form of the second string to the first string
|
||||
* (merging them at the boundary) and returns the first string.
|
||||
* The result is normalized if the first string was normalized.
|
||||
* The first and second strings must be different objects.
|
||||
* @param first string, should be normalized
|
||||
* @param second string, will be normalized
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return first
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
normalizeSecondAndAppend(UnicodeString &first,
|
||||
const UnicodeString &second,
|
||||
UErrorCode &errorCode) const = 0;
|
||||
/**
|
||||
* Appends the second string to the first string
|
||||
* (merging them at the boundary) and returns the first string.
|
||||
* The result is normalized if both the strings were normalized.
|
||||
* The first and second strings must be different objects.
|
||||
* @param first string, should be normalized
|
||||
* @param second string, should be normalized
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return first
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
append(UnicodeString &first,
|
||||
const UnicodeString &second,
|
||||
UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the decomposition mapping of c.
|
||||
* Roughly equivalent to normalizing the String form of c
|
||||
* on a UNORM2_DECOMPOSE Normalizer2 instance, but much faster, and except that this function
|
||||
* returns FALSE and does not write a string
|
||||
* if c does not have a decomposition mapping in this instance's data.
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* @param c code point
|
||||
* @param decomposition String object which will be set to c's
|
||||
* decomposition mapping, if there is one.
|
||||
* @return TRUE if c has a decomposition, otherwise FALSE
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UBool
|
||||
getDecomposition(UChar32 c, UnicodeString &decomposition) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the raw decomposition mapping of c.
|
||||
*
|
||||
* This is similar to the getDecomposition() method but returns the
|
||||
* raw decomposition mapping as specified in UnicodeData.txt or
|
||||
* (for custom data) in the mapping files processed by the gennorm2 tool.
|
||||
* By contrast, getDecomposition() returns the processed,
|
||||
* recursively-decomposed version of this mapping.
|
||||
*
|
||||
* When used on a standard NFKC Normalizer2 instance,
|
||||
* getRawDecomposition() returns the Unicode Decomposition_Mapping (dm) property.
|
||||
*
|
||||
* When used on a standard NFC Normalizer2 instance,
|
||||
* it returns the Decomposition_Mapping only if the Decomposition_Type (dt) is Canonical (Can);
|
||||
* in this case, the result contains either one or two code points (=1..4 UChars).
|
||||
*
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* The default implementation returns FALSE.
|
||||
* @param c code point
|
||||
* @param decomposition String object which will be set to c's
|
||||
* raw decomposition mapping, if there is one.
|
||||
* @return TRUE if c has a decomposition, otherwise FALSE
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual UBool
|
||||
getRawDecomposition(UChar32 c, UnicodeString &decomposition) const;
|
||||
|
||||
/**
|
||||
* Performs pairwise composition of a & b and returns the composite if there is one.
|
||||
*
|
||||
* Returns a composite code point c only if c has a two-way mapping to a+b.
|
||||
* In standard Unicode normalization, this means that
|
||||
* c has a canonical decomposition to a+b
|
||||
* and c does not have the Full_Composition_Exclusion property.
|
||||
*
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* The default implementation returns a negative value.
|
||||
* @param a A (normalization starter) code point.
|
||||
* @param b Another code point.
|
||||
* @return The non-negative composite code point if there is one; otherwise a negative value.
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual UChar32
|
||||
composePair(UChar32 a, UChar32 b) const;
|
||||
|
||||
/**
|
||||
* Gets the combining class of c.
|
||||
* The default implementation returns 0
|
||||
* but all standard implementations return the Unicode Canonical_Combining_Class value.
|
||||
* @param c code point
|
||||
* @return c's combining class
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual uint8_t
|
||||
getCombiningClass(UChar32 c) const;
|
||||
|
||||
/**
|
||||
* Tests if the string is normalized.
|
||||
* Internally, in cases where the quickCheck() method would return "maybe"
|
||||
* (which is only possible for the two COMPOSE modes) this method
|
||||
* resolves to "yes" or "no" to provide a definitive result,
|
||||
* at the cost of doing more work in those cases.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return TRUE if s is normalized
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool
|
||||
isNormalized(const UnicodeString &s, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Tests if the string is normalized.
|
||||
* For the two COMPOSE modes, the result could be "maybe" in cases that
|
||||
* would take a little more work to resolve definitively.
|
||||
* Use spanQuickCheckYes() and normalizeSecondAndAppend() for a faster
|
||||
* combination of quick check + normalization, to avoid
|
||||
* re-checking the "yes" prefix.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return UNormalizationCheckResult
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UNormalizationCheckResult
|
||||
quickCheck(const UnicodeString &s, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the end of the normalized substring of the input string.
|
||||
* In other words, with <code>end=spanQuickCheckYes(s, ec);</code>
|
||||
* the substring <code>UnicodeString(s, 0, end)</code>
|
||||
* will pass the quick check with a "yes" result.
|
||||
*
|
||||
* The returned end index is usually one or more characters before the
|
||||
* "no" or "maybe" character: The end index is at a normalization boundary.
|
||||
* (See the class documentation for more about normalization boundaries.)
|
||||
*
|
||||
* When the goal is a normalized string and most input strings are expected
|
||||
* to be normalized already, then call this method,
|
||||
* and if it returns a prefix shorter than the input string,
|
||||
* copy that prefix and use normalizeSecondAndAppend() for the remainder.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return "yes" span end index
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual int32_t
|
||||
spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Tests if the character always has a normalization boundary before it,
|
||||
* regardless of context.
|
||||
* If true, then the character does not normalization-interact with
|
||||
* preceding characters.
|
||||
* In other words, a string containing this character can be normalized
|
||||
* by processing portions before this character and starting from this
|
||||
* character independently.
|
||||
* This is used for iterative normalization. See the class documentation for details.
|
||||
* @param c character to test
|
||||
* @return TRUE if c has a normalization boundary before it
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool hasBoundaryBefore(UChar32 c) const = 0;
|
||||
|
||||
/**
|
||||
* Tests if the character always has a normalization boundary after it,
|
||||
* regardless of context.
|
||||
* If true, then the character does not normalization-interact with
|
||||
* following characters.
|
||||
* In other words, a string containing this character can be normalized
|
||||
* by processing portions up to this character and after this
|
||||
* character independently.
|
||||
* This is used for iterative normalization. See the class documentation for details.
|
||||
* Note that this operation may be significantly slower than hasBoundaryBefore().
|
||||
* @param c character to test
|
||||
* @return TRUE if c has a normalization boundary after it
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool hasBoundaryAfter(UChar32 c) const = 0;
|
||||
|
||||
/**
|
||||
* Tests if the character is normalization-inert.
|
||||
* If true, then the character does not change, nor normalization-interact with
|
||||
* preceding or following characters.
|
||||
* In other words, a string containing this character can be normalized
|
||||
* by processing portions before this character and after this
|
||||
* character independently.
|
||||
* This is used for iterative normalization. See the class documentation for details.
|
||||
* Note that this operation may be significantly slower than hasBoundaryBefore().
|
||||
* @param c character to test
|
||||
* @return TRUE if c is normalization-inert
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool isInert(UChar32 c) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalization filtered by a UnicodeSet.
|
||||
* Normalizes portions of the text contained in the filter set and leaves
|
||||
* portions not contained in the filter set unchanged.
|
||||
* Filtering is done via UnicodeSet::span(..., USET_SPAN_SIMPLE).
|
||||
* Not-in-the-filter text is treated as "is normalized" and "quick check yes".
|
||||
* This class implements all of (and only) the Normalizer2 API.
|
||||
* An instance of this class is unmodifiable/immutable but is constructed and
|
||||
* must be destructed by the owner.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
class U_COMMON_API FilteredNormalizer2 : public Normalizer2 {
|
||||
public:
|
||||
/**
|
||||
* Constructs a filtered normalizer wrapping any Normalizer2 instance
|
||||
* and a filter set.
|
||||
* Both are aliased and must not be modified or deleted while this object
|
||||
* is used.
|
||||
* The filter set should be frozen; otherwise the performance will suffer greatly.
|
||||
* @param n2 wrapped Normalizer2 instance
|
||||
* @param filterSet UnicodeSet which determines the characters to be normalized
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
FilteredNormalizer2(const Normalizer2 &n2, const UnicodeSet &filterSet) :
|
||||
norm2(n2), set(filterSet) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
~FilteredNormalizer2();
|
||||
|
||||
/**
|
||||
* Writes the normalized form of the source string to the destination string
|
||||
* (replacing its contents) and returns the destination string.
|
||||
* The source and destination strings must be different objects.
|
||||
* @param src source string
|
||||
* @param dest destination string; its contents is replaced with normalized src
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
normalize(const UnicodeString &src,
|
||||
UnicodeString &dest,
|
||||
UErrorCode &errorCode) const;
|
||||
/**
|
||||
* Appends the normalized form of the second string to the first string
|
||||
* (merging them at the boundary) and returns the first string.
|
||||
* The result is normalized if the first string was normalized.
|
||||
* The first and second strings must be different objects.
|
||||
* @param first string, should be normalized
|
||||
* @param second string, will be normalized
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return first
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
normalizeSecondAndAppend(UnicodeString &first,
|
||||
const UnicodeString &second,
|
||||
UErrorCode &errorCode) const;
|
||||
/**
|
||||
* Appends the second string to the first string
|
||||
* (merging them at the boundary) and returns the first string.
|
||||
* The result is normalized if both the strings were normalized.
|
||||
* The first and second strings must be different objects.
|
||||
* @param first string, should be normalized
|
||||
* @param second string, should be normalized
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return first
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
append(UnicodeString &first,
|
||||
const UnicodeString &second,
|
||||
UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Gets the decomposition mapping of c.
|
||||
* For details see the base class documentation.
|
||||
*
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* @param c code point
|
||||
* @param decomposition String object which will be set to c's
|
||||
* decomposition mapping, if there is one.
|
||||
* @return TRUE if c has a decomposition, otherwise FALSE
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
virtual UBool
|
||||
getDecomposition(UChar32 c, UnicodeString &decomposition) const;
|
||||
|
||||
/**
|
||||
* Gets the raw decomposition mapping of c.
|
||||
* For details see the base class documentation.
|
||||
*
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* @param c code point
|
||||
* @param decomposition String object which will be set to c's
|
||||
* raw decomposition mapping, if there is one.
|
||||
* @return TRUE if c has a decomposition, otherwise FALSE
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual UBool
|
||||
getRawDecomposition(UChar32 c, UnicodeString &decomposition) const;
|
||||
|
||||
/**
|
||||
* Performs pairwise composition of a & b and returns the composite if there is one.
|
||||
* For details see the base class documentation.
|
||||
*
|
||||
* This function is independent of the mode of the Normalizer2.
|
||||
* @param a A (normalization starter) code point.
|
||||
* @param b Another code point.
|
||||
* @return The non-negative composite code point if there is one; otherwise a negative value.
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual UChar32
|
||||
composePair(UChar32 a, UChar32 b) const;
|
||||
|
||||
/**
|
||||
* Gets the combining class of c.
|
||||
* The default implementation returns 0
|
||||
* but all standard implementations return the Unicode Canonical_Combining_Class value.
|
||||
* @param c code point
|
||||
* @return c's combining class
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual uint8_t
|
||||
getCombiningClass(UChar32 c) const;
|
||||
|
||||
/**
|
||||
* Tests if the string is normalized.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return TRUE if s is normalized
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool
|
||||
isNormalized(const UnicodeString &s, UErrorCode &errorCode) const;
|
||||
/**
|
||||
* Tests if the string is normalized.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return UNormalizationCheckResult
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UNormalizationCheckResult
|
||||
quickCheck(const UnicodeString &s, UErrorCode &errorCode) const;
|
||||
/**
|
||||
* Returns the end of the normalized substring of the input string.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param s input string
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return "yes" span end index
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual int32_t
|
||||
spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Tests if the character always has a normalization boundary before it,
|
||||
* regardless of context.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param c character to test
|
||||
* @return TRUE if c has a normalization boundary before it
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool hasBoundaryBefore(UChar32 c) const;
|
||||
|
||||
/**
|
||||
* Tests if the character always has a normalization boundary after it,
|
||||
* regardless of context.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param c character to test
|
||||
* @return TRUE if c has a normalization boundary after it
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool hasBoundaryAfter(UChar32 c) const;
|
||||
|
||||
/**
|
||||
* Tests if the character is normalization-inert.
|
||||
* For details see the Normalizer2 base class documentation.
|
||||
* @param c character to test
|
||||
* @return TRUE if c is normalization-inert
|
||||
* @stable ICU 4.4
|
||||
*/
|
||||
virtual UBool isInert(UChar32 c) const;
|
||||
private:
|
||||
UnicodeString &
|
||||
normalize(const UnicodeString &src,
|
||||
UnicodeString &dest,
|
||||
USetSpanCondition spanCondition,
|
||||
UErrorCode &errorCode) const;
|
||||
|
||||
UnicodeString &
|
||||
normalizeSecondAndAppend(UnicodeString &first,
|
||||
const UnicodeString &second,
|
||||
UBool doNormalize,
|
||||
UErrorCode &errorCode) const;
|
||||
|
||||
const Normalizer2 &norm2;
|
||||
const UnicodeSet &set;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // !UCONFIG_NO_NORMALIZATION
|
||||
#endif // __NORMALIZER2_H__
|
||||
@@ -1,797 +0,0 @@
|
||||
/*
|
||||
********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1996-2011, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef NORMLZR_H
|
||||
#define NORMLZR_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Unicode Normalization
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
|
||||
#include "unicode/chariter.h"
|
||||
#include "unicode/normalizer2.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/unorm.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
/**
|
||||
* The Normalizer class supports the standard normalization forms described in
|
||||
* <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
|
||||
* Unicode Standard Annex #15: Unicode Normalization Forms</a>.
|
||||
*
|
||||
* Note: This API has been replaced by the Normalizer2 class and is only available
|
||||
* for backward compatibility. This class simply delegates to the Normalizer2 class.
|
||||
* There is one exception: The new API does not provide a replacement for Normalizer::compare().
|
||||
*
|
||||
* The Normalizer class consists of two parts:
|
||||
* - static functions that normalize strings or test if strings are normalized
|
||||
* - a Normalizer object is an iterator that takes any kind of text and
|
||||
* provides iteration over its normalized form
|
||||
*
|
||||
* The Normalizer class is not suitable for subclassing.
|
||||
*
|
||||
* For basic information about normalization forms and details about the C API
|
||||
* please see the documentation in unorm.h.
|
||||
*
|
||||
* The iterator API with the Normalizer constructors and the non-static functions
|
||||
* use a CharacterIterator as input. It is possible to pass a string which
|
||||
* is then internally wrapped in a CharacterIterator.
|
||||
* The input text is not normalized all at once, but incrementally where needed
|
||||
* (providing efficient random access).
|
||||
* This allows to pass in a large text but spend only a small amount of time
|
||||
* normalizing a small part of that text.
|
||||
* However, if the entire text is normalized, then the iterator will be
|
||||
* slower than normalizing the entire text at once and iterating over the result.
|
||||
* A possible use of the Normalizer iterator is also to report an index into the
|
||||
* original text that is close to where the normalized characters come from.
|
||||
*
|
||||
* <em>Important:</em> The iterator API was cleaned up significantly for ICU 2.0.
|
||||
* The earlier implementation reported the getIndex() inconsistently,
|
||||
* and previous() could not be used after setIndex(), next(), first(), and current().
|
||||
*
|
||||
* Normalizer allows to start normalizing from anywhere in the input text by
|
||||
* calling setIndexOnly(), first(), or last().
|
||||
* Without calling any of these, the iterator will start at the beginning of the text.
|
||||
*
|
||||
* At any time, next() returns the next normalized code point (UChar32),
|
||||
* with post-increment semantics (like CharacterIterator::next32PostInc()).
|
||||
* previous() returns the previous normalized code point (UChar32),
|
||||
* with pre-decrement semantics (like CharacterIterator::previous32()).
|
||||
*
|
||||
* current() returns the current code point
|
||||
* (respectively the one at the newly set index) without moving
|
||||
* the getIndex(). Note that if the text at the current position
|
||||
* needs to be normalized, then these functions will do that.
|
||||
* (This is why current() is not const.)
|
||||
* It is more efficient to call setIndexOnly() instead, which does not
|
||||
* normalize.
|
||||
*
|
||||
* getIndex() always refers to the position in the input text where the normalized
|
||||
* code points are returned from. It does not always change with each returned
|
||||
* code point.
|
||||
* The code point that is returned from any of the functions
|
||||
* corresponds to text at or after getIndex(), according to the
|
||||
* function's iteration semantics (post-increment or pre-decrement).
|
||||
*
|
||||
* next() returns a code point from at or after the getIndex()
|
||||
* from before the next() call. After the next() call, the getIndex()
|
||||
* might have moved to where the next code point will be returned from
|
||||
* (from a next() or current() call).
|
||||
* This is semantically equivalent to array access with array[index++]
|
||||
* (post-increment semantics).
|
||||
*
|
||||
* previous() returns a code point from at or after the getIndex()
|
||||
* from after the previous() call.
|
||||
* This is semantically equivalent to array access with array[--index]
|
||||
* (pre-decrement semantics).
|
||||
*
|
||||
* Internally, the Normalizer iterator normalizes a small piece of text
|
||||
* starting at the getIndex() and ending at a following "safe" index.
|
||||
* The normalized results is stored in an internal string buffer, and
|
||||
* the code points are iterated from there.
|
||||
* With multiple iteration calls, this is repeated until the next piece
|
||||
* of text needs to be normalized, and the getIndex() needs to be moved.
|
||||
*
|
||||
* The following "safe" index, the internal buffer, and the secondary
|
||||
* iteration index into that buffer are not exposed on the API.
|
||||
* This also means that it is currently not practical to return to
|
||||
* a particular, arbitrary position in the text because one would need to
|
||||
* know, and be able to set, in addition to the getIndex(), at least also the
|
||||
* current index into the internal buffer.
|
||||
* It is currently only possible to observe when getIndex() changes
|
||||
* (with careful consideration of the iteration semantics),
|
||||
* at which time the internal index will be 0.
|
||||
* For example, if getIndex() is different after next() than before it,
|
||||
* then the internal index is 0 and one can return to this getIndex()
|
||||
* later with setIndexOnly().
|
||||
*
|
||||
* Note: While the setIndex() and getIndex() refer to indices in the
|
||||
* underlying Unicode input text, the next() and previous() methods
|
||||
* iterate through characters in the normalized output.
|
||||
* This means that there is not necessarily a one-to-one correspondence
|
||||
* between characters returned by next() and previous() and the indices
|
||||
* passed to and returned from setIndex() and getIndex().
|
||||
* It is for this reason that Normalizer does not implement the CharacterIterator interface.
|
||||
*
|
||||
* @author Laura Werner, Mark Davis, Markus Scherer
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API Normalizer : public UObject {
|
||||
public:
|
||||
/**
|
||||
* If DONE is returned from an iteration function that returns a code point,
|
||||
* then there are no more normalization results available.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum {
|
||||
DONE=0xffff
|
||||
};
|
||||
|
||||
// Constructors
|
||||
|
||||
/**
|
||||
* Creates a new <code>Normalizer</code> object for iterating over the
|
||||
* normalized form of a given string.
|
||||
* <p>
|
||||
* @param str The string to be normalized. The normalization
|
||||
* will start at the beginning of the string.
|
||||
*
|
||||
* @param mode The normalization mode.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Normalizer(const UnicodeString& str, UNormalizationMode mode);
|
||||
|
||||
/**
|
||||
* Creates a new <code>Normalizer</code> object for iterating over the
|
||||
* normalized form of a given string.
|
||||
* <p>
|
||||
* @param str The string to be normalized. The normalization
|
||||
* will start at the beginning of the string.
|
||||
*
|
||||
* @param length Length of the string, or -1 if NUL-terminated.
|
||||
* @param mode The normalization mode.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Normalizer(const UChar* str, int32_t length, UNormalizationMode mode);
|
||||
|
||||
/**
|
||||
* Creates a new <code>Normalizer</code> object for iterating over the
|
||||
* normalized form of the given text.
|
||||
* <p>
|
||||
* @param iter The input text to be normalized. The normalization
|
||||
* will start at the beginning of the string.
|
||||
*
|
||||
* @param mode The normalization mode.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Normalizer(const CharacterIterator& iter, UNormalizationMode mode);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param copy The object to be copied.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Normalizer(const Normalizer& copy);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~Normalizer();
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Static utility methods
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Normalizes a <code>UnicodeString</code> according to the specified normalization mode.
|
||||
* This is a wrapper for unorm_normalize(), using UnicodeString's.
|
||||
*
|
||||
* The <code>options</code> parameter specifies which optional
|
||||
* <code>Normalizer</code> features are to be enabled for this operation.
|
||||
*
|
||||
* @param source the input string to be normalized.
|
||||
* @param mode the normalization mode
|
||||
* @param options the optional features to be enabled (0 for no options)
|
||||
* @param result The normalized string (on output).
|
||||
* @param status The error code.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static void U_EXPORT2 normalize(const UnicodeString& source,
|
||||
UNormalizationMode mode, int32_t options,
|
||||
UnicodeString& result,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Compose a <code>UnicodeString</code>.
|
||||
* This is equivalent to normalize() with mode UNORM_NFC or UNORM_NFKC.
|
||||
* This is a wrapper for unorm_normalize(), using UnicodeString's.
|
||||
*
|
||||
* The <code>options</code> parameter specifies which optional
|
||||
* <code>Normalizer</code> features are to be enabled for this operation.
|
||||
*
|
||||
* @param source the string to be composed.
|
||||
* @param compat Perform compatibility decomposition before composition.
|
||||
* If this argument is <code>FALSE</code>, only canonical
|
||||
* decomposition will be performed.
|
||||
* @param options the optional features to be enabled (0 for no options)
|
||||
* @param result The composed string (on output).
|
||||
* @param status The error code.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static void U_EXPORT2 compose(const UnicodeString& source,
|
||||
UBool compat, int32_t options,
|
||||
UnicodeString& result,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Static method to decompose a <code>UnicodeString</code>.
|
||||
* This is equivalent to normalize() with mode UNORM_NFD or UNORM_NFKD.
|
||||
* This is a wrapper for unorm_normalize(), using UnicodeString's.
|
||||
*
|
||||
* The <code>options</code> parameter specifies which optional
|
||||
* <code>Normalizer</code> features are to be enabled for this operation.
|
||||
*
|
||||
* @param source the string to be decomposed.
|
||||
* @param compat Perform compatibility decomposition.
|
||||
* If this argument is <code>FALSE</code>, only canonical
|
||||
* decomposition will be performed.
|
||||
* @param options the optional features to be enabled (0 for no options)
|
||||
* @param result The decomposed string (on output).
|
||||
* @param status The error code.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static void U_EXPORT2 decompose(const UnicodeString& source,
|
||||
UBool compat, int32_t options,
|
||||
UnicodeString& result,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Performing quick check on a string, to quickly determine if the string is
|
||||
* in a particular normalization format.
|
||||
* This is a wrapper for unorm_quickCheck(), using a UnicodeString.
|
||||
*
|
||||
* Three types of result can be returned UNORM_YES, UNORM_NO or
|
||||
* UNORM_MAYBE. Result UNORM_YES indicates that the argument
|
||||
* string is in the desired normalized format, UNORM_NO determines that
|
||||
* argument string is not in the desired normalized format. A
|
||||
* UNORM_MAYBE result indicates that a more thorough check is required,
|
||||
* the user may have to put the string in its normalized form and compare the
|
||||
* results.
|
||||
* @param source string for determining if it is in a normalized format
|
||||
* @param mode normalization format
|
||||
* @param status A reference to a UErrorCode to receive any errors
|
||||
* @return UNORM_YES, UNORM_NO or UNORM_MAYBE
|
||||
*
|
||||
* @see isNormalized
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static inline UNormalizationCheckResult
|
||||
quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Performing quick check on a string; same as the other version of quickCheck
|
||||
* but takes an extra options parameter like most normalization functions.
|
||||
*
|
||||
* @param source string for determining if it is in a normalized format
|
||||
* @param mode normalization format
|
||||
* @param options the optional features to be enabled (0 for no options)
|
||||
* @param status A reference to a UErrorCode to receive any errors
|
||||
* @return UNORM_YES, UNORM_NO or UNORM_MAYBE
|
||||
*
|
||||
* @see isNormalized
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
static UNormalizationCheckResult
|
||||
quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Test if a string is in a given normalization form.
|
||||
* This is semantically equivalent to source.equals(normalize(source, mode)) .
|
||||
*
|
||||
* Unlike unorm_quickCheck(), this function returns a definitive result,
|
||||
* never a "maybe".
|
||||
* For NFD, NFKD, and FCD, both functions work exactly the same.
|
||||
* For NFC and NFKC where quickCheck may return "maybe", this function will
|
||||
* perform further tests to arrive at a TRUE/FALSE result.
|
||||
*
|
||||
* @param src String that is to be tested if it is in a normalization format.
|
||||
* @param mode Which normalization form to test for.
|
||||
* @param errorCode ICU error code in/out parameter.
|
||||
* Must fulfill U_SUCCESS before the function call.
|
||||
* @return Boolean value indicating whether the source string is in the
|
||||
* "mode" normalization form.
|
||||
*
|
||||
* @see quickCheck
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static inline UBool
|
||||
isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Test if a string is in a given normalization form; same as the other version of isNormalized
|
||||
* but takes an extra options parameter like most normalization functions.
|
||||
*
|
||||
* @param src String that is to be tested if it is in a normalization format.
|
||||
* @param mode Which normalization form to test for.
|
||||
* @param options the optional features to be enabled (0 for no options)
|
||||
* @param errorCode ICU error code in/out parameter.
|
||||
* Must fulfill U_SUCCESS before the function call.
|
||||
* @return Boolean value indicating whether the source string is in the
|
||||
* "mode" normalization form.
|
||||
*
|
||||
* @see quickCheck
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
static UBool
|
||||
isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Concatenate normalized strings, making sure that the result is normalized as well.
|
||||
*
|
||||
* If both the left and the right strings are in
|
||||
* the normalization form according to "mode/options",
|
||||
* then the result will be
|
||||
*
|
||||
* \code
|
||||
* dest=normalize(left+right, mode, options)
|
||||
* \endcode
|
||||
*
|
||||
* For details see unorm_concatenate in unorm.h.
|
||||
*
|
||||
* @param left Left source string.
|
||||
* @param right Right source string.
|
||||
* @param result The output string.
|
||||
* @param mode The normalization mode.
|
||||
* @param options A bit set of normalization options.
|
||||
* @param errorCode ICU error code in/out parameter.
|
||||
* Must fulfill U_SUCCESS before the function call.
|
||||
* @return result
|
||||
*
|
||||
* @see unorm_concatenate
|
||||
* @see normalize
|
||||
* @see unorm_next
|
||||
* @see unorm_previous
|
||||
*
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
static UnicodeString &
|
||||
U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right,
|
||||
UnicodeString &result,
|
||||
UNormalizationMode mode, int32_t options,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Compare two strings for canonical equivalence.
|
||||
* Further options include case-insensitive comparison and
|
||||
* code point order (as opposed to code unit order).
|
||||
*
|
||||
* Canonical equivalence between two strings is defined as their normalized
|
||||
* forms (NFD or NFC) being identical.
|
||||
* This function compares strings incrementally instead of normalizing
|
||||
* (and optionally case-folding) both strings entirely,
|
||||
* improving performance significantly.
|
||||
*
|
||||
* Bulk normalization is only necessary if the strings do not fulfill the FCD
|
||||
* conditions. Only in this case, and only if the strings are relatively long,
|
||||
* is memory allocated temporarily.
|
||||
* For FCD strings and short non-FCD strings there is no memory allocation.
|
||||
*
|
||||
* Semantically, this is equivalent to
|
||||
* strcmp[CodePointOrder](NFD(foldCase(s1)), NFD(foldCase(s2)))
|
||||
* where code point order and foldCase are all optional.
|
||||
*
|
||||
* UAX 21 2.5 Caseless Matching specifies that for a canonical caseless match
|
||||
* the case folding must be performed first, then the normalization.
|
||||
*
|
||||
* @param s1 First source string.
|
||||
* @param s2 Second source string.
|
||||
*
|
||||
* @param options A bit set of options:
|
||||
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
|
||||
* Case-sensitive comparison in code unit order, and the input strings
|
||||
* are quick-checked for FCD.
|
||||
*
|
||||
* - UNORM_INPUT_IS_FCD
|
||||
* Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
|
||||
* If not set, the function will quickCheck for FCD
|
||||
* and normalize if necessary.
|
||||
*
|
||||
* - U_COMPARE_CODE_POINT_ORDER
|
||||
* Set to choose code point order instead of code unit order
|
||||
* (see u_strCompare for details).
|
||||
*
|
||||
* - U_COMPARE_IGNORE_CASE
|
||||
* Set to compare strings case-insensitively using case folding,
|
||||
* instead of case-sensitively.
|
||||
* If set, then the following case folding options are used.
|
||||
*
|
||||
* - Options as used with case-insensitive comparisons, currently:
|
||||
*
|
||||
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
|
||||
* (see u_strCaseCompare for details)
|
||||
*
|
||||
* - regular normalization options shifted left by UNORM_COMPARE_NORM_OPTIONS_SHIFT
|
||||
*
|
||||
* @param errorCode ICU error code in/out parameter.
|
||||
* Must fulfill U_SUCCESS before the function call.
|
||||
* @return <0 or 0 or >0 as usual for string comparisons
|
||||
*
|
||||
* @see unorm_compare
|
||||
* @see normalize
|
||||
* @see UNORM_FCD
|
||||
* @see u_strCompare
|
||||
* @see u_strCaseCompare
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static inline int32_t
|
||||
compare(const UnicodeString &s1, const UnicodeString &s2,
|
||||
uint32_t options,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Iteration API
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the current character in the normalized text.
|
||||
* current() may need to normalize some text at getIndex().
|
||||
* The getIndex() is not changed.
|
||||
*
|
||||
* @return the current normalized code point
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar32 current(void);
|
||||
|
||||
/**
|
||||
* Return the first character in the normalized text.
|
||||
* This is equivalent to setIndexOnly(startIndex()) followed by next().
|
||||
* (Post-increment semantics.)
|
||||
*
|
||||
* @return the first normalized code point
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar32 first(void);
|
||||
|
||||
/**
|
||||
* Return the last character in the normalized text.
|
||||
* This is equivalent to setIndexOnly(endIndex()) followed by previous().
|
||||
* (Pre-decrement semantics.)
|
||||
*
|
||||
* @return the last normalized code point
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar32 last(void);
|
||||
|
||||
/**
|
||||
* Return the next character in the normalized text.
|
||||
* (Post-increment semantics.)
|
||||
* If the end of the text has already been reached, DONE is returned.
|
||||
* The DONE value could be confused with a U+FFFF non-character code point
|
||||
* in the text. If this is possible, you can test getIndex()<endIndex()
|
||||
* before calling next(), or (getIndex()<endIndex() || last()!=DONE)
|
||||
* after calling next(). (Calling last() will change the iterator state!)
|
||||
*
|
||||
* The C API unorm_next() is more efficient and does not have this ambiguity.
|
||||
*
|
||||
* @return the next normalized code point
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar32 next(void);
|
||||
|
||||
/**
|
||||
* Return the previous character in the normalized text and decrement.
|
||||
* (Pre-decrement semantics.)
|
||||
* If the beginning of the text has already been reached, DONE is returned.
|
||||
* The DONE value could be confused with a U+FFFF non-character code point
|
||||
* in the text. If this is possible, you can test
|
||||
* (getIndex()>startIndex() || first()!=DONE). (Calling first() will change
|
||||
* the iterator state!)
|
||||
*
|
||||
* The C API unorm_previous() is more efficient and does not have this ambiguity.
|
||||
*
|
||||
* @return the previous normalized code point
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar32 previous(void);
|
||||
|
||||
/**
|
||||
* Set the iteration position in the input text that is being normalized,
|
||||
* without any immediate normalization.
|
||||
* After setIndexOnly(), getIndex() will return the same index that is
|
||||
* specified here.
|
||||
*
|
||||
* @param index the desired index in the input text.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setIndexOnly(int32_t index);
|
||||
|
||||
/**
|
||||
* Reset the index to the beginning of the text.
|
||||
* This is equivalent to setIndexOnly(startIndex)).
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void reset(void);
|
||||
|
||||
/**
|
||||
* Retrieve the current iteration position in the input text that is
|
||||
* being normalized.
|
||||
*
|
||||
* A following call to next() will return a normalized code point from
|
||||
* the input text at or after this index.
|
||||
*
|
||||
* After a call to previous(), getIndex() will point at or before the
|
||||
* position in the input text where the normalized code point
|
||||
* was returned from with previous().
|
||||
*
|
||||
* @return the current index in the input text
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getIndex(void) const;
|
||||
|
||||
/**
|
||||
* Retrieve the index of the start of the input text. This is the begin index
|
||||
* of the <code>CharacterIterator</code> or the start (i.e. index 0) of the string
|
||||
* over which this <code>Normalizer</code> is iterating.
|
||||
*
|
||||
* @return the smallest index in the input text where the Normalizer operates
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t startIndex(void) const;
|
||||
|
||||
/**
|
||||
* Retrieve the index of the end of the input text. This is the end index
|
||||
* of the <code>CharacterIterator</code> or the length of the string
|
||||
* over which this <code>Normalizer</code> is iterating.
|
||||
* This end index is exclusive, i.e., the Normalizer operates only on characters
|
||||
* before this index.
|
||||
*
|
||||
* @return the first index in the input text where the Normalizer does not operate
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t endIndex(void) const;
|
||||
|
||||
/**
|
||||
* Returns TRUE when both iterators refer to the same character in the same
|
||||
* input text.
|
||||
*
|
||||
* @param that a Normalizer object to compare this one to
|
||||
* @return comparison result
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const Normalizer& that) const;
|
||||
|
||||
/**
|
||||
* Returns FALSE when both iterators refer to the same character in the same
|
||||
* input text.
|
||||
*
|
||||
* @param that a Normalizer object to compare this one to
|
||||
* @return comparison result
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
inline UBool operator!=(const Normalizer& that) const;
|
||||
|
||||
/**
|
||||
* Returns a pointer to a new Normalizer that is a clone of this one.
|
||||
* The caller is responsible for deleting the new clone.
|
||||
* @return a pointer to a new Normalizer
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
Normalizer* clone(void) const;
|
||||
|
||||
/**
|
||||
* Generates a hash code for this iterator.
|
||||
*
|
||||
* @return the hash code
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t hashCode(void) const;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Property access methods
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the normalization mode for this object.
|
||||
* <p>
|
||||
* <b>Note:</b>If the normalization mode is changed while iterating
|
||||
* over a string, calls to {@link #next() } and {@link #previous() } may
|
||||
* return previously buffers characters in the old normalization mode
|
||||
* until the iteration is able to re-sync at the next base character.
|
||||
* It is safest to call {@link #setIndexOnly }, {@link #reset() },
|
||||
* {@link #setText }, {@link #first() },
|
||||
* {@link #last() }, etc. after calling <code>setMode</code>.
|
||||
* <p>
|
||||
* @param newMode the new mode for this <code>Normalizer</code>.
|
||||
* @see #getUMode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setMode(UNormalizationMode newMode);
|
||||
|
||||
/**
|
||||
* Return the normalization mode for this object.
|
||||
*
|
||||
* This is an unusual name because there used to be a getMode() that
|
||||
* returned a different type.
|
||||
*
|
||||
* @return the mode for this <code>Normalizer</code>
|
||||
* @see #setMode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UNormalizationMode getUMode(void) const;
|
||||
|
||||
/**
|
||||
* Set options that affect this <code>Normalizer</code>'s operation.
|
||||
* Options do not change the basic composition or decomposition operation
|
||||
* that is being performed, but they control whether
|
||||
* certain optional portions of the operation are done.
|
||||
* Currently the only available option is obsolete.
|
||||
*
|
||||
* It is possible to specify multiple options that are all turned on or off.
|
||||
*
|
||||
* @param option the option(s) whose value is/are to be set.
|
||||
* @param value the new setting for the option. Use <code>TRUE</code> to
|
||||
* turn the option(s) on and <code>FALSE</code> to turn it/them off.
|
||||
*
|
||||
* @see #getOption
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setOption(int32_t option,
|
||||
UBool value);
|
||||
|
||||
/**
|
||||
* Determine whether an option is turned on or off.
|
||||
* If multiple options are specified, then the result is TRUE if any
|
||||
* of them are set.
|
||||
* <p>
|
||||
* @param option the option(s) that are to be checked
|
||||
* @return TRUE if any of the option(s) are set
|
||||
* @see #setOption
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool getOption(int32_t option) const;
|
||||
|
||||
/**
|
||||
* Set the input text over which this <code>Normalizer</code> will iterate.
|
||||
* The iteration position is set to the beginning.
|
||||
*
|
||||
* @param newText a string that replaces the current input text
|
||||
* @param status a UErrorCode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const UnicodeString& newText,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Set the input text over which this <code>Normalizer</code> will iterate.
|
||||
* The iteration position is set to the beginning.
|
||||
*
|
||||
* @param newText a CharacterIterator object that replaces the current input text
|
||||
* @param status a UErrorCode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const CharacterIterator& newText,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Set the input text over which this <code>Normalizer</code> will iterate.
|
||||
* The iteration position is set to the beginning.
|
||||
*
|
||||
* @param newText a string that replaces the current input text
|
||||
* @param length the length of the string, or -1 if NUL-terminated
|
||||
* @param status a UErrorCode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const UChar* newText,
|
||||
int32_t length,
|
||||
UErrorCode &status);
|
||||
/**
|
||||
* Copies the input text into the UnicodeString argument.
|
||||
*
|
||||
* @param result Receives a copy of the text under iteration.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void getText(UnicodeString& result);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
* @returns a UClassID for this class.
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
* @return a UClassID for the actual class.
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
private:
|
||||
//-------------------------------------------------------------------------
|
||||
// Private functions
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
Normalizer(); // default constructor not implemented
|
||||
Normalizer &operator=(const Normalizer &that); // assignment operator not implemented
|
||||
|
||||
// Private utility methods for iteration
|
||||
// For documentation, see the source code
|
||||
UBool nextNormalize();
|
||||
UBool previousNormalize();
|
||||
|
||||
void init();
|
||||
void clearBuffer(void);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Private data
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
FilteredNormalizer2*fFilteredNorm2; // owned if not NULL
|
||||
const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
|
||||
UNormalizationMode fUMode;
|
||||
int32_t fOptions;
|
||||
|
||||
// The input text and our position in it
|
||||
CharacterIterator *text;
|
||||
|
||||
// The normalization buffer is the result of normalization
|
||||
// of the source in [currentIndex..nextIndex[ .
|
||||
int32_t currentIndex, nextIndex;
|
||||
|
||||
// A buffer for holding intermediate results
|
||||
UnicodeString buffer;
|
||||
int32_t bufferPos;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Inline implementations
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
inline UBool
|
||||
Normalizer::operator!= (const Normalizer& other) const
|
||||
{ return ! operator==(other); }
|
||||
|
||||
inline UNormalizationCheckResult
|
||||
Normalizer::quickCheck(const UnicodeString& source,
|
||||
UNormalizationMode mode,
|
||||
UErrorCode &status) {
|
||||
return quickCheck(source, mode, 0, status);
|
||||
}
|
||||
|
||||
inline UBool
|
||||
Normalizer::isNormalized(const UnicodeString& source,
|
||||
UNormalizationMode mode,
|
||||
UErrorCode &status) {
|
||||
return isNormalized(source, mode, 0, status);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
|
||||
uint32_t options,
|
||||
UErrorCode &errorCode) {
|
||||
// all argument checking is done in unorm_compare
|
||||
return unorm_compare(s1.getBuffer(), s1.length(),
|
||||
s2.getBuffer(), s2.length(),
|
||||
options,
|
||||
&errorCode);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_NORMALIZATION */
|
||||
|
||||
#endif // NORMLZR_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
*
|
||||
* File NUMSYS.H
|
||||
*
|
||||
* Modification History:*
|
||||
* Date Name Description
|
||||
*
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef NUMSYS
|
||||
#define NUMSYS
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \def NUMSYS_NAME_CAPACITY
|
||||
* Size of a numbering system name.
|
||||
* @internal
|
||||
*/
|
||||
#define NUMSYS_NAME_CAPACITY 8
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: NumberingSystem object
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Defines numbering systems. A numbering system describes the scheme by which
|
||||
* numbers are to be presented to the end user. In its simplest form, a numbering
|
||||
* system describes the set of digit characters that are to be used to display
|
||||
* numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
|
||||
* positional numbering system with a specified radix (typically 10).
|
||||
* More complicated numbering systems are algorithmic in nature, and require use
|
||||
* of an RBNF formatter ( rule based number formatter ), in order to calculate
|
||||
* the characters to be displayed for a given number. Examples of algorithmic
|
||||
* numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
|
||||
* Formatting rules for many commonly used numbering systems are included in
|
||||
* the ICU package, based on the numbering system rules defined in CLDR.
|
||||
* Alternate numbering systems can be specified to a locale by using the
|
||||
* numbers locale keyword.
|
||||
*/
|
||||
|
||||
class U_I18N_API NumberingSystem : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
NumberingSystem();
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
NumberingSystem(const NumberingSystem& other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual ~NumberingSystem();
|
||||
|
||||
/**
|
||||
* Create the default numbering system associated with the specified locale.
|
||||
* @param inLocale The given locale.
|
||||
* @param status ICU status
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create the default numbering system associated with the default locale.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a numbering system using the specified radix, type, and description.
|
||||
* @param radix The radix (base) for this numbering system.
|
||||
* @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
|
||||
* @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
|
||||
* ruleset to be used in an algorithmic system.
|
||||
* @param status ICU status
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
|
||||
|
||||
/**
|
||||
* Return a StringEnumeration over all the names of numbering systems known to ICU.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
|
||||
static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a numbering system from one of the predefined numbering systems specified
|
||||
* by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
|
||||
* is returned by unumsys_openAvailableNames. Note that some of the names listed at
|
||||
* http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
|
||||
* default, native, traditional, finance - do not identify specific numbering systems,
|
||||
* but rather key values that may only be used as part of a locale, which in turn
|
||||
* defines how they are mapped to a specific numbering system such as "latn" or "hant".
|
||||
* @param name The name of the numbering system.
|
||||
* @param status ICU status
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the radix of this numbering system. Simple positional numbering systems
|
||||
* typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
|
||||
* radix is less well-defined for non-positional algorithmic systems.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
int32_t getRadix() const;
|
||||
|
||||
/**
|
||||
* Returns the name of this numbering system if it was created using one of the predefined names
|
||||
* known to ICU. Otherwise, returns NULL.
|
||||
* @stable ICU 4.6
|
||||
*/
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Returns the description string of this numbering system. For simple
|
||||
* positional systems this is the ordered string of digits (with length matching
|
||||
* the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
|
||||
* for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
|
||||
* algorithmic systems this is the name of the RBNF ruleset used for formatting,
|
||||
* e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
|
||||
* "grek".
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual UnicodeString getDescription() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE if the given numbering system is algorithmic
|
||||
*
|
||||
* @return TRUE if the numbering system is algorithmic.
|
||||
* Otherwise, return FALSE.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
UBool isAlgorithmic() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
|
||||
private:
|
||||
UnicodeString desc;
|
||||
int32_t radix;
|
||||
UBool algorithmic;
|
||||
char name[NUMSYS_NAME_CAPACITY+1];
|
||||
|
||||
void setRadix(int32_t radix);
|
||||
|
||||
void setAlgorithmic(UBool algorithmic);
|
||||
|
||||
void setDesc(UnicodeString desc);
|
||||
|
||||
void setName(const char* name);
|
||||
|
||||
static UBool isValidDigitString(const UnicodeString &str);
|
||||
|
||||
UBool hasContiguousDecimalDigits() const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _NUMSYS
|
||||
//eof
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1999-2005, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Date Name Description
|
||||
* 03/14/00 aliu Creation.
|
||||
* 06/27/00 aliu Change from C++ class to C struct
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef PARSEERR_H
|
||||
#define PARSEERR_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: Parse Error Information
|
||||
*/
|
||||
/**
|
||||
* The capacity of the context strings in UParseError.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
enum { U_PARSE_CONTEXT_LEN = 16 };
|
||||
|
||||
/**
|
||||
* A UParseError struct is used to returned detailed information about
|
||||
* parsing errors. It is used by ICU parsing engines that parse long
|
||||
* rules, patterns, or programs, where the text being parsed is long
|
||||
* enough that more information than a UErrorCode is needed to
|
||||
* localize the error.
|
||||
*
|
||||
* <p>The line, offset, and context fields are optional; parsing
|
||||
* engines may choose not to use to use them.
|
||||
*
|
||||
* <p>The preContext and postContext strings include some part of the
|
||||
* context surrounding the error. If the source text is "let for=7"
|
||||
* and "for" is the error (e.g., because it is a reserved word), then
|
||||
* some examples of what a parser might produce are the following:
|
||||
*
|
||||
* <pre>
|
||||
* preContext postContext
|
||||
* "" "" The parser does not support context
|
||||
* "let " "=7" Pre- and post-context only
|
||||
* "let " "for=7" Pre- and post-context and error text
|
||||
* "" "for" Error text only
|
||||
* </pre>
|
||||
*
|
||||
* <p>Examples of engines which use UParseError (or may use it in the
|
||||
* future) are Transliterator, RuleBasedBreakIterator, and
|
||||
* RegexPattern.
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
typedef struct UParseError {
|
||||
|
||||
/**
|
||||
* The line on which the error occured. If the parser uses this
|
||||
* field, it sets it to the line number of the source text line on
|
||||
* which the error appears, which will be be a value >= 1. If the
|
||||
* parse does not support line numbers, the value will be <= 0.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t line;
|
||||
|
||||
/**
|
||||
* The character offset to the error. If the line field is >= 1,
|
||||
* then this is the offset from the start of the line. Otherwise,
|
||||
* this is the offset from the start of the text. If the parser
|
||||
* does not support this field, it will have a value < 0.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t offset;
|
||||
|
||||
/**
|
||||
* Textual context before the error. Null-terminated. The empty
|
||||
* string if not supported by parser.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar preContext[U_PARSE_CONTEXT_LEN];
|
||||
|
||||
/**
|
||||
* The error itself and/or textual context after the error.
|
||||
* Null-terminated. The empty string if not supported by parser.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UChar postContext[U_PARSE_CONTEXT_LEN];
|
||||
|
||||
} UParseError;
|
||||
|
||||
#endif
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
* File PARSEPOS.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 07/09/97 helena Converted from java.
|
||||
* 07/17/98 stephen Added errorIndex support.
|
||||
* 05/11/99 stephen Cleaned up.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef PARSEPOS_H
|
||||
#define PARSEPOS_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Canonical Iterator
|
||||
*/
|
||||
/**
|
||||
* <code>ParsePosition</code> is a simple class used by <code>Format</code>
|
||||
* and its subclasses to keep track of the current position during parsing.
|
||||
* The <code>parseObject</code> method in the various <code>Format</code>
|
||||
* classes requires a <code>ParsePosition</code> object as an argument.
|
||||
*
|
||||
* <p>
|
||||
* By design, as you parse through a string with different formats,
|
||||
* you can use the same <code>ParsePosition</code>, since the index parameter
|
||||
* records the current position.
|
||||
*
|
||||
* The ParsePosition class is not suitable for subclassing.
|
||||
*
|
||||
* @version 1.3 10/30/97
|
||||
* @author Mark Davis, Helena Shih
|
||||
* @see java.text.Format
|
||||
*/
|
||||
|
||||
class U_COMMON_API ParsePosition : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Default constructor, the index starts with 0 as default.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ParsePosition()
|
||||
: UObject(),
|
||||
index(0),
|
||||
errorIndex(-1)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Create a new ParsePosition with the given initial index.
|
||||
* @param newIndex the new text offset.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ParsePosition(int32_t newIndex)
|
||||
: UObject(),
|
||||
index(newIndex),
|
||||
errorIndex(-1)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param copy the object to be copied from.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ParsePosition(const ParsePosition& copy)
|
||||
: UObject(copy),
|
||||
index(copy.index),
|
||||
errorIndex(copy.errorIndex)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~ParsePosition();
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ParsePosition& operator=(const ParsePosition& copy);
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @return TRUE if the two parse positions are equal, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator==(const ParsePosition& that) const;
|
||||
|
||||
/**
|
||||
* Equality operator.
|
||||
* @return TRUE if the two parse positions are not equal, FALSE otherwise.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const ParsePosition& that) const;
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If an error occurs, then NULL is returned.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
ParsePosition *clone() const;
|
||||
|
||||
/**
|
||||
* Retrieve the current parse position. On input to a parse method, this
|
||||
* is the index of the character at which parsing will begin; on output, it
|
||||
* is the index of the character following the last character parsed.
|
||||
* @return the current index.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getIndex(void) const;
|
||||
|
||||
/**
|
||||
* Set the current parse position.
|
||||
* @param index the new index.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setIndex(int32_t index);
|
||||
|
||||
/**
|
||||
* Set the index at which a parse error occurred. Formatters
|
||||
* should set this before returning an error code from their
|
||||
* parseObject method. The default value is -1 if this is not
|
||||
* set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setErrorIndex(int32_t ei);
|
||||
|
||||
/**
|
||||
* Retrieve the index at which an error occurred, or -1 if the
|
||||
* error index has not been set.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t getErrorIndex(void) const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Input: the place you start parsing.
|
||||
* <br>Output: position where the parse stopped.
|
||||
* This is designed to be used serially,
|
||||
* with each call setting index up for the next one.
|
||||
*/
|
||||
int32_t index;
|
||||
|
||||
/**
|
||||
* The index at which a parse error occurred.
|
||||
*/
|
||||
int32_t errorIndex;
|
||||
|
||||
};
|
||||
|
||||
inline ParsePosition&
|
||||
ParsePosition::operator=(const ParsePosition& copy)
|
||||
{
|
||||
index = copy.index;
|
||||
errorIndex = copy.errorIndex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline UBool
|
||||
ParsePosition::operator==(const ParsePosition& copy) const
|
||||
{
|
||||
if(index != copy.index || errorIndex != copy.errorIndex)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline UBool
|
||||
ParsePosition::operator!=(const ParsePosition& copy) const
|
||||
{
|
||||
return !operator==(copy);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
ParsePosition::getIndex() const
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
inline void
|
||||
ParsePosition::setIndex(int32_t offset)
|
||||
{
|
||||
this->index = offset;
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
ParsePosition::getErrorIndex() const
|
||||
{
|
||||
return errorIndex;
|
||||
}
|
||||
|
||||
inline void
|
||||
ParsePosition::setErrorIndex(int32_t ei)
|
||||
{
|
||||
this->errorIndex = ei;
|
||||
}
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,755 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* FILE NAME : platform.h
|
||||
*
|
||||
* Date Name Description
|
||||
* 05/13/98 nos Creation (content moved here from ptypes.h).
|
||||
* 03/02/99 stephen Added AS400 support.
|
||||
* 03/30/99 stephen Added Linux support.
|
||||
* 04/13/99 stephen Reworked for autoconf.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _PLATFORM_H
|
||||
#define _PLATFORM_H
|
||||
|
||||
#include "unicode/uconfig.h"
|
||||
#include "unicode/uvernum.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief Basic types for the platform.
|
||||
*
|
||||
* This file used to be generated by autoconf/configure.
|
||||
* Starting with ICU 49, platform.h is a normal source file,
|
||||
* to simplify cross-compiling and working with non-autoconf/make build systems.
|
||||
*
|
||||
* When a value in this file does not work on a platform, then please
|
||||
* try to derive it from the U_PLATFORM value
|
||||
* (for which we might need a new value constant in rare cases)
|
||||
* and/or from other macros that are predefined by the compiler
|
||||
* or defined in standard (POSIX or platform or compiler) headers.
|
||||
*
|
||||
* As a temporary workaround, you can add an explicit <code>#define</code> for some macros
|
||||
* before it is first tested, or add an equivalent -D macro definition
|
||||
* to the compiler's command line.
|
||||
*
|
||||
* Note: Some compilers provide ways to show the predefined macros.
|
||||
* For example, with gcc you can compile an empty .c file and have the compiler
|
||||
* print the predefined macros with
|
||||
* \code
|
||||
* gcc -E -dM -x c /dev/null | sort
|
||||
* \endcode
|
||||
* (You can provide an actual empty .c file rather than /dev/null.
|
||||
* <code>-x c++</code> is for C++.)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define some things so that they can be documented.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_IN_DOXYGEN
|
||||
/*
|
||||
* Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
|
||||
* Solution: #define any defines for non @internal API here, so that they are visible in the docs. If you just set PREDEFINED in Doxyfile.in, they won't be documented.
|
||||
*/
|
||||
|
||||
/* None for now. */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM
|
||||
* The U_PLATFORM macro defines the platform we're on.
|
||||
*
|
||||
* We used to define one different, value-less macro per platform.
|
||||
* That made it hard to know the set of relevant platforms and macros,
|
||||
* and hard to deal with variants of platforms.
|
||||
*
|
||||
* Starting with ICU 49, we define platforms as numeric macros,
|
||||
* with ranges of values for related platforms and their variants.
|
||||
* The U_PLATFORM macro is set to one of these values.
|
||||
*
|
||||
* Historical note from the Solaris Wikipedia article:
|
||||
* AT&T and Sun collaborated on a project to merge the most popular Unix variants
|
||||
* on the market at that time: BSD, System V, and Xenix.
|
||||
* This became Unix System V Release 4 (SVR4).
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
/** Unknown platform. @internal */
|
||||
#define U_PF_UNKNOWN 0
|
||||
/** Windows @internal */
|
||||
#define U_PF_WINDOWS 1000
|
||||
/** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */
|
||||
#define U_PF_MINGW 1800
|
||||
/**
|
||||
* Cygwin. Windows, calls to cygwin1.dll for Posix functions,
|
||||
* using MSVC or GNU gcc and binutils.
|
||||
* @internal
|
||||
*/
|
||||
#define U_PF_CYGWIN 1900
|
||||
/* Reserve 2000 for U_PF_UNIX? */
|
||||
/** HP-UX is based on UNIX System V. @internal */
|
||||
#define U_PF_HPUX 2100
|
||||
/** Solaris is a Unix operating system based on SVR4. @internal */
|
||||
#define U_PF_SOLARIS 2600
|
||||
/** BSD is a UNIX operating system derivative. @internal */
|
||||
#define U_PF_BSD 3000
|
||||
/** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */
|
||||
#define U_PF_AIX 3100
|
||||
/** IRIX is based on UNIX System V with BSD extensions. @internal */
|
||||
#define U_PF_IRIX 3200
|
||||
/**
|
||||
* Darwin is a POSIX-compliant operating system, composed of code developed by Apple,
|
||||
* as well as code derived from NeXTSTEP, BSD, and other projects,
|
||||
* built around the Mach kernel.
|
||||
* Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based.
|
||||
* (Original description modified from WikiPedia.)
|
||||
* @internal
|
||||
*/
|
||||
#define U_PF_DARWIN 3500
|
||||
/** iPhone OS (iOS) is a derivative of Mac OS X. @internal */
|
||||
#define U_PF_IPHONE 3550
|
||||
/** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */
|
||||
#define U_PF_QNX 3700
|
||||
/** Linux is a Unix-like operating system. @internal */
|
||||
#define U_PF_LINUX 4000
|
||||
/** Android is based on Linux. @internal */
|
||||
#define U_PF_ANDROID 4050
|
||||
/** "Classic" Mac OS (1984-2001) @internal */
|
||||
#define U_PF_CLASSIC_MACOS 8000
|
||||
/** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
|
||||
#define U_PF_OS390 9000
|
||||
/** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
|
||||
#define U_PF_OS400 9400
|
||||
|
||||
#ifdef U_PLATFORM
|
||||
/* Use the predefined value. */
|
||||
#elif defined(__MINGW32__)
|
||||
# define U_PLATFORM U_PF_MINGW
|
||||
#elif defined(__CYGWIN__)
|
||||
# define U_PLATFORM U_PF_CYGWIN
|
||||
#elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
# define U_PLATFORM U_PF_WINDOWS
|
||||
#elif defined(__ANDROID__)
|
||||
# define U_PLATFORM U_PF_ANDROID
|
||||
/* Android wchar_t support depends on the API level. */
|
||||
# include <android/api-level.h>
|
||||
#elif defined(linux) || defined(__linux__) || defined(__linux)
|
||||
# define U_PLATFORM U_PF_LINUX
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
# include <TargetConditionals.h>
|
||||
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
|
||||
# define U_PLATFORM U_PF_IPHONE
|
||||
# else
|
||||
# define U_PLATFORM U_PF_DARWIN
|
||||
# endif
|
||||
#elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
|
||||
# define U_PLATFORM U_PF_BSD
|
||||
#elif defined(sun) || defined(__sun)
|
||||
/* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
|
||||
# define U_PLATFORM U_PF_SOLARIS
|
||||
# if defined(__GNUC__)
|
||||
/* Solaris/GCC needs this header file to get the proper endianness. Normally, this
|
||||
* header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
|
||||
* is included which does not include this header file.
|
||||
*/
|
||||
# include <sys/isa_defs.h>
|
||||
# endif
|
||||
#elif defined(_AIX) || defined(__TOS_AIX__)
|
||||
# define U_PLATFORM U_PF_AIX
|
||||
#elif defined(_hpux) || defined(hpux) || defined(__hpux)
|
||||
# define U_PLATFORM U_PF_HPUX
|
||||
#elif defined(sgi) || defined(__sgi)
|
||||
# define U_PLATFORM U_PF_IRIX
|
||||
#elif defined(macintosh)
|
||||
# define U_PLATFORM U_PF_CLASSIC_MACOS
|
||||
#elif defined(__QNX__) || defined(__QNXNTO__)
|
||||
# define U_PLATFORM U_PF_QNX
|
||||
#elif defined(__TOS_MVS__)
|
||||
# define U_PLATFORM U_PF_OS390
|
||||
#elif defined(__OS400__) || defined(__TOS_OS400__)
|
||||
# define U_PLATFORM U_PF_OS400
|
||||
#else
|
||||
# define U_PLATFORM U_PF_UNKNOWN
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def CYGWINMSVC
|
||||
* Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
|
||||
* Otherwise undefined.
|
||||
* @internal
|
||||
*/
|
||||
/* Commented out because this is already set in mh-cygwin-msvc
|
||||
#if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
|
||||
# define CYGWINMSVC
|
||||
#endif
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM_USES_ONLY_WIN32_API
|
||||
* Defines whether the platform uses only the Win32 API.
|
||||
* Set to 1 for Windows/MSVC and MinGW but not Cygwin.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_PLATFORM_USES_ONLY_WIN32_API
|
||||
/* Use the predefined value. */
|
||||
#elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
|
||||
# define U_PLATFORM_USES_ONLY_WIN32_API 1
|
||||
#else
|
||||
/* Cygwin implements POSIX. */
|
||||
# define U_PLATFORM_USES_ONLY_WIN32_API 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM_HAS_WIN32_API
|
||||
* Defines whether the Win32 API is available on the platform.
|
||||
* Set to 1 for Windows/MSVC, MinGW and Cygwin.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_PLATFORM_HAS_WIN32_API
|
||||
/* Use the predefined value. */
|
||||
#elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
|
||||
# define U_PLATFORM_HAS_WIN32_API 1
|
||||
#else
|
||||
# define U_PLATFORM_HAS_WIN32_API 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM_IMPLEMENTS_POSIX
|
||||
* Defines whether the platform implements (most of) the POSIX API.
|
||||
* Set to 1 for Cygwin and most other platforms.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_PLATFORM_IMPLEMENTS_POSIX
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS
|
||||
# define U_PLATFORM_IMPLEMENTS_POSIX 0
|
||||
#else
|
||||
# define U_PLATFORM_IMPLEMENTS_POSIX 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM_IS_LINUX_BASED
|
||||
* Defines whether the platform is Linux or one of its derivatives.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_PLATFORM_IS_LINUX_BASED
|
||||
/* Use the predefined value. */
|
||||
#elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= U_PF_ANDROID
|
||||
# define U_PLATFORM_IS_LINUX_BASED 1
|
||||
#else
|
||||
# define U_PLATFORM_IS_LINUX_BASED 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_PLATFORM_IS_DARWIN_BASED
|
||||
* Defines whether the platform is Darwin or one of its derivatives.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_PLATFORM_IS_DARWIN_BASED
|
||||
/* Use the predefined value. */
|
||||
#elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
|
||||
# define U_PLATFORM_IS_DARWIN_BASED 1
|
||||
#else
|
||||
# define U_PLATFORM_IS_DARWIN_BASED 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_HAVE_STDINT_H
|
||||
* Defines whether stdint.h is available. It is a C99 standard header.
|
||||
* We used to include inttypes.h which includes stdint.h but we usually do not need
|
||||
* the additional definitions from inttypes.h.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_HAVE_STDINT_H
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
||||
# if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600)
|
||||
/* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
|
||||
# define U_HAVE_STDINT_H 1
|
||||
# else
|
||||
# define U_HAVE_STDINT_H 0
|
||||
# endif
|
||||
#elif U_PLATFORM == U_PF_SOLARIS
|
||||
/* Solaris has inttypes.h but not stdint.h. */
|
||||
# define U_HAVE_STDINT_H 0
|
||||
#elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
|
||||
/* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
|
||||
# define U_HAVE_STDINT_H 0
|
||||
#else
|
||||
# define U_HAVE_STDINT_H 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_HAVE_INTTYPES_H
|
||||
* Defines whether inttypes.h is available. It is a C99 standard header.
|
||||
* We include inttypes.h where it is available but stdint.h is not.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_HAVE_INTTYPES_H
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM == U_PF_SOLARIS
|
||||
/* Solaris has inttypes.h but not stdint.h. */
|
||||
# define U_HAVE_INTTYPES_H 1
|
||||
#elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
|
||||
/* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
|
||||
# define U_HAVE_INTTYPES_H 1
|
||||
#else
|
||||
/* Most platforms have both inttypes.h and stdint.h, or neither. */
|
||||
# define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_IOSTREAM_SOURCE
|
||||
* Defines what support for C++ streams is available.
|
||||
*
|
||||
* If U_IOSTREAM_SOURCE is set to 199711, then <iostream> is available
|
||||
* (the ISO/IEC C++ FDIS was published in November 1997), and then
|
||||
* one should qualify streams using the std namespace in ICU header
|
||||
* files.
|
||||
* Starting with ICU 49, this is the only supported version.
|
||||
*
|
||||
* If U_IOSTREAM_SOURCE is set to 198506, then <iostream.h> is
|
||||
* available instead (in June 1985 Stroustrup published
|
||||
* "An Extensible I/O Facility for C++" at the summer USENIX conference).
|
||||
* Starting with ICU 49, this version is not supported any more.
|
||||
*
|
||||
* If U_IOSTREAM_SOURCE is 0 (or any value less than 199711),
|
||||
* then C++ streams are not available and
|
||||
* support for them will be silently suppressed in ICU.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#ifndef U_IOSTREAM_SOURCE
|
||||
#define U_IOSTREAM_SOURCE 199711
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_HAVE_STD_STRING
|
||||
* Defines whether the standard C++ (STL) <string> header is available.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_HAVE_STD_STRING
|
||||
/* Use the predefined value. */
|
||||
#else
|
||||
# define U_HAVE_STD_STRING 1
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/** @{ Compiler and environment features */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* \def U_GCC_MAJOR_MINOR
|
||||
* Indicates whether the compiler is gcc (test for != 0),
|
||||
* and if so, contains its major (times 100) and minor version numbers.
|
||||
* If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0.
|
||||
*
|
||||
* For example, for testing for whether we have gcc, and whether it's 4.6 or higher,
|
||||
* use "#if U_GCC_MAJOR_MINOR >= 406".
|
||||
* @internal
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
# define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
#else
|
||||
# define U_GCC_MAJOR_MINOR 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_IS_BIG_ENDIAN
|
||||
* Determines the endianness of the platform.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_IS_BIG_ENDIAN
|
||||
/* Use the predefined value. */
|
||||
#elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
|
||||
# define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
|
||||
/* gcc */
|
||||
# define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
#elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
|
||||
# define U_IS_BIG_ENDIAN 1
|
||||
#elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
|
||||
# define U_IS_BIG_ENDIAN 0
|
||||
#elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
|
||||
/* These platforms do not appear to predefine any endianness macros. */
|
||||
# define U_IS_BIG_ENDIAN 1
|
||||
#elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
|
||||
/* HPPA do not appear to predefine any endianness macros. */
|
||||
# define U_IS_BIG_ENDIAN 1
|
||||
#elif defined(sparc) || defined(__sparc) || defined(__sparc__)
|
||||
/* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
|
||||
# define U_IS_BIG_ENDIAN 1
|
||||
#else
|
||||
# define U_IS_BIG_ENDIAN 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_HAVE_PLACEMENT_NEW
|
||||
* Determines whether to override placement new and delete for STL.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
#ifdef U_HAVE_PLACEMENT_NEW
|
||||
/* Use the predefined value. */
|
||||
#elif defined(__BORLANDC__)
|
||||
# define U_HAVE_PLACEMENT_NEW 0
|
||||
#else
|
||||
# define U_HAVE_PLACEMENT_NEW 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_HAVE_DEBUG_LOCATION_NEW
|
||||
* Define this to define the MFC debug version of the operator new.
|
||||
*
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
#ifdef U_HAVE_DEBUG_LOCATION_NEW
|
||||
/* Use the predefined value. */
|
||||
#elif defined(_MSC_VER)
|
||||
# define U_HAVE_DEBUG_LOCATION_NEW 1
|
||||
#else
|
||||
# define U_HAVE_DEBUG_LOCATION_NEW 0
|
||||
#endif
|
||||
|
||||
/* Compatibility with non clang compilers */
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_MALLOC_ATTR
|
||||
* Attribute to mark functions as malloc-like
|
||||
* @internal
|
||||
*/
|
||||
#if defined(__GNUC__) && __GNUC__>=3
|
||||
# define U_MALLOC_ATTR __attribute__ ((__malloc__))
|
||||
#else
|
||||
# define U_MALLOC_ATTR
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_ALLOC_SIZE_ATTR
|
||||
* Attribute to specify the size of the allocated buffer for malloc-like functions
|
||||
* @internal
|
||||
*/
|
||||
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
|
||||
# define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
|
||||
# define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
|
||||
#else
|
||||
# define U_ALLOC_SIZE_ATTR(X)
|
||||
# define U_ALLOC_SIZE_ATTR2(X,Y)
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/** @{ Character data types */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#define U_ASCII_FAMILY 0
|
||||
|
||||
/**
|
||||
* U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#define U_EBCDIC_FAMILY 1
|
||||
|
||||
/**
|
||||
* \def U_CHARSET_FAMILY
|
||||
*
|
||||
* <p>These definitions allow to specify the encoding of text
|
||||
* in the char data type as defined by the platform and the compiler.
|
||||
* It is enough to determine the code point values of "invariant characters",
|
||||
* which are the ones shared by all encodings that are in use
|
||||
* on a given platform.</p>
|
||||
*
|
||||
* <p>Those "invariant characters" should be all the uppercase and lowercase
|
||||
* latin letters, the digits, the space, and "basic punctuation".
|
||||
* Also, '\\n', '\\r', '\\t' should be available.</p>
|
||||
*
|
||||
* <p>The list of "invariant characters" is:<br>
|
||||
* \code
|
||||
* A-Z a-z 0-9 SPACE " % & ' ( ) * + , - . / : ; < = > ? _
|
||||
* \endcode
|
||||
* <br>
|
||||
* (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
|
||||
*
|
||||
* <p>This matches the IBM Syntactic Character Set (CS 640).</p>
|
||||
*
|
||||
* <p>In other words, all the graphic characters in 7-bit ASCII should
|
||||
* be safely accessible except the following:</p>
|
||||
*
|
||||
* \code
|
||||
* '\' <backslash>
|
||||
* '[' <left bracket>
|
||||
* ']' <right bracket>
|
||||
* '{' <left brace>
|
||||
* '}' <right brace>
|
||||
* '^' <circumflex>
|
||||
* '~' <tilde>
|
||||
* '!' <exclamation mark>
|
||||
* '#' <number sign>
|
||||
* '|' <vertical line>
|
||||
* '$' <dollar sign>
|
||||
* '@' <commercial at>
|
||||
* '`' <grave accent>
|
||||
* \endcode
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#ifdef U_CHARSET_FAMILY
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
|
||||
# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
|
||||
#elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
|
||||
# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
|
||||
#else
|
||||
# define U_CHARSET_FAMILY U_ASCII_FAMILY
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_CHARSET_IS_UTF8
|
||||
*
|
||||
* Hardcode the default charset to UTF-8.
|
||||
*
|
||||
* If this is set to 1, then
|
||||
* - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
|
||||
* contain UTF-8 text, regardless of what the system API uses
|
||||
* - some ICU code will use fast functions like u_strFromUTF8()
|
||||
* rather than the more general and more heavy-weight conversion API (ucnv.h)
|
||||
* - ucnv_getDefaultName() always returns "UTF-8"
|
||||
* - ucnv_setDefaultName() is disabled and will not change the default charset
|
||||
* - static builds of ICU are smaller
|
||||
* - more functionality is available with the UCONFIG_NO_CONVERSION build-time
|
||||
* configuration option (see unicode/uconfig.h)
|
||||
* - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
|
||||
*
|
||||
* @stable ICU 4.2
|
||||
* @see UCONFIG_NO_CONVERSION
|
||||
*/
|
||||
#ifdef U_CHARSET_IS_UTF8
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
|
||||
# define U_CHARSET_IS_UTF8 1
|
||||
#else
|
||||
# define U_CHARSET_IS_UTF8 0
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/** @{ Information about wchar support */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* \def U_HAVE_WCHAR_H
|
||||
* Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#ifdef U_HAVE_WCHAR_H
|
||||
/* Use the predefined value. */
|
||||
#elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
|
||||
/*
|
||||
* Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
|
||||
* The type and header existed, but the library functions did not work as expected.
|
||||
* The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
|
||||
*/
|
||||
# define U_HAVE_WCHAR_H 0
|
||||
#else
|
||||
# define U_HAVE_WCHAR_H 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_SIZEOF_WCHAR_T
|
||||
* U_SIZEOF_WCHAR_T==sizeof(wchar_t)
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#ifdef U_SIZEOF_WCHAR_T
|
||||
/* Use the predefined value. */
|
||||
#elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) || U_PLATFORM == U_PF_CLASSIC_MACOS
|
||||
/*
|
||||
* Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
|
||||
* Newer Mac OS X has size 4.
|
||||
*/
|
||||
# define U_SIZEOF_WCHAR_T 1
|
||||
#elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
|
||||
# define U_SIZEOF_WCHAR_T 2
|
||||
#elif U_PLATFORM == U_PF_AIX
|
||||
/*
|
||||
* AIX 6.1 information, section "Wide character data representation":
|
||||
* "... the wchar_t datatype is 32-bit in the 64-bit environment and
|
||||
* 16-bit in the 32-bit environment."
|
||||
* and
|
||||
* "All locales use Unicode for their wide character code values (process code),
|
||||
* except the IBM-eucTW codeset."
|
||||
*/
|
||||
# ifdef __64BIT__
|
||||
# define U_SIZEOF_WCHAR_T 4
|
||||
# else
|
||||
# define U_SIZEOF_WCHAR_T 2
|
||||
# endif
|
||||
#elif U_PLATFORM == U_PF_OS390
|
||||
/*
|
||||
* z/OS V1R11 information center, section "LP64 | ILP32":
|
||||
* "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
|
||||
* Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
|
||||
*/
|
||||
# ifdef _LP64
|
||||
# define U_SIZEOF_WCHAR_T 4
|
||||
# else
|
||||
# define U_SIZEOF_WCHAR_T 2
|
||||
# endif
|
||||
#elif U_PLATFORM == U_PF_OS400
|
||||
# if defined(__UTF32__)
|
||||
/*
|
||||
* LOCALETYPE(*LOCALEUTF) is specified.
|
||||
* Wide-character strings are in UTF-32,
|
||||
* narrow-character strings are in UTF-8.
|
||||
*/
|
||||
# define U_SIZEOF_WCHAR_T 4
|
||||
# elif defined(__UCS2__)
|
||||
/*
|
||||
* LOCALETYPE(*LOCALEUCS2) is specified.
|
||||
* Wide-character strings are in UCS-2,
|
||||
* narrow-character strings are in EBCDIC.
|
||||
*/
|
||||
# define U_SIZEOF_WCHAR_T 2
|
||||
#else
|
||||
/*
|
||||
* LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
|
||||
* Wide-character strings are in 16-bit EBCDIC,
|
||||
* narrow-character strings are in EBCDIC.
|
||||
*/
|
||||
# define U_SIZEOF_WCHAR_T 2
|
||||
# endif
|
||||
#else
|
||||
# define U_SIZEOF_WCHAR_T 4
|
||||
#endif
|
||||
|
||||
#ifndef U_HAVE_WCSCPY
|
||||
#define U_HAVE_WCSCPY U_HAVE_WCHAR_H
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \def U_HAVE_CHAR16_T
|
||||
* Defines whether the char16_t type is available for UTF-16
|
||||
* and u"abc" UTF-16 string literals are supported.
|
||||
* This is a new standard type and standard string literal syntax in C++0x
|
||||
* but has been available in some compilers before.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_HAVE_CHAR16_T
|
||||
/* Use the predefined value. */
|
||||
#else
|
||||
/*
|
||||
* Notes:
|
||||
* Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
|
||||
* does not support u"abc" string literals.
|
||||
* gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
|
||||
* does not support u"abc" string literals.
|
||||
* C++11 and C11 require support for UTF-16 literals
|
||||
*/
|
||||
# if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
|
||||
# define U_HAVE_CHAR16_T 1
|
||||
# else
|
||||
# define U_HAVE_CHAR16_T 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @{
|
||||
* \def U_DECLARE_UTF16
|
||||
* Do not use this macro because it is not defined on all platforms.
|
||||
* Use the UNICODE_STRING or U_STRING_DECL macros instead.
|
||||
* @internal
|
||||
*/
|
||||
#ifdef U_DECLARE_UTF16
|
||||
/* Use the predefined value. */
|
||||
#elif U_HAVE_CHAR16_T \
|
||||
|| (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
|
||||
|| (defined(__HP_aCC) && __HP_aCC >= 035000) \
|
||||
|| (defined(__HP_cc) && __HP_cc >= 111106)
|
||||
# define U_DECLARE_UTF16(string) u ## string
|
||||
#elif U_SIZEOF_WCHAR_T == 2 \
|
||||
&& (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
|
||||
# define U_DECLARE_UTF16(string) L ## string
|
||||
#else
|
||||
/* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/** @{ Symbol import-export control */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef U_EXPORT
|
||||
/* Use the predefined value. */
|
||||
#elif defined(U_STATIC_IMPLEMENTATION)
|
||||
# define U_EXPORT
|
||||
#elif defined(__GNUC__)
|
||||
# define U_EXPORT __attribute__((visibility("default")))
|
||||
#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
|
||||
|| (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
|
||||
# define U_EXPORT __global
|
||||
/*#elif defined(__HP_aCC) || defined(__HP_cc)
|
||||
# define U_EXPORT __declspec(dllexport)*/
|
||||
#elif defined(_MSC_VER)
|
||||
# define U_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define U_EXPORT
|
||||
#endif
|
||||
|
||||
/* U_CALLCONV is releated to U_EXPORT2 */
|
||||
#ifdef U_EXPORT2
|
||||
/* Use the predefined value. */
|
||||
#elif defined(_MSC_VER)
|
||||
# define U_EXPORT2 __cdecl
|
||||
#else
|
||||
# define U_EXPORT2
|
||||
#endif
|
||||
|
||||
#ifdef U_IMPORT
|
||||
/* Use the predefined value. */
|
||||
#elif defined(_MSC_VER)
|
||||
/* Windows needs to export/import data. */
|
||||
# define U_IMPORT __declspec(dllimport)
|
||||
#else
|
||||
# define U_IMPORT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_CALLCONV
|
||||
* Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
|
||||
* in callback function typedefs to make sure that the calling convention
|
||||
* is compatible.
|
||||
*
|
||||
* This is only used for non-ICU-API functions.
|
||||
* When a function is a public ICU API,
|
||||
* you must use the U_CAPI and U_EXPORT2 qualifiers.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
|
||||
# define U_CALLCONV __cdecl
|
||||
#else
|
||||
# define U_CALLCONV U_EXPORT2
|
||||
#endif
|
||||
|
||||
/* @} */
|
||||
|
||||
#endif
|
||||
@@ -1,610 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
|
||||
* File PLURFMT.H
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef PLURFMT
|
||||
#define PLURFMT
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: PluralFormat object
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/messagepattern.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/plurrule.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class Hashtable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <code>PluralFormat</code> supports the creation of internationalized
|
||||
* messages with plural inflection. It is based on <i>plural
|
||||
* selection</i>, i.e. the caller specifies messages for each
|
||||
* plural case that can appear in the user's language and the
|
||||
* <code>PluralFormat</code> selects the appropriate message based on
|
||||
* the number.
|
||||
* </p>
|
||||
* <h4>The Problem of Plural Forms in Internationalized Messages</h4>
|
||||
* <p>
|
||||
* Different languages have different ways to inflect
|
||||
* plurals. Creating internationalized messages that include plural
|
||||
* forms is only feasible when the framework is able to handle plural
|
||||
* forms of <i>all</i> languages correctly. <code>ChoiceFormat</code>
|
||||
* doesn't handle this well, because it attaches a number interval to
|
||||
* each message and selects the message whose interval contains a
|
||||
* given number. This can only handle a finite number of
|
||||
* intervals. But in some languages, like Polish, one plural case
|
||||
* applies to infinitely many intervals (e.g., the plural case applies to
|
||||
* numbers ending with 2, 3, or 4 except those ending with 12, 13, or
|
||||
* 14). Thus <code>ChoiceFormat</code> is not adequate.
|
||||
* </p><p>
|
||||
* <code>PluralFormat</code> deals with this by breaking the problem
|
||||
* into two parts:
|
||||
* <ul>
|
||||
* <li>It uses <code>PluralRules</code> that can define more complex
|
||||
* conditions for a plural case than just a single interval. These plural
|
||||
* rules define both what plural cases exist in a language, and to
|
||||
* which numbers these cases apply.
|
||||
* <li>It provides predefined plural rules for many languages. Thus, the programmer
|
||||
* need not worry about the plural cases of a language and
|
||||
* does not have to define the plural cases; they can simply
|
||||
* use the predefined keywords. The whole plural formatting of messages can
|
||||
* be done using localized patterns from resource bundles. For predefined plural
|
||||
* rules, see the CLDR <i>Language Plural Rules</i> page at
|
||||
* http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
|
||||
* </ul>
|
||||
* </p>
|
||||
* <h4>Usage of <code>PluralFormat</code></h4>
|
||||
* <p>Note: Typically, plural formatting is done via <code>MessageFormat</code>
|
||||
* with a <code>plural</code> argument type,
|
||||
* rather than using a stand-alone <code>PluralFormat</code>.
|
||||
* </p><p>
|
||||
* This discussion assumes that you use <code>PluralFormat</code> with
|
||||
* a predefined set of plural rules. You can create one using one of
|
||||
* the constructors that takes a <code>locale</code> object. To
|
||||
* specify the message pattern, you can either pass it to the
|
||||
* constructor or set it explicitly using the
|
||||
* <code>applyPattern()</code> method. The <code>format()</code>
|
||||
* method takes a number object and selects the message of the
|
||||
* matching plural case. This message will be returned.
|
||||
* </p>
|
||||
* <h5>Patterns and Their Interpretation</h5>
|
||||
* <p>
|
||||
* The pattern text defines the message output for each plural case of the
|
||||
* specified locale. Syntax:
|
||||
* <pre>
|
||||
* pluralStyle = [offsetValue] (selector '{' message '}')+
|
||||
* offsetValue = "offset:" number
|
||||
* selector = explicitValue | keyword
|
||||
* explicitValue = '=' number // adjacent, no white space in between
|
||||
* keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
|
||||
* message: see {@link MessageFormat}
|
||||
* </pre>
|
||||
* Pattern_White_Space between syntax elements is ignored, except
|
||||
* between the {curly braces} and their sub-message,
|
||||
* and between the '=' and the number of an explicitValue.
|
||||
*
|
||||
* </p><p>
|
||||
* There are 6 predefined casekeyword in CLDR/ICU - 'zero', 'one', 'two', 'few', 'many' and
|
||||
* 'other'. You always have to define a message text for the default plural case
|
||||
* <code>other</code> which is contained in every rule set.
|
||||
* If you do not specify a message text for a particular plural case, the
|
||||
* message text of the plural case <code>other</code> gets assigned to this
|
||||
* plural case.
|
||||
* </p><p>
|
||||
* When formatting, the input number is first matched against the explicitValue clauses.
|
||||
* If there is no exact-number match, then a keyword is selected by calling
|
||||
* the <code>PluralRules</code> with the input number <em>minus the offset</em>.
|
||||
* (The offset defaults to 0 if it is omitted from the pattern string.)
|
||||
* If there is no clause with that keyword, then the "other" clauses is returned.
|
||||
* </p><p>
|
||||
* An unquoted pound sign (<code>#</code>) in the selected sub-message
|
||||
* itself (i.e., outside of arguments nested in the sub-message)
|
||||
* is replaced by the input number minus the offset.
|
||||
* The number-minus-offset value is formatted using a
|
||||
* <code>NumberFormat</code> for the <code>PluralFormat</code>'s locale. If you
|
||||
* need special number formatting, you have to use a <code>MessageFormat</code>
|
||||
* and explicitly specify a <code>NumberFormat</code> argument.
|
||||
* <strong>Note:</strong> That argument is formatting without subtracting the offset!
|
||||
* If you need a custom format and have a non-zero offset, then you need to pass the
|
||||
* number-minus-offset value as a separate parameter.
|
||||
* </p>
|
||||
* For a usage example, see the {@link MessageFormat} class documentation.
|
||||
*
|
||||
* <h4>Defining Custom Plural Rules</h4>
|
||||
* <p>If you need to use <code>PluralFormat</code> with custom rules, you can
|
||||
* create a <code>PluralRules</code> object and pass it to
|
||||
* <code>PluralFormat</code>'s constructor. If you also specify a locale in this
|
||||
* constructor, this locale will be used to format the number in the message
|
||||
* texts.
|
||||
* </p><p>
|
||||
* For more information about <code>PluralRules</code>, see
|
||||
* {@link PluralRules}.
|
||||
* </p>
|
||||
*
|
||||
* ported from Java
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
|
||||
class U_I18N_API PluralFormat : public Format {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new cardinal-number <code>PluralFormat</code> for the default locale.
|
||||
* This locale will be used to get the set of plural rules and for standard
|
||||
* number formatting.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new cardinal-number <code>PluralFormat</code> for a given locale.
|
||||
* @param locale the <code>PluralFormat</code> will be configured with
|
||||
* rules for this locale. This locale will also be used for
|
||||
* standard number formatting.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for a given set of rules.
|
||||
* The standard number formatting will be done using the default locale.
|
||||
* @param rules defines the behavior of the <code>PluralFormat</code>
|
||||
* object.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const PluralRules& rules, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for a given set of rules.
|
||||
* The standard number formatting will be done using the given locale.
|
||||
* @param locale the default number formatting will be done using this
|
||||
* locale.
|
||||
* @param rules defines the behavior of the <code>PluralFormat</code>
|
||||
* object.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
* <p>
|
||||
* <h4>Sample code</h4>
|
||||
* \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1
|
||||
* \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample
|
||||
* <p>
|
||||
*/
|
||||
PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for the plural type.
|
||||
* The standard number formatting will be done using the given locale.
|
||||
* @param locale the default number formatting will be done using this
|
||||
* locale.
|
||||
* @param type The plural type (e.g., cardinal or ordinal).
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string.
|
||||
* The default locale will be used to get the set of plural rules and for
|
||||
* standard number formatting.
|
||||
* @param pattern the pattern for this <code>PluralFormat</code>.
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string and
|
||||
* locale.
|
||||
* The locale will be used to get the set of plural rules and for
|
||||
* standard number formatting.
|
||||
* @param locale the <code>PluralFormat</code> will be configured with
|
||||
* rules for this locale. This locale will also be used for
|
||||
* standard number formatting.
|
||||
* @param pattern the pattern for this <code>PluralFormat</code>.
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for a given set of rules, a
|
||||
* pattern and a locale.
|
||||
* @param rules defines the behavior of the <code>PluralFormat</code>
|
||||
* object.
|
||||
* @param pattern the pattern for this <code>PluralFormat</code>.
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const PluralRules& rules,
|
||||
const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for a given set of rules, a
|
||||
* pattern and a locale.
|
||||
* @param locale the <code>PluralFormat</code> will be configured with
|
||||
* rules for this locale. This locale will also be used for
|
||||
* standard number formatting.
|
||||
* @param rules defines the behavior of the <code>PluralFormat</code>
|
||||
* object.
|
||||
* @param pattern the pattern for this <code>PluralFormat</code>.
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const Locale& locale,
|
||||
const PluralRules& rules,
|
||||
const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a new <code>PluralFormat</code> for a plural type, a
|
||||
* pattern and a locale.
|
||||
* @param locale the <code>PluralFormat</code> will be configured with
|
||||
* rules for this locale. This locale will also be used for
|
||||
* standard number formatting.
|
||||
* @param type The plural type (e.g., cardinal or ordinal).
|
||||
* @param pattern the pattern for this <code>PluralFormat</code>.
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
PluralFormat(const Locale& locale,
|
||||
UPluralType type,
|
||||
const UnicodeString& pattern,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* copy constructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat(const PluralFormat& other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual ~PluralFormat();
|
||||
|
||||
/**
|
||||
* Sets the pattern used by this plural format.
|
||||
* The method parses the pattern and creates a map of format strings
|
||||
* for the plural rules.
|
||||
* Patterns and their interpretation are specified in the class description.
|
||||
*
|
||||
* @param pattern the pattern for this plural format
|
||||
* errors are returned to status if the pattern is invalid.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
void applyPattern(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
|
||||
using Format::format;
|
||||
|
||||
/**
|
||||
* Formats a plural message for a given number.
|
||||
*
|
||||
* @param number a number for which the plural message should be formatted
|
||||
* for. If no pattern has been applied to this
|
||||
* <code>PluralFormat</code> object yet, the formatted number
|
||||
* will be returned.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return the string containing the formatted plural message.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString format(int32_t number, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Formats a plural message for a given number.
|
||||
*
|
||||
* @param number a number for which the plural message should be formatted
|
||||
* for. If no pattern has been applied to this
|
||||
* PluralFormat object yet, the formatted number
|
||||
* will be returned.
|
||||
* @param status output param set to success or failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return the string containing the formatted plural message.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString format(double number, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Formats a plural message for a given number.
|
||||
*
|
||||
* @param number a number for which the plural message should be formatted
|
||||
* for. If no pattern has been applied to this
|
||||
* <code>PluralFormat</code> object yet, the formatted number
|
||||
* will be returned.
|
||||
* @param appendTo output parameter to receive result.
|
||||
* result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return the string containing the formatted plural message.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& format(int32_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Formats a plural message for a given number.
|
||||
*
|
||||
* @param number a number for which the plural message should be formatted
|
||||
* for. If no pattern has been applied to this
|
||||
* PluralFormat object yet, the formatted number
|
||||
* will be returned.
|
||||
* @param appendTo output parameter to receive result.
|
||||
* result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return the string containing the formatted plural message.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& format(double number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Sets the locale used by this <code>PluraFormat</code> object.
|
||||
* Note: Calling this method resets this <code>PluraFormat</code> object,
|
||||
* i.e., a pattern that was applied previously will be removed,
|
||||
* and the NumberFormat is set to the default number format for
|
||||
* the locale. The resulting format behaves the same as one
|
||||
* constructed from {@link #PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status)}
|
||||
* with UPLURAL_TYPE_CARDINAL.
|
||||
* @param locale the <code>locale</code> to use to configure the formatter.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @deprecated ICU 50 This method clears the pattern and might create
|
||||
* a different kind of PluralRules instance;
|
||||
* use one of the constructors to create a new instance instead.
|
||||
*/
|
||||
void setLocale(const Locale& locale, UErrorCode& status);
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Sets the number format used by this formatter. You only need to
|
||||
* call this if you want a different number format than the default
|
||||
* formatter for the locale.
|
||||
* @param format the number format to use.
|
||||
* @param status output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
void setNumberFormat(const NumberFormat* format, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*
|
||||
* @param other the PluralFormat object to copy from.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralFormat& operator=(const PluralFormat& other);
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*
|
||||
* @param other the PluralFormat object to be compared with.
|
||||
* @return true if other is semantically equal to this.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*
|
||||
* @param other the PluralFormat object to be compared with.
|
||||
* @return true if other is semantically unequal to this.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator!=(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Clones this Format object polymorphically. The caller owns the
|
||||
* result and should delete it when done.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual Format* clone(void) const;
|
||||
|
||||
/**
|
||||
* Formats a plural message for a number taken from a Formattable object.
|
||||
*
|
||||
* @param obj The object containing a number for which the
|
||||
* plural message should be formatted.
|
||||
* The object must be of a numeric type.
|
||||
* @param appendTo output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @param status output param filled with success/failure status.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns the pattern from applyPattern() or constructor().
|
||||
*
|
||||
* @param appendTo output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @return the UnicodeString with inserted pattern.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString& toPattern(UnicodeString& appendTo);
|
||||
|
||||
/**
|
||||
* This method is not yet supported by <code>PluralFormat</code>.
|
||||
* <P>
|
||||
* Before calling, set parse_pos.index to the offset you want to start
|
||||
* parsing at in the source. After calling, parse_pos.index is the end of
|
||||
* the text you parsed. If error occurs, index is unchanged.
|
||||
* <P>
|
||||
* When parsing, leading whitespace is discarded (with a successful parse),
|
||||
* while trailing whitespace is left as is.
|
||||
* <P>
|
||||
* See Format::parseObject() for more.
|
||||
*
|
||||
* @param source The string to be parsed into an object.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parse_pos The position to start parsing at. Upon return
|
||||
* this param is set to the position after the
|
||||
* last character successfully parsed. If the
|
||||
* source is not parsed successfully, this param
|
||||
* will remain unchanged.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual void parseObject(const UnicodeString& source,
|
||||
Formattable& result,
|
||||
ParsePosition& parse_pos) const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
#if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
|
||||
// Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
|
||||
// prevent PluralSelectorAdapter from implementing private PluralSelector.
|
||||
// xlC error message:
|
||||
// 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
|
||||
public:
|
||||
#else
|
||||
private:
|
||||
#endif
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class U_I18N_API PluralSelector : public UMemory {
|
||||
public:
|
||||
virtual ~PluralSelector();
|
||||
/**
|
||||
* Given a number, returns the appropriate PluralFormat keyword.
|
||||
*
|
||||
* @param context worker object for the selector.
|
||||
* @param number The number to be plural-formatted.
|
||||
* @param ec Error code.
|
||||
* @return The selected PluralFormat keyword.
|
||||
* @internal
|
||||
*/
|
||||
virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class U_I18N_API PluralSelectorAdapter : public PluralSelector {
|
||||
public:
|
||||
PluralSelectorAdapter() : pluralRules(NULL) {
|
||||
}
|
||||
|
||||
virtual ~PluralSelectorAdapter();
|
||||
|
||||
virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; /**< @internal */
|
||||
|
||||
void reset();
|
||||
|
||||
PluralRules* pluralRules;
|
||||
};
|
||||
|
||||
#if defined(__xlC__)
|
||||
// End of xlC bug workaround, keep remaining definitions private.
|
||||
private:
|
||||
#endif
|
||||
Locale locale;
|
||||
MessagePattern msgPattern;
|
||||
NumberFormat* numberFormat;
|
||||
double offset;
|
||||
PluralSelectorAdapter pluralRulesWrapper;
|
||||
|
||||
PluralFormat(); // default constructor not implemented
|
||||
void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
|
||||
/**
|
||||
* Copies dynamically allocated values (pointer fields).
|
||||
* Others are copied using their copy constructors and assignment operators.
|
||||
*/
|
||||
void copyObjects(const PluralFormat& other);
|
||||
|
||||
UnicodeString& format(const Formattable& numberObject, double number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const; /**< @internal */
|
||||
|
||||
/**
|
||||
* Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
|
||||
* @param pattern A MessagePattern.
|
||||
* @param partIndex the index of the first PluralFormat argument style part.
|
||||
* @param selector the PluralSelector for mapping the number (minus offset) to a keyword.
|
||||
* @param context worker object for the selector.
|
||||
* @param number a number to be matched to one of the PluralFormat argument's explicit values,
|
||||
* or mapped via the PluralSelector.
|
||||
* @param ec ICU error code.
|
||||
* @return the sub-message start part index.
|
||||
*/
|
||||
static int32_t findSubMessage(
|
||||
const MessagePattern& pattern, int32_t partIndex,
|
||||
const PluralSelector& selector, void *context, double number, UErrorCode& ec); /**< @internal */
|
||||
|
||||
friend class MessageFormat;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _PLURFMT
|
||||
//eof
|
||||
@@ -1,481 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
*
|
||||
* File PLURRULE.H
|
||||
*
|
||||
* Modification History:*
|
||||
* Date Name Description
|
||||
*
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef PLURRULE
|
||||
#define PLURRULE
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: PluralRules object
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/upluralrules.h"
|
||||
|
||||
/**
|
||||
* Value returned by PluralRules::getUniqueKeywordValue() when there is no
|
||||
* unique value to return.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
#define UPLRULES_NO_UNIQUE_VALUE ((double)-0.00123456777)
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class Hashtable;
|
||||
class FixedDecimal;
|
||||
class RuleChain;
|
||||
class PluralRuleParser;
|
||||
class PluralKeywordEnumeration;
|
||||
class AndConstraint;
|
||||
|
||||
/**
|
||||
* Defines rules for mapping non-negative numeric values onto a small set of
|
||||
* keywords. Rules are constructed from a text description, consisting
|
||||
* of a series of keywords and conditions. The {@link #select} method
|
||||
* examines each condition in order and returns the keyword for the
|
||||
* first condition that matches the number. If none match,
|
||||
* default rule(other) is returned.
|
||||
*
|
||||
* For more information, details, and tips for writing rules, see the
|
||||
* LDML spec, C.11 Language Plural Rules:
|
||||
* http://www.unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
|
||||
*
|
||||
* Examples:<pre>
|
||||
* "one: n is 1; few: n in 2..4"</pre>
|
||||
* This defines two rules, for 'one' and 'few'. The condition for
|
||||
* 'one' is "n is 1" which means that the number must be equal to
|
||||
* 1 for this condition to pass. The condition for 'few' is
|
||||
* "n in 2..4" which means that the number must be between 2 and
|
||||
* 4 inclusive for this condition to pass. All other numbers
|
||||
* are assigned the keyword "other" by the default rule.
|
||||
* </p><pre>
|
||||
* "zero: n is 0; one: n is 1; zero: n mod 100 in 1..19"</pre>
|
||||
* This illustrates that the same keyword can be defined multiple times.
|
||||
* Each rule is examined in order, and the first keyword whose condition
|
||||
* passes is the one returned. Also notes that a modulus is applied
|
||||
* to n in the last rule. Thus its condition holds for 119, 219, 319...
|
||||
* </p><pre>
|
||||
* "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14"</pre>
|
||||
* This illustrates conjunction and negation. The condition for 'few'
|
||||
* has two parts, both of which must be met: "n mod 10 in 2..4" and
|
||||
* "n mod 100 not in 12..14". The first part applies a modulus to n
|
||||
* before the test as in the previous example. The second part applies
|
||||
* a different modulus and also uses negation, thus it matches all
|
||||
* numbers _not_ in 12, 13, 14, 112, 113, 114, 212, 213, 214...
|
||||
* </p>
|
||||
* <p>
|
||||
* Syntax:<pre>
|
||||
* \code
|
||||
* rules = rule (';' rule)*
|
||||
* rule = keyword ':' condition
|
||||
* keyword = <identifier>
|
||||
* condition = and_condition ('or' and_condition)*
|
||||
* and_condition = relation ('and' relation)*
|
||||
* relation = is_relation | in_relation | within_relation | 'n' <EOL>
|
||||
* is_relation = expr 'is' ('not')? value
|
||||
* in_relation = expr ('not')? 'in' range_list
|
||||
* within_relation = expr ('not')? 'within' range
|
||||
* expr = ('n' | 'i' | 'f' | 'v' | 'j') ('mod' value)?
|
||||
* range_list = (range | value) (',' range_list)*
|
||||
* value = digit+ ('.' digit+)?
|
||||
* digit = 0|1|2|3|4|5|6|7|8|9
|
||||
* range = value'..'value
|
||||
* \endcode
|
||||
* </pre></p>
|
||||
* <p>
|
||||
* <p>
|
||||
* The i, f, and v values are defined as follows:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>i to be the integer digits.</li>
|
||||
* <li>f to be the visible fractional digits, as an integer.</li>
|
||||
* <li>v to be the number of visible fraction digits.</li>
|
||||
* <li>j is defined to only match integers. That is j is 3 fails if v != 0 (eg for 3.1 or 3.0).</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples are in the following table:
|
||||
* </p>
|
||||
* <table border='1' style="border-collapse:collapse">
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th>n</th>
|
||||
* <th>i</th>
|
||||
* <th>f</th>
|
||||
* <th>v</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>1.0</td>
|
||||
* <td>1</td>
|
||||
* <td align="right">0</td>
|
||||
* <td>1</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>1.00</td>
|
||||
* <td>1</td>
|
||||
* <td align="right">0</td>
|
||||
* <td>2</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>1.3</td>
|
||||
* <td>1</td>
|
||||
* <td align="right">3</td>
|
||||
* <td>1</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>1.03</td>
|
||||
* <td>1</td>
|
||||
* <td align="right">3</td>
|
||||
* <td>2</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>1.23</td>
|
||||
* <td>1</td>
|
||||
* <td align="right">23</td>
|
||||
* <td>2</td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
* <p>
|
||||
* The difference between 'in' and 'within' is that 'in' only includes integers in the specified range, while 'within'
|
||||
* includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's
|
||||
* not an error).
|
||||
* </p>
|
||||
|
||||
* An "identifier" is a sequence of characters that do not have the
|
||||
* Unicode Pattern_Syntax or Pattern_White_Space properties.
|
||||
* <p>
|
||||
* The difference between 'in' and 'within' is that 'in' only includes
|
||||
* integers in the specified range, while 'within' includes all values.
|
||||
* Using 'within' with a range_list consisting entirely of values is the
|
||||
* same as using 'in' (it's not an error).
|
||||
*</p>
|
||||
* <p>
|
||||
* Keywords
|
||||
* could be defined by users or from ICU locale data. There are 6
|
||||
* predefined values in ICU - 'zero', 'one', 'two', 'few', 'many' and
|
||||
* 'other'. Callers need to check the value of keyword returned by
|
||||
* {@link #select} method.
|
||||
* </p>
|
||||
*
|
||||
* Examples:<pre>
|
||||
* UnicodeString keyword = pl->select(number);
|
||||
* if (keyword== UnicodeString("one") {
|
||||
* ...
|
||||
* }
|
||||
* else if ( ... )
|
||||
* </pre>
|
||||
* <strong>Note:</strong><br>
|
||||
* <p>
|
||||
* ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>.
|
||||
* For these predefined rules, see CLDR page at
|
||||
* http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
|
||||
* </p>
|
||||
*/
|
||||
class U_I18N_API PluralRules : public UObject {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralRules(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralRules(const PluralRules& other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual ~PluralRules();
|
||||
|
||||
/**
|
||||
* Clone
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralRules* clone() const;
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
PluralRules& operator=(const PluralRules&);
|
||||
|
||||
/**
|
||||
* Creates a PluralRules from a description if it is parsable, otherwise
|
||||
* returns NULL.
|
||||
*
|
||||
* @param description rule description
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return new PluralRules pointer. NULL if there is an error.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* The default rules that accept any number.
|
||||
*
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return new PluralRules pointer. NULL if there is an error.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Provides access to the predefined cardinal-number <code>PluralRules</code> for a given
|
||||
* locale.
|
||||
* Same as forLocale(locale, UPLURAL_TYPE_CARDINAL, status).
|
||||
*
|
||||
* @param locale The locale for which a <code>PluralRules</code> object is
|
||||
* returned.
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return The predefined <code>PluralRules</code> object pointer for
|
||||
* this locale. If there's no predefined rules for this locale,
|
||||
* the rules for the closest parent in the locale hierarchy
|
||||
* that has one will be returned. The final fallback always
|
||||
* returns the default 'other' rules.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Provides access to the predefined <code>PluralRules</code> for a given
|
||||
* locale and the plural type.
|
||||
*
|
||||
* @param locale The locale for which a <code>PluralRules</code> object is
|
||||
* returned.
|
||||
* @param type The plural type (e.g., cardinal or ordinal).
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return The predefined <code>PluralRules</code> object pointer for
|
||||
* this locale. If there's no predefined rules for this locale,
|
||||
* the rules for the closest parent in the locale hierarchy
|
||||
* that has one will be returned. The final fallback always
|
||||
* returns the default 'other' rules.
|
||||
* @stable ICU 50
|
||||
*/
|
||||
static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Return a StringEnumeration over the locales for which there is plurals data.
|
||||
* @return a StringEnumeration over the locales available.
|
||||
* @internal
|
||||
*/
|
||||
static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Returns whether or not there are overrides.
|
||||
* @param locale the locale to check.
|
||||
* @return
|
||||
* @internal
|
||||
*/
|
||||
static UBool hasOverride(const Locale &locale);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Given a number, returns the keyword of the first rule that applies to
|
||||
* the number. This function can be used with isKeyword* functions to
|
||||
* determine the keyword for default plural rules.
|
||||
*
|
||||
* @param number The number for which the rule has to be determined.
|
||||
* @return The keyword of the selected rule.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString select(int32_t number) const;
|
||||
|
||||
/**
|
||||
* Given a number, returns the keyword of the first rule that applies to
|
||||
* the number. This function can be used with isKeyword* functions to
|
||||
* determine the keyword for default plural rules.
|
||||
*
|
||||
* @param number The number for which the rule has to be determined.
|
||||
* @return The keyword of the selected rule.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString select(double number) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
UnicodeString select(const FixedDecimal &number) const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Returns a list of all rule keywords used in this <code>PluralRules</code>
|
||||
* object. The rule 'other' is always present by default.
|
||||
*
|
||||
* @param status Output param set to success/failure code on exit, which
|
||||
* must not indicate a failure before the function call.
|
||||
* @return StringEnumeration with the keywords.
|
||||
* The caller must delete the object.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
StringEnumeration* getKeywords(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns a unique value for this keyword if it exists, else the constant
|
||||
* UPLRULES_NO_UNIQUE_VALUE.
|
||||
*
|
||||
* @param keyword The keyword.
|
||||
* @return The unique value that generates the keyword, or
|
||||
* UPLRULES_NO_UNIQUE_VALUE if the keyword is undefined or there is no
|
||||
* unique value that generates this keyword.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
double getUniqueKeywordValue(const UnicodeString& keyword);
|
||||
|
||||
/**
|
||||
* Returns all the values for which select() would return the keyword. If
|
||||
* the keyword is unknown, returns no values, but this is not an error. If
|
||||
* the number of values is unlimited, returns no values and -1 as the
|
||||
* count.
|
||||
*
|
||||
* The number of returned values is typically small.
|
||||
*
|
||||
* @param keyword The keyword.
|
||||
* @param dest Array into which to put the returned values. May
|
||||
* be NULL if destCapacity is 0.
|
||||
* @param destCapacity The capacity of the array, must be at least 0.
|
||||
* @param status The error code.
|
||||
* @return The count of values available, or -1. This count
|
||||
* can be larger than destCapacity, but no more than
|
||||
* destCapacity values will be written.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getAllKeywordValues(const UnicodeString &keyword,
|
||||
double *dest, int32_t destCapacity,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Returns sample values for which select() would return the keyword. If
|
||||
* the keyword is unknown, returns no values, but this is not an error.
|
||||
*
|
||||
* The number of returned values is typically small.
|
||||
*
|
||||
* @param keyword The keyword.
|
||||
* @param dest Array into which to put the returned values. May
|
||||
* be NULL if destCapacity is 0.
|
||||
* @param destCapacity The capacity of the array, must be at least 0.
|
||||
* @param status The error code.
|
||||
* @return The count of values written.
|
||||
* If more than destCapacity samples are available, then
|
||||
* only destCapacity are written, and destCapacity is returned as the count,
|
||||
* rather than setting a U_BUFFER_OVERFLOW_ERROR.
|
||||
* (The actual number of keyword values could be unlimited.)
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
int32_t getSamples(const UnicodeString &keyword,
|
||||
double *dest, int32_t destCapacity,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Returns TRUE if the given keyword is defined in this
|
||||
* <code>PluralRules</code> object.
|
||||
*
|
||||
* @param keyword the input keyword.
|
||||
* @return TRUE if the input keyword is defined.
|
||||
* Otherwise, return FALSE.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool isKeyword(const UnicodeString& keyword) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns keyword for default plural form.
|
||||
*
|
||||
* @return keyword for default plural form.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UnicodeString getKeywordOther() const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
UnicodeString getRules() const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
/**
|
||||
* Compares the equality of two PluralRules objects.
|
||||
*
|
||||
* @param other The other PluralRules object to be compared with.
|
||||
* @return True if the given PluralRules is the same as this
|
||||
* PluralRules; false otherwise.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UBool operator==(const PluralRules& other) const;
|
||||
|
||||
/**
|
||||
* Compares the inequality of two PluralRules objects.
|
||||
*
|
||||
* @param other The PluralRules object to be compared with.
|
||||
* @return True if the given PluralRules is not the same as this
|
||||
* PluralRules; false otherwise.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
UBool operator!=(const PluralRules& other) const {return !operator==(other);}
|
||||
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
|
||||
private:
|
||||
RuleChain *mRules;
|
||||
|
||||
PluralRules(); // default constructor not implemented
|
||||
void parseDescription(const UnicodeString& ruleData, UErrorCode &status);
|
||||
int32_t getNumberValue(const UnicodeString& token) const;
|
||||
UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
|
||||
RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
|
||||
|
||||
friend class PluralRuleParser;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _PLURRULE
|
||||
//eof
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* FILE NAME : ptypes.h
|
||||
*
|
||||
* Date Name Description
|
||||
* 05/13/98 nos Creation (content moved here from ptypes.h).
|
||||
* 03/02/99 stephen Added AS400 support.
|
||||
* 03/30/99 stephen Added Linux support.
|
||||
* 04/13/99 stephen Reworked for autoconf.
|
||||
* 09/18/08 srl Moved basic types back to ptypes.h from platform.h
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: Definitions of integer types of various widths
|
||||
*/
|
||||
|
||||
#ifndef _PTYPES_H
|
||||
#define _PTYPES_H
|
||||
|
||||
/**
|
||||
* \def __STDC_LIMIT_MACROS
|
||||
* According to the Linux stdint.h, the ISO C99 standard specifies that in C++ implementations
|
||||
* macros like INT32_MIN and UINTPTR_MAX should only be defined if explicitly requested.
|
||||
* We need to define __STDC_LIMIT_MACROS before including stdint.h in C++ code
|
||||
* that uses such limit macros.
|
||||
* @internal
|
||||
*/
|
||||
#ifndef __STDC_LIMIT_MACROS
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#endif
|
||||
|
||||
/* NULL, size_t, wchar_t */
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* If all compilers provided all of the C99 headers and types,
|
||||
* we would just unconditionally #include <stdint.h> here
|
||||
* and not need any of the stuff after including platform.h.
|
||||
*/
|
||||
|
||||
/* Find out if we have stdint.h etc. */
|
||||
#include "unicode/platform.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Generic data types */
|
||||
/*===========================================================================*/
|
||||
|
||||
/* If your platform does not have the <stdint.h> header, you may
|
||||
need to edit the typedefs in the #else section below.
|
||||
Use #if...#else...#endif with predefined compiler macros if possible. */
|
||||
#if U_HAVE_STDINT_H
|
||||
|
||||
/*
|
||||
* We mostly need <stdint.h> (which defines the standard integer types) but not <inttypes.h>.
|
||||
* <inttypes.h> includes <stdint.h> and adds the printf/scanf helpers PRId32, SCNx16 etc.
|
||||
* which we almost never use, plus stuff like imaxabs() which we never use.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#if U_PLATFORM == U_PF_OS390
|
||||
/* The features header is needed to get (u)int64_t sometimes. */
|
||||
#include <features.h>
|
||||
/* z/OS has <stdint.h>, but some versions are missing uint8_t (APAR PK62248). */
|
||||
#if !defined(__uint8_t)
|
||||
#define __uint8_t 1
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
#endif /* U_PLATFORM == U_PF_OS390 */
|
||||
|
||||
#elif U_HAVE_INTTYPES_H
|
||||
|
||||
# include <inttypes.h>
|
||||
|
||||
#else /* neither U_HAVE_STDINT_H nor U_HAVE_INTTYPES_H */
|
||||
|
||||
#if ! U_HAVE_INT8_T
|
||||
typedef signed char int8_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_UINT8_T
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_INT16_T
|
||||
typedef signed short int16_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_UINT16_T
|
||||
typedef unsigned short uint16_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_INT32_T
|
||||
typedef signed int int32_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_UINT32_T
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_INT64_T
|
||||
#ifdef _MSC_VER
|
||||
typedef signed __int64 int64_t;
|
||||
#else
|
||||
typedef signed long long int64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ! U_HAVE_UINT64_T
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* U_HAVE_STDINT_H / U_HAVE_INTTYPES_H */
|
||||
|
||||
#endif /* _PTYPES_H */
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* FILE NAME : putil.h
|
||||
*
|
||||
* Date Name Description
|
||||
* 05/14/98 nos Creation (content moved here from utypes.h).
|
||||
* 06/17/99 erm Added IEEE_754
|
||||
* 07/22/98 stephen Added IEEEremainder, max, min, trunc
|
||||
* 08/13/98 stephen Added isNegativeInfinity, isPositiveInfinity
|
||||
* 08/24/98 stephen Added longBitsFromDouble
|
||||
* 03/02/99 stephen Removed openFile(). Added AS400 support.
|
||||
* 04/15/99 stephen Converted to C
|
||||
* 11/15/99 helena Integrated S/390 changes for IEEE support.
|
||||
* 01/11/00 helena Added u_getVersion.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef PUTIL_H
|
||||
#define PUTIL_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: Platform Utilities
|
||||
*/
|
||||
|
||||
/*==========================================================================*/
|
||||
/* Platform utilities */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* Platform utilities isolates the platform dependencies of the
|
||||
* libarary. For each platform which this code is ported to, these
|
||||
* functions may have to be re-implemented.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the ICU data directory.
|
||||
* The data directory is where common format ICU data files (.dat files)
|
||||
* are loaded from. Note that normal use of the built-in ICU
|
||||
* facilities does not require loading of an external data file;
|
||||
* unless you are adding custom data to ICU, the data directory
|
||||
* does not need to be set.
|
||||
*
|
||||
* The data directory is determined as follows:
|
||||
* If u_setDataDirectory() has been called, that is it, otherwise
|
||||
* if the ICU_DATA environment variable is set, use that, otherwise
|
||||
* If a data directory was specifed at ICU build time
|
||||
* <code>
|
||||
* \code
|
||||
* #define ICU_DATA_DIR "path"
|
||||
* \endcode
|
||||
* </code> use that,
|
||||
* otherwise no data directory is available.
|
||||
*
|
||||
* @return the data directory, or an empty string ("") if no data directory has
|
||||
* been specified.
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
U_STABLE const char* U_EXPORT2 u_getDataDirectory(void);
|
||||
|
||||
/**
|
||||
* Set the ICU data directory.
|
||||
* The data directory is where common format ICU data files (.dat files)
|
||||
* are loaded from. Note that normal use of the built-in ICU
|
||||
* facilities does not require loading of an external data file;
|
||||
* unless you are adding custom data to ICU, the data directory
|
||||
* does not need to be set.
|
||||
*
|
||||
* This function should be called at most once in a process, before the
|
||||
* first ICU operation (e.g., u_init()) that will require the loading of an
|
||||
* ICU data file.
|
||||
* This function is not thread-safe. Use it before calling ICU APIs from
|
||||
* multiple threads.
|
||||
*
|
||||
* @param directory The directory to be set.
|
||||
*
|
||||
* @see u_init
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
U_STABLE void U_EXPORT2 u_setDataDirectory(const char *directory);
|
||||
|
||||
/**
|
||||
* @{
|
||||
* Filesystem file and path separator characters.
|
||||
* Example: '/' and ':' on Unix, '\\' and ';' on Windows.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
#if U_PLATFORM == U_PF_CLASSIC_MACOS
|
||||
# define U_FILE_SEP_CHAR ':'
|
||||
# define U_FILE_ALT_SEP_CHAR ':'
|
||||
# define U_PATH_SEP_CHAR ';'
|
||||
# define U_FILE_SEP_STRING ":"
|
||||
# define U_FILE_ALT_SEP_STRING ":"
|
||||
# define U_PATH_SEP_STRING ";"
|
||||
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
||||
# define U_FILE_SEP_CHAR '\\'
|
||||
# define U_FILE_ALT_SEP_CHAR '/'
|
||||
# define U_PATH_SEP_CHAR ';'
|
||||
# define U_FILE_SEP_STRING "\\"
|
||||
# define U_FILE_ALT_SEP_STRING "/"
|
||||
# define U_PATH_SEP_STRING ";"
|
||||
#else
|
||||
# define U_FILE_SEP_CHAR '/'
|
||||
# define U_FILE_ALT_SEP_CHAR '/'
|
||||
# define U_PATH_SEP_CHAR ':'
|
||||
# define U_FILE_SEP_STRING "/"
|
||||
# define U_FILE_ALT_SEP_STRING "/"
|
||||
# define U_PATH_SEP_STRING ":"
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Convert char characters to UChar characters.
|
||||
* This utility function is useful only for "invariant characters"
|
||||
* that are encoded in the platform default encoding.
|
||||
* They are a small, constant subset of the encoding and include
|
||||
* just the latin letters, digits, and some punctuation.
|
||||
* For details, see U_CHARSET_FAMILY.
|
||||
*
|
||||
* @param cs Input string, points to <code>length</code>
|
||||
* character bytes from a subset of the platform encoding.
|
||||
* @param us Output string, points to memory for <code>length</code>
|
||||
* Unicode characters.
|
||||
* @param length The number of characters to convert; this may
|
||||
* include the terminating <code>NUL</code>.
|
||||
*
|
||||
* @see U_CHARSET_FAMILY
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
U_STABLE void U_EXPORT2
|
||||
u_charsToUChars(const char *cs, UChar *us, int32_t length);
|
||||
|
||||
/**
|
||||
* Convert UChar characters to char characters.
|
||||
* This utility function is useful only for "invariant characters"
|
||||
* that can be encoded in the platform default encoding.
|
||||
* They are a small, constant subset of the encoding and include
|
||||
* just the latin letters, digits, and some punctuation.
|
||||
* For details, see U_CHARSET_FAMILY.
|
||||
*
|
||||
* @param us Input string, points to <code>length</code>
|
||||
* Unicode characters that can be encoded with the
|
||||
* codepage-invariant subset of the platform encoding.
|
||||
* @param cs Output string, points to memory for <code>length</code>
|
||||
* character bytes.
|
||||
* @param length The number of characters to convert; this may
|
||||
* include the terminating <code>NUL</code>.
|
||||
*
|
||||
* @see U_CHARSET_FAMILY
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
U_STABLE void U_EXPORT2
|
||||
u_UCharsToChars(const UChar *us, char *cs, int32_t length);
|
||||
|
||||
#endif
|
||||
@@ -1,782 +0,0 @@
|
||||
/*
|
||||
***************************************************************************
|
||||
* Copyright (C) 1999-2013 International Business Machines Corporation *
|
||||
* and others. All rights reserved. *
|
||||
***************************************************************************
|
||||
|
||||
**********************************************************************
|
||||
* Date Name Description
|
||||
* 10/22/99 alan Creation.
|
||||
* 11/11/99 rgillam Complete port from Java.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef RBBI_H
|
||||
#define RBBI_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Rule Based Break Iterator
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
|
||||
#include "unicode/brkiter.h"
|
||||
#include "unicode/udata.h"
|
||||
#include "unicode/parseerr.h"
|
||||
#include "unicode/schriter.h"
|
||||
#include "unicode/uchriter.h"
|
||||
|
||||
|
||||
struct UTrie;
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/** @internal */
|
||||
struct RBBIDataHeader;
|
||||
class RuleBasedBreakIteratorTables;
|
||||
class BreakIterator;
|
||||
class RBBIDataWrapper;
|
||||
class UStack;
|
||||
class LanguageBreakEngine;
|
||||
class UnhandledEngine;
|
||||
struct RBBIStateTable;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* A subclass of BreakIterator whose behavior is specified using a list of rules.
|
||||
* <p>Instances of this class are most commonly created by the factory methods of
|
||||
* BreakIterator::createWordInstance(), BreakIterator::createLineInstance(), etc.,
|
||||
* and then used via the abstract API in class BreakIterator</p>
|
||||
*
|
||||
* <p>See the ICU User Guide for information on Break Iterator Rules.</p>
|
||||
*
|
||||
* <p>This class is not intended to be subclassed. (Class DictionaryBasedBreakIterator
|
||||
* is a subclass, but that relationship is effectively internal to the ICU
|
||||
* implementation. The subclassing interface to RulesBasedBreakIterator is
|
||||
* not part of the ICU API, and may not remain stable.</p>
|
||||
*
|
||||
*/
|
||||
class U_COMMON_API RuleBasedBreakIterator : public BreakIterator {
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The UText through which this BreakIterator accesses the text
|
||||
* @internal
|
||||
*/
|
||||
UText *fText;
|
||||
|
||||
/**
|
||||
* A character iterator that refers to the same text as the UText, above.
|
||||
* Only included for compatibility with old API, which was based on CharacterIterators.
|
||||
* Value may be adopted from outside, or one of fSCharIter or fDCharIter, below.
|
||||
*/
|
||||
CharacterIterator *fCharIter;
|
||||
|
||||
/**
|
||||
* When the input text is provided by a UnicodeString, this will point to
|
||||
* a characterIterator that wraps that data. Needed only for the
|
||||
* implementation of getText(), a backwards compatibility issue.
|
||||
*/
|
||||
StringCharacterIterator *fSCharIter;
|
||||
|
||||
/**
|
||||
* When the input text is provided by a UText, this
|
||||
* dummy CharacterIterator over an empty string will
|
||||
* be returned from getText()
|
||||
*/
|
||||
UCharCharacterIterator *fDCharIter;
|
||||
|
||||
/**
|
||||
* The rule data for this BreakIterator instance
|
||||
* @internal
|
||||
*/
|
||||
RBBIDataWrapper *fData;
|
||||
|
||||
/** Index of the Rule {tag} values for the most recent match.
|
||||
* @internal
|
||||
*/
|
||||
int32_t fLastRuleStatusIndex;
|
||||
|
||||
/**
|
||||
* Rule tag value valid flag.
|
||||
* Some iterator operations don't intrinsically set the correct tag value.
|
||||
* This flag lets us lazily compute the value if we are ever asked for it.
|
||||
* @internal
|
||||
*/
|
||||
UBool fLastStatusIndexValid;
|
||||
|
||||
/**
|
||||
* Counter for the number of characters encountered with the "dictionary"
|
||||
* flag set.
|
||||
* @internal
|
||||
*/
|
||||
uint32_t fDictionaryCharCount;
|
||||
|
||||
/**
|
||||
* When a range of characters is divided up using the dictionary, the break
|
||||
* positions that are discovered are stored here, preventing us from having
|
||||
* to use either the dictionary or the state table again until the iterator
|
||||
* leaves this range of text. Has the most impact for line breaking.
|
||||
* @internal
|
||||
*/
|
||||
int32_t* fCachedBreakPositions;
|
||||
|
||||
/**
|
||||
* The number of elements in fCachedBreakPositions
|
||||
* @internal
|
||||
*/
|
||||
int32_t fNumCachedBreakPositions;
|
||||
|
||||
/**
|
||||
* if fCachedBreakPositions is not null, this indicates which item in the
|
||||
* cache the current iteration position refers to
|
||||
* @internal
|
||||
*/
|
||||
int32_t fPositionInCache;
|
||||
|
||||
/**
|
||||
*
|
||||
* If present, UStack of LanguageBreakEngine objects that might handle
|
||||
* dictionary characters. Searched from top to bottom to find an object to
|
||||
* handle a given character.
|
||||
* @internal
|
||||
*/
|
||||
UStack *fLanguageBreakEngines;
|
||||
|
||||
/**
|
||||
*
|
||||
* If present, the special LanguageBreakEngine used for handling
|
||||
* characters that are in the dictionary set, but not handled by any
|
||||
* LangugageBreakEngine.
|
||||
* @internal
|
||||
*/
|
||||
UnhandledEngine *fUnhandledBreakEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
* The type of the break iterator, or -1 if it has not been set.
|
||||
* @internal
|
||||
*/
|
||||
int32_t fBreakType;
|
||||
|
||||
protected:
|
||||
//=======================================================================
|
||||
// constructors
|
||||
//=======================================================================
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Constant to be used in the constructor
|
||||
* RuleBasedBreakIterator(RBBIDataHeader*, EDontAdopt, UErrorCode &);
|
||||
* which does not adopt the memory indicated by the RBBIDataHeader*
|
||||
* parameter.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
enum EDontAdopt {
|
||||
kDontAdopt
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor from a flattened set of RBBI data in malloced memory.
|
||||
* RulesBasedBreakIterators built from a custom set of rules
|
||||
* are created via this constructor; the rules are compiled
|
||||
* into memory, then the break iterator is constructed here.
|
||||
*
|
||||
* The break iterator adopts the memory, and will
|
||||
* free it when done.
|
||||
* @internal
|
||||
*/
|
||||
RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Constructor from a flattened set of RBBI data in memory which need not
|
||||
* be malloced (e.g. it may be a memory-mapped file, etc.).
|
||||
*
|
||||
* This version does not adopt the memory, and does not
|
||||
* free it when done.
|
||||
* @internal
|
||||
*/
|
||||
RuleBasedBreakIterator(const RBBIDataHeader* data, enum EDontAdopt dontAdopt, UErrorCode &status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
|
||||
friend class RBBIRuleBuilder;
|
||||
/** @internal */
|
||||
friend class BreakIterator;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor. Creates an empty shell of an iterator, with no
|
||||
* rules or text to iterate over. Object can subsequently be assigned to.
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
RuleBasedBreakIterator();
|
||||
|
||||
/**
|
||||
* Copy constructor. Will produce a break iterator with the same behavior,
|
||||
* and which iterates over the same text, as the one passed in.
|
||||
* @param that The RuleBasedBreakIterator passed to be copied
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
|
||||
|
||||
/**
|
||||
* Construct a RuleBasedBreakIterator from a set of rules supplied as a string.
|
||||
* @param rules The break rules to be used.
|
||||
* @param parseError In the event of a syntax error in the rules, provides the location
|
||||
* within the rules of the problem.
|
||||
* @param status Information on any errors encountered.
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
RuleBasedBreakIterator( const UnicodeString &rules,
|
||||
UParseError &parseError,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Contruct a RuleBasedBreakIterator from a set of precompiled binary rules.
|
||||
* Binary rules are obtained from RulesBasedBreakIterator::getBinaryRules().
|
||||
* Construction of a break iterator in this way is substantially faster than
|
||||
* constuction from source rules.
|
||||
*
|
||||
* Ownership of the storage containing the compiled rules remains with the
|
||||
* caller of this function. The compiled rules must not be modified or
|
||||
* deleted during the life of the break iterator.
|
||||
*
|
||||
* The compiled rules are not compatible across different major versions of ICU.
|
||||
* The compiled rules are comaptible only between machines with the same
|
||||
* byte ordering (little or big endian) and the same base character set family
|
||||
* (ASCII or EBCDIC).
|
||||
*
|
||||
* @see #getBinaryRules
|
||||
* @param compiledRules A pointer to the compiled break rules to be used.
|
||||
* @param ruleLength The length of the compiled break rules, in bytes. This
|
||||
* corresponds to the length value produced by getBinaryRules().
|
||||
* @param status Information on any errors encountered, including invalid
|
||||
* binary rules.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
RuleBasedBreakIterator(const uint8_t *compiledRules,
|
||||
uint32_t ruleLength,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* This constructor uses the udata interface to create a BreakIterator
|
||||
* whose internal tables live in a memory-mapped file. "image" is an
|
||||
* ICU UDataMemory handle for the pre-compiled break iterator tables.
|
||||
* @param image handle to the memory image for the break iterator data.
|
||||
* Ownership of the UDataMemory handle passes to the Break Iterator,
|
||||
* which will be responsible for closing it when it is no longer needed.
|
||||
* @param status Information on any errors encountered.
|
||||
* @see udata_open
|
||||
* @see #getBinaryRules
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~RuleBasedBreakIterator();
|
||||
|
||||
/**
|
||||
* Assignment operator. Sets this iterator to have the same behavior,
|
||||
* and iterate over the same text, as the one passed in.
|
||||
* @param that The RuleBasedBreakItertor passed in
|
||||
* @return the newly created RuleBasedBreakIterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
|
||||
|
||||
/**
|
||||
* Equality operator. Returns TRUE if both BreakIterators are of the
|
||||
* same class, have the same behavior, and iterate over the same text.
|
||||
* @param that The BreakIterator to be compared for equality
|
||||
* @return TRUE if both BreakIterators are of the
|
||||
* same class, have the same behavior, and iterate over the same text.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const BreakIterator& that) const;
|
||||
|
||||
/**
|
||||
* Not-equal operator. If operator== returns TRUE, this returns FALSE,
|
||||
* and vice versa.
|
||||
* @param that The BreakIterator to be compared for inequality
|
||||
* @return TRUE if both BreakIterators are not same.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool operator!=(const BreakIterator& that) const;
|
||||
|
||||
/**
|
||||
* Returns a newly-constructed RuleBasedBreakIterator with the same
|
||||
* behavior, and iterating over the same text, as this one.
|
||||
* Differs from the copy constructor in that it is polymorphic, and
|
||||
* will correctly clone (copy) a derived class.
|
||||
* clone() is thread safe. Multiple threads may simultaeneously
|
||||
* clone the same source break iterator.
|
||||
* @return a newly-constructed RuleBasedBreakIterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual BreakIterator* clone() const;
|
||||
|
||||
/**
|
||||
* Compute a hash code for this BreakIterator
|
||||
* @return A hash code
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t hashCode(void) const;
|
||||
|
||||
/**
|
||||
* Returns the description used to create this iterator
|
||||
* @return the description used to create this iterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual const UnicodeString& getRules(void) const;
|
||||
|
||||
//=======================================================================
|
||||
// BreakIterator overrides
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Return a CharacterIterator over the text being analyzed.
|
||||
* The returned character iterator is owned by the break iterator, and must
|
||||
* not be deleted by the caller. Repeated calls to this function may
|
||||
* return the same CharacterIterator.
|
||||
* </p>
|
||||
* <p>
|
||||
* The returned character iterator must not be used concurrently with
|
||||
* the break iterator. If concurrent operation is needed, clone the
|
||||
* returned character iterator first and operate on the clone.
|
||||
* </p>
|
||||
* <p>
|
||||
* When the break iterator is operating on text supplied via a UText,
|
||||
* this function will fail. Lacking any way to signal failures, it
|
||||
* returns an CharacterIterator containing no text.
|
||||
* The function getUText() provides similar functionality,
|
||||
* is reliable, and is more efficient.
|
||||
* </p>
|
||||
*
|
||||
* TODO: deprecate this function?
|
||||
*
|
||||
* @return An iterator over the text being analyzed.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual CharacterIterator& getText(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a UText for the text being analyzed.
|
||||
* The returned UText is a shallow clone of the UText used internally
|
||||
* by the break iterator implementation. It can safely be used to
|
||||
* access the text without impacting any break iterator operations,
|
||||
* but the underlying text itself must not be altered.
|
||||
*
|
||||
* @param fillIn A UText to be filled in. If NULL, a new UText will be
|
||||
* allocated to hold the result.
|
||||
* @param status receives any error codes.
|
||||
* @return The current UText for this break iterator. If an input
|
||||
* UText was provided, it will always be returned.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
virtual UText *getUText(UText *fillIn, UErrorCode &status) const;
|
||||
|
||||
/**
|
||||
* Set the iterator to analyze a new piece of text. This function resets
|
||||
* the current iteration position to the beginning of the text.
|
||||
* @param newText An iterator over the text to analyze. The BreakIterator
|
||||
* takes ownership of the character iterator. The caller MUST NOT delete it!
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptText(CharacterIterator* newText);
|
||||
|
||||
/**
|
||||
* Set the iterator to analyze a new piece of text. This function resets
|
||||
* the current iteration position to the beginning of the text.
|
||||
* @param newText The text to analyze.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setText(const UnicodeString& newText);
|
||||
|
||||
/**
|
||||
* Reset the break iterator to operate over the text represented by
|
||||
* the UText. The iterator position is reset to the start.
|
||||
*
|
||||
* This function makes a shallow clone of the supplied UText. This means
|
||||
* that the caller is free to immediately close or otherwise reuse the
|
||||
* Utext that was passed as a parameter, but that the underlying text itself
|
||||
* must not be altered while being referenced by the break iterator.
|
||||
*
|
||||
* @param text The UText used to change the text.
|
||||
* @param status Receives any error codes.
|
||||
* @stable ICU 3.4
|
||||
*/
|
||||
virtual void setText(UText *text, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Sets the current iteration position to the beginning of the text.
|
||||
* @return The offset of the beginning of the text.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t first(void);
|
||||
|
||||
/**
|
||||
* Sets the current iteration position to the end of the text.
|
||||
* @return The text's past-the-end offset.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t last(void);
|
||||
|
||||
/**
|
||||
* Advances the iterator either forward or backward the specified number of steps.
|
||||
* Negative values move backward, and positive values move forward. This is
|
||||
* equivalent to repeatedly calling next() or previous().
|
||||
* @param n The number of steps to move. The sign indicates the direction
|
||||
* (negative is backwards, and positive is forwards).
|
||||
* @return The character offset of the boundary position n boundaries away from
|
||||
* the current one.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t next(int32_t n);
|
||||
|
||||
/**
|
||||
* Advances the iterator to the next boundary position.
|
||||
* @return The position of the first boundary after this one.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t next(void);
|
||||
|
||||
/**
|
||||
* Moves the iterator backwards, to the last boundary preceding this one.
|
||||
* @return The position of the last boundary position preceding this one.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t previous(void);
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first boundary position following
|
||||
* the specified position.
|
||||
* @param offset The position from which to begin searching for a break position.
|
||||
* @return The position of the first break after the current position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t following(int32_t offset);
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the last boundary position before the
|
||||
* specified position.
|
||||
* @param offset The position to begin searching for a break from.
|
||||
* @return The position of the last boundary before the starting position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t preceding(int32_t offset);
|
||||
|
||||
/**
|
||||
* Returns true if the specfied position is a boundary position. As a side
|
||||
* effect, leaves the iterator pointing to the first boundary position at
|
||||
* or after "offset".
|
||||
* @param offset the offset to check.
|
||||
* @return True if "offset" is a boundary position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool isBoundary(int32_t offset);
|
||||
|
||||
/**
|
||||
* Returns the current iteration position.
|
||||
* @return The current iteration position.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t current(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Return the status tag from the break rule that determined the most recently
|
||||
* returned break position. For break rules that do not specify a
|
||||
* status, a default value of 0 is returned. If more than one break rule
|
||||
* would cause a boundary to be located at some position in the text,
|
||||
* the numerically largest of the applicable status values is returned.
|
||||
* <p>
|
||||
* Of the standard types of ICU break iterators, only word break and
|
||||
* line break provide status values. The values are defined in
|
||||
* the header file ubrk.h. For Word breaks, the status allows distinguishing between words
|
||||
* that contain alphabetic letters, "words" that appear to be numbers,
|
||||
* punctuation and spaces, words containing ideographic characters, and
|
||||
* more. For Line Break, the status distinguishes between hard (mandatory) breaks
|
||||
* and soft (potential) break positions.
|
||||
* <p>
|
||||
* <code>getRuleStatus()</code> can be called after obtaining a boundary
|
||||
* position from <code>next()</code>, <code>previous()</code>, or
|
||||
* any other break iterator functions that returns a boundary position.
|
||||
* <p>
|
||||
* When creating custom break rules, one is free to define whatever
|
||||
* status values may be convenient for the application.
|
||||
* <p>
|
||||
* Note: this function is not thread safe. It should not have been
|
||||
* declared const, and the const remains only for compatibility
|
||||
* reasons. (The function is logically const, but not bit-wise const).
|
||||
* <p>
|
||||
* @return the status from the break rule that determined the most recently
|
||||
* returned break position.
|
||||
*
|
||||
* @see UWordBreak
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual int32_t getRuleStatus() const;
|
||||
|
||||
/**
|
||||
* Get the status (tag) values from the break rule(s) that determined the most
|
||||
* recently returned break position.
|
||||
* <p>
|
||||
* The returned status value(s) are stored into an array provided by the caller.
|
||||
* The values are stored in sorted (ascending) order.
|
||||
* If the capacity of the output array is insufficient to hold the data,
|
||||
* the output will be truncated to the available length, and a
|
||||
* U_BUFFER_OVERFLOW_ERROR will be signaled.
|
||||
*
|
||||
* @param fillInVec an array to be filled in with the status values.
|
||||
* @param capacity the length of the supplied vector. A length of zero causes
|
||||
* the function to return the number of status values, in the
|
||||
* normal way, without attemtping to store any values.
|
||||
* @param status receives error codes.
|
||||
* @return The number of rule status values from rules that determined
|
||||
* the most recent boundary returned by the break iterator.
|
||||
* In the event of a U_BUFFER_OVERFLOW_ERROR, the return value
|
||||
* is the total number of status values that were available,
|
||||
* not the reduced number that were actually returned.
|
||||
* @see getRuleStatus
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
|
||||
* This method is to implement a simple version of RTTI, since not all
|
||||
* C++ compilers support genuine RTTI. Polymorphic operator==() and
|
||||
* clone() methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Returns the class ID for this class. This is useful only for
|
||||
* comparing to a return value from getDynamicClassID(). For example:
|
||||
*
|
||||
* Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* Derived::getStaticClassID()) ...
|
||||
*
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Deprecated functionality. Use clone() instead.
|
||||
*
|
||||
* Create a clone (copy) of this break iterator in memory provided
|
||||
* by the caller. The idea is to increase performance by avoiding
|
||||
* a storage allocation. Use of this functoin is NOT RECOMMENDED.
|
||||
* Performance gains are minimal, and correct buffer management is
|
||||
* tricky. Use clone() instead.
|
||||
*
|
||||
* @param stackBuffer The pointer to the memory into which the cloned object
|
||||
* should be placed. If NULL, allocate heap memory
|
||||
* for the cloned object.
|
||||
* @param BufferSize The size of the buffer. If zero, return the required
|
||||
* buffer size, but do not clone the object. If the
|
||||
* size was too small (but not zero), allocate heap
|
||||
* storage for the cloned object.
|
||||
*
|
||||
* @param status Error status. U_SAFECLONE_ALLOCATED_WARNING will be
|
||||
* returned if the the provided buffer was too small, and
|
||||
* the clone was therefore put on the heap.
|
||||
*
|
||||
* @return Pointer to the clone object. This may differ from the stackBuffer
|
||||
* address if the byte alignment of the stack buffer was not suitable
|
||||
* or if the stackBuffer was too small to hold the clone.
|
||||
* @deprecated ICU 52. Use clone() instead.
|
||||
*/
|
||||
virtual BreakIterator * createBufferClone(void *stackBuffer,
|
||||
int32_t &BufferSize,
|
||||
UErrorCode &status);
|
||||
|
||||
|
||||
/**
|
||||
* Return the binary form of compiled break rules,
|
||||
* which can then be used to create a new break iterator at some
|
||||
* time in the future. Creating a break iterator from pre-compiled rules
|
||||
* is much faster than building one from the source form of the
|
||||
* break rules.
|
||||
*
|
||||
* The binary data can only be used with the same version of ICU
|
||||
* and on the same platform type (processor endian-ness)
|
||||
*
|
||||
* @param length Returns the length of the binary data. (Out paramter.)
|
||||
*
|
||||
* @return A pointer to the binary (compiled) rule data. The storage
|
||||
* belongs to the RulesBasedBreakIterator object, not the
|
||||
* caller, and must not be modified or deleted.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
virtual const uint8_t *getBinaryRules(uint32_t &length);
|
||||
|
||||
/**
|
||||
* Set the subject text string upon which the break iterator is operating
|
||||
* without changing any other aspect of the matching state.
|
||||
* The new and previous text strings must have the same content.
|
||||
*
|
||||
* This function is intended for use in environments where ICU is operating on
|
||||
* strings that may move around in memory. It provides a mechanism for notifying
|
||||
* ICU that the string has been relocated, and providing a new UText to access the
|
||||
* string in its new position.
|
||||
*
|
||||
* Note that the break iterator implementation never copies the underlying text
|
||||
* of a string being processed, but always operates directly on the original text
|
||||
* provided by the user. Refreshing simply drops the references to the old text
|
||||
* and replaces them with references to the new.
|
||||
*
|
||||
* Caution: this function is normally used only by very specialized,
|
||||
* system-level code. One example use case is with garbage collection that moves
|
||||
* the text in memory.
|
||||
*
|
||||
* @param input The new (moved) text string.
|
||||
* @param status Receives errors detected by this function.
|
||||
* @return *this
|
||||
*
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status);
|
||||
|
||||
|
||||
protected:
|
||||
//=======================================================================
|
||||
// implementation
|
||||
//=======================================================================
|
||||
/**
|
||||
* Dumps caches and performs other actions associated with a complete change
|
||||
* in text or iteration position.
|
||||
* @internal
|
||||
*/
|
||||
virtual void reset(void);
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Return true if the category lookup for this char
|
||||
* indicates that it is in the set of dictionary lookup chars.
|
||||
* This function is intended for use by dictionary based break iterators.
|
||||
* @return true if the category lookup for this char
|
||||
* indicates that it is in the set of dictionary lookup chars.
|
||||
* @internal
|
||||
*/
|
||||
virtual UBool isDictionaryChar(UChar32);
|
||||
|
||||
/**
|
||||
* Get the type of the break iterator.
|
||||
* @internal
|
||||
*/
|
||||
virtual int32_t getBreakType() const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the type of the break iterator.
|
||||
* @internal
|
||||
*/
|
||||
virtual void setBreakType(int32_t type);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Common initialization function, used by constructors and bufferClone.
|
||||
* @internal
|
||||
*/
|
||||
void init();
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* This method backs the iterator back up to a "safe position" in the text.
|
||||
* This is a position that we know, without any context, must be a break position.
|
||||
* The various calling methods then iterate forward from this safe position to
|
||||
* the appropriate position to return. (For more information, see the description
|
||||
* of buildBackwardsStateTable() in RuleBasedBreakIterator.Builder.)
|
||||
* @param statetable state table used of moving backwards
|
||||
* @internal
|
||||
*/
|
||||
int32_t handlePrevious(const RBBIStateTable *statetable);
|
||||
|
||||
/**
|
||||
* This method is the actual implementation of the next() method. All iteration
|
||||
* vectors through here. This method initializes the state machine to state 1
|
||||
* and advances through the text character by character until we reach the end
|
||||
* of the text or the state machine transitions to state 0. We update our return
|
||||
* value every time the state machine passes through a possible end state.
|
||||
* @param statetable state table used of moving forwards
|
||||
* @internal
|
||||
*/
|
||||
int32_t handleNext(const RBBIStateTable *statetable);
|
||||
|
||||
protected:
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This is the function that actually implements dictionary-based
|
||||
* breaking. Covering at least the range from startPos to endPos,
|
||||
* it checks for dictionary characters, and if it finds them determines
|
||||
* the appropriate object to deal with them. It may cache found breaks in
|
||||
* fCachedBreakPositions as it goes. It may well also look at text outside
|
||||
* the range startPos to endPos.
|
||||
* If going forward, endPos is the normal Unicode break result, and
|
||||
* if goind in reverse, startPos is the normal Unicode break result
|
||||
* @param startPos The start position of a range of text
|
||||
* @param endPos The end position of a range of text
|
||||
* @param reverse The call is for the reverse direction
|
||||
* @internal
|
||||
*/
|
||||
int32_t checkDictionary(int32_t startPos, int32_t endPos, UBool reverse);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* This function returns the appropriate LanguageBreakEngine for a
|
||||
* given character c.
|
||||
* @param c A character in the dictionary set
|
||||
* @internal
|
||||
*/
|
||||
const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void makeRuleStatusValid();
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Inline Functions Definitions ...
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline UBool RuleBasedBreakIterator::operator!=(const BreakIterator& that) const {
|
||||
return !operator==(that);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
||||
|
||||
#endif
|
||||
@@ -1,992 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1997-2013, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef RBNF_H
|
||||
#define RBNF_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Rule Based Number Format
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def U_HAVE_RBNF
|
||||
* This will be 0 if RBNF support is not included in ICU
|
||||
* and 1 if it is.
|
||||
*
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
#if UCONFIG_NO_FORMATTING
|
||||
#define U_HAVE_RBNF 0
|
||||
#else
|
||||
#define U_HAVE_RBNF 1
|
||||
|
||||
#include "unicode/coll.h"
|
||||
#include "unicode/dcfmtsym.h"
|
||||
#include "unicode/fmtable.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/strenum.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class NFRuleSet;
|
||||
class LocalizationInfo;
|
||||
|
||||
/**
|
||||
* Tags for the predefined rulesets.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
enum URBNFRuleSetTag {
|
||||
URBNF_SPELLOUT,
|
||||
URBNF_ORDINAL,
|
||||
URBNF_DURATION,
|
||||
URBNF_NUMBERING_SYSTEM,
|
||||
URBNF_COUNT
|
||||
};
|
||||
|
||||
#if UCONFIG_NO_COLLATION
|
||||
class Collator;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The RuleBasedNumberFormat class formats numbers according to a set of rules. This number formatter is
|
||||
* typically used for spelling out numeric values in words (e.g., 25,3476 as
|
||||
* "twenty-five thousand three hundred seventy-six" or "vingt-cinq mille trois
|
||||
* cents soixante-seize" or
|
||||
* "fünfundzwanzigtausenddreihundertsechsundsiebzig"), but can also be used for
|
||||
* other complicated formatting tasks, such as formatting a number of seconds as hours,
|
||||
* minutes and seconds (e.g., 3,730 as "1:02:10").
|
||||
*
|
||||
* <p>The resources contain three predefined formatters for each locale: spellout, which
|
||||
* spells out a value in words (123 is "one hundred twenty-three"); ordinal, which
|
||||
* appends an ordinal suffix to the end of a numeral (123 is "123rd"); and
|
||||
* duration, which shows a duration in seconds as hours, minutes, and seconds (123 is
|
||||
* "2:03"). The client can also define more specialized <tt>RuleBasedNumberFormat</tt>s
|
||||
* by supplying programmer-defined rule sets.</p>
|
||||
*
|
||||
* <p>The behavior of a <tt>RuleBasedNumberFormat</tt> is specified by a textual description
|
||||
* that is either passed to the constructor as a <tt>String</tt> or loaded from a resource
|
||||
* bundle. In its simplest form, the description consists of a semicolon-delimited list of <em>rules.</em>
|
||||
* Each rule has a string of output text and a value or range of values it is applicable to.
|
||||
* In a typical spellout rule set, the first twenty rules are the words for the numbers from
|
||||
* 0 to 19:</p>
|
||||
*
|
||||
* <pre>zero; one; two; three; four; five; six; seven; eight; nine;
|
||||
* ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen; seventeen; eighteen; nineteen;</pre>
|
||||
*
|
||||
* <p>For larger numbers, we can use the preceding set of rules to format the ones place, and
|
||||
* we only have to supply the words for the multiples of 10:</p>
|
||||
*
|
||||
* <pre> 20: twenty[->>];
|
||||
* 30: thirty[->>];
|
||||
* 40: forty[->>];
|
||||
* 50: fifty[->>];
|
||||
* 60: sixty[->>];
|
||||
* 70: seventy[->>];
|
||||
* 80: eighty[->>];
|
||||
* 90: ninety[->>];</pre>
|
||||
*
|
||||
* <p>In these rules, the <em>base value</em> is spelled out explicitly and set off from the
|
||||
* rule's output text with a colon. The rules are in a sorted list, and a rule is applicable
|
||||
* to all numbers from its own base value to one less than the next rule's base value. The
|
||||
* ">>" token is called a <em>substitution</em> and tells the fomatter to
|
||||
* isolate the number's ones digit, format it using this same set of rules, and place the
|
||||
* result at the position of the ">>" token. Text in brackets is omitted if
|
||||
* the number being formatted is an even multiple of 10 (the hyphen is a literal hyphen; 24
|
||||
* is "twenty-four," not "twenty four").</p>
|
||||
*
|
||||
* <p>For even larger numbers, we can actually look up several parts of the number in the
|
||||
* list:</p>
|
||||
*
|
||||
* <pre>100: << hundred[ >>];</pre>
|
||||
*
|
||||
* <p>The "<<" represents a new kind of substitution. The << isolates
|
||||
* the hundreds digit (and any digits to its left), formats it using this same rule set, and
|
||||
* places the result where the "<<" was. Notice also that the meaning of
|
||||
* >> has changed: it now refers to both the tens and the ones digits. The meaning of
|
||||
* both substitutions depends on the rule's base value. The base value determines the rule's <em>divisor,</em>
|
||||
* which is the highest power of 10 that is less than or equal to the base value (the user
|
||||
* can change this). To fill in the substitutions, the formatter divides the number being
|
||||
* formatted by the divisor. The integral quotient is used to fill in the <<
|
||||
* substitution, and the remainder is used to fill in the >> substitution. The meaning
|
||||
* of the brackets changes similarly: text in brackets is omitted if the value being
|
||||
* formatted is an even multiple of the rule's divisor. The rules are applied recursively, so
|
||||
* if a substitution is filled in with text that includes another substitution, that
|
||||
* substitution is also filled in.</p>
|
||||
*
|
||||
* <p>This rule covers values up to 999, at which point we add another rule:</p>
|
||||
*
|
||||
* <pre>1000: << thousand[ >>];</pre>
|
||||
*
|
||||
* <p>Again, the meanings of the brackets and substitution tokens shift because the rule's
|
||||
* base value is a higher power of 10, changing the rule's divisor. This rule can actually be
|
||||
* used all the way up to 999,999. This allows us to finish out the rules as follows:</p>
|
||||
*
|
||||
* <pre> 1,000,000: << million[ >>];
|
||||
* 1,000,000,000: << billion[ >>];
|
||||
* 1,000,000,000,000: << trillion[ >>];
|
||||
* 1,000,000,000,000,000: OUT OF RANGE!;</pre>
|
||||
*
|
||||
* <p>Commas, periods, and spaces can be used in the base values to improve legibility and
|
||||
* are ignored by the rule parser. The last rule in the list is customarily treated as an
|
||||
* "overflow rule," applying to everything from its base value on up, and often (as
|
||||
* in this example) being used to print out an error message or default representation.
|
||||
* Notice also that the size of the major groupings in large numbers is controlled by the
|
||||
* spacing of the rules: because in English we group numbers by thousand, the higher rules
|
||||
* are separated from each other by a factor of 1,000.</p>
|
||||
*
|
||||
* <p>To see how these rules actually work in practice, consider the following example:
|
||||
* Formatting 25,430 with this rule set would work like this:</p>
|
||||
*
|
||||
* <table border="0" width="100%">
|
||||
* <tr>
|
||||
* <td><strong><< thousand >></strong></td>
|
||||
* <td>[the rule whose base value is 1,000 is applicable to 25,340]</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><strong>twenty->></strong> thousand >></td>
|
||||
* <td>[25,340 over 1,000 is 25. The rule for 20 applies.]</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>twenty-<strong>five</strong> thousand >></td>
|
||||
* <td>[25 mod 10 is 5. The rule for 5 is "five."</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>twenty-five thousand <strong><< hundred >></strong></td>
|
||||
* <td>[25,340 mod 1,000 is 340. The rule for 100 applies.]</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>twenty-five thousand <strong>three</strong> hundred >></td>
|
||||
* <td>[340 over 100 is 3. The rule for 3 is "three."]</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>twenty-five thousand three hundred <strong>forty</strong></td>
|
||||
* <td>[340 mod 100 is 40. The rule for 40 applies. Since 40 divides
|
||||
* evenly by 10, the hyphen and substitution in the brackets are omitted.]</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The above syntax suffices only to format positive integers. To format negative numbers,
|
||||
* we add a special rule:</p>
|
||||
*
|
||||
* <pre>-x: minus >>;</pre>
|
||||
*
|
||||
* <p>This is called a <em>negative-number rule,</em> and is identified by "-x"
|
||||
* where the base value would be. This rule is used to format all negative numbers. the
|
||||
* >> token here means "find the number's absolute value, format it with these
|
||||
* rules, and put the result here."</p>
|
||||
*
|
||||
* <p>We also add a special rule called a <em>fraction rule </em>for numbers with fractional
|
||||
* parts:</p>
|
||||
*
|
||||
* <pre>x.x: << point >>;</pre>
|
||||
*
|
||||
* <p>This rule is used for all positive non-integers (negative non-integers pass through the
|
||||
* negative-number rule first and then through this rule). Here, the << token refers to
|
||||
* the number's integral part, and the >> to the number's fractional part. The
|
||||
* fractional part is formatted as a series of single-digit numbers (e.g., 123.456 would be
|
||||
* formatted as "one hundred twenty-three point four five six").</p>
|
||||
*
|
||||
* <p>To see how this rule syntax is applied to various languages, examine the resource data.</p>
|
||||
*
|
||||
* <p>There is actually much more flexibility built into the rule language than the
|
||||
* description above shows. A formatter may own multiple rule sets, which can be selected by
|
||||
* the caller, and which can use each other to fill in their substitutions. Substitutions can
|
||||
* also be filled in with digits, using a DecimalFormat object. There is syntax that can be
|
||||
* used to alter a rule's divisor in various ways. And there is provision for much more
|
||||
* flexible fraction handling. A complete description of the rule syntax follows:</p>
|
||||
*
|
||||
* <hr>
|
||||
*
|
||||
* <p>The description of a <tt>RuleBasedNumberFormat</tt>'s behavior consists of one or more <em>rule
|
||||
* sets.</em> Each rule set consists of a name, a colon, and a list of <em>rules.</em> A rule
|
||||
* set name must begin with a % sign. Rule sets with names that begin with a single % sign
|
||||
* are <em>public:</em> the caller can specify that they be used to format and parse numbers.
|
||||
* Rule sets with names that begin with %% are <em>private:</em> they exist only for the use
|
||||
* of other rule sets. If a formatter only has one rule set, the name may be omitted.</p>
|
||||
*
|
||||
* <p>The user can also specify a special "rule set" named <tt>%%lenient-parse</tt>.
|
||||
* The body of <tt>%%lenient-parse</tt> isn't a set of number-formatting rules, but a <tt>RuleBasedCollator</tt>
|
||||
* description which is used to define equivalences for lenient parsing. For more information
|
||||
* on the syntax, see <tt>RuleBasedCollator</tt>. For more information on lenient parsing,
|
||||
* see <tt>setLenientParse()</tt>. <em>Note:</em> symbols that have syntactic meaning
|
||||
* in collation rules, such as '&', have no particular meaning when appearing outside
|
||||
* of the <tt>lenient-parse</tt> rule set.</p>
|
||||
*
|
||||
* <p>The body of a rule set consists of an ordered, semicolon-delimited list of <em>rules.</em>
|
||||
* Internally, every rule has a base value, a divisor, rule text, and zero, one, or two <em>substitutions.</em>
|
||||
* These parameters are controlled by the description syntax, which consists of a <em>rule
|
||||
* descriptor,</em> a colon, and a <em>rule body.</em></p>
|
||||
*
|
||||
* <p>A rule descriptor can take one of the following forms (text in <em>italics</em> is the
|
||||
* name of a token):</p>
|
||||
*
|
||||
* <table border="0" width="100%">
|
||||
* <tr>
|
||||
* <td><em>bv</em>:</td>
|
||||
* <td><em>bv</em> specifies the rule's base value. <em>bv</em> is a decimal
|
||||
* number expressed using ASCII digits. <em>bv</em> may contain spaces, period, and commas,
|
||||
* which are ignored. The rule's divisor is the highest power of 10 less than or equal to
|
||||
* the base value.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><em>bv</em>/<em>rad</em>:</td>
|
||||
* <td><em>bv</em> specifies the rule's base value. The rule's divisor is the
|
||||
* highest power of <em>rad</em> less than or equal to the base value.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><em>bv</em>>:</td>
|
||||
* <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
|
||||
* let the radix be 10, and the exponent be the highest exponent of the radix that yields a
|
||||
* result less than or equal to the base value. Every > character after the base value
|
||||
* decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
|
||||
* raised to the power of the exponent; otherwise, the divisor is 1.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><em>bv</em>/<em>rad</em>>:</td>
|
||||
* <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
|
||||
* let the radix be <em>rad</em>, and the exponent be the highest exponent of the radix that
|
||||
* yields a result less than or equal to the base value. Every > character after the radix
|
||||
* decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
|
||||
* raised to the power of the exponent; otherwise, the divisor is 1.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>-x:</td>
|
||||
* <td>The rule is a negative-number rule.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>x.x:</td>
|
||||
* <td>The rule is an <em>improper fraction rule.</em></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>0.x:</td>
|
||||
* <td>The rule is a <em>proper fraction rule.</em></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>x.0:</td>
|
||||
* <td>The rule is a <em>master rule.</em></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><em>nothing</em></td>
|
||||
* <td>If the rule's rule descriptor is left out, the base value is one plus the
|
||||
* preceding rule's base value (or zero if this is the first rule in the list) in a normal
|
||||
* rule set. In a fraction rule set, the base value is the same as the preceding rule's
|
||||
* base value.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>A rule set may be either a regular rule set or a <em>fraction rule set,</em> depending
|
||||
* on whether it is used to format a number's integral part (or the whole number) or a
|
||||
* number's fractional part. Using a rule set to format a rule's fractional part makes it a
|
||||
* fraction rule set.</p>
|
||||
*
|
||||
* <p>Which rule is used to format a number is defined according to one of the following
|
||||
* algorithms: If the rule set is a regular rule set, do the following:
|
||||
*
|
||||
* <ul>
|
||||
* <li>If the rule set includes a master rule (and the number was passed in as a <tt>double</tt>),
|
||||
* use the master rule. (If the number being formatted was passed in as a <tt>long</tt>,
|
||||
* the master rule is ignored.)</li>
|
||||
* <li>If the number is negative, use the negative-number rule.</li>
|
||||
* <li>If the number has a fractional part and is greater than 1, use the improper fraction
|
||||
* rule.</li>
|
||||
* <li>If the number has a fractional part and is between 0 and 1, use the proper fraction
|
||||
* rule.</li>
|
||||
* <li>Binary-search the rule list for the rule with the highest base value less than or equal
|
||||
* to the number. If that rule has two substitutions, its base value is not an even multiple
|
||||
* of its divisor, and the number <em>is</em> an even multiple of the rule's divisor, use the
|
||||
* rule that precedes it in the rule list. Otherwise, use the rule itself.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the rule set is a fraction rule set, do the following:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Ignore negative-number and fraction rules.</li>
|
||||
* <li>For each rule in the list, multiply the number being formatted (which will always be
|
||||
* between 0 and 1) by the rule's base value. Keep track of the distance between the result
|
||||
* the nearest integer.</li>
|
||||
* <li>Use the rule that produced the result closest to zero in the above calculation. In the
|
||||
* event of a tie or a direct hit, use the first matching rule encountered. (The idea here is
|
||||
* to try each rule's base value as a possible denominator of a fraction. Whichever
|
||||
* denominator produces the fraction closest in value to the number being formatted wins.) If
|
||||
* the rule following the matching rule has the same base value, use it if the numerator of
|
||||
* the fraction is anything other than 1; if the numerator is 1, use the original matching
|
||||
* rule. (This is to allow singular and plural forms of the rule text without a lot of extra
|
||||
* hassle.)</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>A rule's body consists of a string of characters terminated by a semicolon. The rule
|
||||
* may include zero, one, or two <em>substitution tokens,</em> and a range of text in
|
||||
* brackets. The brackets denote optional text (and may also include one or both
|
||||
* substitutions). The exact meanings of the substitution tokens, and under what conditions
|
||||
* optional text is omitted, depend on the syntax of the substitution token and the context.
|
||||
* The rest of the text in a rule body is literal text that is output when the rule matches
|
||||
* the number being formatted.</p>
|
||||
*
|
||||
* <p>A substitution token begins and ends with a <em>token character.</em> The token
|
||||
* character and the context together specify a mathematical operation to be performed on the
|
||||
* number being formatted. An optional <em>substitution descriptor </em>specifies how the
|
||||
* value resulting from that operation is used to fill in the substitution. The position of
|
||||
* the substitution token in the rule body specifies the location of the resultant text in
|
||||
* the original rule text.</p>
|
||||
*
|
||||
* <p>The meanings of the substitution token characters are as follows:</p>
|
||||
*
|
||||
* <table border="0" width="100%">
|
||||
* <tr>
|
||||
* <td>>></td>
|
||||
* <td>in normal rule</td>
|
||||
* <td>Divide the number by the rule's divisor and format the remainder</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in negative-number rule</td>
|
||||
* <td>Find the absolute value of the number and format the result</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in fraction or master rule</td>
|
||||
* <td>Isolate the number's fractional part and format it.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in rule in fraction rule set</td>
|
||||
* <td>Not allowed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>>>></td>
|
||||
* <td>in normal rule</td>
|
||||
* <td>Divide the number by the rule's divisor and format the remainder,
|
||||
* but bypass the normal rule-selection process and just use the
|
||||
* rule that precedes this one in this rule list.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in all other rules</td>
|
||||
* <td>Not allowed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><<</td>
|
||||
* <td>in normal rule</td>
|
||||
* <td>Divide the number by the rule's divisor and format the quotient</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in negative-number rule</td>
|
||||
* <td>Not allowed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in fraction or master rule</td>
|
||||
* <td>Isolate the number's integral part and format it.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in rule in fraction rule set</td>
|
||||
* <td>Multiply the number by the rule's base value and format the result.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>==</td>
|
||||
* <td>in all rule sets</td>
|
||||
* <td>Format the number unchanged</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>[]</td>
|
||||
* <td>in normal rule</td>
|
||||
* <td>Omit the optional text if the number is an even multiple of the rule's divisor</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in negative-number rule</td>
|
||||
* <td>Not allowed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in improper-fraction rule</td>
|
||||
* <td>Omit the optional text if the number is between 0 and 1 (same as specifying both an
|
||||
* x.x rule and a 0.x rule)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in master rule</td>
|
||||
* <td>Omit the optional text if the number is an integer (same as specifying both an x.x
|
||||
* rule and an x.0 rule)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in proper-fraction rule</td>
|
||||
* <td>Not allowed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td></td>
|
||||
* <td>in rule in fraction rule set</td>
|
||||
* <td>Omit the optional text if multiplying the number by the rule's base value yields 1.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The substitution descriptor (i.e., the text between the token characters) may take one
|
||||
* of three forms:</p>
|
||||
*
|
||||
* <table border="0" width="100%">
|
||||
* <tr>
|
||||
* <td>a rule set name</td>
|
||||
* <td>Perform the mathematical operation on the number, and format the result using the
|
||||
* named rule set.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>a DecimalFormat pattern</td>
|
||||
* <td>Perform the mathematical operation on the number, and format the result using a
|
||||
* DecimalFormat with the specified pattern. The pattern must begin with 0 or #.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>nothing</td>
|
||||
* <td>Perform the mathematical operation on the number, and format the result using the rule
|
||||
* set containing the current rule, except:
|
||||
* <ul>
|
||||
* <li>You can't have an empty substitution descriptor with a == substitution.</li>
|
||||
* <li>If you omit the substitution descriptor in a >> substitution in a fraction rule,
|
||||
* format the result one digit at a time using the rule set containing the current rule.</li>
|
||||
* <li>If you omit the substitution descriptor in a << substitution in a rule in a
|
||||
* fraction rule set, format the result using the default rule set for this formatter.</li>
|
||||
* </ul>
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>Whitespace is ignored between a rule set name and a rule set body, between a rule
|
||||
* descriptor and a rule body, or between rules. If a rule body begins with an apostrophe,
|
||||
* the apostrophe is ignored, but all text after it becomes significant (this is how you can
|
||||
* have a rule's rule text begin with whitespace). There is no escape function: the semicolon
|
||||
* is not allowed in rule set names or in rule text, and the colon is not allowed in rule set
|
||||
* names. The characters beginning a substitution token are always treated as the beginning
|
||||
* of a substitution token.</p>
|
||||
*
|
||||
* <p>See the resource data and the demo program for annotated examples of real rule sets
|
||||
* using these features.</p>
|
||||
*
|
||||
* <p><em>User subclasses are not supported.</em> While clients may write
|
||||
* subclasses, such code will not necessarily work and will not be
|
||||
* guaranteed to work stably from release to release.
|
||||
*
|
||||
* <p><b>Localizations</b></p>
|
||||
* <p>Constructors are available that allow the specification of localizations for the
|
||||
* public rule sets (and also allow more control over what public rule sets are available).
|
||||
* Localization data is represented as a textual description. The description represents
|
||||
* an array of arrays of string. The first element is an array of the public rule set names,
|
||||
* each of these must be one of the public rule set names that appear in the rules. Only
|
||||
* names in this array will be treated as public rule set names by the API. Each subsequent
|
||||
* element is an array of localizations of these names. The first element of one of these
|
||||
* subarrays is the locale name, and the remaining elements are localizations of the
|
||||
* public rule set names, in the same order as they were listed in the first arrray.</p>
|
||||
* <p>In the syntax, angle brackets '<', '>' are used to delimit the arrays, and comma ',' is used
|
||||
* to separate elements of an array. Whitespace is ignored, unless quoted.</p>
|
||||
* <p>For example:<pre>
|
||||
* < < %foo, %bar, %baz >,
|
||||
* < en, Foo, Bar, Baz >,
|
||||
* < fr, 'le Foo', 'le Bar', 'le Baz' >
|
||||
* < zh, \\u7532, \\u4e59, \\u4e19 > >
|
||||
* </pre></p>
|
||||
* @author Richard Gillam
|
||||
* @see NumberFormat
|
||||
* @see DecimalFormat
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
|
||||
public:
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// constructors
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat that behaves according to the description
|
||||
* passed in. The formatter uses the default locale.
|
||||
* @param rules A description of the formatter's desired behavior.
|
||||
* See the class documentation for a complete explanation of the description
|
||||
* syntax.
|
||||
* @param perror The parse error if an error was encountered.
|
||||
* @param status The status indicating whether the constructor succeeded.
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat that behaves according to the description
|
||||
* passed in. The formatter uses the default locale.
|
||||
* <p>
|
||||
* The localizations data provides information about the public
|
||||
* rule sets and their localized display names for different
|
||||
* locales. The first element in the list is an array of the names
|
||||
* of the public rule sets. The first element in this array is
|
||||
* the initial default ruleset. The remaining elements in the
|
||||
* list are arrays of localizations of the names of the public
|
||||
* rule sets. Each of these is one longer than the initial array,
|
||||
* with the first String being the ULocale ID, and the remaining
|
||||
* Strings being the localizations of the rule set names, in the
|
||||
* same order as the initial array. Arrays are NULL-terminated.
|
||||
* @param rules A description of the formatter's desired behavior.
|
||||
* See the class documentation for a complete explanation of the description
|
||||
* syntax.
|
||||
* @param localizations the localization information.
|
||||
* names in the description. These will be copied by the constructor.
|
||||
* @param perror The parse error if an error was encountered.
|
||||
* @param status The status indicating whether the constructor succeeded.
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
|
||||
UParseError& perror, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat that behaves according to the rules
|
||||
* passed in. The formatter uses the specified locale to determine the
|
||||
* characters to use when formatting numerals, and to define equivalences
|
||||
* for lenient parsing.
|
||||
* @param rules The formatter rules.
|
||||
* See the class documentation for a complete explanation of the rule
|
||||
* syntax.
|
||||
* @param locale A locale that governs which characters are used for
|
||||
* formatting values in numerals and which characters are equivalent in
|
||||
* lenient parsing.
|
||||
* @param perror The parse error if an error was encountered.
|
||||
* @param status The status indicating whether the constructor succeeded.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
|
||||
UParseError& perror, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat that behaves according to the description
|
||||
* passed in. The formatter uses the default locale.
|
||||
* <p>
|
||||
* The localizations data provides information about the public
|
||||
* rule sets and their localized display names for different
|
||||
* locales. The first element in the list is an array of the names
|
||||
* of the public rule sets. The first element in this array is
|
||||
* the initial default ruleset. The remaining elements in the
|
||||
* list are arrays of localizations of the names of the public
|
||||
* rule sets. Each of these is one longer than the initial array,
|
||||
* with the first String being the ULocale ID, and the remaining
|
||||
* Strings being the localizations of the rule set names, in the
|
||||
* same order as the initial array. Arrays are NULL-terminated.
|
||||
* @param rules A description of the formatter's desired behavior.
|
||||
* See the class documentation for a complete explanation of the description
|
||||
* syntax.
|
||||
* @param localizations a list of localizations for the rule set
|
||||
* names in the description. These will be copied by the constructor.
|
||||
* @param locale A locale that governs which characters are used for
|
||||
* formatting values in numerals and which characters are equivalent in
|
||||
* lenient parsing.
|
||||
* @param perror The parse error if an error was encountered.
|
||||
* @param status The status indicating whether the constructor succeeded.
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
|
||||
const Locale& locale, UParseError& perror, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Creates a RuleBasedNumberFormat from a predefined ruleset. The selector
|
||||
* code choosed among three possible predefined formats: spellout, ordinal,
|
||||
* and duration.
|
||||
* @param tag A selector code specifying which kind of formatter to create for that
|
||||
* locale. There are four legal values: URBNF_SPELLOUT, which creates a formatter that
|
||||
* spells out a value in words in the desired language, URBNF_ORDINAL, which attaches
|
||||
* an ordinal suffix from the desired language to the end of a number (e.g. "123rd"),
|
||||
* URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds,
|
||||
* and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
|
||||
* systems such as the Hebrew numbering system, or for Roman Numerals, etc.
|
||||
* @param locale The locale for the formatter.
|
||||
* @param status The status indicating whether the constructor succeeded.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// boilerplate
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param rhs the object to be copied from.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @param rhs the object to be copied from.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
|
||||
|
||||
/**
|
||||
* Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual ~RuleBasedNumberFormat();
|
||||
|
||||
/**
|
||||
* Clone this object polymorphically. The caller is responsible
|
||||
* for deleting the result when done.
|
||||
* @return A copy of the object.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual Format* clone(void) const;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
* @param other the object to be compared with.
|
||||
* @return true if the given Format objects are semantically equal.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual UBool operator==(const Format& other) const;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// public API functions
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* return the rules that were provided to the RuleBasedNumberFormat.
|
||||
* @return the result String that was passed in
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString getRules() const;
|
||||
|
||||
/**
|
||||
* Return the number of public rule set names.
|
||||
* @return the number of public rule set names.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual int32_t getNumberOfRuleSetNames() const;
|
||||
|
||||
/**
|
||||
* Return the name of the index'th public ruleSet. If index is not valid,
|
||||
* the function returns null.
|
||||
* @param index the index of the ruleset
|
||||
* @return the name of the index'th public ruleSet.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString getRuleSetName(int32_t index) const;
|
||||
|
||||
/**
|
||||
* Return the number of locales for which we have localized rule set display names.
|
||||
* @return the number of locales for which we have localized rule set display names.
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
|
||||
|
||||
/**
|
||||
* Return the index'th display name locale.
|
||||
* @param index the index of the locale
|
||||
* @param status set to a failure code when this function fails
|
||||
* @return the locale
|
||||
* @see #getNumberOfRuleSetDisplayNameLocales
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Return the rule set display names for the provided locale. These are in the same order
|
||||
* as those returned by getRuleSetName. The locale is matched against the locales for
|
||||
* which there is display name data, using normal fallback rules. If no locale matches,
|
||||
* the default display names are returned. (These are the internal rule set names minus
|
||||
* the leading '%'.)
|
||||
* @param index the index of the rule set
|
||||
* @param locale the locale (returned by getRuleSetDisplayNameLocales) for which the localized
|
||||
* display name is desired
|
||||
* @return the display name for the given index, which might be bogus if there is an error
|
||||
* @see #getRuleSetName
|
||||
* @stable ICU 3.2
|
||||
*/
|
||||
virtual UnicodeString getRuleSetDisplayName(int32_t index,
|
||||
const Locale& locale = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Return the rule set display name for the provided rule set and locale.
|
||||
* The locale is matched against the locales for which there is display name data, using
|
||||
* normal fallback rules. If no locale matches, the default display name is returned.
|
||||
* @return the display name for the rule set
|
||||
* @stable ICU 3.2
|
||||
* @see #getRuleSetDisplayName
|
||||
*/
|
||||
virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
|
||||
const Locale& locale = Locale::getDefault());
|
||||
|
||||
|
||||
using NumberFormat::format;
|
||||
|
||||
/**
|
||||
* Formats the specified 32-bit number using the default ruleset.
|
||||
* @param number The number to format.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(int32_t number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Formats the specified 64-bit number using the default ruleset.
|
||||
* @param number The number to format.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
virtual UnicodeString& format(int64_t number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
/**
|
||||
* Formats the specified number using the default ruleset.
|
||||
* @param number The number to format.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Formats the specified number using the named ruleset.
|
||||
* @param number The number to format.
|
||||
* @param ruleSetName The name of the rule set to format the number with.
|
||||
* This must be the name of a valid public rule set for this formatter.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @param status the status
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(int32_t number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Formats the specified 64-bit number using the named ruleset.
|
||||
* @param number The number to format.
|
||||
* @param ruleSetName The name of the rule set to format the number with.
|
||||
* This must be the name of a valid public rule set for this formatter.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @param status the status
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
virtual UnicodeString& format(int64_t number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
/**
|
||||
* Formats the specified number using the named ruleset.
|
||||
* @param number The number to format.
|
||||
* @param ruleSetName The name of the rule set to format the number with.
|
||||
* This must be the name of a valid public rule set for this formatter.
|
||||
* @param toAppendTo the string that will hold the (appended) result
|
||||
* @param pos the fieldposition
|
||||
* @param status the status
|
||||
* @return A textual representation of the number.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
const UnicodeString& ruleSetName,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const;
|
||||
|
||||
using NumberFormat::parse;
|
||||
|
||||
/**
|
||||
* Parses the specfied string, beginning at the specified position, according
|
||||
* to this formatter's rules. This will match the string against all of the
|
||||
* formatter's public rule sets and return the value corresponding to the longest
|
||||
* parseable substring. This function's behavior is affected by the lenient
|
||||
* parse mode.
|
||||
* @param text The string to parse
|
||||
* @param result the result of the parse, either a double or a long.
|
||||
* @param parsePosition On entry, contains the position of the first character
|
||||
* in "text" to examine. On exit, has been updated to contain the position
|
||||
* of the first character in "text" that wasn't consumed by the parse.
|
||||
* @see #setLenient
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const;
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
|
||||
/**
|
||||
* Turns lenient parse mode on and off.
|
||||
*
|
||||
* When in lenient parse mode, the formatter uses a Collator for parsing the text.
|
||||
* Only primary differences are treated as significant. This means that case
|
||||
* differences, accent differences, alternate spellings of the same letter
|
||||
* (e.g., ae and a-umlaut in German), ignorable characters, etc. are ignored in
|
||||
* matching the text. In many cases, numerals will be accepted in place of words
|
||||
* or phrases as well.
|
||||
*
|
||||
* For example, all of the following will correctly parse as 255 in English in
|
||||
* lenient-parse mode:
|
||||
* <br>"two hundred fifty-five"
|
||||
* <br>"two hundred fifty five"
|
||||
* <br>"TWO HUNDRED FIFTY-FIVE"
|
||||
* <br>"twohundredfiftyfive"
|
||||
* <br>"2 hundred fifty-5"
|
||||
*
|
||||
* The Collator used is determined by the locale that was
|
||||
* passed to this object on construction. The description passed to this object
|
||||
* on construction may supply additional collation rules that are appended to the
|
||||
* end of the default collator for the locale, enabling additional equivalences
|
||||
* (such as adding more ignorable characters or permitting spelled-out version of
|
||||
* symbols; see the demo program for examples).
|
||||
*
|
||||
* It's important to emphasize that even strict parsing is relatively lenient: it
|
||||
* will accept some text that it won't produce as output. In English, for example,
|
||||
* it will correctly parse "two hundred zero" and "fifteen hundred".
|
||||
*
|
||||
* @param enabled If true, turns lenient-parse mode on; if false, turns it off.
|
||||
* @see RuleBasedCollator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void setLenient(UBool enabled);
|
||||
|
||||
/**
|
||||
* Returns true if lenient-parse mode is turned on. Lenient parsing is off
|
||||
* by default.
|
||||
* @return true if lenient-parse mode is turned on.
|
||||
* @see #setLenient
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual inline UBool isLenient(void) const;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Override the default rule set to use. If ruleSetName is null, reset
|
||||
* to the initial default rule set. If the rule set is not a public rule set name,
|
||||
* U_ILLEGAL_ARGUMENT_ERROR is returned in status.
|
||||
* @param ruleSetName the name of the rule set, or null to reset the initial default.
|
||||
* @param status set to failure code when a problem occurs.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Return the name of the current default rule set. If the current rule set is
|
||||
* not public, returns a bogus (and empty) UnicodeString.
|
||||
* @return the name of the current default rule set
|
||||
* @stable ICU 3.0
|
||||
*/
|
||||
virtual UnicodeString getDefaultRuleSetName() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Sets the decimal format symbols, which is generally not changed
|
||||
* by the programmer or user. The formatter takes ownership of
|
||||
* symbolsToAdopt; the client must not delete it.
|
||||
*
|
||||
* @param symbolsToAdopt DecimalFormatSymbols to be adopted.
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
|
||||
|
||||
/**
|
||||
* Sets the decimal format symbols, which is generally not changed
|
||||
* by the programmer or user. A clone of the symbols is created and
|
||||
* the symbols is _not_ adopted; the client is still responsible for
|
||||
* deleting it.
|
||||
*
|
||||
* @param symbols DecimalFormatSymbols.
|
||||
* @stable ICU 49
|
||||
*/
|
||||
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
|
||||
|
||||
private:
|
||||
RuleBasedNumberFormat(); // default constructor not implemented
|
||||
|
||||
// this will ref the localizations if they are not NULL
|
||||
// caller must deref to get adoption
|
||||
RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
|
||||
const Locale& locale, UParseError& perror, UErrorCode& status);
|
||||
|
||||
void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
|
||||
void dispose();
|
||||
void stripWhitespace(UnicodeString& src);
|
||||
void initDefaultRuleSet();
|
||||
void format(double number, NFRuleSet& ruleSet);
|
||||
NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
|
||||
|
||||
/* friend access */
|
||||
friend class NFSubstitution;
|
||||
friend class NFRule;
|
||||
friend class FractionalPartSubstitution;
|
||||
|
||||
inline NFRuleSet * getDefaultRuleSet() const;
|
||||
Collator * getCollator() const;
|
||||
DecimalFormatSymbols * getDecimalFormatSymbols() const;
|
||||
|
||||
private:
|
||||
NFRuleSet **ruleSets;
|
||||
UnicodeString* ruleSetDescriptions;
|
||||
int32_t numRuleSets;
|
||||
NFRuleSet *defaultRuleSet;
|
||||
Locale locale;
|
||||
Collator* collator;
|
||||
DecimalFormatSymbols* decimalFormatSymbols;
|
||||
UBool lenient;
|
||||
UnicodeString* lenientParseRules;
|
||||
LocalizationInfo* localizations;
|
||||
};
|
||||
|
||||
// ---------------
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
|
||||
inline UBool
|
||||
RuleBasedNumberFormat::isLenient(void) const {
|
||||
return lenient;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline NFRuleSet*
|
||||
RuleBasedNumberFormat::getDefaultRuleSet() const {
|
||||
return defaultRuleSet;
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
/* U_HAVE_RBNF */
|
||||
#endif
|
||||
|
||||
/* RBNF_H */
|
||||
#endif
|
||||
@@ -1,362 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef RBTZ_H
|
||||
#define RBTZ_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Rule based customizable time zone
|
||||
*/
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/basictz.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
// forward declaration
|
||||
class UVector;
|
||||
struct Transition;
|
||||
|
||||
/**
|
||||
* a BasicTimeZone subclass implemented in terms of InitialTimeZoneRule and TimeZoneRule instances
|
||||
* @see BasicTimeZone
|
||||
* @see InitialTimeZoneRule
|
||||
* @see TimeZoneRule
|
||||
*/
|
||||
class U_I18N_API RuleBasedTimeZone : public BasicTimeZone {
|
||||
public:
|
||||
/**
|
||||
* Constructs a <code>RuleBasedTimeZone</code> object with the ID and the
|
||||
* <code>InitialTimeZoneRule</code>. The input <code>InitialTimeZoneRule</code>
|
||||
* is adopted by this <code>RuleBasedTimeZone</code>, thus the caller must not
|
||||
* delete it.
|
||||
* @param id The time zone ID.
|
||||
* @param initialRule The initial time zone rule.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param source The RuleBasedTimeZone object to be copied.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
RuleBasedTimeZone(const RuleBasedTimeZone& source);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual ~RuleBasedTimeZone();
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @param right The object to be copied.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
RuleBasedTimeZone& operator=(const RuleBasedTimeZone& right);
|
||||
|
||||
/**
|
||||
* Return true if the given <code>TimeZone</code> objects are
|
||||
* semantically equal. Objects of different subclasses are considered unequal.
|
||||
* @param that The object to be compared with.
|
||||
* @return true if the given <code>TimeZone</code> objects are
|
||||
*semantically equal.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool operator==(const TimeZone& that) const;
|
||||
|
||||
/**
|
||||
* Return true if the given <code>TimeZone</code> objects are
|
||||
* semantically unequal. Objects of different subclasses are considered unequal.
|
||||
* @param that The object to be compared with.
|
||||
* @return true if the given <code>TimeZone</code> objects are
|
||||
* semantically unequal.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool operator!=(const TimeZone& that) const;
|
||||
|
||||
/**
|
||||
* Adds the <code>TimeZoneRule</code> which represents time transitions.
|
||||
* The <code>TimeZoneRule</code> must have start times, that is, the result
|
||||
* of isTransitionRule() must be true. Otherwise, U_ILLEGAL_ARGUMENT_ERROR
|
||||
* is set to the error code.
|
||||
* The input <code>TimeZoneRule</code> is adopted by this
|
||||
* <code>RuleBasedTimeZone</code> on successful completion of this method,
|
||||
* thus, the caller must not delete it when no error is returned.
|
||||
* After all rules are added, the caller must call complete() method to
|
||||
* make this <code>RuleBasedTimeZone</code> ready to handle common time
|
||||
* zone functions.
|
||||
* @param rule The <code>TimeZoneRule</code>.
|
||||
* @param status Output param to filled in with a success or an error.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void addTransitionRule(TimeZoneRule* rule, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Makes the <code>TimeZoneRule</code> ready to handle actual timezone
|
||||
* calcuation APIs. This method collects time zone rules specified
|
||||
* by the caller via the constructor and addTransitionRule() and
|
||||
* builds internal structure for making the object ready to support
|
||||
* time zone APIs such as getOffset(), getNextTransition() and others.
|
||||
* @param status Output param to filled in with a success or an error.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
void complete(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Clones TimeZone objects polymorphically. Clients are responsible for deleting
|
||||
* the TimeZone object cloned.
|
||||
*
|
||||
* @return A new copy of this TimeZone object.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual TimeZone* clone(void) const;
|
||||
|
||||
/**
|
||||
* Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time in this time zone, taking daylight savings time into
|
||||
* account) as of a particular reference date. The reference date is used to determine
|
||||
* whether daylight savings time is in effect and needs to be figured into the offset
|
||||
* that is returned (in other words, what is the adjusted GMT offset in this time zone
|
||||
* at this particular date and time?). For the time zones produced by createTimeZone(),
|
||||
* the reference data is specified according to the Gregorian calendar, and the date
|
||||
* and time fields are local standard time.
|
||||
*
|
||||
* <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
|
||||
* which returns both the raw and the DST offset for a given time. This method
|
||||
* is retained only for backward compatibility.
|
||||
*
|
||||
* @param era The reference date's era
|
||||
* @param year The reference date's year
|
||||
* @param month The reference date's month (0-based; 0 is January)
|
||||
* @param day The reference date's day-in-month (1-based)
|
||||
* @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
|
||||
* @param millis The reference date's milliseconds in day, local standard time
|
||||
* @param status Output param to filled in with a success or an error.
|
||||
* @return The offset in milliseconds to add to GMT to get local time.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
|
||||
uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the time zone offset, for current date, modified in case of
|
||||
* daylight savings. This is the offset to add *to* UTC to get local time.
|
||||
*
|
||||
* <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
|
||||
* which returns both the raw and the DST offset for a given time. This method
|
||||
* is retained only for backward compatibility.
|
||||
*
|
||||
* @param era The reference date's era
|
||||
* @param year The reference date's year
|
||||
* @param month The reference date's month (0-based; 0 is January)
|
||||
* @param day The reference date's day-in-month (1-based)
|
||||
* @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
|
||||
* @param millis The reference date's milliseconds in day, local standard time
|
||||
* @param monthLength The length of the given month in days.
|
||||
* @param status Output param to filled in with a success or an error.
|
||||
* @return The offset in milliseconds to add to GMT to get local time.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
|
||||
uint8_t dayOfWeek, int32_t millis,
|
||||
int32_t monthLength, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns the time zone raw and GMT offset for the given moment
|
||||
* in time. Upon return, local-millis = GMT-millis + rawOffset +
|
||||
* dstOffset. All computations are performed in the proleptic
|
||||
* Gregorian calendar. The default implementation in the TimeZone
|
||||
* class delegates to the 8-argument getOffset().
|
||||
*
|
||||
* @param date moment in time for which to return offsets, in
|
||||
* units of milliseconds from January 1, 1970 0:00 GMT, either GMT
|
||||
* time or local wall time, depending on `local'.
|
||||
* @param local if true, `date' is local wall time; otherwise it
|
||||
* is in GMT time.
|
||||
* @param rawOffset output parameter to receive the raw offset, that
|
||||
* is, the offset not including DST adjustments
|
||||
* @param dstOffset output parameter to receive the DST offset,
|
||||
* that is, the offset to be added to `rawOffset' to obtain the
|
||||
* total offset between local and GMT time. If DST is not in
|
||||
* effect, this value is zero; otherwise it is a positive value,
|
||||
* typically one hour.
|
||||
* @param ec input-output error code
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
|
||||
int32_t& dstOffset, UErrorCode& ec) const;
|
||||
|
||||
/**
|
||||
* Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time, before taking daylight savings time into account).
|
||||
*
|
||||
* @param offsetMillis The new raw GMT offset for this time zone.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual void setRawOffset(int32_t offsetMillis);
|
||||
|
||||
/**
|
||||
* Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time, before taking daylight savings time into account).
|
||||
*
|
||||
* @return The TimeZone's raw GMT offset.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual int32_t getRawOffset(void) const;
|
||||
|
||||
/**
|
||||
* Queries if this time zone uses daylight savings time.
|
||||
* @return true if this time zone uses daylight savings time,
|
||||
* false, otherwise.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool useDaylightTime(void) const;
|
||||
|
||||
/**
|
||||
* Queries if the given date is in daylight savings time in
|
||||
* this time zone.
|
||||
* This method is wasteful since it creates a new GregorianCalendar and
|
||||
* deletes it each time it is called. This is a deprecated method
|
||||
* and provided only for Java compatibility.
|
||||
*
|
||||
* @param date the given UDate.
|
||||
* @param status Output param filled in with success/error code.
|
||||
* @return true if the given date is in daylight savings time,
|
||||
* false, otherwise.
|
||||
* @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
|
||||
*/
|
||||
virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns true if this zone has the same rule and offset as another zone.
|
||||
* That is, if this zone differs only in ID, if at all.
|
||||
* @param other the <code>TimeZone</code> object to be compared with
|
||||
* @return true if the given zone is the same as this one,
|
||||
* with the possible exception of the ID
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool hasSameRules(const TimeZone& other) const;
|
||||
|
||||
/**
|
||||
* Gets the first time zone transition after the base time.
|
||||
* @param base The base time.
|
||||
* @param inclusive Whether the base time is inclusive or not.
|
||||
* @param result Receives the first transition after the base time.
|
||||
* @return TRUE if the transition is found.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
|
||||
|
||||
/**
|
||||
* Gets the most recent time zone transition before the base time.
|
||||
* @param base The base time.
|
||||
* @param inclusive Whether the base time is inclusive or not.
|
||||
* @param result Receives the most recent transition before the base time.
|
||||
* @return TRUE if the transition is found.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
|
||||
|
||||
/**
|
||||
* Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
|
||||
* for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
|
||||
* <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
|
||||
* @param status Receives error status code.
|
||||
* @return The number of <code>TimeZoneRule</code>s representing time transitions.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual int32_t countTransitionRules(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
|
||||
* which represent time transitions for this time zone. On successful return,
|
||||
* the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
|
||||
* the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
|
||||
* instances up to the size specified by trscount. The results are referencing the
|
||||
* rule instance held by this time zone instance. Therefore, after this time zone
|
||||
* is destructed, they are no longer available.
|
||||
* @param initial Receives the initial timezone rule
|
||||
* @param trsrules Receives the timezone transition rules
|
||||
* @param trscount On input, specify the size of the array 'transitions' receiving
|
||||
* the timezone transition rules. On output, actual number of
|
||||
* rules filled in the array will be set.
|
||||
* @param status Receives error status code.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
|
||||
const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Get time zone offsets from local wall time.
|
||||
* @internal
|
||||
*/
|
||||
virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
|
||||
int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
|
||||
|
||||
private:
|
||||
void deleteRules(void);
|
||||
void deleteTransitions(void);
|
||||
UVector* copyRules(UVector* source);
|
||||
TimeZoneRule* findRuleInFinal(UDate date, UBool local,
|
||||
int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
|
||||
UBool findNext(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
|
||||
UBool findPrev(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
|
||||
int32_t getLocalDelta(int32_t rawBefore, int32_t dstBefore, int32_t rawAfter, int32_t dstAfter,
|
||||
int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
|
||||
UDate getTransitionTime(Transition* transition, UBool local,
|
||||
int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
|
||||
void getOffsetInternal(UDate date, UBool local, int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
|
||||
int32_t& rawOffset, int32_t& dstOffset, UErrorCode& ec) const;
|
||||
void completeConst(UErrorCode &status) const;
|
||||
|
||||
InitialTimeZoneRule *fInitialRule;
|
||||
UVector *fHistoricRules;
|
||||
UVector *fFinalRules;
|
||||
UVector *fHistoricTransitions;
|
||||
UBool fUpToDate;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to
|
||||
* a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . erived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
||||
* method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
||||
* methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // RBTZ_H
|
||||
|
||||
//eof
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef REGION_H
|
||||
#define REGION_H
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Region classes (territory containment)
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uregion.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/uniset.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/strenum.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* <code>Region</code> is the class representing a Unicode Region Code, also known as a
|
||||
* Unicode Region Subtag, which is defined based upon the BCP 47 standard. We often think of
|
||||
* "regions" as "countries" when defining the characteristics of a locale. Region codes There are different
|
||||
* types of region codes that are important to distinguish.
|
||||
* <p>
|
||||
* Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or
|
||||
* selected economic and other grouping" as defined in
|
||||
* UN M.49 (http://unstats.un.org/unsd/methods/m49/m49regin.htm).
|
||||
* These are typically 3-digit codes, but contain some 2-letter codes, such as the LDML code QO
|
||||
* added for Outlying Oceania. Not all UNM.49 codes are defined in LDML, but most of them are.
|
||||
* Macroregions are represented in ICU by one of three region types: WORLD ( region code 001 ),
|
||||
* CONTINENTS ( regions contained directly by WORLD ), and SUBCONTINENTS ( things contained directly
|
||||
* by a continent ).
|
||||
* <p>
|
||||
* TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also
|
||||
* include areas that are not separate countries, such as the code "AQ" for Antarctica or the code
|
||||
* "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate
|
||||
* codes. The codes are typically 2-letter codes aligned with the ISO 3166 standard, but BCP47 allows
|
||||
* for the use of 3-digit codes in the future.
|
||||
* <p>
|
||||
* UNKNOWN - The code ZZ is defined by Unicode LDML for use to indicate that the Region is unknown,
|
||||
* or that the value supplied as a region was invalid.
|
||||
* <p>
|
||||
* DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage,
|
||||
* usually due to a country splitting into multiple territories or changing its name.
|
||||
* <p>
|
||||
* GROUPING - A widely understood grouping of territories that has a well defined membership such
|
||||
* that a region code has been assigned for it. Some of these are UNM.49 codes that do't fall into
|
||||
* the world/continent/sub-continent hierarchy, while others are just well known groupings that have
|
||||
* their own region code. Region "EU" (European Union) is one such region code that is a grouping.
|
||||
* Groupings will never be returned by the getContainingRegion() API, since a different type of region
|
||||
* ( WORLD, CONTINENT, or SUBCONTINENT ) will always be the containing region instead.
|
||||
*
|
||||
* The Region class is not intended for public subclassing.
|
||||
*
|
||||
* @author John Emmons
|
||||
* @draft ICU 51
|
||||
*/
|
||||
|
||||
class U_I18N_API Region : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
virtual ~Region();
|
||||
|
||||
/**
|
||||
* Returns true if the two regions are equal.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
UBool operator==(const Region &that) const;
|
||||
|
||||
/**
|
||||
* Returns true if the two regions are NOT equal; that is, if operator ==() returns false.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
UBool operator!=(const Region &that) const;
|
||||
|
||||
/**
|
||||
* Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code,
|
||||
* 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification.
|
||||
* The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR.
|
||||
* If the region code is NULL or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR )
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static const Region* U_EXPORT2 getInstance(const char *region_code, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized,
|
||||
* the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ).
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static const Region* U_EXPORT2 getInstance (int32_t code, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Returns an enumeration over the IDs of all known regions that match the given type.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
static StringEnumeration* U_EXPORT2 getAvailable(URegionType type);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the region that contains this region. Returns NULL if this region is code "001" (World)
|
||||
* or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the
|
||||
* region "039" (Southern Europe).
|
||||
* @draft ICU 51
|
||||
*/
|
||||
const Region* getContainingRegion() const;
|
||||
|
||||
/**
|
||||
* Return a pointer to the region that geographically contains this region and matches the given type,
|
||||
* moving multiple steps up the containment chain if necessary. Returns NULL if no containing region can be found
|
||||
* that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN"
|
||||
* are not appropriate for use in this API. NULL will be returned in this case. For example, calling this method
|
||||
* with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ).
|
||||
* @draft ICU 51
|
||||
*/
|
||||
const Region* getContainingRegion(URegionType type) const;
|
||||
|
||||
/**
|
||||
* Return an enumeration over the IDs of all the regions that are immediate children of this region in the
|
||||
* region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two,
|
||||
* depending on the containment data as defined in CLDR. This API may return NULL if this region doesn't have
|
||||
* any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing
|
||||
* the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe)
|
||||
* and "155" (Western Europe).
|
||||
* @draft ICU 51
|
||||
*/
|
||||
StringEnumeration* getContainedRegions() const;
|
||||
|
||||
/**
|
||||
* Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region
|
||||
* hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any
|
||||
* sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type
|
||||
* "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. )
|
||||
* @draft ICU 51
|
||||
*/
|
||||
StringEnumeration* getContainedRegions( URegionType type ) const;
|
||||
|
||||
/**
|
||||
* Returns true if this region contains the supplied other region anywhere in the region hierarchy.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
UBool contains(const Region &other) const;
|
||||
|
||||
/**
|
||||
* For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement
|
||||
* regions for this region. Returns null for a non-deprecated region. For example, calling this method with region
|
||||
* "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc...
|
||||
* @draft ICU 51
|
||||
*/
|
||||
StringEnumeration* getPreferredValues() const;
|
||||
|
||||
|
||||
/**
|
||||
* Return this region's canonical region code.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
const char* getRegionCode() const;
|
||||
|
||||
/**
|
||||
* Return this region's numeric code.
|
||||
* Returns a negative value if the given region does not have a numeric code assigned to it.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
int32_t getNumericCode() const;
|
||||
|
||||
/**
|
||||
* Returns the region type of this region.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URegionType getType() const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Cleans up statically allocated memory.
|
||||
* @internal
|
||||
*/
|
||||
static void cleanupRegionData();
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
private:
|
||||
char id[4];
|
||||
UnicodeString idStr;
|
||||
int32_t code;
|
||||
URegionType type;
|
||||
Region *containingRegion;
|
||||
UVector *containedRegions;
|
||||
UVector *preferredValues;
|
||||
|
||||
/**
|
||||
* Default Constructor. Internal - use factory methods only.
|
||||
*/
|
||||
Region();
|
||||
|
||||
|
||||
/*
|
||||
* Initializes the region data from the ICU resource bundles. The region data
|
||||
* contains the basic relationships such as which regions are known, what the numeric
|
||||
* codes are, any known aliases, and the territory containment data.
|
||||
*
|
||||
* If the region data has already loaded, then this method simply returns without doing
|
||||
* anything meaningful.
|
||||
*/
|
||||
|
||||
static void loadRegionData();
|
||||
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
#endif // REGION_H
|
||||
|
||||
//eof
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
**************************************************************************
|
||||
* Copyright (C) 1999-2012, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
**************************************************************************
|
||||
* Date Name Description
|
||||
* 11/17/99 aliu Creation. Ported from java. Modified to
|
||||
* match current UnicodeString API. Forced
|
||||
* to use name "handleReplaceBetween" because
|
||||
* of existing methods in UnicodeString.
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef REP_H
|
||||
#define REP_H
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Replaceable String
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class UnicodeString;
|
||||
|
||||
/**
|
||||
* <code>Replaceable</code> is an abstract base class representing a
|
||||
* string of characters that supports the replacement of a range of
|
||||
* itself with a new string of characters. It is used by APIs that
|
||||
* change a piece of text while retaining metadata. Metadata is data
|
||||
* other than the Unicode characters returned by char32At(). One
|
||||
* example of metadata is style attributes; another is an edit
|
||||
* history, marking each character with an author and revision number.
|
||||
*
|
||||
* <p>An implicit aspect of the <code>Replaceable</code> API is that
|
||||
* during a replace operation, new characters take on the metadata of
|
||||
* the old characters. For example, if the string "the <b>bold</b>
|
||||
* font" has range (4, 8) replaced with "strong", then it becomes "the
|
||||
* <b>strong</b> font".
|
||||
*
|
||||
* <p><code>Replaceable</code> specifies ranges using a start
|
||||
* offset and a limit offset. The range of characters thus specified
|
||||
* includes the characters at offset start..limit-1. That is, the
|
||||
* start offset is inclusive, and the limit offset is exclusive.
|
||||
*
|
||||
* <p><code>Replaceable</code> also includes API to access characters
|
||||
* in the string: <code>length()</code>, <code>charAt()</code>,
|
||||
* <code>char32At()</code>, and <code>extractBetween()</code>.
|
||||
*
|
||||
* <p>For a subclass to support metadata, typical behavior of
|
||||
* <code>replace()</code> is the following:
|
||||
* <ul>
|
||||
* <li>Set the metadata of the new text to the metadata of the first
|
||||
* character replaced</li>
|
||||
* <li>If no characters are replaced, use the metadata of the
|
||||
* previous character</li>
|
||||
* <li>If there is no previous character (i.e. start == 0), use the
|
||||
* following character</li>
|
||||
* <li>If there is no following character (i.e. the replaceable was
|
||||
* empty), use default metadata.<br>
|
||||
* <li>If the code point U+FFFF is seen, it should be interpreted as
|
||||
* a special marker having no metadata<li>
|
||||
* </li>
|
||||
* </ul>
|
||||
* If this is not the behavior, the subclass should document any differences.
|
||||
* @author Alan Liu
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API Replaceable : public UObject {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~Replaceable();
|
||||
|
||||
/**
|
||||
* Returns the number of 16-bit code units in the text.
|
||||
* @return number of 16-bit code units in text
|
||||
* @stable ICU 1.8
|
||||
*/
|
||||
inline int32_t length() const;
|
||||
|
||||
/**
|
||||
* Returns the 16-bit code unit at the given offset into the text.
|
||||
* @param offset an integer between 0 and <code>length()</code>-1
|
||||
* inclusive
|
||||
* @return 16-bit code unit of text at given offset
|
||||
* @stable ICU 1.8
|
||||
*/
|
||||
inline UChar charAt(int32_t offset) const;
|
||||
|
||||
/**
|
||||
* Returns the 32-bit code point at the given 16-bit offset into
|
||||
* the text. This assumes the text is stored as 16-bit code units
|
||||
* with surrogate pairs intermixed. If the offset of a leading or
|
||||
* trailing code unit of a surrogate pair is given, return the
|
||||
* code point of the surrogate pair.
|
||||
*
|
||||
* @param offset an integer between 0 and <code>length()</code>-1
|
||||
* inclusive
|
||||
* @return 32-bit code point of text at given offset
|
||||
* @stable ICU 1.8
|
||||
*/
|
||||
inline UChar32 char32At(int32_t offset) const;
|
||||
|
||||
/**
|
||||
* Copies characters in the range [<tt>start</tt>, <tt>limit</tt>)
|
||||
* into the UnicodeString <tt>target</tt>.
|
||||
* @param start offset of first character which will be copied
|
||||
* @param limit offset immediately following the last character to
|
||||
* be copied
|
||||
* @param target UnicodeString into which to copy characters.
|
||||
* @return A reference to <TT>target</TT>
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
virtual void extractBetween(int32_t start,
|
||||
int32_t limit,
|
||||
UnicodeString& target) const = 0;
|
||||
|
||||
/**
|
||||
* Replaces a substring of this object with the given text. If the
|
||||
* characters being replaced have metadata, the new characters
|
||||
* that replace them should be given the same metadata.
|
||||
*
|
||||
* <p>Subclasses must ensure that if the text between start and
|
||||
* limit is equal to the replacement text, that replace has no
|
||||
* effect. That is, any metadata
|
||||
* should be unaffected. In addition, subclasses are encouraged to
|
||||
* check for initial and trailing identical characters, and make a
|
||||
* smaller replacement if possible. This will preserve as much
|
||||
* metadata as possible.
|
||||
* @param start the beginning index, inclusive; <code>0 <= start
|
||||
* <= limit</code>.
|
||||
* @param limit the ending index, exclusive; <code>start <= limit
|
||||
* <= length()</code>.
|
||||
* @param text the text to replace characters <code>start</code>
|
||||
* to <code>limit - 1</code>
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void handleReplaceBetween(int32_t start,
|
||||
int32_t limit,
|
||||
const UnicodeString& text) = 0;
|
||||
// Note: All other methods in this class take the names of
|
||||
// existing UnicodeString methods. This method is the exception.
|
||||
// It is named differently because all replace methods of
|
||||
// UnicodeString return a UnicodeString&. The 'between' is
|
||||
// required in order to conform to the UnicodeString naming
|
||||
// convention; API taking start/length are named <operation>, and
|
||||
// those taking start/limit are named <operationBetween>. The
|
||||
// 'handle' is added because 'replaceBetween' and
|
||||
// 'doReplaceBetween' are already taken.
|
||||
|
||||
/**
|
||||
* Copies a substring of this object, retaining metadata.
|
||||
* This method is used to duplicate or reorder substrings.
|
||||
* The destination index must not overlap the source range.
|
||||
*
|
||||
* @param start the beginning index, inclusive; <code>0 <= start <=
|
||||
* limit</code>.
|
||||
* @param limit the ending index, exclusive; <code>start <= limit <=
|
||||
* length()</code>.
|
||||
* @param dest the destination index. The characters from
|
||||
* <code>start..limit-1</code> will be copied to <code>dest</code>.
|
||||
* Implementations of this method may assume that <code>dest <= start ||
|
||||
* dest >= limit</code>.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void copy(int32_t start, int32_t limit, int32_t dest) = 0;
|
||||
|
||||
/**
|
||||
* Returns true if this object contains metadata. If a
|
||||
* Replaceable object has metadata, calls to the Replaceable API
|
||||
* must be made so as to preserve metadata. If it does not, calls
|
||||
* to the Replaceable API may be optimized to improve performance.
|
||||
* The default implementation returns true.
|
||||
* @return true if this object contains metadata
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UBool hasMetaData() const;
|
||||
|
||||
/**
|
||||
* Clone this object, an instance of a subclass of Replaceable.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If a subclass does not implement clone(), or if an error occurs,
|
||||
* then NULL is returned.
|
||||
* The clone functions in all subclasses return a pointer to a Replaceable
|
||||
* because some compilers do not support covariant (same-as-this)
|
||||
* return types; cast to the appropriate subclass if necessary.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
virtual Replaceable *clone() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
inline Replaceable();
|
||||
|
||||
/*
|
||||
* Assignment operator not declared. The compiler will provide one
|
||||
* which does nothing since this class does not contain any data members.
|
||||
* API/code coverage may show the assignment operator as present and
|
||||
* untested - ignore.
|
||||
* Subclasses need this assignment operator if they use compiler-provided
|
||||
* assignment operators of their own. An alternative to not declaring one
|
||||
* here would be to declare and empty-implement a protected or public one.
|
||||
Replaceable &Replaceable::operator=(const Replaceable &);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Virtual version of length().
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual int32_t getLength() const = 0;
|
||||
|
||||
/**
|
||||
* Virtual version of charAt().
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual UChar getCharAt(int32_t offset) const = 0;
|
||||
|
||||
/**
|
||||
* Virtual version of char32At().
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
virtual UChar32 getChar32At(int32_t offset) const = 0;
|
||||
};
|
||||
|
||||
inline Replaceable::Replaceable() {}
|
||||
|
||||
inline int32_t
|
||||
Replaceable::length() const {
|
||||
return getLength();
|
||||
}
|
||||
|
||||
inline UChar
|
||||
Replaceable::charAt(int32_t offset) const {
|
||||
return getCharAt(offset);
|
||||
}
|
||||
|
||||
inline UChar32
|
||||
Replaceable::char32At(int32_t offset) const {
|
||||
return getChar32At(offset);
|
||||
}
|
||||
|
||||
// There is no rep.cpp, see unistr.cpp for Replaceable function implementations.
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,490 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1996-2013, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* File resbund.h
|
||||
*
|
||||
* CREATED BY
|
||||
* Richard Gillam
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 2/5/97 aliu Added scanForLocaleInFile. Added
|
||||
* constructor which attempts to read resource bundle
|
||||
* from a specific file, without searching other files.
|
||||
* 2/11/97 aliu Added UErrorCode return values to constructors. Fixed
|
||||
* infinite loops in scanForFile and scanForLocale.
|
||||
* Modified getRawResourceData to not delete storage
|
||||
* in localeData and resourceData which it doesn't own.
|
||||
* Added Mac compatibility #ifdefs for tellp() and
|
||||
* ios::nocreate.
|
||||
* 2/18/97 helena Updated with 100% documentation coverage.
|
||||
* 3/13/97 aliu Rewrote to load in entire resource bundle and store
|
||||
* it as a Hashtable of ResourceBundleData objects.
|
||||
* Added state table to govern parsing of files.
|
||||
* Modified to load locale index out of new file
|
||||
* distinct from default.txt.
|
||||
* 3/25/97 aliu Modified to support 2-d arrays, needed for timezone
|
||||
* data. Added support for custom file suffixes. Again,
|
||||
* needed to support timezone data.
|
||||
* 4/7/97 aliu Cleaned up.
|
||||
* 03/02/99 stephen Removed dependency on FILE*.
|
||||
* 03/29/99 helena Merged Bertrand and Stephen's changes.
|
||||
* 06/11/99 stephen Removed parsing of .txt files.
|
||||
* Reworked to use new binary format.
|
||||
* Cleaned up.
|
||||
* 06/14/99 stephen Removed methods taking a filename suffix.
|
||||
* 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef RESBUND_H
|
||||
#define RESBUND_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/ures.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/locid.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Resource Bundle
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A class representing a collection of resource information pertaining to a given
|
||||
* locale. A resource bundle provides a way of accessing locale- specfic information in
|
||||
* a data file. You create a resource bundle that manages the resources for a given
|
||||
* locale and then ask it for individual resources.
|
||||
* <P>
|
||||
* Resource bundles in ICU4C are currently defined using text files which conform to the following
|
||||
* <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
|
||||
* More on resource bundle concepts and syntax can be found in the
|
||||
* <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
|
||||
* <P>
|
||||
*
|
||||
* The ResourceBundle class is not suitable for subclassing.
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API ResourceBundle : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param packageName The packageName and locale together point to an ICU udata object,
|
||||
* as defined by <code> udata_open( packageName, "res", locale, err) </code>
|
||||
* or equivalent. Typically, packageName will refer to a (.dat) file, or to
|
||||
* a package registered with udata_setAppData(). Using a full file or directory
|
||||
* pathname for packageName is deprecated.
|
||||
* @param locale This is the locale this resource bundle is for. To get resources
|
||||
* for the French locale, for example, you would create a
|
||||
* ResourceBundle passing Locale::FRENCH for the "locale" parameter,
|
||||
* and all subsequent calls to that resource bundle will return
|
||||
* resources that pertain to the French locale. If the caller doesn't
|
||||
* pass a locale parameter, the default locale for the system (as
|
||||
* returned by Locale::getDefault()) will be used.
|
||||
* @param err The Error Code.
|
||||
* The UErrorCode& err parameter is used to return status information to the user. To
|
||||
* check whether the construction succeeded or not, you should check the value of
|
||||
* U_SUCCESS(err). If you wish more detailed information, you can check for
|
||||
* informational error results which still indicate success. U_USING_FALLBACK_WARNING
|
||||
* indicates that a fall back locale was used. For example, 'de_CH' was requested,
|
||||
* but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
|
||||
* the default locale data was used; neither the requested locale nor any of its
|
||||
* fall back locales could be found.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(const UnicodeString& packageName,
|
||||
const Locale& locale,
|
||||
UErrorCode& err);
|
||||
|
||||
/**
|
||||
* Construct a resource bundle for the default bundle in the specified package.
|
||||
*
|
||||
* @param packageName The packageName and locale together point to an ICU udata object,
|
||||
* as defined by <code> udata_open( packageName, "res", locale, err) </code>
|
||||
* or equivalent. Typically, packageName will refer to a (.dat) file, or to
|
||||
* a package registered with udata_setAppData(). Using a full file or directory
|
||||
* pathname for packageName is deprecated.
|
||||
* @param err A UErrorCode value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(const UnicodeString& packageName,
|
||||
UErrorCode& err);
|
||||
|
||||
/**
|
||||
* Construct a resource bundle for the ICU default bundle.
|
||||
*
|
||||
* @param err A UErrorCode value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(UErrorCode &err);
|
||||
|
||||
/**
|
||||
* Standard constructor, onstructs a resource bundle for the locale-specific
|
||||
* bundle in the specified package.
|
||||
*
|
||||
* @param packageName The packageName and locale together point to an ICU udata object,
|
||||
* as defined by <code> udata_open( packageName, "res", locale, err) </code>
|
||||
* or equivalent. Typically, packageName will refer to a (.dat) file, or to
|
||||
* a package registered with udata_setAppData(). Using a full file or directory
|
||||
* pathname for packageName is deprecated.
|
||||
* NULL is used to refer to ICU data.
|
||||
* @param locale The locale for which to open a resource bundle.
|
||||
* @param err A UErrorCode value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(const char* packageName,
|
||||
const Locale& locale,
|
||||
UErrorCode& err);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param original The resource bundle to copy.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(const ResourceBundle &original);
|
||||
|
||||
/**
|
||||
* Constructor from a C UResourceBundle. The resource bundle is
|
||||
* copied and not adopted. ures_close will still need to be used on the
|
||||
* original resource bundle.
|
||||
*
|
||||
* @param res A pointer to the C resource bundle.
|
||||
* @param status A UErrorCode value.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle(UResourceBundle *res,
|
||||
UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*
|
||||
* @param other The resource bundle to copy.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle&
|
||||
operator=(const ResourceBundle& other);
|
||||
|
||||
/** Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~ResourceBundle();
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
* Clones can be used concurrently in multiple threads.
|
||||
* If an error occurs, then NULL is returned.
|
||||
* The caller must delete the clone.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*
|
||||
* @see getDynamicClassID
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
ResourceBundle *clone() const;
|
||||
|
||||
/**
|
||||
* Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is
|
||||
* the number of child resources.
|
||||
* @warning Integer array is treated as a scalar type. There are no
|
||||
* APIs to access individual members of an integer array. It
|
||||
* is always returned as a whole.
|
||||
*
|
||||
* @return number of resources in a given resource.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t
|
||||
getSize(void) const;
|
||||
|
||||
/**
|
||||
* returns a string from a string resource type
|
||||
*
|
||||
* @param status fills in the outgoing error code
|
||||
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
||||
* could be a warning
|
||||
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
||||
* @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString
|
||||
getString(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* returns a binary data from a resource. Can be used at most primitive resource types (binaries,
|
||||
* strings, ints)
|
||||
*
|
||||
* @param len fills in the length of resulting byte chunk
|
||||
* @param status fills in the outgoing error code
|
||||
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
||||
* could be a warning
|
||||
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
||||
* @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const uint8_t*
|
||||
getBinary(int32_t& len, UErrorCode& status) const;
|
||||
|
||||
|
||||
/**
|
||||
* returns an integer vector from a resource.
|
||||
*
|
||||
* @param len fills in the length of resulting integer vector
|
||||
* @param status fills in the outgoing error code
|
||||
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
||||
* could be a warning
|
||||
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
||||
* @return a pointer to a vector of integers that lives in a memory mapped/DLL file.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const int32_t*
|
||||
getIntVector(int32_t& len, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* returns an unsigned integer from a resource.
|
||||
* This integer is originally 28 bits.
|
||||
*
|
||||
* @param status fills in the outgoing error code
|
||||
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
||||
* could be a warning
|
||||
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
||||
* @return an unsigned integer value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
uint32_t
|
||||
getUInt(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* returns a signed integer from a resource.
|
||||
* This integer is originally 28 bit and the sign gets propagated.
|
||||
*
|
||||
* @param status fills in the outgoing error code
|
||||
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
||||
* could be a warning
|
||||
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
||||
* @return a signed integer value
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
int32_t
|
||||
getInt(UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Checks whether the resource has another element to iterate over.
|
||||
*
|
||||
* @return TRUE if there are more elements, FALSE if there is no more elements
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UBool
|
||||
hasNext(void) const;
|
||||
|
||||
/**
|
||||
* Resets the internal context of a resource so that iteration starts from the first element.
|
||||
*
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void
|
||||
resetIterator(void);
|
||||
|
||||
/**
|
||||
* Returns the key associated with this resource. Not all the resources have a key - only
|
||||
* those that are members of a table.
|
||||
*
|
||||
* @return a key associated to this resource, or NULL if it doesn't have a key
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const char*
|
||||
getKey(void) const;
|
||||
|
||||
/**
|
||||
* Gets the locale ID of the resource bundle as a string.
|
||||
* Same as getLocale().getName() .
|
||||
*
|
||||
* @return the locale ID of the resource bundle as a string
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
const char*
|
||||
getName(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the type of a resource. Available types are defined in enum UResType
|
||||
*
|
||||
* @return type of the given resource.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UResType
|
||||
getType(void) const;
|
||||
|
||||
/**
|
||||
* Returns the next resource in a given resource or NULL if there are no more resources
|
||||
*
|
||||
* @param status fills in the outgoing error code
|
||||
* @return ResourceBundle object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle
|
||||
getNext(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Returns the next string in a resource or NULL if there are no more resources
|
||||
* to iterate over.
|
||||
*
|
||||
* @param status fills in the outgoing error code
|
||||
* @return an UnicodeString object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString
|
||||
getNextString(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Returns the next string in a resource or NULL if there are no more resources
|
||||
* to iterate over.
|
||||
*
|
||||
* @param key fill in for key associated with this string
|
||||
* @param status fills in the outgoing error code
|
||||
* @return an UnicodeString object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString
|
||||
getNextString(const char ** key,
|
||||
UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Returns the resource in a resource at the specified index.
|
||||
*
|
||||
* @param index an index to the wanted resource.
|
||||
* @param status fills in the outgoing error code
|
||||
* @return ResourceBundle object. If there is an error, resource is invalid.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle
|
||||
get(int32_t index,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns the string in a given resource at the specified index.
|
||||
*
|
||||
* @param index an index to the wanted string.
|
||||
* @param status fills in the outgoing error code
|
||||
* @return an UnicodeString object. If there is an error, string is bogus
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString
|
||||
getStringEx(int32_t index,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns a resource in a resource that has a given key. This procedure works only with table
|
||||
* resources.
|
||||
*
|
||||
* @param key a key associated with the wanted resource
|
||||
* @param status fills in the outgoing error code.
|
||||
* @return ResourceBundle object. If there is an error, resource is invalid.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
ResourceBundle
|
||||
get(const char* key,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Returns a string in a resource that has a given key. This procedure works only with table
|
||||
* resources.
|
||||
*
|
||||
* @param key a key associated with the wanted string
|
||||
* @param status fills in the outgoing error code
|
||||
* @return an UnicodeString object. If there is an error, string is bogus
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString
|
||||
getStringEx(const char* key,
|
||||
UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Return the version number associated with this ResourceBundle as a string. Please
|
||||
* use getVersion, as this method is going to be deprecated.
|
||||
*
|
||||
* @return A version number string as specified in the resource bundle or its parent.
|
||||
* The caller does not own this string.
|
||||
* @see getVersion
|
||||
* @deprecated ICU 2.8 Use getVersion instead.
|
||||
*/
|
||||
const char*
|
||||
getVersionNumber(void) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Return the version number associated with this ResourceBundle as a UVersionInfo array.
|
||||
*
|
||||
* @param versionInfo A UVersionInfo array that is filled with the version number
|
||||
* as specified in the resource bundle or its parent.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void
|
||||
getVersion(UVersionInfo versionInfo) const;
|
||||
|
||||
#ifndef U_HIDE_DEPRECATED_API
|
||||
/**
|
||||
* Return the Locale associated with this ResourceBundle.
|
||||
*
|
||||
* @return a Locale object
|
||||
* @deprecated ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.
|
||||
*/
|
||||
const Locale&
|
||||
getLocale(void) const;
|
||||
#endif /* U_HIDE_DEPRECATED_API */
|
||||
|
||||
/**
|
||||
* Return the Locale associated with this ResourceBundle.
|
||||
* @param type You can choose between requested, valid and actual
|
||||
* locale. For description see the definition of
|
||||
* ULocDataLocaleType in uloc.h
|
||||
* @param status just for catching illegal arguments
|
||||
*
|
||||
* @return a Locale object
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
const Locale
|
||||
getLocale(ULocDataLocaleType type, UErrorCode &status) const;
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* This API implements multilevel fallback
|
||||
* @internal
|
||||
*/
|
||||
ResourceBundle
|
||||
getWithFallback(const char* key, UErrorCode& status);
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for this class.
|
||||
*
|
||||
* @stable ICU 2.2
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID();
|
||||
|
||||
private:
|
||||
ResourceBundle(); // default constructor not implemented
|
||||
|
||||
UResourceBundle *fResource;
|
||||
void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);
|
||||
Locale *fLocale;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2005, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* File schriter.h
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 05/05/99 stephen Cleaned up.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef SCHRITER_H
|
||||
#define SCHRITER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/chariter.h"
|
||||
#include "unicode/uchriter.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: String Character Iterator
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
/**
|
||||
* A concrete subclass of CharacterIterator that iterates over the
|
||||
* characters (code units or code points) in a UnicodeString.
|
||||
* It's possible not only to create an
|
||||
* iterator that iterates over an entire UnicodeString, but also to
|
||||
* create one that iterates over only a subrange of a UnicodeString
|
||||
* (iterators over different subranges of the same UnicodeString don't
|
||||
* compare equal).
|
||||
* @see CharacterIterator
|
||||
* @see ForwardCharacterIterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
class U_COMMON_API StringCharacterIterator : public UCharCharacterIterator {
|
||||
public:
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "textStr".
|
||||
* The UnicodeString object is copied.
|
||||
* The iteration range is the whole string, and the starting position is 0.
|
||||
* @param textStr The unicode string used to create an iterator
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& textStr);
|
||||
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "textStr".
|
||||
* The iteration range is the whole string, and the starting
|
||||
* position is specified by "textPos". If "textPos" is outside the valid
|
||||
* iteration range, the behavior of this object is undefined.
|
||||
* @param textStr The unicode string used to create an iterator
|
||||
* @param textPos The starting position of the iteration
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& textStr,
|
||||
int32_t textPos);
|
||||
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "textStr".
|
||||
* The UnicodeString object is copied.
|
||||
* The iteration range begins with the code unit specified by
|
||||
* "textBegin" and ends with the code unit BEFORE the code unit specfied
|
||||
* by "textEnd". The starting position is specified by "textPos". If
|
||||
* "textBegin" and "textEnd" don't form a valid range on "text" (i.e.,
|
||||
* textBegin >= textEnd or either is negative or greater than text.size()),
|
||||
* or "textPos" is outside the range defined by "textBegin" and "textEnd",
|
||||
* the behavior of this iterator is undefined.
|
||||
* @param textStr The unicode string used to create the StringCharacterIterator
|
||||
* @param textBegin The begin position of the iteration range
|
||||
* @param textEnd The end position of the iteration range
|
||||
* @param textPos The starting position of the iteration
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& textStr,
|
||||
int32_t textBegin,
|
||||
int32_t textEnd,
|
||||
int32_t textPos);
|
||||
|
||||
/**
|
||||
* Copy constructor. The new iterator iterates over the same range
|
||||
* of the same string as "that", and its initial position is the
|
||||
* same as "that"'s current position.
|
||||
* The UnicodeString object in "that" is copied.
|
||||
* @param that The StringCharacterIterator to be copied
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator(const StringCharacterIterator& that);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual ~StringCharacterIterator();
|
||||
|
||||
/**
|
||||
* Assignment operator. *this is altered to iterate over the same
|
||||
* range of the same string as "that", and refers to the same
|
||||
* character within that string as "that" does.
|
||||
* @param that The object to be copied.
|
||||
* @return the newly created object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator&
|
||||
operator=(const StringCharacterIterator& that);
|
||||
|
||||
/**
|
||||
* Returns true if the iterators iterate over the same range of the
|
||||
* same string and are pointing at the same character.
|
||||
* @param that The ForwardCharacterIterator to be compared for equality
|
||||
* @return true if the iterators iterate over the same range of the
|
||||
* same string and are pointing at the same character.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UBool operator==(const ForwardCharacterIterator& that) const;
|
||||
|
||||
/**
|
||||
* Returns a new StringCharacterIterator referring to the same
|
||||
* character in the same range of the same string as this one. The
|
||||
* caller must delete the new iterator.
|
||||
* @return the newly cloned object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual CharacterIterator* clone(void) const;
|
||||
|
||||
/**
|
||||
* Sets the iterator to iterate over the provided string.
|
||||
* @param newText The string to be iterated over
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const UnicodeString& newText);
|
||||
|
||||
/**
|
||||
* Copies the UnicodeString under iteration into the UnicodeString
|
||||
* referred to by "result". Even if this iterator iterates across
|
||||
* only a part of this string, the whole string is copied.
|
||||
* @param result Receives a copy of the text under iteration.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void getText(UnicodeString& result);
|
||||
|
||||
/**
|
||||
* Return a class ID for this object (not really public)
|
||||
* @return a class ID for this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Return a class ID for this class (not really public)
|
||||
* @return a class ID for this class
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor, iteration over empty string.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
StringCharacterIterator();
|
||||
|
||||
/**
|
||||
* Sets the iterator to iterate over the provided string.
|
||||
* @param newText The string to be iterated over
|
||||
* @param newTextLength The length of the String
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
void setText(const UChar* newText, int32_t newTextLength);
|
||||
|
||||
/**
|
||||
* Copy of the iterated string object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
UnicodeString text;
|
||||
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user