diff --git a/icu4c/source/common/caniter.cpp b/icu4c/source/common/caniter.cpp
index e7779a1a9fe..aee9f4ee31a 100644
--- a/icu4c/source/common/caniter.cpp
+++ b/icu4c/source/common/caniter.cpp
@@ -311,12 +311,12 @@ void U_EXPORT2 CanonicalIterator::permute(UnicodeString &source, UBool skipZeros
// see what the permutations of the characters before and after this one are
//Hashtable *subpermute = permute(source.substring(0,i) + source.substring(i + UTF16.getCharCount(cp)));
- permute(subPermuteString.replace(i, U16_LENGTH(cp), NULL, 0), skipZeros, &subpermute, status);
+ permute(subPermuteString.remove(i, U16_LENGTH(cp)), skipZeros, &subpermute, status);
/* Test for buffer overflows */
if(U_FAILURE(status)) {
return;
}
- // The upper replace is destructive. The question is do we have to make a copy, or we don't care about the contents
+ // The upper remove is destructive. The question is do we have to make a copy, or we don't care about the contents
// of source at this point.
// prefix this character to all of them
diff --git a/icu4c/source/common/common.vcxproj b/icu4c/source/common/common.vcxproj
index b735ee9398e..33ef60e2b99 100644
--- a/icu4c/source/common/common.vcxproj
+++ b/icu4c/source/common/common.vcxproj
@@ -1530,6 +1530,20 @@
* \code
- * void processChar( UChar c )
+ * void processChar( char16_t c )
* {
* cout << " " << c;
* }
@@ -294,7 +294,7 @@ protected:
* \code
* void traverseForward(CharacterIterator& iter)
* {
- * for(UChar c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
+ * for(char16_t c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
* processChar(c);
* }
* }
@@ -305,7 +305,7 @@ protected:
* \code
* void traverseBackward(CharacterIterator& iter)
* {
- * for(UChar c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
+ * for(char16_t c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
* processChar(c);
* }
* }
@@ -317,7 +317,7 @@ protected:
* \code
* void traverseOut(CharacterIterator& iter, int32_t pos)
* {
- * UChar c;
+ * char16_t c;
* for (c = iter.setIndex(pos);
* c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
* c = iter.next()) {}
@@ -386,7 +386,7 @@ public:
* @return the first code unit in its iteration range.
* @stable ICU 2.0
*/
- virtual UChar first(void) = 0;
+ virtual char16_t first(void) = 0;
/**
* Sets the iterator to refer to the first code unit in its
@@ -396,7 +396,7 @@ public:
* @return the first code unit in its iteration range.
* @stable ICU 2.0
*/
- virtual UChar firstPostInc(void);
+ virtual char16_t firstPostInc(void);
/**
* Sets the iterator to refer to the first code point in its
@@ -435,7 +435,7 @@ public:
* @return the last code unit.
* @stable ICU 2.0
*/
- virtual UChar last(void) = 0;
+ virtual char16_t last(void) = 0;
/**
* Sets the iterator to refer to the last code point in its
@@ -463,7 +463,7 @@ public:
* @return the "position"-th code unit.
* @stable ICU 2.0
*/
- virtual UChar setIndex(int32_t position) = 0;
+ virtual char16_t setIndex(int32_t position) = 0;
/**
* Sets the iterator to refer to the beginning of the code point
@@ -483,7 +483,7 @@ public:
* @return the current code unit.
* @stable ICU 2.0
*/
- virtual UChar current(void) const = 0;
+ virtual char16_t current(void) const = 0;
/**
* Returns the code point the iterator currently refers to.
@@ -499,7 +499,7 @@ public:
* @return the next code unit.
* @stable ICU 2.0
*/
- virtual UChar next(void) = 0;
+ virtual char16_t next(void) = 0;
/**
* Advances to the next code point in the iteration range
@@ -520,7 +520,7 @@ public:
* @return the previous code unit.
* @stable ICU 2.0
*/
- virtual UChar previous(void) = 0;
+ virtual char16_t previous(void) = 0;
/**
* Advances to the previous code point in the iteration range
diff --git a/icu4c/source/common/unicode/localpointer.h b/icu4c/source/common/unicode/localpointer.h
index aa374f83b86..3ab820188f7 100644
--- a/icu4c/source/common/unicode/localpointer.h
+++ b/icu4c/source/common/unicode/localpointer.h
@@ -174,9 +174,9 @@ private:
* \code
* LocalPointer
Normalizer
object for iterating over the
@@ -704,7 +704,7 @@ public:
* @param status a UErrorCode
* @deprecated ICU 56 Use Normalizer2 instead.
*/
- void setText(const UChar* newText,
+ void setText(ConstChar16Ptr newText,
int32_t length,
UErrorCode &status);
/**
@@ -796,8 +796,8 @@ 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(),
+ return unorm_compare(toUCharPtr(s1.getBuffer()), s1.length(),
+ toUCharPtr(s2.getBuffer()), s2.length(),
options,
&errorCode);
}
diff --git a/icu4c/source/common/unicode/platform.h b/icu4c/source/common/unicode/platform.h
index b553b6878da..e6d449b57ab 100644
--- a/icu4c/source/common/unicode/platform.h
+++ b/icu4c/source/common/unicode/platform.h
@@ -150,7 +150,7 @@
# define U_PLATFORM U_PF_ANDROID
/* Android wchar_t support depends on the API level. */
# include
Strings may take the form of const char*, const UChar*, or const + *
Strings may take the form of const char*, const char16_t*, or const * UnicodeString*. The type you get is determine by the variant of * 'next' that you call. In general the StringEnumeration is * optimized for one of these types, but all StringEnumerations can @@ -112,7 +112,7 @@ public: *
If the iterator is out of sync with its service, status is set * to U_ENUM_OUT_OF_SYNC_ERROR and NULL is returned.
* - *If the native service string is a UChar* string, it is + *
If the native service string is a char16_t* string, it is * converted to char* with the invariant converter. If the * conversion fails (because a character cannot be converted) then * status is set to U_INVARIANT_CONVERSION_ERROR and the return @@ -131,7 +131,7 @@ public: virtual const char* next(int32_t *resultLength, UErrorCode& status); /** - *
Returns the next element as a NUL-terminated UChar*. If there + *
Returns the next element as a NUL-terminated char16_t*. If there * are no more elements, returns NULL. If the resultLength pointer * is not NULL, the length of the string (not counting the * terminating NUL) is returned at that address. If an error @@ -153,7 +153,7 @@ public: * * @stable ICU 2.4 */ - virtual const UChar* unext(int32_t *resultLength, UErrorCode& status); + virtual const char16_t* unext(int32_t *resultLength, UErrorCode& status); /** *
Returns the next element a UnicodeString*. If there are no
diff --git a/icu4c/source/common/unicode/stringtriebuilder.h b/icu4c/source/common/unicode/stringtriebuilder.h
index 91f1bd24dab..bcad2484e7b 100644
--- a/icu4c/source/common/unicode/stringtriebuilder.h
+++ b/icu4c/source/common/unicode/stringtriebuilder.h
@@ -105,7 +105,7 @@ protected:
/** @internal */
virtual int32_t getElementStringLength(int32_t i) const = 0;
/** @internal */
- virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const = 0;
+ virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const = 0;
/** @internal */
virtual int32_t getElementValue(int32_t i) const = 0;
@@ -120,7 +120,7 @@ protected:
/** @internal */
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const = 0;
/** @internal */
- virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const = 0;
+ virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const = 0;
/** @internal */
virtual UBool matchNodesCanHaveValues() const = 0;
@@ -137,7 +137,7 @@ protected:
/** @internal */
static const int32_t kMaxBranchLinearSubNodeLength=5;
- // Maximum number of nested split-branch levels for a branch on all 2^16 possible UChar units.
+ // Maximum number of nested split-branch levels for a branch on all 2^16 possible char16_t units.
// log2(2^16/kMaxBranchLinearSubNodeLength) rounded up.
/** @internal */
static const int32_t kMaxSplitBranchLevels=14;
@@ -338,7 +338,7 @@ protected:
virtual void write(StringTrieBuilder &builder);
// Adds a unit with a final value.
void add(int32_t c, int32_t value) {
- units[length]=(UChar)c;
+ units[length]=(char16_t)c;
equal[length]=NULL;
values[length]=value;
++length;
@@ -346,7 +346,7 @@ protected:
}
// Adds a unit which leads to another match node.
void add(int32_t c, Node *node) {
- units[length]=(UChar)c;
+ units[length]=(char16_t)c;
equal[length]=node;
values[length]=0;
++length;
@@ -356,7 +356,7 @@ protected:
Node *equal[kMaxBranchLinearSubNodeLength]; // NULL means "has final value".
int32_t length;
int32_t values[kMaxBranchLinearSubNodeLength];
- UChar units[kMaxBranchLinearSubNodeLength];
+ char16_t units[kMaxBranchLinearSubNodeLength];
};
/**
@@ -364,7 +364,7 @@ protected:
*/
class SplitBranchNode : public BranchNode {
public:
- SplitBranchNode(UChar middleUnit, Node *lessThanNode, Node *greaterOrEqualNode)
+ SplitBranchNode(char16_t middleUnit, Node *lessThanNode, Node *greaterOrEqualNode)
: BranchNode(((0x555555*37+middleUnit)*37+
hashCode(lessThanNode))*37+hashCode(greaterOrEqualNode)),
unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
@@ -372,7 +372,7 @@ protected:
virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
virtual void write(StringTrieBuilder &builder);
protected:
- UChar unit;
+ char16_t unit;
Node *lessThan;
Node *greaterOrEqual;
};
diff --git a/icu4c/source/common/unicode/ucharstrie.h b/icu4c/source/common/unicode/ucharstrie.h
index 91c5ba1c2c2..dfc93f6d0ba 100644
--- a/icu4c/source/common/unicode/ucharstrie.h
+++ b/icu4c/source/common/unicode/ucharstrie.h
@@ -36,7 +36,7 @@ class UVector32;
/**
* Light-weight, non-const reader class for a UCharsTrie.
- * Traverses a UChar-serialized data structure with minimal state,
+ * Traverses a char16_t-serialized data structure with minimal state,
* for mapping strings (16-bit-unit sequences) to non-negative integer values.
*
* This class owns the serialized trie data only if it was constructed by
@@ -52,18 +52,18 @@ public:
/**
* Constructs a UCharsTrie reader instance.
*
- * The trieUChars must contain a copy of a UChar sequence from the UCharsTrieBuilder,
- * starting with the first UChar of that sequence.
- * The UCharsTrie object will not read more UChars than
+ * The trieUChars must contain a copy of a char16_t sequence from the UCharsTrieBuilder,
+ * starting with the first char16_t of that sequence.
+ * The UCharsTrie object will not read more char16_ts than
* the UCharsTrieBuilder generated in the corresponding build() call.
*
* The array is not copied/cloned and must not be modified while
* the UCharsTrie object is in use.
*
- * @param trieUChars The UChar array that contains the serialized trie.
+ * @param trieUChars The char16_t array that contains the serialized trie.
* @stable ICU 4.8
*/
- UCharsTrie(const UChar *trieUChars)
+ UCharsTrie(ConstChar16Ptr trieUChars)
: ownedArray_(NULL), uchars_(trieUChars),
pos_(uchars_), remainingMatchLength_(-1) {}
@@ -75,7 +75,7 @@ public:
/**
* Copy constructor, copies the other trie reader object and its state,
- * but not the UChar array which will be shared. (Shallow copy.)
+ * but not the char16_t array which will be shared. (Shallow copy.)
* @param other Another UCharsTrie object.
* @stable ICU 4.8
*/
@@ -109,8 +109,8 @@ public:
private:
friend class UCharsTrie;
- const UChar *uchars;
- const UChar *pos;
+ const char16_t *uchars;
+ const char16_t *pos;
int32_t remainingMatchLength;
};
@@ -148,14 +148,14 @@ public:
/**
* Determines whether the string so far matches, whether it has a value,
- * and whether another input UChar can continue a matching string.
+ * and whether another input char16_t can continue a matching string.
* @return The match/value Result.
* @stable ICU 4.8
*/
UStringTrieResult current() const;
/**
- * Traverses the trie from the initial state for this input UChar.
+ * Traverses the trie from the initial state for this input char16_t.
* Equivalent to reset().next(uchar).
* @param uchar Input char value. Values below 0 and above 0xffff will never match.
* @return The match/value Result.
@@ -177,7 +177,7 @@ public:
UStringTrieResult firstForCodePoint(UChar32 cp);
/**
- * Traverses the trie from the current state for this input UChar.
+ * Traverses the trie from the current state for this input char16_t.
* @param uchar Input char value. Values below 0 and above 0xffff will never match.
* @return The match/value Result.
* @stable ICU 4.8
@@ -208,7 +208,7 @@ public:
* @return The match/value Result.
* @stable ICU 4.8
*/
- UStringTrieResult next(const UChar *s, int32_t length);
+ UStringTrieResult next(ConstChar16Ptr s, int32_t length);
/**
* Returns a matching string's value if called immediately after
@@ -220,7 +220,7 @@ public:
* @stable ICU 4.8
*/
inline int32_t getValue() const {
- const UChar *pos=pos_;
+ const char16_t *pos=pos_;
int32_t leadUnit=*pos++;
// U_ASSERT(leadUnit>=kMinValueLead);
return leadUnit&kValueIsFinal ?
@@ -237,16 +237,16 @@ public:
* @stable ICU 4.8
*/
inline UBool hasUniqueValue(int32_t &uniqueValue) const {
- const UChar *pos=pos_;
+ const char16_t *pos=pos_;
// Skip the rest of a pending linear-match node.
return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue);
}
/**
- * Finds each UChar which continues the string from the current state.
- * That is, each UChar c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
- * @param out Each next UChar is appended to this object.
- * @return the number of UChars which continue the string from here
+ * Finds each char16_t which continues the string from the current state.
+ * That is, each char16_t c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
+ * @param out Each next char16_t is appended to this object.
+ * @return the number of char16_ts which continue the string from here
* @stable ICU 4.8
*/
int32_t getNextUChars(Appendable &out) const;
@@ -258,8 +258,8 @@ public:
class U_COMMON_API Iterator : public UMemory {
public:
/**
- * Iterates from the root of a UChar-serialized UCharsTrie.
- * @param trieUChars The trie UChars.
+ * Iterates from the root of a char16_t-serialized UCharsTrie.
+ * @param trieUChars The trie char16_ts.
* @param maxStringLength If 0, the iterator returns full strings.
* Otherwise, the iterator returns strings with this maximum length.
* @param errorCode Standard ICU error code. Its input value must
@@ -268,7 +268,7 @@ public:
* function chaining. (See User Guide for details.)
* @stable ICU 4.8
*/
- Iterator(const UChar *trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
+ Iterator(ConstChar16Ptr trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
/**
* Iterates from the current state of the specified UCharsTrie.
@@ -336,11 +336,11 @@ public:
return TRUE;
}
- const UChar *branchNext(const UChar *pos, int32_t length, UErrorCode &errorCode);
+ const char16_t *branchNext(const char16_t *pos, int32_t length, UErrorCode &errorCode);
- const UChar *uchars_;
- const UChar *pos_;
- const UChar *initialPos_;
+ const char16_t *uchars_;
+ const char16_t *pos_;
+ const char16_t *initialPos_;
int32_t remainingMatchLength_;
int32_t initialRemainingMatchLength_;
UBool skipValue_; // Skip intermediate value which was already delivered.
@@ -368,7 +368,7 @@ private:
* this constructor adopts the builder's array.
* This constructor is only called by the builder.
*/
- UCharsTrie(UChar *adoptUChars, const UChar *trieUChars)
+ UCharsTrie(char16_t *adoptUChars, const char16_t *trieUChars)
: ownedArray_(adoptUChars), uchars_(trieUChars),
pos_(uchars_), remainingMatchLength_(-1) {}
@@ -381,7 +381,7 @@ private:
// Reads a compact 32-bit integer.
// pos is already after the leadUnit, and the lead unit has bit 15 reset.
- static inline int32_t readValue(const UChar *pos, int32_t leadUnit) {
+ static inline int32_t readValue(const char16_t *pos, int32_t leadUnit) {
int32_t value;
if(leadUnit In ICU, a Unicode string consists of 16-bit Unicode code units.
* A Unicode character may be stored with either one code unit
* (the most common case) or with a matched pair of special code units
- * ("surrogates"). The data type for code units is UChar.
+ * ("surrogates"). The data type for code units is char16_t.
* For single-character handling, a Unicode character code point is a value
* in the range 0..0x10ffff. ICU uses the UChar32 type for code points. Example of use:
*
- * To efficiently work with UChar *strings, wrap the data in a UnicodeString
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
* using one of the aliasing constructors, such as
- *
- * To efficiently work with UChar *strings, wrap the data in a UnicodeString
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
* using one of the aliasing constructors, such as
- *
- * To efficiently work with UChar *strings, wrap the data in a UnicodeString
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
* using one of the aliasing constructors, such as
- *
- * Subclassing:
- * Within the ResourceBundle, this method searches for five keys:
- *
* @param cal The calendar system whose date format symbols are desired.
* @param locale The locale whose symbols are desired.
*
@@ -2211,57 +2161,6 @@ public class DateFormatSymbols implements Serializable, Cloneable {
/**
* Returns the {@link DateFormatSymbols} object that should be used to format a
* calendar system's dates in the given locale.
- *
- * Subclassing:
- * Within the ResourceBundle, this method searches for five keys:
- *
* @param cal The calendar system whose date format symbols are desired.
* @param locale The ulocale whose symbols are desired.
*
length-1
.
* text is only aliased, not adopted (the
* destructor will not delete it).
- * @param textPtr The UChar array to be iterated over
- * @param length The length of the UChar array
+ * @param textPtr The char16_t array to be iterated over
+ * @param length The length of the char16_t array
* @stable ICU 2.0
*/
- UCharCharacterIterator(const UChar* textPtr, int32_t length);
+ UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length);
/**
- * Create an iterator over the UChar array referred to by "textPtr".
+ * Create an iterator over the char16_t array referred to by "textPtr".
* The iteration range is 0 to length-1
.
* text is only aliased, not adopted (the
* destructor will not delete it).
* The starting
* position is specified by "position". If "position" is outside the valid
* iteration range, the behavior of this object is undefined.
- * @param textPtr The UChar array to be iteratd over
- * @param length The length of the UChar array
+ * @param textPtr The char16_t array to be iteratd over
+ * @param length The length of the char16_t array
* @param position The starting position of the iteration
* @stable ICU 2.0
*/
- UCharCharacterIterator(const UChar* textPtr, int32_t length,
+ UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
int32_t position);
/**
- * Create an iterator over the UChar array referred to by "textPtr".
+ * Create an iterator over the char16_t array referred to by "textPtr".
* The iteration range is 0 to end-1
.
* text is only aliased, not adopted (the
* destructor will not delete it).
@@ -70,14 +70,14 @@ public:
* position is specified by "position". If begin and end do not
* form a valid iteration range or "position" is outside the valid
* iteration range, the behavior of this object is undefined.
- * @param textPtr The UChar array to be iterated over
- * @param length The length of the UChar array
+ * @param textPtr The char16_t array to be iterated over
+ * @param length The length of the char16_t array
* @param textBegin The begin position of the iteration range
* @param textEnd The end position of the iteration range
* @param position The starting position of the iteration
* @stable ICU 2.0
*/
- UCharCharacterIterator(const UChar* textPtr, int32_t length,
+ UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
int32_t textBegin,
int32_t textEnd,
int32_t position);
@@ -141,7 +141,7 @@ public:
* @return the first code unit in its iteration range.
* @stable ICU 2.0
*/
- virtual UChar first(void);
+ virtual char16_t first(void);
/**
* Sets the iterator to refer to the first code unit in its
@@ -151,7 +151,7 @@ public:
* @return the first code unit in its iteration range
* @stable ICU 2.0
*/
- virtual UChar firstPostInc(void);
+ virtual char16_t firstPostInc(void);
/**
* Sets the iterator to refer to the first code point in its
@@ -181,7 +181,7 @@ public:
* @return the last code unit in its iteration range.
* @stable ICU 2.0
*/
- virtual UChar last(void);
+ virtual char16_t last(void);
/**
* Sets the iterator to refer to the last code point in its
@@ -200,7 +200,7 @@ public:
* @return the code unit
* @stable ICU 2.0
*/
- virtual UChar setIndex(int32_t position);
+ virtual char16_t setIndex(int32_t position);
/**
* Sets the iterator to refer to the beginning of the code point
@@ -220,7 +220,7 @@ public:
* @return the code unit the iterator currently refers to.
* @stable ICU 2.0
*/
- virtual UChar current(void) const;
+ virtual char16_t current(void) const;
/**
* Returns the code point the iterator currently refers to.
@@ -236,7 +236,7 @@ public:
* @return the next code unit in the iteration range.
* @stable ICU 2.0
*/
- virtual UChar next(void);
+ virtual char16_t next(void);
/**
* Gets the current code unit for returning and advances to the next code unit
@@ -246,7 +246,7 @@ public:
* @return the current code unit.
* @stable ICU 2.0
*/
- virtual UChar nextPostInc(void);
+ virtual char16_t nextPostInc(void);
/**
* Advances to the next code point in the iteration range (toward
@@ -288,7 +288,7 @@ public:
* @return the previous code unit in the iteration range.
* @stable ICU 2.0
*/
- virtual UChar previous(void);
+ virtual char16_t previous(void);
/**
* Advances to the previous code point in the iteration range (toward
@@ -340,10 +340,10 @@ public:
* Sets the iterator to iterate over a new range of text
* @stable ICU 2.0
*/
- void setText(const UChar* newText, int32_t newTextLength);
+ void setText(ConstChar16Ptr newText, int32_t newTextLength);
/**
- * Copies the UChar array under iteration into the UnicodeString
+ * Copies the char16_t array 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.
@@ -375,7 +375,7 @@ protected:
* Protected member text
* @stable ICU 2.0
*/
- const UChar* text;
+ const char16_t* text;
};
diff --git a/icu4c/source/common/unicode/umachine.h b/icu4c/source/common/unicode/umachine.h
index fbd2bfe5686..cc28e4b687e 100644
--- a/icu4c/source/common/unicode/umachine.h
+++ b/icu4c/source/common/unicode/umachine.h
@@ -301,32 +301,75 @@ typedef int8_t UBool;
/**
* \var UChar
*
- * For C++, UChar is always defined to be char16_t.
+ * The base type for UTF-16 code units and pointers.
+ * Unsigned 16-bit integer.
+ * Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar.
*
- * For plain C, define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
- * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
- * If neither is available, then define UChar to be uint16_t.
+ * UChar is configurable by defining the macro UCHAR_TYPE
+ * on the preprocessor or compiler command line:
+ * -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc.
+ * (The UCHAR_TYPE can also be #defined earlier in this file, for outside the ICU library code.)
+ * This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16.
*
- * This makes the definition of UChar platform-dependent
- * but allows direct string type compatibility with platforms with
- * 16-bit wchar_t types.
+ * The default is UChar=char16_t.
+ *
+ * C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type.
+ *
+ * In C, char16_t is a simple typedef of uint_least16_t.
+ * ICU requires uint_least16_t=uint16_t for data memory mapping.
+ * On macOS, char16_t is not available because the uchar.h standard header is missing.
*
* @stable ICU 4.4
*/
-#ifdef __cplusplus
+
+#if 1
+ // #if 1 is normal. UChar defaults to char16_t in C++.
+ // For configuration testing of UChar=uint16_t temporarily change this to #if 0.
+ // The intltest Makefile #defines UCHAR_TYPE=char16_t,
+ // so we only #define it to uint16_t if it is undefined so far.
+#elif !defined(UCHAR_TYPE)
+# define UCHAR_TYPE uint16_t
+#endif
+
+#if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || \
+ defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
+ // Inside the ICU library code, never configurable.
typedef char16_t UChar;
#elif defined(UCHAR_TYPE)
typedef UCHAR_TYPE UChar;
-#elif U_SIZEOF_WCHAR_T==2
- typedef wchar_t UChar;
-#elif U_HAVE_CHAR16_T
+#elif defined(__cplusplus)
typedef char16_t UChar;
-#elif defined(__CHAR16_TYPE__)
- typedef __CHAR16_TYPE__ UChar;
#else
typedef uint16_t UChar;
#endif
+/**
+ * \var OldUChar
+ * Default ICU 58 definition of UChar.
+ * A base type for UTF-16 code units and pointers.
+ * Unsigned 16-bit integer.
+ *
+ * Define OldUChar to be wchar_t if that is 16 bits wide.
+ * If wchar_t is not 16 bits wide, then define UChar to be uint16_t.
+ *
+ * This makes the definition of OldUChar platform-dependent
+ * but allows direct string type compatibility with platforms with
+ * 16-bit wchar_t types.
+ *
+ * This is how UChar was defined in ICU 58, for transition convenience.
+ * Exception: ICU 58 UChar was defined to UCHAR_TYPE if that macro was defined.
+ * The current UChar responds to UCHAR_TYPE but OldUChar does not.
+ *
+ * @draft ICU 59
+ */
+#if U_SIZEOF_WCHAR_T==2
+ typedef wchar_t OldUChar;
+#elif defined(__CHAR16_TYPE__)
+ typedef __CHAR16_TYPE__ OldUChar;
+#else
+ typedef uint16_t OldUChar;
+#endif
+
/**
* Define UChar32 as a type for single Unicode code points.
* UChar32 is a signed 32-bit integer (same as int32_t).
diff --git a/icu4c/source/common/unicode/unifilt.h b/icu4c/source/common/unicode/unifilt.h
index a23d871a151..e10527154b6 100644
--- a/icu4c/source/common/unicode/unifilt.h
+++ b/icu4c/source/common/unicode/unifilt.h
@@ -30,7 +30,7 @@ U_NAMESPACE_BEGIN
* defined range.
* @stable ICU 3.0
*/
-#define U_ETHER ((UChar)0xFFFF)
+#define U_ETHER ((char16_t)0xFFFF)
/**
*
diff --git a/icu4c/source/common/unicode/uniset.h b/icu4c/source/common/unicode/uniset.h
index 133c2cf7f8d..4a4ce193b64 100644
--- a/icu4c/source/common/unicode/uniset.h
+++ b/icu4c/source/common/unicode/uniset.h
@@ -294,7 +294,7 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter {
* indicating that toPattern() must generate a pattern
* representation from the inversion list.
*/
- UChar *pat;
+ char16_t *pat;
UVector* strings; // maintained in sorted order
UnicodeSetStringSpan *stringSpan;
@@ -891,7 +891,7 @@ public:
* @stable ICU 3.8
* @see USetSpanCondition
*/
- int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
+ int32_t span(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
/**
* Returns the end of the substring of the input string according to the USetSpanCondition.
@@ -924,7 +924,7 @@ public:
* @stable ICU 3.8
* @see USetSpanCondition
*/
- int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
+ int32_t spanBack(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
/**
* Returns the start of the substring of the input string according to the USetSpanCondition.
diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h
index 0d215d67bb0..42ef43b293e 100644
--- a/icu4c/source/common/unicode/unistr.h
+++ b/icu4c/source/common/unicode/unistr.h
@@ -28,7 +28,9 @@
* \brief C++ API: Unicode String
*/
+#include NUL
, must be specified as a constant.
* @stable ICU 2.0
*/
-#define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)u ## cs, _length)
+#define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
/**
* Unicode String literals in C++.
@@ -137,7 +139,7 @@ class UnicodeStringAppendable; // unicode/appendable.h
/**
* \def UNISTR_FROM_CHAR_EXPLICIT
* This can be defined to be empty or "explicit".
- * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32)
+ * If explicit, then the UnicodeString(char16_t) and UnicodeString(UChar32)
* constructors are marked as explicit, preventing their inadvertent use.
* @stable ICU 49
*/
@@ -154,7 +156,7 @@ class UnicodeStringAppendable; // unicode/appendable.h
/**
* \def UNISTR_FROM_STRING_EXPLICIT
* This can be defined to be empty or "explicit".
- * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *)
+ * If explicit, then the UnicodeString(const char *) and UnicodeString(const char16_t *)
* constructors are marked as explicit, preventing their inadvertent use.
*
* In particular, this helps prevent accidentally depending on ICU conversion code
@@ -188,18 +190,18 @@ class UnicodeStringAppendable; // unicode/appendable.h
* to 4 * sizeof(pointer) (or 3 * sizeof(pointer) for P128 data models),
* to hold the fields for heap-allocated strings.
* Such a minimum size also ensures that the object is easily large enough
- * to hold at least 2 UChars, for one supplementary code point (U16_MAX_LENGTH).
+ * to hold at least 2 char16_ts, for one supplementary code point (U16_MAX_LENGTH).
*
* sizeof(UnicodeString) >= 48 should work for all known platforms.
*
* For example, on a 64-bit machine where sizeof(vtable pointer) is 8,
* sizeof(UnicodeString) = 64 would leave space for
* (64 - sizeof(vtable pointer) - 2) / U_SIZEOF_UCHAR = (64 - 8 - 2) / 2 = 27
- * UChars stored inside the object.
+ * char16_ts stored inside the object.
*
* The minimum object size on a 64-bit machine would be
* 4 * sizeof(pointer) = 4 * 8 = 32 bytes,
- * and the internal buffer would hold up to 11 UChars in that case.
+ * and the internal buffer would hold up to 11 char16_ts in that case.
*
* @see U16_MAX_LENGTH
* @stable ICU 56
@@ -231,7 +233,7 @@ class UnicodeStringAppendable; // unicode/appendable.h
* srcChars
.
* @stable ICU 2.0
*/
- inline int8_t compare(const UChar *srcChars,
+ inline int8_t compare(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
@@ -453,7 +455,7 @@ public:
*/
inline int8_t compare(int32_t start,
int32_t length,
- const UChar *srcChars) const;
+ const char16_t *srcChars) const;
/**
* Compare the characters bitwise in the range
@@ -474,7 +476,7 @@ public:
*/
inline int8_t compare(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -588,7 +590,7 @@ public:
* in code point order
* @stable ICU 2.0
*/
- inline int8_t compareCodePointOrder(const UChar *srcChars,
+ inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
@@ -612,7 +614,7 @@ public:
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
- const UChar *srcChars) const;
+ const char16_t *srcChars) const;
/**
* Compare two Unicode strings in code point order.
@@ -637,7 +639,7 @@ public:
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -761,7 +763,7 @@ public:
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
- inline int8_t caseCompare(const UChar *srcChars,
+ inline int8_t caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const;
@@ -787,7 +789,7 @@ public:
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
uint32_t options) const;
/**
@@ -814,7 +816,7 @@ public:
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
@@ -879,7 +881,7 @@ public:
* FALSE otherwise
* @stable ICU 2.0
*/
- inline UBool startsWith(const UChar *srcChars,
+ inline UBool startsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
@@ -891,7 +893,7 @@ public:
* @return TRUE if this ends with the characters in srcChars, FALSE otherwise
* @stable ICU 2.0
*/
- inline UBool startsWith(const UChar *srcChars,
+ inline UBool startsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -926,7 +928,7 @@ public:
* FALSE otherwise
* @stable ICU 2.0
*/
- inline UBool endsWith(const UChar *srcChars,
+ inline UBool endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
@@ -939,7 +941,7 @@ public:
* FALSE otherwise
* @stable ICU 2.0
*/
- inline UBool endsWith(const UChar *srcChars,
+ inline UBool endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -1016,7 +1018,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t indexOf(const UChar *srcChars,
+ inline int32_t indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
@@ -1032,7 +1034,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t indexOf(const UChar *srcChars,
+ inline int32_t indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
@@ -1053,7 +1055,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- int32_t indexOf(const UChar *srcChars,
+ int32_t indexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
@@ -1066,7 +1068,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t indexOf(UChar c) const;
+ inline int32_t indexOf(char16_t c) const;
/**
* Locate in this the first occurrence of the code point c,
@@ -1086,7 +1088,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t indexOf(UChar c,
+ inline int32_t indexOf(char16_t c,
int32_t start) const;
/**
@@ -1111,7 +1113,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t indexOf(UChar c,
+ inline int32_t indexOf(char16_t c,
int32_t start,
int32_t length) const;
@@ -1199,7 +1201,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t lastIndexOf(const UChar *srcChars,
+ inline int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
@@ -1215,7 +1217,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t lastIndexOf(const UChar *srcChars,
+ inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
@@ -1236,7 +1238,7 @@ public:
* or -1 if not found.
* @stable ICU 2.0
*/
- int32_t lastIndexOf(const UChar *srcChars,
+ int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
@@ -1249,7 +1251,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t lastIndexOf(UChar c) const;
+ inline int32_t lastIndexOf(char16_t c) const;
/**
* Locate in this the last occurrence of the code point c,
@@ -1269,7 +1271,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t lastIndexOf(UChar c,
+ inline int32_t lastIndexOf(char16_t c,
int32_t start) const;
/**
@@ -1294,7 +1296,7 @@ public:
* @return The offset into this of c, or -1 if not found.
* @stable ICU 2.0
*/
- inline int32_t lastIndexOf(UChar c,
+ inline int32_t lastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
@@ -1324,7 +1326,7 @@ public:
* or 0xffff if the offset is not valid for this string
* @stable ICU 2.0
*/
- inline UChar charAt(int32_t offset) const;
+ inline char16_t charAt(int32_t offset) const;
/**
* Return the code unit at offset offset.
@@ -1333,7 +1335,7 @@ public:
* @return the code unit at offset offset
* @stable ICU 2.0
*/
- inline UChar operator[] (int32_t offset) const;
+ inline char16_t operator[] (int32_t offset) const;
/**
* Return the code point that contains the code unit
@@ -1454,7 +1456,7 @@ public:
*/
inline void extract(int32_t start,
int32_t length,
- UChar *dst,
+ Char16Ptr dst,
int32_t dstStart = 0) const;
/**
@@ -1473,13 +1475,13 @@ public:
* then extract() will not copy the contents.
*
* @param dest Destination string buffer.
- * @param destCapacity Number of UChars available at dest.
+ * @param destCapacity Number of char16_ts available at dest.
* @param errorCode ICU error code.
* @return length()
* @stable ICU 2.0
*/
int32_t
- extract(UChar *dest, int32_t destCapacity,
+ extract(Char16Ptr dest, int32_t destCapacity,
UErrorCode &errorCode) const;
/**
@@ -1509,7 +1511,7 @@ public:
*/
inline void extractBetween(int32_t start,
int32_t limit,
- UChar *dst,
+ char16_t *dst,
int32_t dstStart = 0) const;
/**
@@ -1750,7 +1752,7 @@ public:
/**
* Return the length of the UnicodeString object.
- * The length is the number of UChar code units are in the UnicodeString.
+ * The length is the number of char16_t code units are in the UnicodeString.
* If you want the number of code points, please use countChar32().
* @return the length of the UnicodeString object
* @see countChar32
@@ -1759,14 +1761,14 @@ public:
inline int32_t length(void) const;
/**
- * Count Unicode code points in the length UChar code units of the string.
- * A code point may occupy either one or two UChar code units.
+ * Count Unicode code points in the length char16_t code units of the string.
+ * A code point may occupy either one or two char16_t code units.
* Counting code points involves reading all code units.
*
* This functions is basically the inverse of moveIndex32().
*
* @param start the index of the first code unit to check
- * @param length the number of UChar code units to check
+ * @param length the number of char16_t code units to check
* @return the number of code points in the specified code units
* @see length
* @stable ICU 2.0
@@ -1775,7 +1777,7 @@ public:
countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
/**
- * Check if the length UChar code units of the string
+ * Check if the length char16_t code units of the string
* contain more Unicode code points than a certain number.
* This is more efficient than counting all code points in this part of the string
* and comparing that number with a threshold.
@@ -1783,10 +1785,10 @@ public:
* falls within a certain range, and
* never needs to count more than 'number+1' code points.
* Logically equivalent to (countChar32(start, length)>number).
- * A Unicode code point may occupy either one or two UChar code units.
+ * A Unicode code point may occupy either one or two char16_t code units.
*
* @param start the index of the first code unit to check (0 for the entire string)
- * @param length the number of UChar code units to check
+ * @param length the number of char16_t code units to check
* (use INT32_MAX for the entire string; remember that start/length
* values are pinned)
* @param number The number of code points in the (sub)string is compared against
@@ -1812,7 +1814,7 @@ public:
* This is useful together with the getBuffer functions.
* See there for details.
*
- * @return the number of UChars available in the internal buffer
+ * @return the number of char16_ts available in the internal buffer
* @see getBuffer
* @stable ICU 2.0
*/
@@ -1946,7 +1948,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& operator= (UChar ch);
+ inline UnicodeString& operator= (char16_t ch);
/**
* Assignment operator. Replace the characters in this UnicodeString
@@ -2006,7 +2008,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& setTo(const UChar *srcChars,
+ inline UnicodeString& setTo(const char16_t *srcChars,
int32_t srcLength);
/**
@@ -2017,7 +2019,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- UnicodeString& setTo(UChar srcChar);
+ UnicodeString& setTo(char16_t srcChar);
/**
* Set the characters in the UnicodeString object to the code point
@@ -2030,7 +2032,7 @@ public:
UnicodeString& setTo(UChar32 srcChar);
/**
- * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
+ * Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
@@ -2053,11 +2055,11 @@ public:
* @stable ICU 2.0
*/
UnicodeString &setTo(UBool isTerminated,
- const UChar *text,
+ ConstChar16Ptr text,
int32_t textLength);
/**
- * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
+ * Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
@@ -2066,16 +2068,16 @@ public:
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
- * The extract(UChar *dst) function detects whether the dst pointer is the same
+ * The extract(Char16Ptr dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in buffer
to alias.
- * @param buffCapacity The size of buffer
in UChars.
+ * @param buffCapacity The size of buffer
in char16_ts.
* @return a reference to this
* @stable ICU 2.0
*/
- UnicodeString &setTo(UChar *buffer,
+ UnicodeString &setTo(char16_t *buffer,
int32_t buffLength,
int32_t buffCapacity);
@@ -2111,7 +2113,7 @@ public:
* s.truncate(0); // set to an empty string (complete truncation), or
* s=UnicodeString(); // assign an empty string, or
* s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
- * static const UChar nul=0;
+ * static const char16_t nul=0;
* s.setTo(&nul, 0); // set to an empty C Unicode string
* }
* \endcode
@@ -2129,7 +2131,7 @@ public:
* @stable ICU 2.0
*/
UnicodeString& setCharAt(int32_t offset,
- UChar ch);
+ char16_t ch);
/* Append operations */
@@ -2141,7 +2143,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& operator+= (UChar ch);
+ inline UnicodeString& operator+= (char16_t ch);
/**
* Append operator. Append the code point ch to the UnicodeString
@@ -2201,7 +2203,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& append(const UChar *srcChars,
+ inline UnicodeString& append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
@@ -2214,7 +2216,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& append(const UChar *srcChars,
+ inline UnicodeString& append(ConstChar16Ptr srcChars,
int32_t srcLength);
/**
@@ -2223,7 +2225,7 @@ public:
* @return a reference to this
* @stable ICU 2.0
*/
- inline UnicodeString& append(UChar srcChar);
+ inline UnicodeString& append(char16_t srcChar);
/**
* Append the code point srcChar to the UnicodeString object.
@@ -2279,7 +2281,7 @@ public:
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
@@ -2293,7 +2295,7 @@ public:
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
- const UChar *srcChars,
+ ConstChar16Ptr srcChars,
int32_t srcLength);
/**
@@ -2305,7 +2307,7 @@ public:
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
- UChar srcChar);
+ char16_t srcChar);
/**
* Insert the code point srcChar into the UnicodeString object at
@@ -2379,7 +2381,7 @@ public:
*/
UnicodeString& replace(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
@@ -2397,7 +2399,7 @@ public:
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
- const UChar *srcChars,
+ ConstChar16Ptr srcChars,
int32_t srcLength);
/**
@@ -2413,7 +2415,7 @@ public:
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
- UChar srcChar);
+ char16_t srcChar);
/**
* Replace the characters in the range
@@ -2611,7 +2613,7 @@ public:
* @stable ICU 2.0
*/
UBool padLeading(int32_t targetLength,
- UChar padChar = 0x0020);
+ char16_t padChar = 0x0020);
/**
* Pad the end of this UnicodeString with the character padChar.
@@ -2625,7 +2627,7 @@ public:
* @stable ICU 2.0
*/
UBool padTrailing(int32_t targetLength,
- UChar padChar = 0x0020);
+ char16_t padChar = 0x0020);
/**
* Truncate this UnicodeString to the targetLength.
@@ -2812,7 +2814,7 @@ public:
/**
* Get a read/write pointer to the internal buffer.
- * The buffer is guaranteed to be large enough for at least minCapacity UChars,
+ * The buffer is guaranteed to be large enough for at least minCapacity char16_ts,
* writable, and is still owned by the UnicodeString object.
* Calls to getBuffer(minCapacity) must not be nested, and
* must be matched with calls to releaseBuffer(newLength).
@@ -2843,17 +2845,17 @@ public:
* - You must call releaseBuffer(newLength) before and in order to
* return to normal UnicodeString operation.
*
- * @param minCapacity the minimum number of UChars that are to be available
+ * @param minCapacity the minimum number of char16_ts that are to be available
* in the buffer, starting at the returned pointer;
* default to the current string capacity if minCapacity==-1
* @return a writable pointer to the internal string buffer,
- * or 0 if an error occurs (nested calls, out of memory)
+ * or nullptr if an error occurs (nested calls, out of memory)
*
* @see releaseBuffer
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
- UChar *getBuffer(int32_t minCapacity);
+ char16_t *getBuffer(int32_t minCapacity);
/**
* Release a read/write buffer on a UnicodeString object with an
@@ -2901,13 +2903,13 @@ public:
* be modified.
*
* @return a read-only pointer to the internal string buffer,
- * or 0 if the string is empty or bogus
+ * or nullptr if the string is empty or bogus
*
* @see getBuffer(int32_t minCapacity)
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
- inline const UChar *getBuffer() const;
+ inline const char16_t *getBuffer() const;
/**
* Get a read-only pointer to the internal buffer,
@@ -2942,7 +2944,7 @@ public:
* @see getBuffer()
* @stable ICU 2.2
*/
- const UChar *getTerminatedBuffer();
+ const char16_t *getTerminatedBuffer();
//========================================
// Constructors
@@ -2954,8 +2956,8 @@ public:
inline UnicodeString();
/**
- * Construct a UnicodeString with capacity to hold capacity UChars
- * @param capacity the number of UChars this UnicodeString should hold
+ * Construct a UnicodeString with capacity to hold capacity char16_ts
+ * @param capacity the number of char16_ts this UnicodeString should hold
* before a resize is necessary; if count is greater than 0 and count
* code points c take up more space than capacity, then capacity is adjusted
* accordingly.
@@ -2967,7 +2969,7 @@ public:
UnicodeString(int32_t capacity, UChar32 c, int32_t count);
/**
- * Single UChar (code unit) constructor.
+ * Single char16_t (code unit) constructor.
*
* It is recommended to mark this constructor "explicit" by
* -DUNISTR_FROM_CHAR_EXPLICIT=explicit
@@ -2975,7 +2977,7 @@ public:
* @param ch the character to place in the UnicodeString
* @stable ICU 2.0
*/
- UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
+ UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
/**
* Single UChar32 (code point) constructor.
@@ -2989,7 +2991,7 @@ public:
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
/**
- * UChar* constructor.
+ * char16_t* constructor.
*
* It is recommended to mark this constructor "explicit" by
* -DUNISTR_FROM_STRING_EXPLICIT=explicit
@@ -2998,20 +3000,93 @@ public:
* must be NULL (U+0000) terminated.
* @stable ICU 2.0
*/
- UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
+ UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
/**
- * UChar* constructor.
+ * uint16_t * constructor.
+ * Delegates to UnicodeString(const char16_t *).
+ *
+ * It is recommended to mark this constructor "explicit" by
+ * -DUNISTR_FROM_STRING_EXPLICIT=explicit
+ * on the compiler command line or similar.
+ * @param text NUL-terminated UTF-16 string
+ * @draft ICU 59
+ */
+ UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
+ UnicodeString(ConstChar16Ptr(text)) {}
+
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+ /**
+ * wchar_t * constructor.
+ * (Only defined if U_SIZEOF_WCHAR_T==2.)
+ * Delegates to UnicodeString(const char16_t *).
+ *
+ * It is recommended to mark this constructor "explicit" by
+ * -DUNISTR_FROM_STRING_EXPLICIT=explicit
+ * on the compiler command line or similar.
+ * @param text NUL-terminated UTF-16 string
+ * @draft ICU 59
+ */
+ UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
+ UnicodeString(ConstChar16Ptr(text)) {}
+#endif
+
+ /**
+ * nullptr_t constructor.
+ * Effectively the same as the default constructor, makes an empty string object.
+ *
+ * It is recommended to mark this constructor "explicit" by
+ * -DUNISTR_FROM_STRING_EXPLICIT=explicit
+ * on the compiler command line or similar.
+ * @param text nullptr
+ * @draft ICU 59
+ */
+ UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
+
+ /**
+ * char16_t* constructor.
* @param text The characters to place in the UnicodeString.
* @param textLength The number of Unicode characters in text
* to copy.
* @stable ICU 2.0
*/
- UnicodeString(const UChar *text,
+ UnicodeString(const char16_t *text,
int32_t textLength);
/**
- * Readonly-aliasing UChar* constructor.
+ * uint16_t * constructor.
+ * Delegates to UnicodeString(const char16_t *, int32_t).
+ * @param text UTF-16 string
+ * @param length string length
+ * @draft ICU 59
+ */
+ UnicodeString(const uint16_t *text, int32_t length) :
+ UnicodeString(ConstChar16Ptr(text), length) {}
+
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+ /**
+ * wchar_t * constructor.
+ * (Only defined if U_SIZEOF_WCHAR_T==2.)
+ * Delegates to UnicodeString(const char16_t *, int32_t).
+ * @param text NUL-terminated UTF-16 string
+ * @param length string length
+ * @draft ICU 59
+ */
+ UnicodeString(const wchar_t *text, int32_t length) :
+ UnicodeString(ConstChar16Ptr(text), length) {}
+#endif
+
+ /**
+ * nullptr_t constructor.
+ * Effectively the same as the default constructor, makes an empty string object.
+ * @param text nullptr
+ * @param length ignored
+ * @draft ICU 59
+ */
+ inline UnicodeString(const std::nullptr_t text, int32_t length);
+
+ /**
+ * Readonly-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
@@ -3033,11 +3108,11 @@ public:
* @stable ICU 2.0
*/
UnicodeString(UBool isTerminated,
- const UChar *text,
+ ConstChar16Ptr text,
int32_t textLength);
/**
- * Writable-aliasing UChar* constructor.
+ * Writable-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
@@ -3046,15 +3121,50 @@ public:
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
- * The extract(UChar *dst) function detects whether the dst pointer is the same
+ * The extract(Char16Ptr dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in buffer
to alias.
- * @param buffCapacity The size of buffer
in UChars.
+ * @param buffCapacity The size of buffer
in char16_ts.
* @stable ICU 2.0
*/
- UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
+ UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
+
+ /**
+ * Writable-aliasing uint16_t * constructor.
+ * Delegates to UnicodeString(const char16_t *, int32_t, int32_t).
+ * @param buffer writable buffer of/for UTF-16 text
+ * @param buffLength length of the current buffer contents
+ * @param buffCapacity buffer capacity
+ * @draft ICU 59
+ */
+ UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
+ UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
+
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+ /**
+ * Writable-aliasing wchar_t * constructor.
+ * (Only defined if U_SIZEOF_WCHAR_T==2.)
+ * Delegates to UnicodeString(const char16_t *, int32_t, int32_t).
+ * @param buffer writable buffer of/for UTF-16 text
+ * @param buffLength length of the current buffer contents
+ * @param buffCapacity buffer capacity
+ * @draft ICU 59
+ */
+ UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
+ UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
+#endif
+
+ /**
+ * Writable-aliasing nullptr_t constructor.
+ * Effectively the same as the default constructor, makes an empty string object.
+ * @param buffer nullptr
+ * @param buffLength ignored
+ * @param buffCapacity ignored
+ * @draft ICU 59
+ */
+ inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
@@ -3371,7 +3481,7 @@ protected:
* UnicodeString::charAt() to be inline again (see jitterbug 709).
* @stable ICU 2.4
*/
- virtual UChar getCharAt(int32_t offset) const;
+ virtual char16_t getCharAt(int32_t offset) const;
/**
* The change in Replaceable to use virtual getChar32At() allows
@@ -3407,7 +3517,7 @@ private:
int8_t doCompare(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -3420,7 +3530,7 @@ private:
int8_t doCompareCodePointOrder(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
@@ -3435,12 +3545,12 @@ private:
int8_t
doCaseCompare(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
- int32_t doIndexOf(UChar c,
+ int32_t doIndexOf(char16_t c,
int32_t start,
int32_t length) const;
@@ -3448,7 +3558,7 @@ private:
int32_t start,
int32_t length) const;
- int32_t doLastIndexOf(UChar c,
+ int32_t doLastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
@@ -3458,14 +3568,14 @@ private:
void doExtract(int32_t start,
int32_t length,
- UChar *dst,
+ char16_t *dst,
int32_t dstStart) const;
inline void doExtract(int32_t start,
int32_t length,
UnicodeString& target) const;
- inline UChar doCharAt(int32_t offset) const;
+ inline char16_t doCharAt(int32_t offset) const;
UnicodeString& doReplace(int32_t start,
int32_t length,
@@ -3475,12 +3585,12 @@ private:
UnicodeString& doReplace(int32_t start,
int32_t length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
- UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
+ UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
UnicodeString& doReverse(int32_t start,
int32_t length);
@@ -3490,8 +3600,8 @@ private:
// get pointer to start of array
// these do not check for kOpenGetBuffer, unlike the public getBuffer() function
- inline UChar* getArrayStart(void);
- inline const UChar* getArrayStart(void) const;
+ inline char16_t* getArrayStart(void);
+ inline const char16_t* getArrayStart(void) const;
inline UBool hasShortLength() const;
inline int32_t getShortLength() const;
@@ -3508,7 +3618,7 @@ private:
inline void setShortLength(int32_t len);
inline void setLength(int32_t len);
inline void setToEmpty();
- inline void setArray(UChar *array, int32_t len, int32_t capacity); // sets length but not flags
+ inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
// allocate the array; result may be the stack buffer
// sets refCount to 1 if appropriate
@@ -3686,15 +3796,15 @@ private:
// Each struct of the union must begin with fLengthAndFlags.
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
- UChar fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
+ char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
} fStackFields;
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
int32_t fLength; // number of characters in fArray if >127; else undefined
- int32_t fCapacity; // capacity of fArray (in UChars)
+ int32_t fCapacity; // capacity of fArray (in char16_ts)
// array pointer last to minimize padding for machines with P128 data model
// or pointer sizes that are not a power of 2
- UChar *fArray; // the Unicode data
+ char16_t *fArray; // the Unicode data
} fFields;
} fUnion;
};
@@ -3747,13 +3857,13 @@ UnicodeString::pinIndices(int32_t& start,
}
}
-inline UChar*
+inline char16_t*
UnicodeString::getArrayStart() {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
}
-inline const UChar*
+inline const char16_t*
UnicodeString::getArrayStart() const {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
@@ -3768,6 +3878,18 @@ UnicodeString::UnicodeString() {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
+inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
+ fUnion.fStackFields.fLengthAndFlags=kShortString;
+}
+
+inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
+ fUnion.fStackFields.fLengthAndFlags=kShortString;
+}
+
+inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
+ fUnion.fStackFields.fLengthAndFlags=kShortString;
+}
+
//========================================
// Read-only implementation methods
//========================================
@@ -3814,10 +3936,10 @@ UnicodeString::isBufferWritable() const
(!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
}
-inline const UChar *
+inline const char16_t *
UnicodeString::getBuffer() const {
if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
- return 0;
+ return nullptr;
} else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
return fUnion.fStackFields.fBuffer;
} else {
@@ -3885,7 +4007,7 @@ UnicodeString::compare(int32_t start,
{ return doCompare(start, _length, srcText, 0, srcText.length()); }
inline int8_t
-UnicodeString::compare(const UChar *srcChars,
+UnicodeString::compare(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompare(0, length(), srcChars, 0, srcLength); }
@@ -3900,13 +4022,13 @@ UnicodeString::compare(int32_t start,
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
- const UChar *srcChars) const
+ const char16_t *srcChars) const
{ return doCompare(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
@@ -3946,7 +4068,7 @@ UnicodeString::compareCodePointOrder(int32_t start,
{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
inline int8_t
-UnicodeString::compareCodePointOrder(const UChar *srcChars,
+UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
@@ -3961,13 +4083,13 @@ UnicodeString::compareCodePointOrder(int32_t start,
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
- const UChar *srcChars) const
+ const char16_t *srcChars) const
{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
@@ -4011,7 +4133,7 @@ UnicodeString::caseCompare(int32_t start,
}
inline int8_t
-UnicodeString::caseCompare(const UChar *srcChars,
+UnicodeString::caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
@@ -4030,7 +4152,7 @@ UnicodeString::caseCompare(int32_t start,
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ const char16_t *srcChars,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, 0, _length, options);
}
@@ -4038,7 +4160,7 @@ UnicodeString::caseCompare(int32_t start,
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
@@ -4089,7 +4211,7 @@ UnicodeString::indexOf(const UnicodeString& text,
{ return indexOf(text, 0, text.length(), start, _length); }
inline int32_t
-UnicodeString::indexOf(const UChar *srcChars,
+UnicodeString::indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
@@ -4097,14 +4219,14 @@ UnicodeString::indexOf(const UChar *srcChars,
}
inline int32_t
-UnicodeString::indexOf(const UChar *srcChars,
+UnicodeString::indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return indexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
-UnicodeString::indexOf(UChar c,
+UnicodeString::indexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
@@ -4116,7 +4238,7 @@ UnicodeString::indexOf(UChar32 c,
{ return doIndexOf(c, start, _length); }
inline int32_t
-UnicodeString::indexOf(UChar c) const
+UnicodeString::indexOf(char16_t c) const
{ return doIndexOf(c, 0, length()); }
inline int32_t
@@ -4124,7 +4246,7 @@ UnicodeString::indexOf(UChar32 c) const
{ return indexOf(c, 0, length()); }
inline int32_t
-UnicodeString::indexOf(UChar c,
+UnicodeString::indexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doIndexOf(c, start, length() - start);
@@ -4138,14 +4260,14 @@ UnicodeString::indexOf(UChar32 c,
}
inline int32_t
-UnicodeString::lastIndexOf(const UChar *srcChars,
+UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
-UnicodeString::lastIndexOf(const UChar *srcChars,
+UnicodeString::lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
@@ -4186,7 +4308,7 @@ UnicodeString::lastIndexOf(const UnicodeString& text) const
{ return lastIndexOf(text, 0, text.length(), 0, length()); }
inline int32_t
-UnicodeString::lastIndexOf(UChar c,
+UnicodeString::lastIndexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doLastIndexOf(c, start, _length); }
@@ -4199,7 +4321,7 @@ UnicodeString::lastIndexOf(UChar32 c,
}
inline int32_t
-UnicodeString::lastIndexOf(UChar c) const
+UnicodeString::lastIndexOf(char16_t c) const
{ return doLastIndexOf(c, 0, length()); }
inline int32_t
@@ -4208,7 +4330,7 @@ UnicodeString::lastIndexOf(UChar32 c) const {
}
inline int32_t
-UnicodeString::lastIndexOf(UChar c,
+UnicodeString::lastIndexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doLastIndexOf(c, start, length() - start);
@@ -4232,17 +4354,17 @@ UnicodeString::startsWith(const UnicodeString& srcText,
{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
inline UBool
-UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
+UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
if(srcLength < 0) {
- srcLength = u_strlen(srcChars);
+ srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
}
inline UBool
-UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
+UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
if(srcLength < 0) {
- srcLength = u_strlen(srcChars);
+ srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
}
@@ -4262,21 +4384,21 @@ UnicodeString::endsWith(const UnicodeString& srcText,
}
inline UBool
-UnicodeString::endsWith(const UChar *srcChars,
+UnicodeString::endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const {
if(srcLength < 0) {
- srcLength = u_strlen(srcChars);
+ srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(length() - srcLength, srcLength,
srcChars, 0, srcLength) == 0;
}
inline UBool
-UnicodeString::endsWith(const UChar *srcChars,
+UnicodeString::endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const {
if(srcLength < 0) {
- srcLength = u_strlen(srcChars + srcStart);
+ srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
}
return doCompare(length() - srcLength, srcLength,
srcChars, srcStart, srcLength) == 0;
@@ -4302,14 +4424,14 @@ UnicodeString::replace(int32_t start,
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
@@ -4317,7 +4439,7 @@ UnicodeString::replace(int32_t start,
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
- UChar srcChar)
+ char16_t srcChar)
{ return doReplace(start, _length, &srcChar, 0, 1); }
inline UnicodeString&
@@ -4360,7 +4482,7 @@ UnicodeString::doExtract(int32_t start,
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
- UChar *target,
+ Char16Ptr target,
int32_t targetStart) const
{ doExtract(start, _length, target, targetStart); }
@@ -4388,7 +4510,7 @@ UnicodeString::extract(int32_t start,
inline void
UnicodeString::extractBetween(int32_t start,
int32_t limit,
- UChar *dst,
+ char16_t *dst,
int32_t dstStart) const {
pinIndex(start);
pinIndex(limit);
@@ -4400,7 +4522,7 @@ UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
return tempSubString(start, limit - start);
}
-inline UChar
+inline char16_t
UnicodeString::doCharAt(int32_t offset) const
{
if((uint32_t)offset < (uint32_t)length()) {
@@ -4410,11 +4532,11 @@ UnicodeString::doCharAt(int32_t offset) const
}
}
-inline UChar
+inline char16_t
UnicodeString::charAt(int32_t offset) const
{ return doCharAt(offset); }
-inline UChar
+inline char16_t
UnicodeString::operator[] (int32_t offset) const
{ return doCharAt(offset); }
@@ -4455,14 +4577,14 @@ UnicodeString::setToEmpty() {
}
inline void
-UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
+UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
setLength(len);
fUnion.fFields.fArray = array;
fUnion.fFields.fCapacity = capacity;
}
inline UnicodeString&
-UnicodeString::operator= (UChar ch)
+UnicodeString::operator= (char16_t ch)
{ return doReplace(0, length(), &ch, 0, 1); }
inline UnicodeString&
@@ -4494,7 +4616,7 @@ UnicodeString::setTo(const UnicodeString& srcText)
}
inline UnicodeString&
-UnicodeString::setTo(const UChar *srcChars,
+UnicodeString::setTo(const char16_t *srcChars,
int32_t srcLength)
{
unBogus();
@@ -4502,7 +4624,7 @@ UnicodeString::setTo(const UChar *srcChars,
}
inline UnicodeString&
-UnicodeString::setTo(UChar srcChar)
+UnicodeString::setTo(char16_t srcChar)
{
unBogus();
return doReplace(0, length(), &srcChar, 0, 1);
@@ -4526,22 +4648,22 @@ UnicodeString::append(const UnicodeString& srcText)
{ return doAppend(srcText, 0, srcText.length()); }
inline UnicodeString&
-UnicodeString::append(const UChar *srcChars,
+UnicodeString::append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doAppend(srcChars, srcStart, srcLength); }
inline UnicodeString&
-UnicodeString::append(const UChar *srcChars,
+UnicodeString::append(ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doAppend(srcChars, 0, srcLength); }
inline UnicodeString&
-UnicodeString::append(UChar srcChar)
+UnicodeString::append(char16_t srcChar)
{ return doAppend(&srcChar, 0, 1); }
inline UnicodeString&
-UnicodeString::operator+= (UChar ch)
+UnicodeString::operator+= (char16_t ch)
{ return doAppend(&ch, 0, 1); }
inline UnicodeString&
@@ -4567,20 +4689,20 @@ UnicodeString::insert(int32_t start,
inline UnicodeString&
UnicodeString::insert(int32_t start,
- const UChar *srcChars,
+ const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
- const UChar *srcChars,
+ ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
- UChar srcChar)
+ char16_t srcChar)
{ return doReplace(start, 0, &srcChar, 0, 1); }
inline UnicodeString&
diff --git a/icu4c/source/common/unicode/utypes.h b/icu4c/source/common/unicode/utypes.h
index 6b61c4c1646..d60450b5a56 100644
--- a/icu4c/source/common/unicode/utypes.h
+++ b/icu4c/source/common/unicode/utypes.h
@@ -178,12 +178,12 @@
/**
* \def NULL
- * Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
+ * Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
* @stable ICU 2.0
*/
#ifndef NULL
#ifdef __cplusplus
-#define NULL 0
+#define NULL nullptr
#else
#define NULL ((void *)0)
#endif
diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp
index bb4de3afa7e..1bfb71aa107 100644
--- a/icu4c/source/common/unistr.cpp
+++ b/icu4c/source/common/unistr.cpp
@@ -218,9 +218,10 @@ UnicodeString::UnicodeString(const UChar *text,
}
UnicodeString::UnicodeString(UBool isTerminated,
- const UChar *text,
+ ConstChar16Ptr textPtr,
int32_t textLength) {
fUnion.fFields.fLengthAndFlags = kReadonlyAlias;
+ const UChar *text = textPtr;
if(text == NULL) {
// treat as an empty string, do not alias
setToEmpty();
@@ -234,7 +235,8 @@ UnicodeString::UnicodeString(UBool isTerminated,
// text is terminated, or else it would have failed the above test
textLength = u_strlen(text);
}
- setArray((UChar *)text, textLength, isTerminated ? textLength + 1 : textLength);
+ setArray(const_cast
- * . UChar ABC[] = {0x41, 0x42, 0x43, 0}; // = "ABC"
- * . UChar abc[] = {0x61, 0x62, 0x63, 0}; // = "abc"
+ * . char16_t ABC[] = {0x41, 0x42, 0x43, 0}; // = "ABC"
+ * . char16_t abc[] = {0x61, 0x62, 0x63, 0}; // = "abc"
* . UErrorCode status = U_ZERO_ERROR;
* . Collator *myCollation =
* . Collator::createInstance(Locale::getUS(), status);
@@ -420,8 +420,8 @@ public:
* target
* @deprecated ICU 2.6 use the overload with UErrorCode &
*/
- virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
- const UChar* target, int32_t targetLength)
+ virtual EComparisonResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength)
const;
/**
@@ -440,8 +440,8 @@ public:
* than target
* @stable ICU 2.6
*/
- virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
- const UChar* target, int32_t targetLength,
+ virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength,
UErrorCode &status) const = 0;
/**
@@ -517,7 +517,7 @@ public:
* @see CollationKey#compare
* @stable ICU 2.0
*/
- virtual CollationKey& getCollationKey(const UChar*source,
+ virtual CollationKey& getCollationKey(const char16_t*source,
int32_t sourceLength,
CollationKey& key,
UErrorCode& status) const = 0;
@@ -911,7 +911,7 @@ public:
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See setMaxVariable().
- * @param varTop one or more (if contraction) UChars to which the variable top should be set
+ * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
* @param len length of variable top string. If -1 it is considered to be zero terminated.
* @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
* U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
@@ -920,7 +920,7 @@ public:
* @return variable top primary weight
* @deprecated ICU 53 Call setMaxVariable() instead.
*/
- virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
+ virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) = 0;
/**
* Sets the variable top to the primary weight of the specified string.
@@ -929,7 +929,7 @@ public:
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See setMaxVariable().
- * @param varTop a UnicodeString size 1 or more (if contraction) of UChars to which the variable top should be set
+ * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
* @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
* U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
* U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
@@ -1002,7 +1002,7 @@ public:
int32_t resultLength) const = 0;
/**
- * Get the sort key as an array of bytes from a UChar buffer.
+ * Get the sort key as an array of bytes from a char16_t buffer.
* Sort key byte arrays are zero-terminated and can be compared using
* strcmp().
*
@@ -1020,7 +1020,7 @@ public:
* @return Number of bytes needed for storing the sort key
* @stable ICU 2.2
*/
- virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
+ virtual int32_t getSortKey(const char16_t*source, int32_t sourceLength,
uint8_t*result, int32_t resultLength) const = 0;
/**
diff --git a/icu4c/source/i18n/unicode/curramt.h b/icu4c/source/i18n/unicode/curramt.h
index 9071f11bd10..e321df861d2 100644
--- a/icu4c/source/i18n/unicode/curramt.h
+++ b/icu4c/source/i18n/unicode/curramt.h
@@ -46,7 +46,7 @@ class U_I18N_API CurrencyAmount: public Measure {
* is invalid, then this will be set to a failing value.
* @stable ICU 3.0
*/
- CurrencyAmount(const Formattable& amount, const UChar* isoCode,
+ CurrencyAmount(const Formattable& amount, ConstChar16Ptr isoCode,
UErrorCode &ec);
/**
@@ -59,7 +59,7 @@ class U_I18N_API CurrencyAmount: public Measure {
* then this will be set to a failing value.
* @stable ICU 3.0
*/
- CurrencyAmount(double amount, const UChar* isoCode,
+ CurrencyAmount(double amount, ConstChar16Ptr isoCode,
UErrorCode &ec);
/**
@@ -115,14 +115,14 @@ class U_I18N_API CurrencyAmount: public Measure {
* Return the ISO currency code of this object.
* @stable ICU 3.0
*/
- inline const UChar* getISOCurrency() const;
+ inline const char16_t* getISOCurrency() const;
};
inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
return (const CurrencyUnit&) getUnit();
}
-inline const UChar* CurrencyAmount::getISOCurrency() const {
+inline const char16_t* CurrencyAmount::getISOCurrency() const {
return getCurrency().getISOCurrency();
}
diff --git a/icu4c/source/i18n/unicode/currunit.h b/icu4c/source/i18n/unicode/currunit.h
index 61f9201ebb2..fd0f9f2bcce 100644
--- a/icu4c/source/i18n/unicode/currunit.h
+++ b/icu4c/source/i18n/unicode/currunit.h
@@ -28,7 +28,7 @@ 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
+ * yen). This class is a thin wrapper over a char16_t string that
* subclasses MeasureUnit, for use with Measure and MeasureFormat.
*
* @author Alan Liu
@@ -44,7 +44,7 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
* then this will be set to a failing value.
* @stable ICU 3.0
*/
- CurrencyUnit(const UChar* isoCode, UErrorCode &ec);
+ CurrencyUnit(ConstChar16Ptr isoCode, UErrorCode &ec);
/**
* Copy constructor
@@ -93,16 +93,16 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
* Return the ISO currency code of this object.
* @stable ICU 3.0
*/
- inline const UChar* getISOCurrency() const;
+ inline const char16_t* getISOCurrency() const;
private:
/**
* The ISO 4217 code of this object.
*/
- UChar isoCode[4];
+ char16_t isoCode[4];
};
-inline const UChar* CurrencyUnit::getISOCurrency() const {
+inline const char16_t* CurrencyUnit::getISOCurrency() const {
return isoCode;
}
diff --git a/icu4c/source/i18n/unicode/dcfmtsym.h b/icu4c/source/i18n/unicode/dcfmtsym.h
index 6e6615ebd9f..3a502d0ec03 100644
--- a/icu4c/source/i18n/unicode/dcfmtsym.h
+++ b/icu4c/source/i18n/unicode/dcfmtsym.h
@@ -393,7 +393,7 @@ public:
* Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
* @internal
*/
- inline const UChar* getCurrencyPattern(void) const;
+ inline const char16_t* getCurrencyPattern(void) const;
#endif /* U_HIDE_INTERNAL_API */
private:
@@ -424,7 +424,7 @@ private:
char actualLocale[ULOC_FULLNAME_CAPACITY];
char validLocale[ULOC_FULLNAME_CAPACITY];
- const UChar* currPattern;
+ const char16_t* currPattern;
UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
@@ -492,7 +492,7 @@ DecimalFormatSymbols::getLocale() const {
}
#ifndef U_HIDE_INTERNAL_API
-inline const UChar*
+inline const char16_t*
DecimalFormatSymbols::getCurrencyPattern() const {
return currPattern;
}
diff --git a/icu4c/source/i18n/unicode/decimfmt.h b/icu4c/source/i18n/unicode/decimfmt.h
index 7ba34dd4a94..1deff5bf921 100644
--- a/icu4c/source/i18n/unicode/decimfmt.h
+++ b/icu4c/source/i18n/unicode/decimfmt.h
@@ -604,7 +604,7 @@ template class U_I18N_API EnumSetUnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);
+ * UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);
* or in a UText, using
- * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);
+ * utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);
*
*/
- RegexMatcher *matcher(const UChar *input,
+ RegexMatcher *matcher(const char16_t *input,
UErrorCode &status) const;
public:
@@ -748,17 +748,17 @@ public:
private:
/**
* Cause a compilation error if an application accidentally attempts to
- * create a matcher with a (UChar *) string as input rather than
+ * create a matcher with a (char16_t *) string as input rather than
* a UnicodeString. Avoids a dangling reference to a temporary string.
* UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);
+ * UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);
* or in a UText, using
- * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);
+ * utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);
*
*/
- RegexMatcher(const UnicodeString ®exp, const UChar *input,
+ RegexMatcher(const UnicodeString ®exp, const char16_t *input,
uint32_t flags, UErrorCode &status);
public:
@@ -1156,17 +1156,17 @@ public:
private:
/**
* Cause a compilation error if an application accidentally attempts to
- * reset a matcher with a (UChar *) string as input rather than
+ * reset a matcher with a (char16_t *) string as input rather than
* a UnicodeString. Avoids a dangling reference to a temporary string.
* UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength);
+ * UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);
* or in a UText, using
- * utext_openUChars(UText *ut, const UChar *text, int64_t textLength, UErrorCode *status);
+ * utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);
*
*/
- RegexMatcher &reset(const UChar *input);
+ RegexMatcher &reset(const char16_t *input);
public:
/**
diff --git a/icu4c/source/i18n/unicode/smpdtfmt.h b/icu4c/source/i18n/unicode/smpdtfmt.h
index e0ab9702ced..4733e759aa7 100644
--- a/icu4c/source/i18n/unicode/smpdtfmt.h
+++ b/icu4c/source/i18n/unicode/smpdtfmt.h
@@ -1170,7 +1170,7 @@ public:
* @param field The UDateFormatField to get
* @stable ICU 54
*/
- const NumberFormat * getNumberFormatForField(UChar field) const;
+ const NumberFormat * getNumberFormatForField(char16_t field) const;
#ifndef U_HIDE_INTERNAL_API
/**
@@ -1262,7 +1262,7 @@ private:
* succeeds.
*/
void subFormat(UnicodeString &appendTo,
- UChar ch,
+ char16_t ch,
int32_t count,
UDisplayContext capitalizationContext,
int32_t fieldNum,
@@ -1294,7 +1294,7 @@ private:
* Return true if the given format character, occuring count
* times, represents a numeric field.
*/
- static UBool isNumeric(UChar formatChar, int32_t count);
+ static UBool isNumeric(char16_t formatChar, int32_t count);
/**
* Returns TRUE if the patternOffset is at the start of a numeric field.
@@ -1412,7 +1412,7 @@ private:
* @return the new start position if matching succeeded; a negative number
* indicating matching failure, otherwise.
*/
- int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
+ int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs,
int32_t *dayPeriod=NULL) const;
@@ -1523,12 +1523,12 @@ private:
/**
* Map calendar field letter into calendar field level.
*/
- static int32_t getLevelFromChar(UChar ch);
+ static int32_t getLevelFromChar(char16_t ch);
/**
* Tell if a character can be used to define a field in a format string.
*/
- static UBool isSyntaxChar(UChar ch);
+ static UBool isSyntaxChar(char16_t ch);
/**
* The formatting pattern for this formatter.
diff --git a/icu4c/source/i18n/unicode/tblcoll.h b/icu4c/source/i18n/unicode/tblcoll.h
index 6767ee93fc0..24ba213b41e 100644
--- a/icu4c/source/i18n/unicode/tblcoll.h
+++ b/icu4c/source/i18n/unicode/tblcoll.h
@@ -308,8 +308,8 @@ public:
* than target
* @stable ICU 2.6
*/
- virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
- const UChar* target, int32_t targetLength,
+ virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength,
UErrorCode &status) const;
/**
@@ -377,7 +377,7 @@ public:
* @see CollationKey
* @stable ICU 2.0
*/
- virtual CollationKey& getCollationKey(const UChar *source,
+ virtual CollationKey& getCollationKey(const char16_t *source,
int32_t sourceLength,
CollationKey& key,
UErrorCode& status) const;
@@ -552,7 +552,7 @@ public:
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See setMaxVariable().
- * @param varTop one or more (if contraction) UChars to which the variable top should be set
+ * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
* @param len length of variable top string. If -1 it is considered to be zero terminated.
* @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
* U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
@@ -561,7 +561,7 @@ public:
* @return variable top primary weight
* @deprecated ICU 53 Call setMaxVariable() instead.
*/
- virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
+ virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status);
/**
* Sets the variable top to the primary weight of the specified string.
@@ -570,7 +570,7 @@ public:
* the top of one of the supported reordering groups,
* and it must not be beyond the last of those groups.
* See setMaxVariable().
- * @param varTop a UnicodeString size 1 or more (if contraction) of UChars to which the variable top should be set
+ * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
* @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
* U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
* U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
@@ -631,7 +631,7 @@ public:
int32_t resultLength) const;
/**
- * Get the sort key as an array of bytes from a UChar buffer.
+ * Get the sort key as an array of bytes from a char16_t buffer.
*
* Note that sort keys are often less efficient than simply doing comparison.
* For more details, see the ICU User Guide.
@@ -646,7 +646,7 @@ public:
* @return Number of bytes needed for storing the sort key
* @stable ICU 2.2
*/
- virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
+ virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength,
uint8_t *result, int32_t resultLength) const;
/**
@@ -821,17 +821,17 @@ private:
void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
// Both lengths must be <0 or else both must be >=0.
- UCollationResult doCompare(const UChar *left, int32_t leftLength,
- const UChar *right, int32_t rightLength,
+ UCollationResult doCompare(const char16_t *left, int32_t leftLength,
+ const char16_t *right, int32_t rightLength,
UErrorCode &errorCode) const;
UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
const uint8_t *right, int32_t rightLength,
UErrorCode &errorCode) const;
- void writeSortKey(const UChar *s, int32_t length,
+ void writeSortKey(const char16_t *s, int32_t length,
SortKeyByteSink &sink, UErrorCode &errorCode) const;
- void writeIdenticalLevel(const UChar *s, const UChar *limit,
+ void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
SortKeyByteSink &sink, UErrorCode &errorCode) const;
const CollationSettings &getDefaultSettings() const;
diff --git a/icu4c/source/i18n/unicode/timezone.h b/icu4c/source/i18n/unicode/timezone.h
index 3d570d23bde..83dee317784 100644
--- a/icu4c/source/i18n/unicode/timezone.h
+++ b/icu4c/source/i18n/unicode/timezone.h
@@ -863,7 +863,7 @@ private:
* @param id zone id string
* @return the pointer of the ID resource, or NULL.
*/
- static const UChar* findID(const UnicodeString& id);
+ static const char16_t* findID(const UnicodeString& id);
/**
* Resolve a link in Olson tzdata. When the given id is known and it's not a link,
@@ -873,7 +873,7 @@ private:
* @param id zone id string
* @return the dereferenced zone or NULL
*/
- static const UChar* dereferOlsonLink(const UnicodeString& id);
+ static const char16_t* dereferOlsonLink(const UnicodeString& id);
/**
* Returns the region code associated with the given zone,
@@ -881,7 +881,7 @@ private:
* @param id zone id string
* @return the region associated with the given zone
*/
- static const UChar* getRegion(const UnicodeString& id);
+ static const char16_t* getRegion(const UnicodeString& id);
public:
#ifndef U_HIDE_INTERNAL_API
@@ -893,7 +893,7 @@ private:
* @return the region associated with the given zone
* @internal
*/
- static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
+ static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
#endif /* U_HIDE_INTERNAL_API */
private:
diff --git a/icu4c/source/i18n/unicode/translit.h b/icu4c/source/i18n/unicode/translit.h
index f4ea9ae8014..bccba548024 100644
--- a/icu4c/source/i18n/unicode/translit.h
+++ b/icu4c/source/i18n/unicode/translit.h
@@ -1319,7 +1319,7 @@ inline int32_t Transliterator::getMaximumContextLength(void) const {
inline void Transliterator::setID(const UnicodeString& id) {
ID = id;
// NUL-terminate the ID string, which is a non-aliased copy.
- ID.append((UChar)0);
+ ID.append((char16_t)0);
ID.truncate(ID.length()-1);
}
diff --git a/icu4c/source/i18n/unicode/tzfmt.h b/icu4c/source/i18n/unicode/tzfmt.h
index 6d2de5bcf06..724ff4d85bb 100644
--- a/icu4c/source/i18n/unicode/tzfmt.h
+++ b/icu4c/source/i18n/unicode/tzfmt.h
@@ -942,7 +942,7 @@ private:
* @param parsedLen the parsed length, or 0 on failure.
* @return the parsed offset in milliseconds.
*/
- int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
+ int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, char16_t separator,
int32_t& parsedLen) const;
/**
@@ -982,7 +982,7 @@ private:
* @param maxFields The maximum fields
* @return The offset string
*/
- static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
+ static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, char16_t sep,
OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
/**
@@ -1012,7 +1012,7 @@ private:
* @param maxFields The maximum Fields to be parsed
* @return Parsed offset, 0 or positive number.
*/
- static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
+ static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, char16_t sep,
OffsetFields minFields, OffsetFields maxFields);
/**
diff --git a/icu4c/source/i18n/zonemeta.cpp b/icu4c/source/i18n/zonemeta.cpp
index b80ac3ea379..84a96578029 100644
--- a/icu4c/source/i18n/zonemeta.cpp
+++ b/icu4c/source/i18n/zonemeta.cpp
@@ -28,6 +28,7 @@
#include "uresimp.h"
#include "uhash.h"
#include "olsontz.h"
+#include "uinvchar.h"
static UMutex gZoneMetaLock = U_MUTEX_INITIALIZER;
@@ -255,6 +256,12 @@ ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
tzid.extract(utzid, ZID_KEY_MAX + 1, tmpStatus);
U_ASSERT(tmpStatus == U_ZERO_ERROR); // we checked the length of tzid already
+ if (!uprv_isInvariantUString(utzid, -1)) {
+ // All of known tz IDs are only containing ASCII invariant characters.
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
// Check if it was already cached
umtx_lock(&gZoneMetaLock);
{
diff --git a/icu4c/source/i18n/zonemeta.h b/icu4c/source/i18n/zonemeta.h
index e0f22b779ed..9dbcc878a22 100644
--- a/icu4c/source/i18n/zonemeta.h
+++ b/icu4c/source/i18n/zonemeta.h
@@ -41,7 +41,11 @@ public:
/**
* Return the canonical id for this tzid defined by CLDR, which might be the id itself.
* This overload method returns a persistent const UChar*, which is guranteed to persist
- * (a pointer to a resource).
+ * (a pointer to a resource). If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR
+ * is set in the status.
+ * @param tzid Zone ID
+ * @param status Receives the status
+ * @return The canonical ID for the input time zone ID
*/
static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status);
diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in
index 416d0a91bf9..c4ba088f4f6 100644
--- a/icu4c/source/test/intltest/Makefile.in
+++ b/icu4c/source/test/intltest/Makefile.in
@@ -35,7 +35,7 @@ BUILDDIR := $(BUILDDIR:test\\intltest/../../=)
BUILDDIR := $(BUILDDIR:TEST\\INTLTEST/../../=)
CPPFLAGS += -I$(srcdir) -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/toolutil -I$(top_srcdir)/tools/ctestfw
-CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT=
+CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT= -DUCHAR_TYPE=char16_t
DEFS += -D'U_TOPSRCDIR="$(top_srcdir)/"' -D'U_TOPBUILDDIR="$(BUILDDIR)"'
LIBS = $(LIBCTESTFW) $(LIBICUI18N) $(LIBICUUC) $(LIBICUTOOLUTIL) $(DEFAULT_LIBS) $(LIB_M) $(LIB_THREAD)
diff --git a/icu4c/source/test/intltest/intltest.vcxproj b/icu4c/source/test/intltest/intltest.vcxproj
index 3779ffa2e22..315adfd51f4 100644
--- a/icu4c/source/test/intltest/intltest.vcxproj
+++ b/icu4c/source/test/intltest/intltest.vcxproj
@@ -368,7 +368,7 @@
- * When creating a new Calendar subclass, you must create the
- * {@link ResourceBundle ResourceBundle}
- * containing its {@link DateFormatSymbols DateFormatSymbols} in a specific place.
- * The resource bundle name is based on the calendar's fully-specified
- * class name, with ".resources" inserted at the end of the package name
- * (just before the class name) and "Symbols" appended to the end.
- * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
- * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
- *
- *
- * DAY_OF_WEEK
field. Even though
- * DAY_OF_WEEK
starts with SUNDAY
= 1,
- * This array is 0-based; the name for Sunday goes in the
- * first position, at index 0. If this key is not found
- * in the bundle, the day names are inherited from the
- * default DateFormatSymbols
for the requested locale.
*
- * DateFormatSymbols
for the locale.
- *
- * MONTH
field. If this key is not found
- * in the bundle, the month names are inherited from the
- * default DateFormatSymbols
for the requested locale.
- *
- * DateFormatSymbols
for the locale.
- *
- * ERA
field. If this key is not found
- * in the bundle, the era names are inherited from the
- * default DateFormatSymbols
for the requested locale.
- *
- * When creating a new Calendar subclass, you must create the
- * {@link ResourceBundle ResourceBundle}
- * containing its {@link DateFormatSymbols DateFormatSymbols} in a specific place.
- * The resource bundle name is based on the calendar's fully-specified
- * class name, with ".resources" inserted at the end of the package name
- * (just before the class name) and "Symbols" appended to the end.
- * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
- * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
- *
- *
- * DAY_OF_WEEK
field. Even though
- * DAY_OF_WEEK
starts with SUNDAY
= 1,
- * This array is 0-based; the name for Sunday goes in the
- * first position, at index 0. If this key is not found
- * in the bundle, the day names are inherited from the
- * default DateFormatSymbols
for the requested locale.
- *
- * DateFormatSymbols
for the locale.
- *
- * MONTH
field. If this key is not found
- * in the bundle, the month names are inherited from the
- * default DateFormatSymbols
for the requested locale.
- *
- * DateFormatSymbols
for the locale.
- *
- * ERA
field. If this key is not found
- * in the bundle, the era names are inherited from the
- * default DateFormatSymbols
for the requested locale.
- *