Update ICU to 76.1

This commit is contained in:
bruvzg 2024-10-24 22:09:23 +03:00
parent 1015a481ff
commit e698870caa
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
194 changed files with 13126 additions and 11221 deletions

View File

@ -477,7 +477,7 @@ if env["builtin_icu4c"]:
] ]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
icu_data_name = "icudt75l.dat" icu_data_name = "icudt76l.dat"
if env.editor_build: if env.editor_build:
env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/" + icu_data_name) env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/" + icu_data_name)

View File

@ -717,7 +717,7 @@ thirdparty_icu_sources = [
] ]
thirdparty_icu_sources = [thirdparty_icu_dir + file for file in thirdparty_icu_sources] thirdparty_icu_sources = [thirdparty_icu_dir + file for file in thirdparty_icu_sources]
icu_data_name = "icudt75l.dat" icu_data_name = "icudt76l.dat"
if env["static_icu_data"]: if env["static_icu_data"]:
env_icu.Depends("../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/" + icu_data_name) env_icu.Depends("../../../thirdparty/icu4c/icudata.gen.h", "../../../thirdparty/icu4c/" + icu_data_name)

View File

@ -96,6 +96,11 @@ using namespace godot;
// Thirdparty headers. // Thirdparty headers.
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#include <unicode/ubidi.h> #include <unicode/ubidi.h>
#include <unicode/ubrk.h> #include <unicode/ubrk.h>
#include <unicode/uchar.h> #include <unicode/uchar.h>
@ -109,6 +114,10 @@ using namespace godot;
#include <unicode/ustring.h> #include <unicode/ustring.h>
#include <unicode/utypes.h> #include <unicode/utypes.h>
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#ifdef MODULE_FREETYPE_ENABLED #ifdef MODULE_FREETYPE_ENABLED
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H

View File

@ -403,7 +403,7 @@ Files extracted from upstream source:
## icu4c ## icu4c
- Upstream: https://github.com/unicode-org/icu - Upstream: https://github.com/unicode-org/icu
- Version: 75.1 (7750081bda4b3bc1768ae03849ec70f67ea10625, 2024) - Version: 76.1 (8eca245c7484ac6cc179e3e5f7c1ea7680810f39, 2024)
- License: Unicode - License: Unicode
Files extracted from upstream source: Files extracted from upstream source:
@ -415,7 +415,7 @@ Files extracted from upstream source:
Files generated from upstream source: Files generated from upstream source:
- The `icudt75l.dat` built with the provided `godot_data.json` config file (see - The `icudt76l.dat` built with the provided `godot_data.json` config file (see
https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/buildtool.md https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/buildtool.md
for instructions). for instructions).
@ -425,7 +425,7 @@ Files generated from upstream source:
3. Reconfigure ICU with custom data config: 3. Reconfigure ICU with custom data config:
`ICU_DATA_FILTER_FILE={GODOT_SOURCE}/thirdparty/icu4c/godot_data.json ./runConfigureICU {PLATFORM} --with-data-packaging=common` `ICU_DATA_FILTER_FILE={GODOT_SOURCE}/thirdparty/icu4c/godot_data.json ./runConfigureICU {PLATFORM} --with-data-packaging=common`
4. Delete `data/out` folder and rebuild data: `cd data && rm -rf ./out && make` 4. Delete `data/out` folder and rebuild data: `cd data && rm -rf ./out && make`
5. Copy `source/data/out/icudt75l.dat` to the `{GODOT_SOURCE}/thirdparty/icu4c/icudt75l.dat` 5. Copy `source/data/out/icudt76l.dat` to the `{GODOT_SOURCE}/thirdparty/icu4c/icudt76l.dat`
## jpeg-compressor ## jpeg-compressor

View File

@ -433,6 +433,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------- ----------------------------------------------------------------------
JSON parsing library (nlohmann/json)
File: vendor/json/upstream/single_include/nlohmann/json.hpp (only for ICU4C)
MIT License
Copyright (c) 2013-2022 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
----------------------------------------------------------------------
File: aclocal.m4 (only for ICU4C) File: aclocal.m4 (only for ICU4C)
Section: pkg.m4 - Macros to locate and utilise pkg-config. Section: pkg.m4 - Macros to locate and utilise pkg-config.
@ -473,7 +501,7 @@ File: config.guess (only for ICU4C)
This file is free software; you can redistribute it and/or modify it This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, but This program is distributed in the hope that it will be useful, but

View File

@ -25,7 +25,7 @@ Appendable::~Appendable() {}
UBool UBool
Appendable::appendCodePoint(UChar32 c) { Appendable::appendCodePoint(UChar32 c) {
if(c<=0xffff) { if(c<=0xffff) {
return appendCodeUnit((char16_t)c); return appendCodeUnit(static_cast<char16_t>(c));
} else { } else {
return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c)); return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
} }

View File

@ -75,7 +75,7 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
int32_t trail=start&0x3f; // Named for UTF-8 2-byte trail byte with lower 6 bits. int32_t trail=start&0x3f; // Named for UTF-8 2-byte trail byte with lower 6 bits.
// Set one bit indicating an all-one block. // Set one bit indicating an all-one block.
uint32_t bits=(uint32_t)1<<lead; uint32_t bits = static_cast<uint32_t>(1) << lead;
if((start+1)==limit) { // Single-character shortcut. if((start+1)==limit) { // Single-character shortcut.
table[trail]|=bits; table[trail]|=bits;
return; return;
@ -100,9 +100,9 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
++lead; ++lead;
} }
if(lead<limitLead) { if(lead<limitLead) {
bits=~(((unsigned)1<<lead)-1); bits = ~((static_cast<unsigned>(1) << lead) - 1);
if(limitLead<0x20) { if(limitLead<0x20) {
bits&=((unsigned)1<<limitLead)-1; bits &= (static_cast<unsigned>(1) << limitLead) - 1;
} }
for(trail=0; trail<64; ++trail) { for(trail=0; trail<64; ++trail) {
table[trail]|=bits; table[trail]|=bits;
@ -111,7 +111,7 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
// limit<=0x800. If limit==0x800 then limitLead=32 and limitTrail=0. // limit<=0x800. If limit==0x800 then limitLead=32 and limitTrail=0.
// In that case, bits=1<<limitLead is undefined but the bits value // In that case, bits=1<<limitLead is undefined but the bits value
// is not used because trail<limitTrail is already false. // is not used because trail<limitTrail is already false.
bits=(uint32_t)1<<((limitLead == 0x20) ? (limitLead - 1) : limitLead); bits = static_cast<uint32_t>(1) << ((limitLead == 0x20) ? (limitLead - 1) : limitLead);
for(trail=0; trail<limitTrail; ++trail) { for(trail=0; trail<limitTrail; ++trail) {
table[trail]|=bits; table[trail]|=bits;
} }
@ -290,22 +290,22 @@ int32_t BMPSet::findCodePoint(UChar32 c, int32_t lo, int32_t hi) const {
UBool UBool
BMPSet::contains(UChar32 c) const { BMPSet::contains(UChar32 c) const {
if((uint32_t)c<=0xff) { if (static_cast<uint32_t>(c) <= 0xff) {
return (UBool)latin1Contains[c]; return latin1Contains[c];
} else if((uint32_t)c<=0x7ff) { } else if (static_cast<uint32_t>(c) <= 0x7ff) {
return (UBool)((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0); return (table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0;
} else if((uint32_t)c<0xd800 || (c>=0xe000 && c<=0xffff)) { } else if (static_cast<uint32_t>(c) < 0xd800 || (c >= 0xe000 && c <= 0xffff)) {
int lead=c>>12; int lead=c>>12;
uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001; uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
if(twoBits<=1) { if(twoBits<=1) {
// All 64 code points with the same bits 15..6 // All 64 code points with the same bits 15..6
// are either in the set or not. // are either in the set or not.
return (UBool)twoBits; return twoBits;
} else { } else {
// Look up the code point in its 4k block of code points. // Look up the code point in its 4k block of code points.
return containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]); return containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]);
} }
} else if((uint32_t)c<=0x10ffff) { } else if (static_cast<uint32_t>(c) <= 0x10ffff) {
// surrogate or supplementary code point // surrogate or supplementary code point
return containsSlow(c, list4kStarts[0xd], list4kStarts[0x11]); return containsSlow(c, list4kStarts[0xd], list4kStarts[0x11]);
} else { } else {
@ -332,7 +332,7 @@ BMPSet::span(const char16_t *s, const char16_t *limit, USetSpanCondition spanCon
break; break;
} }
} else if(c<=0x7ff) { } else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))==0) { if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) == 0) {
break; break;
} }
} else if(c<0xd800 || c>=0xe000) { } else if(c<0xd800 || c>=0xe000) {
@ -372,7 +372,7 @@ BMPSet::span(const char16_t *s, const char16_t *limit, USetSpanCondition spanCon
break; break;
} }
} else if(c<=0x7ff) { } else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) { if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) {
break; break;
} }
} else if(c<0xd800 || c>=0xe000) { } else if(c<0xd800 || c>=0xe000) {
@ -421,7 +421,7 @@ BMPSet::spanBack(const char16_t *s, const char16_t *limit, USetSpanCondition spa
break; break;
} }
} else if(c<=0x7ff) { } else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))==0) { if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) == 0) {
break; break;
} }
} else if(c<0xd800 || c>=0xe000) { } else if(c<0xd800 || c>=0xe000) {
@ -464,7 +464,7 @@ BMPSet::spanBack(const char16_t *s, const char16_t *limit, USetSpanCondition spa
break; break;
} }
} else if(c<=0x7ff) { } else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) { if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) {
break; break;
} }
} else if(c<0xd800 || c>=0xe000) { } else if(c<0xd800 || c>=0xe000) {
@ -527,7 +527,7 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
b=*s; b=*s;
} while(U8_IS_SINGLE(b)); } while(U8_IS_SINGLE(b));
} }
length=(int32_t)(limit-s); length = static_cast<int32_t>(limit - s);
} }
if(spanCondition!=USET_SPAN_NOT_CONTAINED) { if(spanCondition!=USET_SPAN_NOT_CONTAINED) {
@ -547,7 +547,7 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
* the truncated sequence. * the truncated sequence.
*/ */
b=*(limit-1); b=*(limit-1);
if((int8_t)b<0) { if (static_cast<int8_t>(b) < 0) {
// b>=0x80: lead or trail byte // b>=0x80: lead or trail byte
if(b<0xc0) { if(b<0xc0) {
// single trail byte, check for preceding 3- or 4-byte lead byte // single trail byte, check for preceding 3- or 4-byte lead byte
@ -602,15 +602,15 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
if(b>=0xe0) { if(b>=0xe0) {
if(b<0xf0) { if(b<0xf0) {
if( /* handle U+0000..U+FFFF inline */ if( /* handle U+0000..U+FFFF inline */
(t1=(uint8_t)(s[0]-0x80)) <= 0x3f && (t1 = static_cast<uint8_t>(s[0] - 0x80)) <= 0x3f &&
(t2=(uint8_t)(s[1]-0x80)) <= 0x3f (t2 = static_cast<uint8_t>(s[1] - 0x80)) <= 0x3f
) { ) {
b&=0xf; b&=0xf;
uint32_t twoBits=(bmpBlockBits[t1]>>b)&0x10001; uint32_t twoBits=(bmpBlockBits[t1]>>b)&0x10001;
if(twoBits<=1) { if(twoBits<=1) {
// All 64 code points with this lead byte and middle trail byte // All 64 code points with this lead byte and middle trail byte
// are either in the set or not. // are either in the set or not.
if(twoBits!=(uint32_t)spanCondition) { if (twoBits != static_cast<uint32_t>(spanCondition)) {
return s-1; return s-1;
} }
} else { } else {
@ -624,12 +624,12 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
continue; continue;
} }
} else if( /* handle U+10000..U+10FFFF inline */ } else if( /* handle U+10000..U+10FFFF inline */
(t1=(uint8_t)(s[0]-0x80)) <= 0x3f && (t1 = static_cast<uint8_t>(s[0] - 0x80)) <= 0x3f &&
(t2=(uint8_t)(s[1]-0x80)) <= 0x3f && (t2 = static_cast<uint8_t>(s[1] - 0x80)) <= 0x3f &&
(t3=(uint8_t)(s[2]-0x80)) <= 0x3f (t3 = static_cast<uint8_t>(s[2] - 0x80)) <= 0x3f
) { ) {
// Give an illegal sequence the same value as the result of contains(FFFD). // Give an illegal sequence the same value as the result of contains(FFFD).
UChar32 c=((UChar32)(b-0xf0)<<18)|((UChar32)t1<<12)|(t2<<6)|t3; UChar32 c = (static_cast<UChar32>(b - 0xf0) << 18) | (static_cast<UChar32>(t1) << 12) | (t2 << 6) | t3;
if( ( (0x10000<=c && c<=0x10ffff) ? if( ( (0x10000<=c && c<=0x10ffff) ?
containsSlow(c, list4kStarts[0x10], list4kStarts[0x11]) : containsSlow(c, list4kStarts[0x10], list4kStarts[0x11]) :
containsFFFD containsFFFD
@ -643,9 +643,9 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
} else { } else {
if( /* handle U+0000..U+07FF inline */ if( /* handle U+0000..U+07FF inline */
b>=0xc0 && b>=0xc0 &&
(t1=(uint8_t)(*s-0x80)) <= 0x3f (t1 = static_cast<uint8_t>(*s - 0x80)) <= 0x3f
) { ) {
if((USetSpanCondition)((table7FF[t1]&((uint32_t)1<<(b&0x1f)))!=0) != spanCondition) { if (static_cast<USetSpanCondition>((table7FF[t1] & (static_cast<uint32_t>(1) << (b & 0x1f))) != 0) != spanCondition) {
return s-1; return s-1;
} }
++s; ++s;
@ -711,7 +711,7 @@ BMPSet::spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCon
c=utf8_prevCharSafeBody(s, 0, &length, b, -3); c=utf8_prevCharSafeBody(s, 0, &length, b, -3);
// c is a valid code point, not ASCII, not a surrogate // c is a valid code point, not ASCII, not a surrogate
if(c<=0x7ff) { if(c<=0x7ff) {
if((USetSpanCondition)((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) != spanCondition) { if (static_cast<USetSpanCondition>((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) != spanCondition) {
return prev+1; return prev+1;
} }
} else if(c<=0xffff) { } else if(c<=0xffff) {
@ -720,7 +720,7 @@ BMPSet::spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCon
if(twoBits<=1) { if(twoBits<=1) {
// All 64 code points with the same bits 15..6 // All 64 code points with the same bits 15..6
// are either in the set or not. // are either in the set or not.
if(twoBits!=(uint32_t)spanCondition) { if (twoBits != static_cast<uint32_t>(spanCondition)) {
return prev+1; return prev+1;
} }
} else { } else {

View File

@ -156,7 +156,7 @@ private:
}; };
inline UBool BMPSet::containsSlow(UChar32 c, int32_t lo, int32_t hi) const { inline UBool BMPSet::containsSlow(UChar32 c, int32_t lo, int32_t hi) const {
return (UBool)(findCodePoint(c, lo, hi) & 1); return findCodePoint(c, lo, hi) & 1;
} }
U_NAMESPACE_END U_NAMESPACE_END

View File

@ -86,7 +86,7 @@ UnhandledEngine::findBreaks( UText *text,
if (U_FAILURE(status)) return 0; if (U_FAILURE(status)) return 0;
utext_setNativeIndex(text, startPos); utext_setNativeIndex(text, startPos);
UChar32 c = utext_current32(text); UChar32 c = utext_current32(text);
while((int32_t)utext_getNativeIndex(text) < endPos && fHandled->contains(c)) { while (static_cast<int32_t>(utext_getNativeIndex(text)) < endPos && fHandled->contains(c)) {
utext_next32(text); // TODO: recast loop to work with post-increment operations. utext_next32(text); // TODO: recast loop to work with post-increment operations.
c = utext_current32(text); c = utext_current32(text);
} }
@ -146,7 +146,7 @@ ICULanguageBreakFactory::getEngineFor(UChar32 c, const char* locale) {
Mutex m(&gBreakEngineMutex); Mutex m(&gBreakEngineMutex);
int32_t i = fEngines->size(); int32_t i = fEngines->size();
while (--i >= 0) { while (--i >= 0) {
lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i)); lbe = static_cast<const LanguageBreakEngine*>(fEngines->elementAt(i));
if (lbe != nullptr && lbe->handles(c, locale)) { if (lbe != nullptr && lbe->handles(c, locale)) {
return lbe; return lbe;
} }
@ -259,7 +259,7 @@ ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script) {
CharString ext; CharString ext;
const char16_t *extStart = u_memrchr(dictfname, 0x002e, dictnlength); // last dot const char16_t *extStart = u_memrchr(dictfname, 0x002e, dictnlength); // last dot
if (extStart != nullptr) { if (extStart != nullptr) {
int32_t len = (int32_t)(extStart - dictfname); int32_t len = static_cast<int32_t>(extStart - dictfname);
ext.appendInvariantChars(UnicodeString(false, extStart + 1, dictnlength - len - 1), status); ext.appendInvariantChars(UnicodeString(false, extStart + 1, dictnlength - len - 1), status);
dictnlength = len; dictnlength = len;
} }
@ -269,18 +269,18 @@ ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script) {
UDataMemory *file = udata_open(U_ICUDATA_BRKITR, ext.data(), dictnbuf.data(), &status); UDataMemory *file = udata_open(U_ICUDATA_BRKITR, ext.data(), dictnbuf.data(), &status);
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
// build trie // build trie
const uint8_t *data = (const uint8_t *)udata_getMemory(file); const uint8_t* data = static_cast<const uint8_t*>(udata_getMemory(file));
const int32_t *indexes = (const int32_t *)data; const int32_t* indexes = reinterpret_cast<const int32_t*>(data);
const int32_t offset = indexes[DictionaryData::IX_STRING_TRIE_OFFSET]; const int32_t offset = indexes[DictionaryData::IX_STRING_TRIE_OFFSET];
const int32_t trieType = indexes[DictionaryData::IX_TRIE_TYPE] & DictionaryData::TRIE_TYPE_MASK; const int32_t trieType = indexes[DictionaryData::IX_TRIE_TYPE] & DictionaryData::TRIE_TYPE_MASK;
DictionaryMatcher *m = nullptr; DictionaryMatcher *m = nullptr;
if (trieType == DictionaryData::TRIE_TYPE_BYTES) { if (trieType == DictionaryData::TRIE_TYPE_BYTES) {
const int32_t transform = indexes[DictionaryData::IX_TRANSFORM]; const int32_t transform = indexes[DictionaryData::IX_TRANSFORM];
const char *characters = (const char *)(data + offset); const char* characters = reinterpret_cast<const char*>(data + offset);
m = new BytesDictionaryMatcher(characters, transform, file); m = new BytesDictionaryMatcher(characters, transform, file);
} }
else if (trieType == DictionaryData::TRIE_TYPE_UCHARS) { else if (trieType == DictionaryData::TRIE_TYPE_UCHARS) {
const char16_t *characters = (const char16_t *)(data + offset); const char16_t* characters = reinterpret_cast<const char16_t*>(data + offset);
m = new UCharsDictionaryMatcher(characters, file); m = new UCharsDictionaryMatcher(characters, file);
} }
if (m == nullptr) { if (m == nullptr) {
@ -337,12 +337,12 @@ int32_t BreakEngineWrapper::findBreaks(
// extends towards the start or end of the text, depending on 'reverse'. // extends towards the start or end of the text, depending on 'reverse'.
utext_setNativeIndex(text, startPos); utext_setNativeIndex(text, startPos);
int32_t start = (int32_t)utext_getNativeIndex(text); int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t current; int32_t current;
int32_t rangeStart; int32_t rangeStart;
int32_t rangeEnd; int32_t rangeEnd;
UChar32 c = utext_current32(text); UChar32 c = utext_current32(text);
while((current = (int32_t)utext_getNativeIndex(text)) < endPos && delegate->handles(c)) { while ((current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos && delegate->handles(c)) {
utext_next32(text); // TODO: recast loop for postincrement utext_next32(text); // TODO: recast loop for postincrement
c = utext_current32(text); c = utext_current32(text);
} }

View File

@ -85,7 +85,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
// Get the actual string // Get the actual string
brkfname = ures_getString(brkName, &size, &status); brkfname = ures_getString(brkName, &size, &status);
U_ASSERT((size_t)size<sizeof(fnbuff)); U_ASSERT((size_t)size<sizeof(fnbuff));
if ((size_t)size>=sizeof(fnbuff)) { if (static_cast<size_t>(size) >= sizeof(fnbuff)) {
size=0; size=0;
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
status = U_BUFFER_OVERFLOW_ERROR; status = U_BUFFER_OVERFLOW_ERROR;
@ -99,7 +99,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
char16_t* extStart=u_strchr(brkfname, 0x002e); char16_t* extStart=u_strchr(brkfname, 0x002e);
int len = 0; int len = 0;
if (extStart != nullptr){ if (extStart != nullptr){
len = (int)(extStart-brkfname); len = static_cast<int>(extStart - brkfname);
u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
u_UCharsToChars(brkfname, fnbuff, len); u_UCharsToChars(brkfname, fnbuff, len);
} }

View File

@ -64,7 +64,7 @@ ByteSinkUtil::appendChange(const uint8_t *s, const uint8_t *limit,
errorCode = U_INDEX_OUTOFBOUNDS_ERROR; errorCode = U_INDEX_OUTOFBOUNDS_ERROR;
return false; return false;
} }
return appendChange((int32_t)(limit - s), s16, s16Length, sink, edits, errorCode); return appendChange(static_cast<int32_t>(limit - s), s16, s16Length, sink, edits, errorCode);
} }
void void
@ -81,15 +81,15 @@ ByteSinkUtil::appendCodePoint(int32_t length, UChar32 c, ByteSink &sink, Edits *
namespace { namespace {
// See unicode/utf8.h U8_APPEND_UNSAFE(). // See unicode/utf8.h U8_APPEND_UNSAFE().
inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); } inline uint8_t getTwoByteLead(UChar32 c) { return static_cast<uint8_t>((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); } inline uint8_t getTwoByteTrail(UChar32 c) { return static_cast<uint8_t>((c & 0x3f) | 0x80); }
} // namespace } // namespace
void void
ByteSinkUtil::appendTwoBytes(UChar32 c, ByteSink &sink) { ByteSinkUtil::appendTwoBytes(UChar32 c, ByteSink &sink) {
U_ASSERT(0x80 <= c && c <= 0x7ff); // 2-byte UTF-8 U_ASSERT(0x80 <= c && c <= 0x7ff); // 2-byte UTF-8
char s8[2] = { (char)getTwoByteLead(c), (char)getTwoByteTrail(c) }; char s8[2] = {static_cast<char>(getTwoByteLead(c)), static_cast<char>(getTwoByteTrail(c))};
sink.Append(s8, 2); sink.Append(s8, 2);
} }
@ -114,7 +114,7 @@ ByteSinkUtil::appendUnchanged(const uint8_t *s, const uint8_t *limit,
errorCode = U_INDEX_OUTOFBOUNDS_ERROR; errorCode = U_INDEX_OUTOFBOUNDS_ERROR;
return false; return false;
} }
int32_t length = (int32_t)(limit - s); int32_t length = static_cast<int32_t>(limit - s);
if (length > 0) { if (length > 0) {
appendNonEmptyUnchanged(s, length, sink, options, edits); appendNonEmptyUnchanged(s, length, sink, options, edits);
} }

View File

@ -73,7 +73,7 @@ public:
/** The few bytes at [src, nextSrc[ were mapped/changed to valid code point c. */ /** The few bytes at [src, nextSrc[ were mapped/changed to valid code point c. */
static inline void appendCodePoint(const uint8_t *src, const uint8_t *nextSrc, UChar32 c, static inline void appendCodePoint(const uint8_t *src, const uint8_t *nextSrc, UChar32 c,
ByteSink &sink, Edits *edits = nullptr) { ByteSink &sink, Edits *edits = nullptr) {
appendCodePoint((int32_t)(nextSrc - src), c, sink, edits); appendCodePoint(static_cast<int32_t>(nextSrc - src), c, sink, edits);
} }
/** Append the two-byte character (U+0080..U+07FF). */ /** Append the two-byte character (U+0080..U+07FF). */

View File

@ -327,7 +327,7 @@ BytesTrie::findUniqueValueFromBranch(const uint8_t *pos, int32_t length,
++pos; // ignore a comparison byte ++pos; // ignore a comparison byte
// handle its value // handle its value
int32_t node=*pos++; int32_t node=*pos++;
UBool isFinal=(UBool)(node&kValueIsFinal); UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1); int32_t value=readValue(pos, node>>1);
pos=skipValue(pos, node); pos=skipValue(pos, node);
if(isFinal) { if(isFinal) {
@ -366,7 +366,7 @@ BytesTrie::findUniqueValue(const uint8_t *pos, UBool haveUniqueValue, int32_t &u
// linear-match node // linear-match node
pos+=node-kMinLinearMatch+1; // Ignore the match bytes. pos+=node-kMinLinearMatch+1; // Ignore the match bytes.
} else { } else {
UBool isFinal=(UBool)(node&kValueIsFinal); UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1); int32_t value=readValue(pos, node>>1);
if(haveUniqueValue) { if(haveUniqueValue) {
if(value!=uniqueValue) { if(value!=uniqueValue) {
@ -434,7 +434,7 @@ BytesTrie::getNextBranchBytes(const uint8_t *pos, int32_t length, ByteSink &out)
void void
BytesTrie::append(ByteSink &out, int c) { BytesTrie::append(ByteSink &out, int c) {
char ch=(char)c; char ch = static_cast<char>(c);
out.Append(&ch, 1); out.Append(&ch, 1);
} }

View File

@ -43,10 +43,10 @@ public:
int32_t offset=stringOffset; int32_t offset=stringOffset;
int32_t length; int32_t length;
if(offset>=0) { if(offset>=0) {
length=(uint8_t)strings[offset++]; length = static_cast<uint8_t>(strings[offset++]);
} else { } else {
offset=~offset; offset=~offset;
length=((int32_t)(uint8_t)strings[offset]<<8)|(uint8_t)strings[offset+1]; length = (static_cast<int32_t>(static_cast<uint8_t>(strings[offset])) << 8) | static_cast<uint8_t>(strings[offset + 1]);
offset+=2; offset+=2;
} }
return StringPiece(strings.data()+offset, length); return StringPiece(strings.data()+offset, length);
@ -54,10 +54,10 @@ public:
int32_t getStringLength(const CharString &strings) const { int32_t getStringLength(const CharString &strings) const {
int32_t offset=stringOffset; int32_t offset=stringOffset;
if(offset>=0) { if(offset>=0) {
return (uint8_t)strings[offset]; return static_cast<uint8_t>(strings[offset]);
} else { } else {
offset=~offset; offset=~offset;
return ((int32_t)(uint8_t)strings[offset]<<8)|(uint8_t)strings[offset+1]; return (static_cast<int32_t>(static_cast<uint8_t>(strings[offset])) << 8) | static_cast<uint8_t>(strings[offset + 1]);
} }
} }
@ -102,9 +102,9 @@ BytesTrieElement::setTo(StringPiece s, int32_t val,
int32_t offset=strings.length(); int32_t offset=strings.length();
if(length>0xff) { if(length>0xff) {
offset=~offset; offset=~offset;
strings.append((char)(length>>8), errorCode); strings.append(static_cast<char>(length >> 8), errorCode);
} }
strings.append((char)length, errorCode); strings.append(static_cast<char>(length), errorCode);
stringOffset=offset; stringOffset=offset;
value=val; value=val;
strings.append(s, errorCode); strings.append(s, errorCode);
@ -229,7 +229,7 @@ BytesTrieBuilder::buildBytes(UStringTrieBuildOption buildOption, UErrorCode &err
errorCode=U_INDEX_OUTOFBOUNDS_ERROR; errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
return; return;
} }
uprv_sortArray(elements, elementsLength, (int32_t)sizeof(BytesTrieElement), uprv_sortArray(elements, elementsLength, static_cast<int32_t>(sizeof(BytesTrieElement)),
compareElementStrings, strings, compareElementStrings, strings,
false, // need not be a stable sort false, // need not be a stable sort
&errorCode); &errorCode);
@ -284,7 +284,7 @@ BytesTrieBuilder::getElementStringLength(int32_t i) const {
char16_t char16_t
BytesTrieBuilder::getElementUnit(int32_t i, int32_t byteIndex) const { BytesTrieBuilder::getElementUnit(int32_t i, int32_t byteIndex) const {
return (uint8_t)elements[i].charAt(byteIndex, *strings); return static_cast<uint8_t>(elements[i].charAt(byteIndex, *strings));
} }
int32_t int32_t
@ -330,7 +330,7 @@ BytesTrieBuilder::skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t
int32_t int32_t
BytesTrieBuilder::indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const { BytesTrieBuilder::indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const {
char b=(char)byte; char b = static_cast<char>(byte);
while(b==elements[i].charAt(byteIndex, *strings)) { while(b==elements[i].charAt(byteIndex, *strings)) {
++i; ++i;
} }
@ -404,7 +404,7 @@ BytesTrieBuilder::write(int32_t byte) {
int32_t newLength=bytesLength+1; int32_t newLength=bytesLength+1;
if(ensureCapacity(newLength)) { if(ensureCapacity(newLength)) {
bytesLength=newLength; bytesLength=newLength;
bytes[bytesCapacity-bytesLength]=(char)byte; bytes[bytesCapacity - bytesLength] = static_cast<char>(byte);
} }
return bytesLength; return bytesLength;
} }
@ -432,30 +432,30 @@ BytesTrieBuilder::writeValueAndFinal(int32_t i, UBool isFinal) {
char intBytes[5]; char intBytes[5];
int32_t length=1; int32_t length=1;
if(i<0 || i>0xffffff) { if(i<0 || i>0xffffff) {
intBytes[0]=(char)BytesTrie::kFiveByteValueLead; intBytes[0] = static_cast<char>(BytesTrie::kFiveByteValueLead);
intBytes[1]=(char)((uint32_t)i>>24); intBytes[1] = static_cast<char>(static_cast<uint32_t>(i) >> 24);
intBytes[2]=(char)((uint32_t)i>>16); intBytes[2] = static_cast<char>(static_cast<uint32_t>(i) >> 16);
intBytes[3]=(char)((uint32_t)i>>8); intBytes[3] = static_cast<char>(static_cast<uint32_t>(i) >> 8);
intBytes[4]=(char)i; intBytes[4] = static_cast<char>(i);
length=5; length=5;
// } else if(i<=BytesTrie::kMaxOneByteValue) { // } else if(i<=BytesTrie::kMaxOneByteValue) {
// intBytes[0]=(char)(BytesTrie::kMinOneByteValueLead+i); // intBytes[0]=(char)(BytesTrie::kMinOneByteValueLead+i);
} else { } else {
if(i<=BytesTrie::kMaxTwoByteValue) { if(i<=BytesTrie::kMaxTwoByteValue) {
intBytes[0]=(char)(BytesTrie::kMinTwoByteValueLead+(i>>8)); intBytes[0] = static_cast<char>(BytesTrie::kMinTwoByteValueLead + (i >> 8));
} else { } else {
if(i<=BytesTrie::kMaxThreeByteValue) { if(i<=BytesTrie::kMaxThreeByteValue) {
intBytes[0]=(char)(BytesTrie::kMinThreeByteValueLead+(i>>16)); intBytes[0] = static_cast<char>(BytesTrie::kMinThreeByteValueLead + (i >> 16));
} else { } else {
intBytes[0]=(char)BytesTrie::kFourByteValueLead; intBytes[0] = static_cast<char>(BytesTrie::kFourByteValueLead);
intBytes[1]=(char)(i>>16); intBytes[1] = static_cast<char>(i >> 16);
length=2; length=2;
} }
intBytes[length++]=(char)(i>>8); intBytes[length++] = static_cast<char>(i >> 8);
} }
intBytes[length++]=(char)i; intBytes[length++] = static_cast<char>(i);
} }
intBytes[0]=(char)((intBytes[0]<<1)|isFinal); intBytes[0] = static_cast<char>((intBytes[0] << 1) | isFinal);
return write(intBytes, length); return write(intBytes, length);
} }
@ -484,28 +484,28 @@ int32_t
BytesTrieBuilder::internalEncodeDelta(int32_t i, char intBytes[]) { BytesTrieBuilder::internalEncodeDelta(int32_t i, char intBytes[]) {
U_ASSERT(i>=0); U_ASSERT(i>=0);
if(i<=BytesTrie::kMaxOneByteDelta) { if(i<=BytesTrie::kMaxOneByteDelta) {
intBytes[0]=(char)i; intBytes[0] = static_cast<char>(i);
return 1; return 1;
} }
int32_t length=1; int32_t length=1;
if(i<=BytesTrie::kMaxTwoByteDelta) { if(i<=BytesTrie::kMaxTwoByteDelta) {
intBytes[0]=(char)(BytesTrie::kMinTwoByteDeltaLead+(i>>8)); intBytes[0] = static_cast<char>(BytesTrie::kMinTwoByteDeltaLead + (i >> 8));
} else { } else {
if(i<=BytesTrie::kMaxThreeByteDelta) { if(i<=BytesTrie::kMaxThreeByteDelta) {
intBytes[0]=(char)(BytesTrie::kMinThreeByteDeltaLead+(i>>16)); intBytes[0] = static_cast<char>(BytesTrie::kMinThreeByteDeltaLead + (i >> 16));
} else { } else {
if(i<=0xffffff) { if(i<=0xffffff) {
intBytes[0]=(char)BytesTrie::kFourByteDeltaLead; intBytes[0] = static_cast<char>(BytesTrie::kFourByteDeltaLead);
} else { } else {
intBytes[0]=(char)BytesTrie::kFiveByteDeltaLead; intBytes[0] = static_cast<char>(BytesTrie::kFiveByteDeltaLead);
intBytes[1]=(char)(i>>24); intBytes[1] = static_cast<char>(i >> 24);
length=2; length=2;
} }
intBytes[length++]=(char)(i>>16); intBytes[length++] = static_cast<char>(i >> 16);
} }
intBytes[length++]=(char)(i>>8); intBytes[length++] = static_cast<char>(i >> 8);
} }
intBytes[length++]=(char)i; intBytes[length++] = static_cast<char>(i);
return length; return length;
} }

View File

@ -115,14 +115,14 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
pos=bytes_+stack_->elementAti(stackSize-2); pos=bytes_+stack_->elementAti(stackSize-2);
stack_->setSize(stackSize-2); stack_->setSize(stackSize-2);
str_->truncate(length&0xffff); str_->truncate(length&0xffff);
length=(int32_t)((uint32_t)length>>16); length = static_cast<int32_t>(static_cast<uint32_t>(length) >> 16);
if(length>1) { if(length>1) {
pos=branchNext(pos, length, errorCode); pos=branchNext(pos, length, errorCode);
if(pos==nullptr) { if(pos==nullptr) {
return true; // Reached a final value. return true; // Reached a final value.
} }
} else { } else {
str_->append((char)*pos++, errorCode); str_->append(static_cast<char>(*pos++), errorCode);
} }
} }
if(remainingMatchLength_>=0) { if(remainingMatchLength_>=0) {
@ -134,7 +134,7 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
int32_t node=*pos++; int32_t node=*pos++;
if(node>=kMinValueLead) { if(node>=kMinValueLead) {
// Deliver value for the byte sequence so far. // Deliver value for the byte sequence so far.
UBool isFinal=(UBool)(node&kValueIsFinal); UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
value_=readValue(pos, node>>1); value_=readValue(pos, node>>1);
if(isFinal || (maxLength_>0 && str_->length()==maxLength_)) { if(isFinal || (maxLength_>0 && str_->length()==maxLength_)) {
pos_=nullptr; pos_=nullptr;
@ -186,7 +186,7 @@ BytesTrie::Iterator::branchNext(const uint8_t *pos, int32_t length, UErrorCode &
while(length>kMaxBranchLinearSubNodeLength) { while(length>kMaxBranchLinearSubNodeLength) {
++pos; // ignore the comparison byte ++pos; // ignore the comparison byte
// Push state for the greater-or-equal edge. // Push state for the greater-or-equal edge.
stack_->addElement((int32_t)(skipDelta(pos)-bytes_), errorCode); stack_->addElement(static_cast<int32_t>(skipDelta(pos) - bytes_), errorCode);
stack_->addElement(((length-(length>>1))<<16)|str_->length(), errorCode); stack_->addElement(((length-(length>>1))<<16)|str_->length(), errorCode);
// Follow the less-than edge. // Follow the less-than edge.
length>>=1; length>>=1;
@ -196,12 +196,12 @@ BytesTrie::Iterator::branchNext(const uint8_t *pos, int32_t length, UErrorCode &
// Read the first (key, value) pair. // Read the first (key, value) pair.
uint8_t trieByte=*pos++; uint8_t trieByte=*pos++;
int32_t node=*pos++; int32_t node=*pos++;
UBool isFinal=(UBool)(node&kValueIsFinal); UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1); int32_t value=readValue(pos, node>>1);
pos=skipValue(pos, node); pos=skipValue(pos, node);
stack_->addElement((int32_t)(pos-bytes_), errorCode); stack_->addElement(static_cast<int32_t>(pos - bytes_), errorCode);
stack_->addElement(((length-1)<<16)|str_->length(), errorCode); stack_->addElement(((length-1)<<16)|str_->length(), errorCode);
str_->append((char)trieByte, errorCode); str_->append(static_cast<char>(trieByte), errorCode);
if(isFinal) { if(isFinal) {
pos_=nullptr; pos_=nullptr;
value_=value; value_=value;

View File

@ -183,10 +183,10 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
// catch degenerate case // catch degenerate case
if (newSource.length() == 0) { if (newSource.length() == 0) {
pieces = (UnicodeString **)uprv_malloc(sizeof(UnicodeString *)); pieces = static_cast<UnicodeString**>(uprv_malloc(sizeof(UnicodeString*)));
pieces_lengths = (int32_t*)uprv_malloc(1 * sizeof(int32_t)); pieces_lengths = static_cast<int32_t*>(uprv_malloc(1 * sizeof(int32_t)));
pieces_length = 1; pieces_length = 1;
current = (int32_t*)uprv_malloc(1 * sizeof(int32_t)); current = static_cast<int32_t*>(uprv_malloc(1 * sizeof(int32_t)));
current_length = 1; current_length = 1;
if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) { if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
@ -229,10 +229,10 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
// allocate the arrays, and find the strings that are CE to each segment // allocate the arrays, and find the strings that are CE to each segment
pieces = (UnicodeString **)uprv_malloc(list_length * sizeof(UnicodeString *)); pieces = static_cast<UnicodeString**>(uprv_malloc(list_length * sizeof(UnicodeString*)));
pieces_length = list_length; pieces_length = list_length;
pieces_lengths = (int32_t*)uprv_malloc(list_length * sizeof(int32_t)); pieces_lengths = static_cast<int32_t*>(uprv_malloc(list_length * sizeof(int32_t)));
current = (int32_t*)uprv_malloc(list_length * sizeof(int32_t)); current = static_cast<int32_t*>(uprv_malloc(list_length * sizeof(int32_t)));
current_length = list_length; current_length = list_length;
if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) { if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
@ -330,7 +330,7 @@ void U_EXPORT2 CanonicalIterator::permute(UnicodeString &source, UBool skipZeros
// prefix this character to all of them // prefix this character to all of them
ne = subpermute.nextElement(el); ne = subpermute.nextElement(el);
while (ne != nullptr) { while (ne != nullptr) {
UnicodeString *permRes = (UnicodeString *)(ne->value.pointer); UnicodeString* permRes = static_cast<UnicodeString*>(ne->value.pointer);
UnicodeString *chStr = new UnicodeString(cp); UnicodeString *chStr = new UnicodeString(cp);
//test for nullptr //test for nullptr
if (chStr == nullptr) { if (chStr == nullptr) {
@ -363,6 +363,9 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
char16_t USeg[256]; char16_t USeg[256];
int32_t segLen = segment.extract(USeg, 256, status); int32_t segLen = segment.extract(USeg, 256, status);
getEquivalents2(&basic, USeg, segLen, status); getEquivalents2(&basic, USeg, segLen, status);
if (U_FAILURE(status)) {
return nullptr;
}
// now get all the permutations // now get all the permutations
// add only the ones that are canonically equivalent // add only the ones that are canonically equivalent
@ -375,7 +378,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
//while (it.hasNext()) //while (it.hasNext())
while (ne != nullptr) { while (ne != nullptr) {
//String item = (String) it.next(); //String item = (String) it.next();
UnicodeString item = *((UnicodeString *)(ne->value.pointer)); UnicodeString item = *static_cast<UnicodeString*>(ne->value.pointer);
permutations.removeAll(); permutations.removeAll();
permute(item, CANITER_SKIP_ZEROES, &permutations, status); permute(item, CANITER_SKIP_ZEROES, &permutations, status);
@ -387,7 +390,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
while (ne2 != nullptr) { while (ne2 != nullptr) {
//String possible = (String) it2.next(); //String possible = (String) it2.next();
//UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne2->value.pointer))); //UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne2->value.pointer)));
UnicodeString possible(*((UnicodeString *)(ne2->value.pointer))); UnicodeString possible(*static_cast<UnicodeString*>(ne2->value.pointer));
UnicodeString attempt; UnicodeString attempt;
nfd->normalize(possible, attempt, status); nfd->normalize(possible, attempt, status);
@ -429,7 +432,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
el = UHASH_FIRST; el = UHASH_FIRST;
ne = result.nextElement(el); ne = result.nextElement(el);
while(ne != nullptr) { while(ne != nullptr) {
finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer)); finalResult[result_len++] = *static_cast<UnicodeString*>(ne->value.pointer);
ne = result.nextElement(el); ne = result.nextElement(el);
} }
@ -466,6 +469,9 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
Hashtable remainder(status); Hashtable remainder(status);
remainder.setValueDeleter(uprv_deleteUObject); remainder.setValueDeleter(uprv_deleteUObject);
if (extract(&remainder, cp2, segment, segLen, i, status) == nullptr) { if (extract(&remainder, cp2, segment, segLen, i, status) == nullptr) {
if (U_FAILURE(status)) {
return nullptr;
}
continue; continue;
} }
@ -476,7 +482,7 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
int32_t el = UHASH_FIRST; int32_t el = UHASH_FIRST;
const UHashElement *ne = remainder.nextElement(el); const UHashElement *ne = remainder.nextElement(el);
while (ne != nullptr) { while (ne != nullptr) {
UnicodeString item = *((UnicodeString *)(ne->value.pointer)); UnicodeString item = *static_cast<UnicodeString*>(ne->value.pointer);
UnicodeString *toAdd = new UnicodeString(prefix); UnicodeString *toAdd = new UnicodeString(prefix);
/* test for nullptr */ /* test for nullptr */
if (toAdd == nullptr) { if (toAdd == nullptr) {
@ -490,6 +496,13 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
ne = remainder.nextElement(el); ne = remainder.nextElement(el);
} }
// ICU-22642 Guards against strings that have so many permutations
// that they would otherwise hang the function.
constexpr int32_t kResultLimit = 4096;
if (fillinResult->count() > kResultLimit) {
status = U_UNSUPPORTED_ERROR;
return nullptr;
}
} }
} }

View File

@ -58,17 +58,17 @@ icu::UMutex cpMutex;
// Does not use uset.h to reduce code dependencies // Does not use uset.h to reduce code dependencies
void U_CALLCONV void U_CALLCONV
_set_add(USet *set, UChar32 c) { _set_add(USet *set, UChar32 c) {
((UnicodeSet *)set)->add(c); reinterpret_cast<UnicodeSet*>(set)->add(c);
} }
void U_CALLCONV void U_CALLCONV
_set_addRange(USet *set, UChar32 start, UChar32 end) { _set_addRange(USet *set, UChar32 start, UChar32 end) {
((UnicodeSet *)set)->add(start, end); reinterpret_cast<UnicodeSet*>(set)->add(start, end);
} }
void U_CALLCONV void U_CALLCONV
_set_addString(USet *set, const char16_t *str, int32_t length) { _set_addString(USet *set, const char16_t *str, int32_t length) {
((UnicodeSet *)set)->add(icu::UnicodeString((UBool)(length<0), str, length)); reinterpret_cast<UnicodeSet*>(set)->add(icu::UnicodeString(static_cast<UBool>(length < 0), str, length));
} }
UBool U_CALLCONV characterproperties_cleanup() { UBool U_CALLCONV characterproperties_cleanup() {
@ -103,7 +103,7 @@ void U_CALLCONV initInclusion(UPropertySource src, UErrorCode &errorCode) {
return; return;
} }
USetAdder sa = { USetAdder sa = {
(USet *)incl.getAlias(), reinterpret_cast<USet*>(incl.getAlias()),
_set_add, _set_add,
_set_addRange, _set_addRange,
_set_addString, _set_addString,
@ -184,8 +184,12 @@ void U_CALLCONV initInclusion(UPropertySource src, UErrorCode &errorCode) {
sa.add(sa.set, 0x2FFF + 1); sa.add(sa.set, 0x2FFF + 1);
break; break;
case UPROPS_SRC_ID_COMPAT_MATH: case UPROPS_SRC_ID_COMPAT_MATH:
case UPROPS_SRC_MCM:
uprops_addPropertyStarts(src, &sa, &errorCode); uprops_addPropertyStarts(src, &sa, &errorCode);
break; break;
case UPROPS_SRC_BLOCK:
ublock_addPropertyStarts(&sa, errorCode);
break;
default: default:
errorCode = U_INTERNAL_PROGRAM_ERROR; errorCode = U_INTERNAL_PROGRAM_ERROR;
break; break;
@ -289,7 +293,7 @@ UnicodeSet *makeSet(UProperty property, UErrorCode &errorCode) {
const icu::EmojiProps *ep = icu::EmojiProps::getSingleton(errorCode); const icu::EmojiProps *ep = icu::EmojiProps::getSingleton(errorCode);
if (U_FAILURE(errorCode)) { return nullptr; } if (U_FAILURE(errorCode)) { return nullptr; }
USetAdder sa = { USetAdder sa = {
(USet *)set.getAlias(), reinterpret_cast<USet*>(set.getAlias()),
_set_add, _set_add,
_set_addRange, _set_addRange,
_set_addString, _set_addString,

View File

@ -126,7 +126,7 @@ T_CString_toLowerCase(char* str)
if (str) { if (str) {
do do
*str = (char)uprv_tolower(*str); *str = uprv_tolower(*str);
while (*(str++)); while (*(str++));
} }
@ -140,7 +140,7 @@ T_CString_toUpperCase(char* str)
if (str) { if (str) {
do do
*str = (char)uprv_toupper(*str); *str = uprv_toupper(*str);
while (*(str++)); while (*(str++));
} }

View File

@ -61,12 +61,12 @@ DictionaryBreakEngine::findBreaks( UText *text,
// extends towards the start or end of the text, depending on 'reverse'. // extends towards the start or end of the text, depending on 'reverse'.
utext_setNativeIndex(text, startPos); utext_setNativeIndex(text, startPos);
int32_t start = (int32_t)utext_getNativeIndex(text); int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t current; int32_t current;
int32_t rangeStart; int32_t rangeStart;
int32_t rangeEnd; int32_t rangeEnd;
UChar32 c = utext_current32(text); UChar32 c = utext_current32(text);
while((current = (int32_t)utext_getNativeIndex(text)) < endPos && fSet.contains(c)) { while ((current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos && fSet.contains(c)) {
utext_next32(text); // TODO: recast loop for postincrement utext_next32(text); // TODO: recast loop for postincrement
c = utext_current32(text); c = utext_current32(text);
} }
@ -137,7 +137,7 @@ public:
int32_t PossibleWord::candidates( UText *text, DictionaryMatcher *dict, int32_t rangeEnd ) { int32_t PossibleWord::candidates( UText *text, DictionaryMatcher *dict, int32_t rangeEnd ) {
// TODO: If getIndex is too slow, use offset < 0 and add discardAll() // TODO: If getIndex is too slow, use offset < 0 and add discardAll()
int32_t start = (int32_t)utext_getNativeIndex(text); int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
if (start != offset) { if (start != offset) {
offset = start; offset = start;
count = dict->matches(text, rangeEnd-start, UPRV_LENGTHOF(cuLengths), cuLengths, cpLengths, nullptr, &prefix); count = dict->matches(text, rangeEnd-start, UPRV_LENGTHOF(cuLengths), cuLengths, cpLengths, nullptr, &prefix);
@ -253,7 +253,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart); utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) { while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cpWordLength = 0; cpWordLength = 0;
cuWordLength = 0; cuWordLength = 0;
@ -269,7 +269,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
// If there was more than one, see which one can take us forward the most words // If there was more than one, see which one can take us forward the most words
else if (candidates > 1) { else if (candidates > 1) {
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
do { do {
@ -278,7 +278,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%THAI_LOOKAHEAD].markCurrent(); words[wordsFound%THAI_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
@ -308,7 +308,7 @@ foundBest:
// The text iterator should now be positioned at the end of the word we found. // The text iterator should now be positioned at the end of the word we found.
UChar32 uc = 0; UChar32 uc = 0;
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < THAI_ROOT_COMBINE_THRESHOLD) { if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < THAI_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is // if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold // no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize // of characters with a dictionary word, then scan to resynchronize
@ -320,9 +320,9 @@ foundBest:
UChar32 pc; UChar32 pc;
int32_t chars = 0; int32_t chars = 0;
for (;;) { for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text); int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text); pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex; int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize; chars += pcSize;
remaining -= pcSize; remaining -= pcSize;
if (remaining <= 0) { if (remaining <= 0) {
@ -356,28 +356,28 @@ foundBest:
utext_setNativeIndex(text, current+cuWordLength); utext_setNativeIndex(text, current+cuWordLength);
} }
} }
// Never stop before a combining mark. // Never stop before a combining mark.
int32_t currPos; int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) { while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos; cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
} }
// Look ahead for possible suffixes if a dictionary word does not follow. // Look ahead for possible suffixes if a dictionary word does not follow.
// We do this in code rather than using a rule so that the heuristic // We do this in code rather than using a rule so that the heuristic
// resynch continues to function. For example, one of the suffix characters // resynch continues to function. For example, one of the suffix characters
// could be a typo in the middle of a word. // could be a typo in the middle of a word.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cuWordLength > 0) { if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cuWordLength > 0) {
if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0 if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0
&& fSuffixSet.contains(uc = utext_current32(text))) { && fSuffixSet.contains(uc = utext_current32(text))) {
if (uc == THAI_PAIYANNOI) { if (uc == THAI_PAIYANNOI) {
if (!fSuffixSet.contains(utext_previous32(text))) { if (!fSuffixSet.contains(utext_previous32(text))) {
// Skip over previous end and PAIYANNOI // Skip over previous end and PAIYANNOI
utext_next32(text); utext_next32(text);
int32_t paiyannoiIndex = (int32_t)utext_getNativeIndex(text); int32_t paiyannoiIndex = static_cast<int32_t>(utext_getNativeIndex(text));
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - paiyannoiIndex; // Add PAIYANNOI to word cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - paiyannoiIndex; // Add PAIYANNOI to word
uc = utext_current32(text); // Fetch next character uc = utext_current32(text); // Fetch next character
} }
else { else {
@ -389,9 +389,9 @@ foundBest:
if (utext_previous32(text) != THAI_MAIYAMOK) { if (utext_previous32(text) != THAI_MAIYAMOK) {
// Skip over previous end and MAIYAMOK // Skip over previous end and MAIYAMOK
utext_next32(text); utext_next32(text);
int32_t maiyamokIndex = (int32_t)utext_getNativeIndex(text); int32_t maiyamokIndex = static_cast<int32_t>(utext_getNativeIndex(text));
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - maiyamokIndex; // Add MAIYAMOK to word cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - maiyamokIndex; // Add MAIYAMOK to word
} }
else { else {
// Restore prior position // Restore prior position
@ -489,7 +489,7 @@ LaoBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart); utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) { while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0; cuWordLength = 0;
cpWordLength = 0; cpWordLength = 0;
@ -514,7 +514,7 @@ LaoBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%LAO_LOOKAHEAD].markCurrent(); words[wordsFound%LAO_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
@ -541,7 +541,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed // just found (if there is one), but only if the preceding word does not exceed
// the threshold. // the threshold.
// The text iterator should now be positioned at the end of the word we found. // The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < LAO_ROOT_COMBINE_THRESHOLD) { if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < LAO_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is // if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold // no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize // of characters with a dictionary word, then scan to resynchronize
@ -554,9 +554,9 @@ foundBest:
UChar32 uc; UChar32 uc;
int32_t chars = 0; int32_t chars = 0;
for (;;) { for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text); int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text); pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex; int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize; chars += pcSize;
remaining -= pcSize; remaining -= pcSize;
if (remaining <= 0) { if (remaining <= 0) {
@ -590,9 +590,9 @@ foundBest:
// Never stop before a combining mark. // Never stop before a combining mark.
int32_t currPos; int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) { while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos; cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
} }
// Look ahead for possible suffixes if a dictionary word does not follow. // Look ahead for possible suffixes if a dictionary word does not follow.
@ -682,7 +682,7 @@ BurmeseBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart); utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) { while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0; cuWordLength = 0;
cpWordLength = 0; cpWordLength = 0;
@ -707,7 +707,7 @@ BurmeseBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%BURMESE_LOOKAHEAD].markCurrent(); words[wordsFound%BURMESE_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
@ -734,7 +734,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed // just found (if there is one), but only if the preceding word does not exceed
// the threshold. // the threshold.
// The text iterator should now be positioned at the end of the word we found. // The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < BURMESE_ROOT_COMBINE_THRESHOLD) { if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < BURMESE_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is // if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold // no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize // of characters with a dictionary word, then scan to resynchronize
@ -747,9 +747,9 @@ foundBest:
UChar32 uc; UChar32 uc;
int32_t chars = 0; int32_t chars = 0;
for (;;) { for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text); int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text); pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex; int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize; chars += pcSize;
remaining -= pcSize; remaining -= pcSize;
if (remaining <= 0) { if (remaining <= 0) {
@ -783,9 +783,9 @@ foundBest:
// Never stop before a combining mark. // Never stop before a combining mark.
int32_t currPos; int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) { while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos; cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
} }
// Look ahead for possible suffixes if a dictionary word does not follow. // Look ahead for possible suffixes if a dictionary word does not follow.
@ -888,7 +888,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart); utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) { while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0; cuWordLength = 0;
cpWordLength = 0; cpWordLength = 0;
@ -905,7 +905,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
// If there was more than one, see which one can take us forward the most words // If there was more than one, see which one can take us forward the most words
else if (candidates > 1) { else if (candidates > 1) {
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
do { do {
@ -914,7 +914,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound % KHMER_LOOKAHEAD].markCurrent(); words[wordsFound % KHMER_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done // If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) { if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest; goto foundBest;
} }
@ -941,7 +941,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed // just found (if there is one), but only if the preceding word does not exceed
// the threshold. // the threshold.
// The text iterator should now be positioned at the end of the word we found. // The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < KHMER_ROOT_COMBINE_THRESHOLD) { if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < KHMER_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is // if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold // no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize // of characters with a dictionary word, then scan to resynchronize
@ -954,9 +954,9 @@ foundBest:
UChar32 uc; UChar32 uc;
int32_t chars = 0; int32_t chars = 0;
for (;;) { for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text); int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text); pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex; int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize; chars += pcSize;
remaining -= pcSize; remaining -= pcSize;
if (remaining <= 0) { if (remaining <= 0) {
@ -989,9 +989,9 @@ foundBest:
// Never stop before a combining mark. // Never stop before a combining mark.
int32_t currPos; int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) { while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text); utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos; cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
} }
// Look ahead for possible suffixes if a dictionary word does not follow. // Look ahead for possible suffixes if a dictionary word does not follow.
@ -1120,7 +1120,7 @@ static inline bool isKatakana(UChar32 value) {
// Replicates an internal UText function. // Replicates an internal UText function.
static inline int32_t utext_i32_flag(int32_t bitIndex) { static inline int32_t utext_i32_flag(int32_t bitIndex) {
return (int32_t)1 << bitIndex; return static_cast<int32_t>(1) << bitIndex;
} }
/* /*
@ -1167,14 +1167,14 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t limit = rangeEnd; int32_t limit = rangeEnd;
U_ASSERT(limit <= utext_nativeLength(inText)); U_ASSERT(limit <= utext_nativeLength(inText));
if (limit > utext_nativeLength(inText)) { if (limit > utext_nativeLength(inText)) {
limit = (int32_t)utext_nativeLength(inText); limit = static_cast<int32_t>(utext_nativeLength(inText));
} }
inputMap.adoptInsteadAndCheckErrorCode(new UVector32(status), status); inputMap.adoptInsteadAndCheckErrorCode(new UVector32(status), status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
return 0; return 0;
} }
while (utext_getNativeIndex(inText) < limit) { while (utext_getNativeIndex(inText) < limit) {
int32_t nativePosition = (int32_t)utext_getNativeIndex(inText); int32_t nativePosition = static_cast<int32_t>(utext_getNativeIndex(inText));
UChar32 c = utext_next32(inText); UChar32 c = utext_next32(inText);
U_ASSERT(c != U_SENTINEL); U_ASSERT(c != U_SENTINEL);
inString.append(c); inString.append(c);
@ -1304,7 +1304,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t ix = 0; int32_t ix = 0;
bool is_prev_katakana = false; bool is_prev_katakana = false;
for (int32_t i = 0; i < numCodePts; ++i, ix = inString.moveIndex32(ix, 1)) { for (int32_t i = 0; i < numCodePts; ++i, ix = inString.moveIndex32(ix, 1)) {
if ((uint32_t)bestSnlp.elementAti(i) == kuint32max) { if (static_cast<uint32_t>(bestSnlp.elementAti(i)) == kuint32max) {
continue; continue;
} }
@ -1327,9 +1327,9 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
} }
for (int32_t j = 0; j < count; j++) { for (int32_t j = 0; j < count; j++) {
uint32_t newSnlp = (uint32_t)bestSnlp.elementAti(i) + (uint32_t)values.elementAti(j); uint32_t newSnlp = static_cast<uint32_t>(bestSnlp.elementAti(i)) + static_cast<uint32_t>(values.elementAti(j));
int32_t ln_j_i = lengths.elementAti(j) + i; int32_t ln_j_i = lengths.elementAti(j) + i;
if (newSnlp < (uint32_t)bestSnlp.elementAti(ln_j_i)) { if (newSnlp < static_cast<uint32_t>(bestSnlp.elementAti(ln_j_i))) {
bestSnlp.setElementAt(newSnlp, ln_j_i); bestSnlp.setElementAt(newSnlp, ln_j_i);
prev.setElementAt(i, ln_j_i); prev.setElementAt(i, ln_j_i);
} }
@ -1353,7 +1353,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
} }
if (katakanaRunLength < kMaxKatakanaGroupLength) { if (katakanaRunLength < kMaxKatakanaGroupLength) {
uint32_t newSnlp = bestSnlp.elementAti(i) + getKatakanaCost(katakanaRunLength); uint32_t newSnlp = bestSnlp.elementAti(i) + getKatakanaCost(katakanaRunLength);
if (newSnlp < (uint32_t)bestSnlp.elementAti(i+katakanaRunLength)) { if (newSnlp < static_cast<uint32_t>(bestSnlp.elementAti(i + katakanaRunLength))) {
bestSnlp.setElementAt(newSnlp, i+katakanaRunLength); bestSnlp.setElementAt(newSnlp, i+katakanaRunLength);
prev.setElementAt(i, i+katakanaRunLength); // prev[j] = i; prev.setElementAt(i, i+katakanaRunLength); // prev[j] = i;
} }
@ -1371,7 +1371,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t numBreaks = 0; int32_t numBreaks = 0;
// No segmentation found, set boundary to end of range // No segmentation found, set boundary to end of range
if ((uint32_t)bestSnlp.elementAti(numCodePts) == kuint32max) { if (static_cast<uint32_t>(bestSnlp.elementAti(numCodePts)) == kuint32max) {
t_boundary.addElement(numCodePts, status); t_boundary.addElement(numCodePts, status);
numBreaks++; numBreaks++;
} else if (isPhraseBreaking) { } else if (isPhraseBreaking) {

View File

@ -47,13 +47,13 @@ int32_t UCharsDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t
int32_t *prefix) const { int32_t *prefix) const {
UCharsTrie uct(characters); UCharsTrie uct(characters);
int32_t startingTextIndex = (int32_t)utext_getNativeIndex(text); int32_t startingTextIndex = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t wordCount = 0; int32_t wordCount = 0;
int32_t codePointsMatched = 0; int32_t codePointsMatched = 0;
for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) { for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) {
UStringTrieResult result = (codePointsMatched == 0) ? uct.first(c) : uct.next(c); UStringTrieResult result = (codePointsMatched == 0) ? uct.first(c) : uct.next(c);
int32_t lengthMatched = (int32_t)utext_getNativeIndex(text) - startingTextIndex; int32_t lengthMatched = static_cast<int32_t>(utext_getNativeIndex(text)) - startingTextIndex;
codePointsMatched += 1; codePointsMatched += 1;
if (USTRINGTRIE_HAS_VALUE(result)) { if (USTRINGTRIE_HAS_VALUE(result)) {
if (wordCount < limit) { if (wordCount < limit) {
@ -101,7 +101,7 @@ UChar32 BytesDictionaryMatcher::transform(UChar32 c) const {
if (delta < 0 || 0xFD < delta) { if (delta < 0 || 0xFD < delta) {
return U_SENTINEL; return U_SENTINEL;
} }
return (UChar32)delta; return static_cast<UChar32>(delta);
} }
return c; return c;
} }
@ -114,13 +114,13 @@ int32_t BytesDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t
int32_t *lengths, int32_t *cpLengths, int32_t *values, int32_t *lengths, int32_t *cpLengths, int32_t *values,
int32_t *prefix) const { int32_t *prefix) const {
BytesTrie bt(characters); BytesTrie bt(characters);
int32_t startingTextIndex = (int32_t)utext_getNativeIndex(text); int32_t startingTextIndex = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t wordCount = 0; int32_t wordCount = 0;
int32_t codePointsMatched = 0; int32_t codePointsMatched = 0;
for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) { for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) {
UStringTrieResult result = (codePointsMatched == 0) ? bt.first(transform(c)) : bt.next(transform(c)); UStringTrieResult result = (codePointsMatched == 0) ? bt.first(transform(c)) : bt.next(transform(c));
int32_t lengthMatched = (int32_t)utext_getNativeIndex(text) - startingTextIndex; int32_t lengthMatched = static_cast<int32_t>(utext_getNativeIndex(text)) - startingTextIndex;
codePointsMatched += 1; codePointsMatched += 1;
if (USTRINGTRIE_HAS_VALUE(result)) { if (USTRINGTRIE_HAS_VALUE(result)) {
if (wordCount < limit) { if (wordCount < limit) {

View File

@ -47,7 +47,7 @@ Edits &Edits::copyArray(const Edits &other) {
return *this; return *this;
} }
if (length > capacity) { if (length > capacity) {
uint16_t *newArray = (uint16_t *)uprv_malloc((size_t)length * 2); uint16_t* newArray = static_cast<uint16_t*>(uprv_malloc(static_cast<size_t>(length) * 2));
if (newArray == nullptr) { if (newArray == nullptr) {
length = delta = numChanges = 0; length = delta = numChanges = 0;
errorCode_ = U_MEMORY_ALLOCATION_ERROR; errorCode_ = U_MEMORY_ALLOCATION_ERROR;
@ -186,30 +186,30 @@ void Edits::addReplace(int32_t oldLength, int32_t newLength) {
head |= oldLength << 6; head |= oldLength << 6;
} else if(oldLength <= 0x7fff) { } else if(oldLength <= 0x7fff) {
head |= LENGTH_IN_1TRAIL << 6; head |= LENGTH_IN_1TRAIL << 6;
array[limit++] = (uint16_t)(0x8000 | oldLength); array[limit++] = static_cast<uint16_t>(0x8000 | oldLength);
} else { } else {
head |= (LENGTH_IN_2TRAIL + (oldLength >> 30)) << 6; head |= (LENGTH_IN_2TRAIL + (oldLength >> 30)) << 6;
array[limit++] = (uint16_t)(0x8000 | (oldLength >> 15)); array[limit++] = static_cast<uint16_t>(0x8000 | (oldLength >> 15));
array[limit++] = (uint16_t)(0x8000 | oldLength); array[limit++] = static_cast<uint16_t>(0x8000 | oldLength);
} }
if(newLength < LENGTH_IN_1TRAIL) { if(newLength < LENGTH_IN_1TRAIL) {
head |= newLength; head |= newLength;
} else if(newLength <= 0x7fff) { } else if(newLength <= 0x7fff) {
head |= LENGTH_IN_1TRAIL; head |= LENGTH_IN_1TRAIL;
array[limit++] = (uint16_t)(0x8000 | newLength); array[limit++] = static_cast<uint16_t>(0x8000 | newLength);
} else { } else {
head |= LENGTH_IN_2TRAIL + (newLength >> 30); head |= LENGTH_IN_2TRAIL + (newLength >> 30);
array[limit++] = (uint16_t)(0x8000 | (newLength >> 15)); array[limit++] = static_cast<uint16_t>(0x8000 | (newLength >> 15));
array[limit++] = (uint16_t)(0x8000 | newLength); array[limit++] = static_cast<uint16_t>(0x8000 | newLength);
} }
array[length] = (uint16_t)head; array[length] = static_cast<uint16_t>(head);
length = limit; length = limit;
} }
} }
void Edits::append(int32_t r) { void Edits::append(int32_t r) {
if(length < capacity || growArray()) { if(length < capacity || growArray()) {
array[length++] = (uint16_t)r; array[length++] = static_cast<uint16_t>(r);
} }
} }
@ -232,7 +232,7 @@ UBool Edits::growArray() {
errorCode_ = U_INDEX_OUTOFBOUNDS_ERROR; errorCode_ = U_INDEX_OUTOFBOUNDS_ERROR;
return false; return false;
} }
uint16_t *newArray = (uint16_t *)uprv_malloc((size_t)newCapacity * 2); uint16_t* newArray = static_cast<uint16_t*>(uprv_malloc(static_cast<size_t>(newCapacity) * 2));
if (newArray == nullptr) { if (newArray == nullptr) {
errorCode_ = U_MEMORY_ALLOCATION_ERROR; errorCode_ = U_MEMORY_ALLOCATION_ERROR;
return false; return false;
@ -415,7 +415,7 @@ int32_t Edits::Iterator::readLength(int32_t head) {
U_ASSERT(array[index] >= 0x8000); U_ASSERT(array[index] >= 0x8000);
U_ASSERT(array[index + 1] >= 0x8000); U_ASSERT(array[index + 1] >= 0x8000);
int32_t len = ((head & 1) << 30) | int32_t len = ((head & 1) << 30) |
((int32_t)(array[index] & 0x7fff) << 15) | (static_cast<int32_t>(array[index] & 0x7fff) << 15) |
(array[index + 1] & 0x7fff); (array[index + 1] & 0x7fff);
index += 2; index += 2;
return len; return len;

View File

@ -83,8 +83,8 @@ void
EmojiProps::load(UErrorCode &errorCode) { EmojiProps::load(UErrorCode &errorCode) {
memory = udata_openChoice(nullptr, "icu", "uemoji", isAcceptable, this, &errorCode); memory = udata_openChoice(nullptr, "icu", "uemoji", isAcceptable, this, &errorCode);
if (U_FAILURE(errorCode)) { return; } if (U_FAILURE(errorCode)) { return; }
const uint8_t *inBytes = (const uint8_t *)udata_getMemory(memory); const uint8_t* inBytes = static_cast<const uint8_t*>(udata_getMemory(memory));
const int32_t *inIndexes = (const int32_t *)inBytes; const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexesLength = inIndexes[IX_CPTRIE_OFFSET] / 4; int32_t indexesLength = inIndexes[IX_CPTRIE_OFFSET] / 4;
if (indexesLength <= IX_RGI_EMOJI_ZWJ_SEQUENCE_TRIE_OFFSET) { if (indexesLength <= IX_RGI_EMOJI_ZWJ_SEQUENCE_TRIE_OFFSET) {
errorCode = U_INVALID_FORMAT_ERROR; // Not enough indexes. errorCode = U_INVALID_FORMAT_ERROR; // Not enough indexes.
@ -104,7 +104,7 @@ EmojiProps::load(UErrorCode &errorCode) {
offset = inIndexes[i]; offset = inIndexes[i];
nextOffset = inIndexes[i + 1]; nextOffset = inIndexes[i + 1];
// Set/leave nullptr if there is no UCharsTrie. // Set/leave nullptr if there is no UCharsTrie.
const char16_t *p = nextOffset > offset ? (const char16_t *)(inBytes + offset) : nullptr; const char16_t* p = nextOffset > offset ? reinterpret_cast<const char16_t*>(inBytes + offset) : nullptr;
stringTries[getStringTrieIndex(i)] = p; stringTries[getStringTrieIndex(i)] = p;
} }
} }

View File

@ -50,8 +50,8 @@ static void _fb_trace(const char *m, const UnicodeString *s, UBool b, int32_t d,
* Used with sortedInsert() * Used with sortedInsert()
*/ */
static int32_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) { static int32_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
const UnicodeString &a = *(const UnicodeString*)t1.pointer; const UnicodeString& a = *static_cast<const UnicodeString*>(t1.pointer);
const UnicodeString &b = *(const UnicodeString*)t2.pointer; const UnicodeString& b = *static_cast<const UnicodeString*>(t2.pointer);
return a.compare(b); return a.compare(b);
} }
@ -76,7 +76,7 @@ class UStringSet : public UVector {
* Return the ith UnicodeString alias * Return the ith UnicodeString alias
*/ */
inline const UnicodeString* getStringAt(int32_t i) const { inline const UnicodeString* getStringAt(int32_t i) const {
return (const UnicodeString*)elementAt(i); return static_cast<const UnicodeString*>(elementAt(i));
} }
/** /**
* Adopt the UnicodeString if not already contained. * Adopt the UnicodeString if not already contained.

View File

@ -747,7 +747,7 @@ uplug_init(UErrorCode *status) {
FILE *f; FILE *f;
CharString pluginFile; CharString pluginFile;
#ifdef OS390BATCH #ifdef ICU_PLUGINS_DD
/* There are potentially a lot of ways to implement a plugin directory on OS390/zOS */ /* There are potentially a lot of ways to implement a plugin directory on OS390/zOS */
/* Keeping in mind that unauthorized file access is logged, monitored, and enforced */ /* Keeping in mind that unauthorized file access is logged, monitored, and enforced */
/* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNIX */ /* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNIX */

View File

@ -63,7 +63,7 @@ LoadedNormalizer2Impl::isAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x72 && pInfo->dataFormat[1]==0x72 &&
pInfo->dataFormat[2]==0x6d && pInfo->dataFormat[2]==0x6d &&
pInfo->dataFormat[3]==0x32 && pInfo->dataFormat[3]==0x32 &&
pInfo->formatVersion[0]==4 pInfo->formatVersion[0]==5
) { ) {
// Normalizer2Impl *me=(Normalizer2Impl *)context; // Normalizer2Impl *me=(Normalizer2Impl *)context;
// uprv_memcpy(me->dataVersion, pInfo->dataVersion, 4); // uprv_memcpy(me->dataVersion, pInfo->dataVersion, 4);
@ -82,8 +82,8 @@ LoadedNormalizer2Impl::load(const char *packageName, const char *name, UErrorCod
if(U_FAILURE(errorCode)) { if(U_FAILURE(errorCode)) {
return; return;
} }
const uint8_t *inBytes=(const uint8_t *)udata_getMemory(memory); const uint8_t* inBytes = static_cast<const uint8_t*>(udata_getMemory(memory));
const int32_t *inIndexes=(const int32_t *)inBytes; const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexesLength=inIndexes[IX_NORM_TRIE_OFFSET]/4; int32_t indexesLength=inIndexes[IX_NORM_TRIE_OFFSET]/4;
if(indexesLength<=IX_MIN_LCCC_CP) { if(indexesLength<=IX_MIN_LCCC_CP) {
errorCode=U_INVALID_FORMAT_ERROR; // Not enough indexes. errorCode=U_INVALID_FORMAT_ERROR; // Not enough indexes.
@ -101,7 +101,7 @@ LoadedNormalizer2Impl::load(const char *packageName, const char *name, UErrorCod
offset=nextOffset; offset=nextOffset;
nextOffset=inIndexes[IX_SMALL_FCD_OFFSET]; nextOffset=inIndexes[IX_SMALL_FCD_OFFSET];
const uint16_t *inExtraData=(const uint16_t *)(inBytes+offset); const uint16_t* inExtraData = reinterpret_cast<const uint16_t*>(inBytes + offset);
// smallFCD: new in formatVersion 2 // smallFCD: new in formatVersion 2
offset=nextOffset; offset=nextOffset;
@ -311,7 +311,7 @@ Normalizer2::getInstance(const char *packageName,
{ {
Mutex lock; Mutex lock;
if(cache!=nullptr) { if(cache!=nullptr) {
allModes=(Norm2AllModes *)uhash_get(cache, name); allModes = static_cast<Norm2AllModes*>(uhash_get(cache, name));
} }
} }
if(allModes==nullptr) { if(allModes==nullptr) {
@ -331,7 +331,7 @@ Normalizer2::getInstance(const char *packageName,
void *temp=uhash_get(cache, name); void *temp=uhash_get(cache, name);
if(temp==nullptr) { if(temp==nullptr) {
int32_t keyLength= static_cast<int32_t>(uprv_strlen(name)+1); int32_t keyLength= static_cast<int32_t>(uprv_strlen(name)+1);
char *nameCopy=(char *)uprv_malloc(keyLength); char* nameCopy = static_cast<char*>(uprv_malloc(keyLength));
if(nameCopy==nullptr) { if(nameCopy==nullptr) {
errorCode=U_MEMORY_ALLOCATION_ERROR; errorCode=U_MEMORY_ALLOCATION_ERROR;
return nullptr; return nullptr;
@ -341,7 +341,7 @@ Normalizer2::getInstance(const char *packageName,
uhash_put(cache, nameCopy, localAllModes.orphan(), &errorCode); uhash_put(cache, nameCopy, localAllModes.orphan(), &errorCode);
} else { } else {
// race condition // race condition
allModes=(Norm2AllModes *)temp; allModes = static_cast<Norm2AllModes*>(temp);
} }
} }
} }

View File

@ -1,6 +1,8 @@
// © 2019 and later: Unicode, Inc. and others. // © 2019 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html // License & terms of use: http://www.unicode.org/copyright.html
#include <optional>
#include <string_view>
#include <utility> #include <utility>
#include "bytesinkutil.h" // StringByteSink<CharString> #include "bytesinkutil.h" // StringByteSink<CharString>
@ -162,12 +164,15 @@ _isKeywordValue(const char* key, const char* value, int32_t value_len)
// otherwise: unicode extension value // otherwise: unicode extension value
// We need to convert from legacy key/value to unicode // We need to convert from legacy key/value to unicode
// key/value // key/value
const char* unicode_locale_key = uloc_toUnicodeLocaleKey(key); std::optional<std::string_view> unicode_locale_key = ulocimp_toBcpKeyWithFallback(key);
const char* unicode_locale_type = uloc_toUnicodeLocaleType(key, value); std::optional<std::string_view> unicode_locale_type = ulocimp_toBcpTypeWithFallback(key, value);
return unicode_locale_key && unicode_locale_type && return unicode_locale_key.has_value() &&
ultag_isUnicodeLocaleKey(unicode_locale_key, -1) && unicode_locale_type.has_value() &&
ultag_isUnicodeLocaleType(unicode_locale_type, -1); ultag_isUnicodeLocaleKey(unicode_locale_key->data(),
static_cast<int32_t>(unicode_locale_key->size())) &&
ultag_isUnicodeLocaleType(unicode_locale_type->data(),
static_cast<int32_t>(unicode_locale_type->size()));
} }
void void

File diff suppressed because it is too large Load Diff

View File

@ -780,7 +780,7 @@ int32_t acceptLanguage(UEnumeration &supportedLocales, Locale::Iterator &desired
ULOC_ACCEPT_VALID : ULOC_ACCEPT_FALLBACK; ULOC_ACCEPT_VALID : ULOC_ACCEPT_FALLBACK;
} }
const char *bestStr = result.getSupportedLocale()->getName(); const char *bestStr = result.getSupportedLocale()->getName();
int32_t bestLength = (int32_t)uprv_strlen(bestStr); int32_t bestLength = static_cast<int32_t>(uprv_strlen(bestStr));
if (bestLength <= capacity) { if (bestLength <= capacity) {
uprv_memcpy(dest, bestStr, bestLength); uprv_memcpy(dest, bestStr, bestLength);
} }

View File

@ -99,7 +99,7 @@ inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
inline LocaleBased::LocaleBased(const char* validAlias, inline LocaleBased::LocaleBased(const char* validAlias,
const char* actualAlias) : const char* actualAlias) :
// ugh: cast away const // ugh: cast away const
valid((char*)validAlias), actual((char*)actualAlias) { valid(const_cast<char*>(validAlias)), actual(const_cast<char*>(actualAlias)) {
} }
U_NAMESPACE_END U_NAMESPACE_END

View File

@ -245,7 +245,7 @@ Locale::getDisplayName(const Locale &displayLocale,
return result; return result;
} }
#if ! UCONFIG_NO_BREAK_ITERATION #if !UCONFIG_NO_BREAK_ITERATION
// ------------------------------------- // -------------------------------------
// Gets the objectLocale display name in the default locale language. // Gets the objectLocale display name in the default locale language.
@ -351,7 +351,7 @@ _getStringOrCopyKey(const char *path, const char *locale,
} }
} else { } else {
/* no string from a resource bundle: convert the substitute */ /* no string from a resource bundle: convert the substitute */
length=(int32_t)uprv_strlen(substitute); length = static_cast<int32_t>(uprv_strlen(substitute));
u_charsToUChars(substitute, dest, uprv_min(length, destCapacity)); u_charsToUChars(substitute, dest, uprv_min(length, destCapacity));
errorCode = U_USING_DEFAULT_WARNING; errorCode = U_USING_DEFAULT_WARNING;
} }
@ -835,7 +835,10 @@ uloc_getDisplayKeywordValue( const char* locale,
} }
/* get the keyword value */ /* get the keyword value */
CharString keywordValue = ulocimp_getKeywordValue(locale, keyword, *status); CharString keywordValue;
if (keyword != nullptr && *keyword != '\0') {
keywordValue = ulocimp_getKeywordValue(locale, keyword, *status);
}
/* /*
* if the keyword is equal to currency .. then to get the display name * if the keyword is equal to currency .. then to get the display name

View File

@ -336,10 +336,11 @@ LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
{ {
while (length-- > 0) { while (length-- > 0) {
UDisplayContext value = *contexts++; UDisplayContext value = *contexts++;
UDisplayContextType selector = (UDisplayContextType)((uint32_t)value >> 8); UDisplayContextType selector =
static_cast<UDisplayContextType>(static_cast<uint32_t>(value) >> 8);
switch (selector) { switch (selector) {
case UDISPCTX_TYPE_DIALECT_HANDLING: case UDISPCTX_TYPE_DIALECT_HANDLING:
dialectHandling = (UDialectHandling)value; dialectHandling = static_cast<UDialectHandling>(value);
break; break;
case UDISPCTX_TYPE_CAPITALIZATION: case UDISPCTX_TYPE_CAPITALIZATION:
capitalizationContext = value; capitalizationContext = value;
@ -407,7 +408,7 @@ LocaleDisplayNamesImpl::CapitalizationContextSink::~CapitalizationContextSink()
void void
LocaleDisplayNamesImpl::initialize() { LocaleDisplayNamesImpl::initialize() {
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this; LocaleDisplayNamesImpl* nonConstThis = this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot() nonConstThis->locale = langData.getLocale() == Locale::getRoot()
? regionData.getLocale() ? regionData.getLocale()
: langData.getLocale(); : langData.getLocale();
@ -426,16 +427,16 @@ LocaleDisplayNamesImpl::initialize() {
pattern = UnicodeString("{0} ({1})", -1, US_INV); pattern = UnicodeString("{0} ({1})", -1, US_INV);
} }
format.applyPatternMinMaxArguments(pattern, 2, 2, status); format.applyPatternMinMaxArguments(pattern, 2, 2, status);
if (pattern.indexOf((char16_t)0xFF08) >= 0) { if (pattern.indexOf(static_cast<char16_t>(0xFF08)) >= 0) {
formatOpenParen.setTo((char16_t)0xFF08); // fullwidth ( formatOpenParen.setTo(static_cast<char16_t>(0xFF08)); // fullwidth (
formatReplaceOpenParen.setTo((char16_t)0xFF3B); // fullwidth [ formatReplaceOpenParen.setTo(static_cast<char16_t>(0xFF3B)); // fullwidth [
formatCloseParen.setTo((char16_t)0xFF09); // fullwidth ) formatCloseParen.setTo(static_cast<char16_t>(0xFF09)); // fullwidth )
formatReplaceCloseParen.setTo((char16_t)0xFF3D); // fullwidth ] formatReplaceCloseParen.setTo(static_cast<char16_t>(0xFF3D)); // fullwidth ]
} else { } else {
formatOpenParen.setTo((char16_t)0x0028); // ( formatOpenParen.setTo(static_cast<char16_t>(0x0028)); // (
formatReplaceOpenParen.setTo((char16_t)0x005B); // [ formatReplaceOpenParen.setTo(static_cast<char16_t>(0x005B)); // [
formatCloseParen.setTo((char16_t)0x0029); // ) formatCloseParen.setTo(static_cast<char16_t>(0x0029)); // )
formatReplaceCloseParen.setTo((char16_t)0x005D); // ] formatReplaceCloseParen.setTo(static_cast<char16_t>(0x005D)); // ]
} }
UnicodeString ktPattern; UnicodeString ktPattern;
@ -495,7 +496,7 @@ UDisplayContext
LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const { LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
switch (type) { switch (type) {
case UDISPCTX_TYPE_DIALECT_HANDLING: case UDISPCTX_TYPE_DIALECT_HANDLING:
return (UDisplayContext)dialectHandling; return static_cast<UDisplayContext>(dialectHandling);
case UDISPCTX_TYPE_CAPITALIZATION: case UDISPCTX_TYPE_CAPITALIZATION:
return capitalizationContext; return capitalizationContext;
case UDISPCTX_TYPE_DISPLAY_LENGTH: case UDISPCTX_TYPE_DISPLAY_LENGTH:
@ -505,7 +506,7 @@ LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
default: default:
break; break;
} }
return (UDisplayContext)0; return static_cast<UDisplayContext>(0);
} }
UnicodeString& UnicodeString&
@ -652,7 +653,7 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& loc,
appendWithSep(resultRemainder, temp3); appendWithSep(resultRemainder, temp3);
} else { } else {
appendWithSep(resultRemainder, temp) appendWithSep(resultRemainder, temp)
.append((char16_t)0x3d /* = */) .append(static_cast<char16_t>(0x3d) /* = */)
.append(temp2); .append(temp2);
} }
} }

View File

@ -31,6 +31,8 @@
****************************************************************************** ******************************************************************************
*/ */
#include <optional>
#include <string_view>
#include <utility> #include <utility>
#include "unicode/bytestream.h" #include "unicode/bytestream.h"
@ -109,7 +111,7 @@ namespace {
// //
void U_CALLCONV void U_CALLCONV
deleteLocale(void *obj) { deleteLocale(void *obj) {
delete (icu::Locale *) obj; delete static_cast<icu::Locale*>(obj);
} }
UBool U_CALLCONV locale_cleanup() UBool U_CALLCONV locale_cleanup()
@ -132,7 +134,7 @@ void U_CALLCONV locale_init(UErrorCode &status) {
U_NAMESPACE_USE U_NAMESPACE_USE
U_ASSERT(gLocaleCache == nullptr); U_ASSERT(gLocaleCache == nullptr);
gLocaleCache = new Locale[(int)eMAX_LOCALES]; gLocaleCache = new Locale[static_cast<int>(eMAX_LOCALES)];
if (gLocaleCache == nullptr) { if (gLocaleCache == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
return; return;
@ -194,7 +196,7 @@ Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup); ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
} }
Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf.data()); Locale* newDefault = static_cast<Locale*>(uhash_get(gDefaultLocalesHashT, localeNameBuf.data()));
if (newDefault == nullptr) { if (newDefault == nullptr) {
newDefault = new Locale(Locale::eBOGUS); newDefault = new Locale(Locale::eBOGUS);
if (newDefault == nullptr) { if (newDefault == nullptr) {
@ -202,7 +204,7 @@ Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
return gDefaultLocale; return gDefaultLocale;
} }
newDefault->init(localeNameBuf.data(), false); newDefault->init(localeNameBuf.data(), false);
uhash_put(gDefaultLocalesHashT, (char*) newDefault->getName(), newDefault, &status); uhash_put(gDefaultLocalesHashT, const_cast<char*>(newDefault->getName()), newDefault, &status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
return gDefaultLocale; return gDefaultLocale;
} }
@ -296,7 +298,7 @@ Locale::Locale( const char * newLanguage,
// Language // Language
if ( newLanguage != nullptr ) if ( newLanguage != nullptr )
{ {
lsize = (int32_t)uprv_strlen(newLanguage); lsize = static_cast<int32_t>(uprv_strlen(newLanguage));
if ( lsize < 0 || lsize > ULOC_STRING_LIMIT ) { // int32 wrap if ( lsize < 0 || lsize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus(); setToBogus();
return; return;
@ -308,7 +310,7 @@ Locale::Locale( const char * newLanguage,
// _Country // _Country
if ( newCountry != nullptr ) if ( newCountry != nullptr )
{ {
csize = (int32_t)uprv_strlen(newCountry); csize = static_cast<int32_t>(uprv_strlen(newCountry));
if ( csize < 0 || csize > ULOC_STRING_LIMIT ) { // int32 wrap if ( csize < 0 || csize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus(); setToBogus();
return; return;
@ -325,7 +327,7 @@ Locale::Locale( const char * newLanguage,
} }
// remove trailing _'s // remove trailing _'s
vsize = (int32_t)uprv_strlen(newVariant); vsize = static_cast<int32_t>(uprv_strlen(newVariant));
if ( vsize < 0 || vsize > ULOC_STRING_LIMIT ) { // int32 wrap if ( vsize < 0 || vsize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus(); setToBogus();
return; return;
@ -338,7 +340,7 @@ Locale::Locale( const char * newLanguage,
if ( newKeywords != nullptr) if ( newKeywords != nullptr)
{ {
ksize = (int32_t)uprv_strlen(newKeywords); ksize = static_cast<int32_t>(uprv_strlen(newKeywords));
if ( ksize < 0 || ksize > ULOC_STRING_LIMIT ) { if ( ksize < 0 || ksize > ULOC_STRING_LIMIT ) {
setToBogus(); setToBogus();
return; return;
@ -1200,8 +1202,8 @@ AliasReplacer::parseLanguageReplacement(
return; return;
} }
// We have multiple field so we have to allocate and parse // We have multiple field so we have to allocate and parse
CharString* str = new CharString( CharString* str =
replacement, (int32_t)uprv_strlen(replacement), status); new CharString(replacement, static_cast<int32_t>(uprv_strlen(replacement)), status);
LocalPointer<CharString> lpStr(str, status); LocalPointer<CharString> lpStr(str, status);
toBeFreed.adoptElement(lpStr.orphan(), status); toBeFreed.adoptElement(lpStr.orphan(), status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -1213,7 +1215,7 @@ AliasReplacer::parseLanguageReplacement(
*endOfField = '\0'; // null terminiate it. *endOfField = '\0'; // null terminiate it.
endOfField++; endOfField++;
const char* start = endOfField; const char* start = endOfField;
endOfField = (char*) uprv_strchr(start, '_'); endOfField = const_cast<char*>(uprv_strchr(start, '_'));
size_t len = 0; size_t len = 0;
if (endOfField == nullptr) { if (endOfField == nullptr) {
len = uprv_strlen(start); len = uprv_strlen(start);
@ -1228,7 +1230,7 @@ AliasReplacer::parseLanguageReplacement(
return; return;
} }
start = endOfField++; start = endOfField++;
endOfField = (char*)uprv_strchr(start, '_'); endOfField = const_cast<char*>(uprv_strchr(start, '_'));
if (endOfField == nullptr) { if (endOfField == nullptr) {
len = uprv_strlen(start); len = uprv_strlen(start);
} else { } else {
@ -1243,7 +1245,7 @@ AliasReplacer::parseLanguageReplacement(
return; return;
} }
start = endOfField++; start = endOfField++;
endOfField = (char*)uprv_strchr(start, '_'); endOfField = const_cast<char*>(uprv_strchr(start, '_'));
if (endOfField == nullptr) { if (endOfField == nullptr) {
len = uprv_strlen(start); len = uprv_strlen(start);
} else { } else {
@ -1285,7 +1287,7 @@ AliasReplacer::replaceLanguage(
variant_index++) { variant_index++) {
if (checkVariants) { if (checkVariants) {
U_ASSERT(variant_index < variant_size); U_ASSERT(variant_index < variant_size);
searchVariant = (const char*)(variants.elementAt(variant_index)); searchVariant = static_cast<const char*>(variants.elementAt(variant_index));
} }
if (searchVariant != nullptr && uprv_strlen(searchVariant) < 4) { if (searchVariant != nullptr && uprv_strlen(searchVariant) < 4) {
@ -1406,13 +1408,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
U_ASSERT(foundInReplacement[len] == ' ' || U_ASSERT(foundInReplacement[len] == ' ' ||
foundInReplacement[len] == '\0'); foundInReplacement[len] == '\0');
item.adoptInsteadAndCheckErrorCode( item.adoptInsteadAndCheckErrorCode(
new CharString(foundInReplacement, (int32_t)len, status), status); new CharString(foundInReplacement, static_cast<int32_t>(len), status), status);
} }
} }
if (item.isNull() && U_SUCCESS(status)) { if (item.isNull() && U_SUCCESS(status)) {
item.adoptInsteadAndCheckErrorCode( item.adoptInsteadAndCheckErrorCode(
new CharString(replacement, new CharString(replacement,
(int32_t)(firstSpace - replacement), status), status); static_cast<int32_t>(firstSpace - replacement), status), status);
} }
if (U_FAILURE(status)) { return false; } if (U_FAILURE(status)) { return false; }
replacedRegion = item->data(); replacedRegion = item->data();
@ -1454,7 +1456,7 @@ AliasReplacer::replaceVariant(UErrorCode& status)
} }
// Since we may have more than one variant, we need to loop through them. // Since we may have more than one variant, we need to loop through them.
for (int32_t i = 0; i < variants.size(); i++) { for (int32_t i = 0; i < variants.size(); i++) {
const char *variant = (const char*)(variants.elementAt(i)); const char* variant = static_cast<const char*>(variants.elementAt(i));
const char *replacement = data->variantMap().get(variant); const char *replacement = data->variantMap().get(variant);
if (replacement == nullptr) { if (replacement == nullptr) {
// Found no replacement data for this variant. // Found no replacement data for this variant.
@ -1496,7 +1498,7 @@ AliasReplacer::replaceSubdivision(
size_t len = (firstSpace != nullptr) ? size_t len = (firstSpace != nullptr) ?
(firstSpace - replacement) : uprv_strlen(replacement); (firstSpace - replacement) : uprv_strlen(replacement);
if (2 <= len && len <= 8) { if (2 <= len && len <= 8) {
output.append(replacement, (int32_t)len, status); output.append(replacement, static_cast<int32_t>(len), status);
if (2 == len) { if (2 == len) {
// Add 'zzzz' based on changes to UTS #35 for CLDR-14312. // Add 'zzzz' based on changes to UTS #35 for CLDR-14312.
output.append("zzzz", 4, status); output.append("zzzz", 4, status);
@ -1546,7 +1548,7 @@ AliasReplacer::replaceTransformedExtensions(
} }
const char* nextTKey = ultag_getTKeyStart(tvalue); const char* nextTKey = ultag_getTKeyStart(tvalue);
if (nextTKey != nullptr) { if (nextTKey != nullptr) {
*((char*)(nextTKey-1)) = '\0'; // NUL terminate tvalue *const_cast<char*>(nextTKey - 1) = '\0'; // NUL terminate tvalue
} }
tfields.insertElementAt((void*)tkey, tfields.size(), status); tfields.insertElementAt((void*)tkey, tfields.size(), status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -1561,17 +1563,17 @@ AliasReplacer::replaceTransformedExtensions(
if (output.length() > 0) { if (output.length() > 0) {
output.append('-', status); output.append('-', status);
} }
const char* tfield = (const char*) tfields.elementAt(i); const char* tfield = static_cast<const char*>(tfields.elementAt(i));
const char* tvalue = uprv_strchr(tfield, '-'); const char* tvalue = uprv_strchr(tfield, '-');
if (tvalue == nullptr) { if (tvalue == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return false; return false;
} }
// Split the "tkey-tvalue" pair string so that we can canonicalize the tvalue. // Split the "tkey-tvalue" pair string so that we can canonicalize the tvalue.
*((char*)tvalue++) = '\0'; // NUL terminate tkey *const_cast<char*>(tvalue++) = '\0'; // NUL terminate tkey
output.append(tfield, status).append('-', status); output.append(tfield, status).append('-', status);
const char* bcpTValue = ulocimp_toBcpType(tfield, tvalue, nullptr, nullptr); std::optional<std::string_view> bcpTValue = ulocimp_toBcpType(tfield, tvalue);
output.append((bcpTValue == nullptr) ? tvalue : bcpTValue, status); output.append(bcpTValue.has_value() ? *bcpTValue : tvalue, status);
} }
} }
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -1604,7 +1606,7 @@ AliasReplacer::outputToString(
int32_t variantsStart = out.length(); int32_t variantsStart = out.length();
for (int32_t i = 0; i < variants.size(); i++) { for (int32_t i = 0; i < variants.size(); i++) {
out.append(SEP_CHAR, status) out.append(SEP_CHAR, status)
.append((const char*)(variants.elementAt(i)), .append(static_cast<const char*>(variants.elementAt(i)),
status); status);
} }
T_CString_toUpperCase(out.data() + variantsStart); T_CString_toUpperCase(out.data() + variantsStart);
@ -1673,7 +1675,7 @@ AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status
int changed = 0; int changed = 0;
// A UVector to to hold CharString allocated by the replace* method // A UVector to to hold CharString allocated by the replace* method
// and freed when out of scope from his function. // and freed when out of scope from his function.
UVector stringsToBeFreed([](void *obj){ delete ((CharString*) obj); }, UVector stringsToBeFreed([](void *obj) { delete static_cast<CharString*>(obj); },
nullptr, 10, status); nullptr, 10, status);
while (U_SUCCESS(status)) { while (U_SUCCESS(status)) {
// Something wrong with the data cause looping here more than 10 times // Something wrong with the data cause looping here more than 10 times
@ -1866,14 +1868,14 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
uloc_canonicalize(localeID, fullName, sizeof(fullNameBuffer), &err) : uloc_canonicalize(localeID, fullName, sizeof(fullNameBuffer), &err) :
uloc_getName(localeID, fullName, sizeof(fullNameBuffer), &err); uloc_getName(localeID, fullName, sizeof(fullNameBuffer), &err);
if(err == U_BUFFER_OVERFLOW_ERROR || length >= (int32_t)sizeof(fullNameBuffer)) { if (err == U_BUFFER_OVERFLOW_ERROR || length >= static_cast<int32_t>(sizeof(fullNameBuffer))) {
U_ASSERT(baseName == nullptr); U_ASSERT(baseName == nullptr);
/*Go to heap for the fullName if necessary*/ /*Go to heap for the fullName if necessary*/
fullName = (char *)uprv_malloc(sizeof(char)*(length + 1)); char* newFullName = static_cast<char*>(uprv_malloc(sizeof(char) * (length + 1)));
if (fullName == nullptr) { if (newFullName == nullptr) {
fullName = fullNameBuffer;
break; // error: out of memory break; // error: out of memory
} }
fullName = newFullName;
err = U_ZERO_ERROR; err = U_ZERO_ERROR;
length = canonicalize ? length = canonicalize ?
uloc_canonicalize(localeID, fullName, length+1, &err) : uloc_canonicalize(localeID, fullName, length+1, &err) :
@ -1895,7 +1897,7 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
fieldIdx < UPRV_LENGTHOF(field)-1 && fieldIdx < UPRV_LENGTHOF(field)-1 &&
(at == nullptr || separator < at)) { (at == nullptr || separator < at)) {
field[fieldIdx] = separator + 1; field[fieldIdx] = separator + 1;
fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]); fieldLen[fieldIdx - 1] = static_cast<int32_t>(separator - field[fieldIdx - 1]);
fieldIdx++; fieldIdx++;
} }
// variant may contain @foo or .foo POSIX cruft; remove it // variant may contain @foo or .foo POSIX cruft; remove it
@ -1905,12 +1907,12 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
if (separator==nullptr || (sep2!=nullptr && separator > sep2)) { if (separator==nullptr || (sep2!=nullptr && separator > sep2)) {
separator = sep2; separator = sep2;
} }
fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]); fieldLen[fieldIdx - 1] = static_cast<int32_t>(separator - field[fieldIdx - 1]);
} else { } else {
fieldLen[fieldIdx-1] = length - (int32_t)(field[fieldIdx-1] - fullName); fieldLen[fieldIdx - 1] = length - static_cast<int32_t>(field[fieldIdx - 1] - fullName);
} }
if (fieldLen[0] >= (int32_t)(sizeof(language))) if (fieldLen[0] >= static_cast<int32_t>(sizeof(language)))
{ {
break; // error: the language field is too long break; // error: the language field is too long
} }
@ -1941,7 +1943,7 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
if (fieldLen[variantField] > 0) { if (fieldLen[variantField] > 0) {
/* We have a variant */ /* We have a variant */
variantBegin = (int32_t)(field[variantField] - fullName); variantBegin = static_cast<int32_t>(field[variantField] - fullName);
} }
err = U_ZERO_ERROR; err = U_ZERO_ERROR;
@ -1991,12 +1993,13 @@ Locale::initBaseName(UErrorCode &status) {
const char *eqPtr = uprv_strchr(fullName, '='); const char *eqPtr = uprv_strchr(fullName, '=');
if (atPtr && eqPtr && atPtr < eqPtr) { if (atPtr && eqPtr && atPtr < eqPtr) {
// Key words exist. // Key words exist.
int32_t baseNameLength = (int32_t)(atPtr - fullName); int32_t baseNameLength = static_cast<int32_t>(atPtr - fullName);
baseName = (char *)uprv_malloc(baseNameLength + 1); char* newBaseName = static_cast<char*>(uprv_malloc(baseNameLength + 1));
if (baseName == nullptr) { if (newBaseName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
return; return;
} }
baseName = newBaseName;
uprv_strncpy(baseName, fullName, baseNameLength); uprv_strncpy(baseName, fullName, baseNameLength);
baseName[baseNameLength] = 0; baseName[baseNameLength] = 0;
@ -2434,7 +2437,7 @@ public:
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
return new KeywordEnumeration( return new KeywordEnumeration(
keywords.data(), keywords.length(), keywords.data(), keywords.length(),
(int32_t)(current - keywords.data()), status); static_cast<int32_t>(current - keywords.data()), status);
} }
virtual int32_t count(UErrorCode& status) const override { virtual int32_t count(UErrorCode& status) const override {
@ -2453,7 +2456,7 @@ public:
int32_t len; int32_t len;
if(U_SUCCESS(status) && *current != 0) { if(U_SUCCESS(status) && *current != 0) {
result = current; result = current;
len = (int32_t)uprv_strlen(current); len = static_cast<int32_t>(uprv_strlen(current));
current += len+1; current += len+1;
if(resultLength != nullptr) { if(resultLength != nullptr) {
*resultLength = len; *resultLength = len;
@ -2596,13 +2599,7 @@ Locale::getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& sta
return; return;
} }
// TODO: Remove the need for a const char* to a NUL terminated buffer. ulocimp_getKeywordValue(fullName, keywordName, sink, status);
const CharString keywordName_nul(keywordName, status);
if (U_FAILURE(status)) {
return;
}
ulocimp_getKeywordValue(fullName, keywordName_nul.data(), sink, status);
} }
void void
@ -2613,75 +2610,26 @@ Locale::getUnicodeKeywordValue(StringPiece keywordName,
return; return;
} }
// TODO: Remove the need for a const char* to a NUL terminated buffer. std::optional<std::string_view> legacy_key = ulocimp_toLegacyKeyWithFallback(keywordName);
const CharString keywordName_nul(keywordName, status); if (!legacy_key.has_value()) {
if (U_FAILURE(status)) {
return;
}
const char* legacy_key = uloc_toLegacyKey(keywordName_nul.data());
if (legacy_key == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
} }
auto legacy_value = getKeywordValue<CharString>(legacy_key, status); auto legacy_value = getKeywordValue<CharString>(*legacy_key, status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
return; return;
} }
const char* unicode_value = uloc_toUnicodeLocaleType( std::optional<std::string_view> unicode_value =
keywordName_nul.data(), legacy_value.data()); ulocimp_toBcpTypeWithFallback(keywordName, legacy_value.toStringPiece());
if (!unicode_value.has_value()) {
if (unicode_value == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
} }
sink.Append(unicode_value, static_cast<int32_t>(uprv_strlen(unicode_value))); sink.Append(unicode_value->data(), static_cast<int32_t>(unicode_value->size()));
}
void
Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status)
{
if (U_FAILURE(status)) {
return;
}
if (status == U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
}
int32_t bufferLength = uprv_max((int32_t)(uprv_strlen(fullName) + 1), ULOC_FULLNAME_CAPACITY);
int32_t newLength = uloc_setKeywordValue(keywordName, keywordValue, fullName,
bufferLength, &status) + 1;
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
/* Handle the case the current buffer is not enough to hold the new id */
if (status == U_BUFFER_OVERFLOW_ERROR) {
U_ASSERT(newLength > bufferLength);
char* newFullName = (char *)uprv_malloc(newLength);
if (newFullName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_strcpy(newFullName, fullName);
if (fullName != fullNameBuffer) {
// if full Name is already on the heap, need to free it.
uprv_free(fullName);
if (baseName == fullName) {
baseName = newFullName; // baseName should not point to freed memory.
}
}
fullName = newFullName;
status = U_ZERO_ERROR;
uloc_setKeywordValue(keywordName, keywordValue, fullName, newLength, &status);
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
} else {
U_ASSERT(newLength <= bufferLength);
}
if (U_SUCCESS(status) && baseName == fullName) {
// May have added the first keyword, meaning that the fullName is no longer also the baseName.
initBaseName(status);
}
} }
void void
@ -2689,10 +2637,60 @@ Locale::setKeywordValue(StringPiece keywordName,
StringPiece keywordValue, StringPiece keywordValue,
UErrorCode& status) { UErrorCode& status) {
if (U_FAILURE(status)) { return; } if (U_FAILURE(status)) { return; }
// TODO: Remove the need for a const char* to a NUL terminated buffer. if (keywordName.empty()) {
const CharString keywordName_nul(keywordName, status); status = U_ILLEGAL_ARGUMENT_ERROR;
const CharString keywordValue_nul(keywordValue, status); return;
setKeywordValue(keywordName_nul.data(), keywordValue_nul.data(), status); }
if (status == U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
}
int32_t length = static_cast<int32_t>(uprv_strlen(fullName));
int32_t capacity = fullName == fullNameBuffer ? ULOC_FULLNAME_CAPACITY : length + 1;
const char* start = locale_getKeywordsStart(fullName);
int32_t offset = start == nullptr ? length : start - fullName;
for (;;) {
// Remove -1 from the capacity so that this function can guarantee NUL termination.
CheckedArrayByteSink sink(fullName + offset, capacity - offset - 1);
int32_t reslen = ulocimp_setKeywordValue(
{fullName + offset, static_cast<std::string_view::size_type>(length - offset)},
keywordName,
keywordValue,
sink,
status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
capacity = reslen + offset + 1;
char* newFullName = static_cast<char*>(uprv_malloc(capacity));
if (newFullName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_memcpy(newFullName, fullName, length + 1);
if (fullName != fullNameBuffer) {
if (baseName == fullName) {
baseName = newFullName; // baseName should not point to freed memory.
}
// if fullName is already on the heap, need to free it.
uprv_free(fullName);
}
fullName = newFullName;
status = U_ZERO_ERROR;
continue;
}
if (U_FAILURE(status)) { return; }
u_terminateChars(fullName, capacity, reslen + offset, &status);
break;
}
if (baseName == fullName) {
// May have added the first keyword, meaning that the fullName is no longer also the baseName.
initBaseName(status);
}
} }
void void
@ -2703,32 +2701,25 @@ Locale::setUnicodeKeywordValue(StringPiece keywordName,
return; return;
} }
// TODO: Remove the need for a const char* to a NUL terminated buffer. std::optional<std::string_view> legacy_key = ulocimp_toLegacyKeyWithFallback(keywordName);
const CharString keywordName_nul(keywordName, status); if (!legacy_key.has_value()) {
const CharString keywordValue_nul(keywordValue, status);
if (U_FAILURE(status)) {
return;
}
const char* legacy_key = uloc_toLegacyKey(keywordName_nul.data());
if (legacy_key == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
} }
const char* legacy_value = nullptr; std::string_view value;
if (!keywordValue_nul.isEmpty()) { if (!keywordValue.empty()) {
legacy_value = std::optional<std::string_view> legacy_value =
uloc_toLegacyType(keywordName_nul.data(), keywordValue_nul.data()); ulocimp_toLegacyTypeWithFallback(keywordName, keywordValue);
if (!legacy_value.has_value()) {
if (legacy_value == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
} }
value = *legacy_value;
} }
setKeywordValue(legacy_key, legacy_value, status); setKeywordValue(*legacy_key, value, status);
} }
const char * const char *

View File

@ -19,6 +19,7 @@
* that then do not depend on resource bundle code and likely-subtags data. * that then do not depend on resource bundle code and likely-subtags data.
*/ */
#include <string_view>
#include <utility> #include <utility>
#include "unicode/bytestream.h" #include "unicode/bytestream.h"
@ -170,7 +171,7 @@ _uloc_addLikelySubtags(const char* localeID,
return; return;
} }
int32_t trailingLength = (int32_t)uprv_strlen(trailing); int32_t trailingLength = static_cast<int32_t>(uprv_strlen(trailing));
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err); const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err);
if (U_FAILURE(err)) { if (U_FAILURE(err)) {
@ -193,11 +194,11 @@ _uloc_addLikelySubtags(const char* localeID,
} }
createTagStringWithAlternates( createTagStringWithAlternates(
language, language,
(int32_t)uprv_strlen(language), static_cast<int32_t>(uprv_strlen(language)),
lsr.script, lsr.script,
(int32_t)uprv_strlen(lsr.script), static_cast<int32_t>(uprv_strlen(lsr.script)),
lsr.region, lsr.region,
(int32_t)uprv_strlen(lsr.region), static_cast<int32_t>(uprv_strlen(lsr.region)),
variant.data(), variant.data(),
variant.length(), variant.length(),
trailing, trailing,
@ -235,7 +236,7 @@ _uloc_minimizeSubtags(const char* localeID,
return; return;
} }
int32_t trailingLength = (int32_t)uprv_strlen(trailing); int32_t trailingLength = static_cast<int32_t>(uprv_strlen(trailing));
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err); const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err);
if (U_FAILURE(err)) { if (U_FAILURE(err)) {
@ -256,11 +257,11 @@ _uloc_minimizeSubtags(const char* localeID,
} }
createTagStringWithAlternates( createTagStringWithAlternates(
language, language,
(int32_t)uprv_strlen(language), static_cast<int32_t>(uprv_strlen(language)),
lsr.script, lsr.script,
(int32_t)uprv_strlen(lsr.script), static_cast<int32_t>(uprv_strlen(lsr.script)),
lsr.region, lsr.region,
(int32_t)uprv_strlen(lsr.region), static_cast<int32_t>(uprv_strlen(lsr.region)),
variant.data(), variant.data(),
variant.length(), variant.length(),
trailing, trailing,
@ -388,21 +389,32 @@ U_NAMESPACE_END
namespace { namespace {
icu::CharString icu::CharString
GetRegionFromKey(const char* localeID, const char* key, UErrorCode& status) { GetRegionFromKey(const char* localeID, std::string_view key, UErrorCode& status) {
icu::CharString result; icu::CharString result;
// First check for keyword value // First check for keyword value
icu::CharString kw = ulocimp_getKeywordValue(localeID, key, status); icu::CharString kw = ulocimp_getKeywordValue(localeID, key, status);
int32_t len = kw.length(); int32_t len = kw.length();
if (U_SUCCESS(status) && len >= 3 && len <= 7) { // In UTS35
// chop off the subdivision code (which will generally be "zzzz" anyway) // type = alphanum{3,8} (sep alphanum{3,8})* ;
const char* const data = kw.data(); // so we know the subdivision must fit the type already.
if (uprv_isASCIILetter(data[0])) { //
result.append(uprv_toupper(data[0]), status); // unicode_subdivision_id = unicode_region_subtag unicode_subdivision_suffix ;
result.append(uprv_toupper(data[1]), status); // unicode_region_subtag = (alpha{2} | digit{3}) ;
} else { // unicode_subdivision_suffix = alphanum{1,4} ;
// assume three-digit region code // But we also know there are no id in start with digit{3} in
result.append(data, 3, status); // https://github.com/unicode-org/cldr/blob/main/common/validity/subdivision.xml
// Therefore we can simplify as
// unicode_subdivision_id = alpha{2} alphanum{1,4}
//
// and only need to accept/reject the code based on the alpha{2} and the length.
if (U_SUCCESS(status) && len >= 3 && len <= 6 &&
uprv_isASCIILetter(kw[0]) && uprv_isASCIILetter(kw[1])) {
// Additional Check
static icu::RegionValidateMap valid;
const char region[] = {kw[0], kw[1], '\0'};
if (valid.isSet(region)) {
result.append(uprv_toupper(kw[0]), status);
result.append(uprv_toupper(kw[1]), status);
} }
} }
return result; return result;
@ -435,3 +447,55 @@ ulocimp_getRegionForSupplementalData(const char *localeID, bool inferRegion,
return rgBuf; return rgBuf;
} }
namespace {
// The following data is generated by unit test code inside
// test/intltest/regiontst.cpp from the resource data while
// the test failed.
const uint32_t gValidRegionMap[] = {
0xeedf597c, 0xdeddbdef, 0x15943f3f, 0x0e00d580,
0xb0095c00, 0x0015fb9f, 0x781c068d, 0x0340400f,
0xf42b1d00, 0xfd4f8141, 0x25d7fffc, 0x0100084b,
0x538f3c40, 0x40000001, 0xfdf15100, 0x9fbb7ae7,
0x0410419a, 0x00408557, 0x00004002, 0x00100001,
0x00400408, 0x00000001,
};
} // namespace
//
U_NAMESPACE_BEGIN
RegionValidateMap::RegionValidateMap() {
uprv_memcpy(map, gValidRegionMap, sizeof(map));
}
RegionValidateMap::~RegionValidateMap() {
}
bool RegionValidateMap::isSet(const char* region) const {
int32_t index = value(region);
if (index < 0) {
return false;
}
return 0 != (map[index / 32] & (1L << (index % 32)));
}
bool RegionValidateMap::equals(const RegionValidateMap& that) const {
return uprv_memcmp(map, that.map, sizeof(map)) == 0;
}
// The code transform two letter a-z to a integer valued between -1, 26x26.
// -1 indicate the region is outside the range of two letter a-z
// the rest of value is between 0 and 676 (= 26x26) and used as an index
// the the bigmap in map. The map is an array of 22 int32_t.
// since 32x21 < 676/32 < 32x22 we store this 676 bits bitmap into 22 int32_t.
int32_t RegionValidateMap::value(const char* region) const {
if (uprv_isASCIILetter(region[0]) && uprv_isASCIILetter(region[1]) &&
region[2] == '\0') {
return (uprv_toupper(region[0])-'A') * 26 +
(uprv_toupper(region[1])-'A');
}
return -1;
}
U_NAMESPACE_END

View File

@ -564,47 +564,40 @@ LSR LikelySubtags::makeMaximizedLsr(const char *language, const char *script, co
// Handle pseudolocales like en-XA, ar-XB, fr-PSCRACK. // Handle pseudolocales like en-XA, ar-XB, fr-PSCRACK.
// They should match only themselves, // They should match only themselves,
// not other locales with what looks like the same language and script subtags. // not other locales with what looks like the same language and script subtags.
char c1; if (!returnInputIfUnmatch) {
if (region[0] == 'X' && (c1 = region[1]) != 0 && region[2] == 0) { char c1;
switch (c1) { if (region[0] == 'X' && (c1 = region[1]) != 0 && region[2] == 0) {
case 'A': switch (c1) {
if (returnInputIfUnmatch) { case 'A':
return LSR(language, script, region, LSR::EXPLICIT_LSR); return LSR(PSEUDO_ACCENTS_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'B':
return LSR(PSEUDO_BIDI_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'C':
return LSR(PSEUDO_CRACKED_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
default: // normal locale
break;
} }
return LSR(PSEUDO_ACCENTS_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'B':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_BIDI_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'C':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_CRACKED_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
default: // normal locale
break;
} }
}
if (variant[0] == 'P' && variant[1] == 'S') { if (variant[0] == 'P' && variant[1] == 'S') {
int32_t lsrFlags = *region == 0 ? int32_t lsrFlags = *region == 0 ?
LSR::EXPLICIT_LANGUAGE | LSR::EXPLICIT_SCRIPT : LSR::EXPLICIT_LSR; LSR::EXPLICIT_LANGUAGE | LSR::EXPLICIT_SCRIPT : LSR::EXPLICIT_LSR;
if (uprv_strcmp(variant, "PSACCENT") == 0) { if (uprv_strcmp(variant, "PSACCENT") == 0) {
return LSR(PSEUDO_ACCENTS_PREFIX, language, script, return LSR(PSEUDO_ACCENTS_PREFIX, language, script,
*region == 0 ? "XA" : region, lsrFlags, errorCode); *region == 0 ? "XA" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSBIDI") == 0) { } else if (uprv_strcmp(variant, "PSBIDI") == 0) {
return LSR(PSEUDO_BIDI_PREFIX, language, script, return LSR(PSEUDO_BIDI_PREFIX, language, script,
*region == 0 ? "XB" : region, lsrFlags, errorCode); *region == 0 ? "XB" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSCRACK") == 0) { } else if (uprv_strcmp(variant, "PSCRACK") == 0) {
return LSR(PSEUDO_CRACKED_PREFIX, language, script, return LSR(PSEUDO_CRACKED_PREFIX, language, script,
*region == 0 ? "XC" : region, lsrFlags, errorCode); *region == 0 ? "XC" : region, lsrFlags, errorCode);
}
// else normal locale
} }
// else normal locale } // end of if (!returnInputIfUnmatch)
}
language = getCanonical(languageAliases, language); language = getCanonical(languageAliases, language);
// (We have no script mappings.) // (We have no script mappings.)
@ -616,9 +609,9 @@ LSR LikelySubtags::maximize(const char *language, const char *script, const char
bool returnInputIfUnmatch, bool returnInputIfUnmatch,
UErrorCode &errorCode) const { UErrorCode &errorCode) const {
if (U_FAILURE(errorCode)) { return {}; } if (U_FAILURE(errorCode)) { return {}; }
return maximize({language, (int32_t)uprv_strlen(language)}, return maximize({language, static_cast<int32_t>(uprv_strlen(language))},
{script, (int32_t)uprv_strlen(script)}, {script, static_cast<int32_t>(uprv_strlen(script))},
{region, (int32_t)uprv_strlen(region)}, {region, static_cast<int32_t>(uprv_strlen(region))},
returnInputIfUnmatch, returnInputIfUnmatch,
errorCode); errorCode);
} }

View File

@ -979,7 +979,7 @@ getHostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode& status)
if (U_FAILURE(status)) { return locmap_root->hostID; } if (U_FAILURE(status)) { return locmap_root->hostID; }
int32_t bestIdx = 0; int32_t bestIdx = 0;
int32_t bestIdxDiff = 0; int32_t bestIdxDiff = 0;
int32_t posixIDlen = (int32_t)uprv_strlen(posixID); int32_t posixIDlen = static_cast<int32_t>(uprv_strlen(posixID));
uint32_t idx; uint32_t idx;
for (idx = 0; idx < this_0->numRegions; idx++ ) { for (idx = 0; idx < this_0->numRegions; idx++ ) {

View File

@ -171,7 +171,7 @@ LocaleUtility::initLocaleFromName(const UnicodeString& id, Locale& result)
prev = 0; prev = 0;
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
do { do {
i = id.indexOf((char16_t)0x40, prev); i = id.indexOf(static_cast<char16_t>(0x40), prev);
if(i < 0) { if(i < 0) {
// no @ between prev and the rest of the string // no @ between prev and the rest of the string
buffer.appendInvariantChars(id.tempSubString(prev), status); buffer.appendInvariantChars(id.tempSubString(prev), status);
@ -224,7 +224,7 @@ LocaleUtility::getAvailableLocaleNames(const UnicodeString& bundleID)
Hashtable* htp; Hashtable* htp;
umtx_lock(nullptr); umtx_lock(nullptr);
htp = (Hashtable*) cache->get(bundleID); htp = static_cast<Hashtable*>(cache->get(bundleID));
umtx_unlock(nullptr); umtx_unlock(nullptr);
if (htp == nullptr) { if (htp == nullptr) {

View File

@ -164,7 +164,7 @@ public:
Array1D() : memory_(nullptr), data_(nullptr), d1_(0) {} Array1D() : memory_(nullptr), data_(nullptr), d1_(0) {}
Array1D(int32_t d1, UErrorCode &status) Array1D(int32_t d1, UErrorCode &status)
: memory_(uprv_malloc(d1 * sizeof(float))), : memory_(uprv_malloc(d1 * sizeof(float))),
data_((float*)memory_), d1_(d1) { data_(static_cast<float*>(memory_)), d1_(d1) {
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
if (memory_ == nullptr) { if (memory_ == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
@ -301,7 +301,7 @@ public:
Array2D() : memory_(nullptr), data_(nullptr), d1_(0), d2_(0) {} Array2D() : memory_(nullptr), data_(nullptr), d1_(0), d2_(0) {}
Array2D(int32_t d1, int32_t d2, UErrorCode &status) Array2D(int32_t d1, int32_t d2, UErrorCode &status)
: memory_(uprv_malloc(d1 * d2 * sizeof(float))), : memory_(uprv_malloc(d1 * d2 * sizeof(float))),
data_((float*)memory_), d1_(d1), d2_(d2) { data_(static_cast<float*>(memory_)), d1_(d1), d2_(d2) {
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
if (memory_ == nullptr) { if (memory_ == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
@ -526,11 +526,11 @@ void CodePointsVectorizer::vectorize(
int32_t current; int32_t current;
char16_t str[2] = {0, 0}; char16_t str[2] = {0, 0};
while (U_SUCCESS(status) && while (U_SUCCESS(status) &&
(current = (int32_t)utext_getNativeIndex(text)) < endPos) { (current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos) {
// Since the LSTMBreakEngine is currently only accept chars in BMP, // Since the LSTMBreakEngine is currently only accept chars in BMP,
// we can ignore the possibility of hitting supplementary code // we can ignore the possibility of hitting supplementary code
// point. // point.
str[0] = (char16_t) utext_next32(text); str[0] = static_cast<char16_t>(utext_next32(text));
U_ASSERT(!U_IS_SURROGATE(str[0])); U_ASSERT(!U_IS_SURROGATE(str[0]));
offsets.addElement(current, status); offsets.addElement(current, status);
indices.addElement(stringToIndex(str), status); indices.addElement(stringToIndex(str), status);
@ -733,7 +733,7 @@ LSTMBreakEngine::divideUpDictionaryRange( UText *text,
#endif // LSTM_DEBUG #endif // LSTM_DEBUG
// current = argmax(logp) // current = argmax(logp)
LSTMClass current = (LSTMClass)logp.maxIndex(); LSTMClass current = static_cast<LSTMClass>(logp.maxIndex());
// BIES logic. // BIES logic.
if (current == BEGIN || current == SINGLE) { if (current == BEGIN || current == SINGLE) {
if (i != 0) { if (i != 0) {

View File

@ -351,7 +351,7 @@ MessagePattern::autoQuoteApostropheDeep() const {
for(int32_t i=count; i>0;) { for(int32_t i=count; i>0;) {
const Part &part=getPart(--i); const Part &part=getPart(--i);
if(part.getType()==UMSGPAT_PART_TYPE_INSERT_CHAR) { if(part.getType()==UMSGPAT_PART_TYPE_INSERT_CHAR) {
modified.insert(part.index, (char16_t)part.value); modified.insert(part.index, static_cast<char16_t>(part.value));
} }
} }
return modified; return modified;
@ -437,7 +437,7 @@ MessagePattern::parseMessage(int32_t index, int32_t msgStartLength,
if(U_FAILURE(errorCode)) { if(U_FAILURE(errorCode)) {
return 0; return 0;
} }
if(nestingLevel>Part::MAX_VALUE) { if(nestingLevel>Part::MAX_NESTED_LEVELS) {
errorCode=U_INDEX_OUTOFBOUNDS_ERROR; errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
return 0; return 0;
} }
@ -628,7 +628,7 @@ MessagePattern::parseArg(int32_t index, int32_t argStartLength, int32_t nestingL
} }
} }
// change the ARG_START type from NONE to argType // change the ARG_START type from NONE to argType
partsList->a[argStart].value=(int16_t)argType; partsList->a[argStart].value = static_cast<int16_t>(argType);
if(argType==UMSGPAT_ARG_TYPE_SIMPLE) { if(argType==UMSGPAT_ARG_TYPE_SIMPLE) {
addPart(UMSGPAT_PART_TYPE_ARG_TYPE, typeIndex, length, 0, errorCode); addPart(UMSGPAT_PART_TYPE_ARG_TYPE, typeIndex, length, 0, errorCode);
} }
@ -980,13 +980,13 @@ MessagePattern::parseDouble(int32_t start, int32_t limit, UBool allowInfinity,
} }
// Let Double.parseDouble() throw a NumberFormatException. // Let Double.parseDouble() throw a NumberFormatException.
char numberChars[128]; char numberChars[128];
int32_t capacity=(int32_t)sizeof(numberChars); int32_t capacity = static_cast<int32_t>(sizeof(numberChars));
int32_t length=limit-start; int32_t length=limit-start;
if(length>=capacity) { if(length>=capacity) {
break; // number too long break; // number too long
} }
msg.extract(start, length, numberChars, capacity, US_INV); msg.extract(start, length, numberChars, capacity, US_INV);
if((int32_t)uprv_strlen(numberChars)<length) { if (static_cast<int32_t>(uprv_strlen(numberChars)) < length) {
break; // contains non-invariant character that was turned into NUL break; // contains non-invariant character that was turned into NUL
} }
char *end; char *end;
@ -1006,7 +1006,7 @@ MessagePattern::skipWhiteSpace(int32_t index) {
const char16_t *s=msg.getBuffer(); const char16_t *s=msg.getBuffer();
int32_t msgLength=msg.length(); int32_t msgLength=msg.length();
const char16_t *t=PatternProps::skipWhiteSpace(s+index, msgLength-index); const char16_t *t=PatternProps::skipWhiteSpace(s+index, msgLength-index);
return (int32_t)(t-s); return static_cast<int32_t>(t - s);
} }
int32_t int32_t
@ -1014,7 +1014,7 @@ MessagePattern::skipIdentifier(int32_t index) {
const char16_t *s=msg.getBuffer(); const char16_t *s=msg.getBuffer();
int32_t msgLength=msg.length(); int32_t msgLength=msg.length();
const char16_t *t=PatternProps::skipIdentifier(s+index, msgLength-index); const char16_t *t=PatternProps::skipIdentifier(s+index, msgLength-index);
return (int32_t)(t-s); return static_cast<int32_t>(t - s);
} }
int32_t int32_t
@ -1105,8 +1105,8 @@ MessagePattern::addPart(UMessagePatternPartType type, int32_t index, int32_t len
Part &part=partsList->a[partsLength++]; Part &part=partsList->a[partsLength++];
part.type=type; part.type=type;
part.index=index; part.index=index;
part.length=(uint16_t)length; part.length = static_cast<uint16_t>(length);
part.value=(int16_t)value; part.value = static_cast<int16_t>(value);
part.limitPartIndex=0; part.limitPartIndex=0;
} }
} }

View File

@ -57,12 +57,12 @@ int32_t MlBreakEngine::divideUpRange(UText *inText, int32_t rangeStart, int32_t
// moving forward, finally the last six values in the indexList are // moving forward, finally the last six values in the indexList are
// [length-4, length-3, length-2, length-1, -1, -1]. The "+4" here means four extra "-1". // [length-4, length-3, length-2, length-1, -1, -1]. The "+4" here means four extra "-1".
int32_t indexSize = codePointLength + 4; int32_t indexSize = codePointLength + 4;
int32_t *indexList = (int32_t *)uprv_malloc(indexSize * sizeof(int32_t)); LocalMemory<int32_t> indexList(static_cast<int32_t*>(uprv_malloc(indexSize * sizeof(int32_t))));
if (indexList == nullptr) { if (indexList.isNull()) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
return 0; return 0;
} }
int32_t numCodeUnits = initIndexList(inString, indexList, status); int32_t numCodeUnits = initIndexList(inString, indexList.getAlias(), status);
// Add a break for the start. // Add a break for the start.
boundary.addElement(0, status); boundary.addElement(0, status);
@ -71,13 +71,12 @@ int32_t MlBreakEngine::divideUpRange(UText *inText, int32_t rangeStart, int32_t
for (int32_t idx = 0; idx + 1 < codePointLength && U_SUCCESS(status); idx++) { for (int32_t idx = 0; idx + 1 < codePointLength && U_SUCCESS(status); idx++) {
numBreaks = numBreaks =
evaluateBreakpoint(inString, indexList, idx, numCodeUnits, numBreaks, boundary, status); evaluateBreakpoint(inString, indexList.getAlias(), idx, numCodeUnits, numBreaks, boundary, status);
if (idx + 4 < codePointLength) { if (idx + 4 < codePointLength) {
indexList[idx + 6] = numCodeUnits; indexList[idx + 6] = numCodeUnits;
numCodeUnits += U16_LENGTH(inString.char32At(indexList[idx + 6])); numCodeUnits += U16_LENGTH(inString.char32At(indexList[idx + 6]));
} }
} }
uprv_free(indexList);
if (U_FAILURE(status)) return 0; if (U_FAILURE(status)) return 0;

File diff suppressed because it is too large Load Diff

View File

@ -174,7 +174,7 @@ public:
errorCode=U_ILLEGAL_ARGUMENT_ERROR; errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0; return 0;
} }
return (int32_t)(spanQuickCheckYes(sArray, sArray+s.length(), errorCode)-sArray); return static_cast<int32_t>(spanQuickCheckYes(sArray, sArray + s.length(), errorCode) - sArray);
} }
virtual const char16_t * virtual const char16_t *
spanQuickCheckYes(const char16_t *src, const char16_t *limit, UErrorCode &errorCode) const = 0; spanQuickCheckYes(const char16_t *src, const char16_t *limit, UErrorCode &errorCode) const = 0;

View File

@ -380,8 +380,8 @@ normalizeSecondAndAppend(const UNormalizer2 *norm2,
firstLength=firstString.length(); // In case it was -1. firstLength=firstString.length(); // In case it was -1.
// secondLength==0: Nothing to do, and n2wi->normalizeAndAppend(nullptr, nullptr, buffer, ...) would crash. // secondLength==0: Nothing to do, and n2wi->normalizeAndAppend(nullptr, nullptr, buffer, ...) would crash.
if(secondLength!=0) { if(secondLength!=0) {
const Normalizer2 *n2=(const Normalizer2 *)norm2; const Normalizer2* n2 = reinterpret_cast<const Normalizer2*>(norm2);
const Normalizer2WithImpl *n2wi=dynamic_cast<const Normalizer2WithImpl *>(n2); const Normalizer2WithImpl* n2wi = dynamic_cast<const Normalizer2WithImpl*>(n2);
if(n2wi!=nullptr) { if(n2wi!=nullptr) {
// Avoid duplicate argument checking and support NUL-terminated src. // Avoid duplicate argument checking and support NUL-terminated src.
UnicodeString safeMiddle; UnicodeString safeMiddle;

View File

@ -53,9 +53,9 @@ namespace {
*/ */
inline uint8_t leadByteForCP(UChar32 c) { inline uint8_t leadByteForCP(UChar32 c) {
if (c <= 0x7f) { if (c <= 0x7f) {
return (uint8_t)c; return static_cast<uint8_t>(c);
} else if (c <= 0x7ff) { } else if (c <= 0x7ff) {
return (uint8_t)(0xc0+(c>>6)); return static_cast<uint8_t>(0xc0 + (c >> 6));
} else { } else {
// Should not occur because ccc(U+0300)!=0. // Should not occur because ccc(U+0300)!=0.
return 0xe0; return 0xe0;
@ -82,7 +82,7 @@ UChar32 codePointFromValidUTF8(const uint8_t *cpStart, const uint8_t *cpLimit) {
return ((c&0x1f)<<6) | (cpStart[1]&0x3f); return ((c&0x1f)<<6) | (cpStart[1]&0x3f);
case 3: case 3:
// no need for (c&0xf) because the upper bits are truncated after <<12 in the cast to (char16_t) // no need for (c&0xf) because the upper bits are truncated after <<12 in the cast to (char16_t)
return (char16_t)((c<<12) | ((cpStart[1]&0x3f)<<6) | (cpStart[2]&0x3f)); return static_cast<char16_t>((c << 12) | ((cpStart[1] & 0x3f) << 6) | (cpStart[2] & 0x3f));
case 4: case 4:
return ((c&7)<<18) | ((cpStart[1]&0x3f)<<12) | ((cpStart[2]&0x3f)<<6) | (cpStart[3]&0x3f); return ((c&7)<<18) | ((cpStart[1]&0x3f)<<12) | ((cpStart[2]&0x3f)<<6) | (cpStart[3]&0x3f);
default: default:
@ -100,8 +100,8 @@ UChar32 previousHangulOrJamo(const uint8_t *start, const uint8_t *p) {
uint8_t l = *p; uint8_t l = *p;
uint8_t t1, t2; uint8_t t1, t2;
if (0xe1 <= l && l <= 0xed && if (0xe1 <= l && l <= 0xed &&
(t1 = (uint8_t)(p[1] - 0x80)) <= 0x3f && (t1 = static_cast<uint8_t>(p[1] - 0x80)) <= 0x3f &&
(t2 = (uint8_t)(p[2] - 0x80)) <= 0x3f && (t2 = static_cast<uint8_t>(p[2] - 0x80)) <= 0x3f &&
(l < 0xed || t1 <= 0x1f)) { (l < 0xed || t1 <= 0x1f)) {
return ((l & 0xf) << 12) | (t1 << 6) | t2; return ((l & 0xf) << 12) | (t1 << 6) | t2;
} }
@ -125,7 +125,7 @@ int32_t getJamoTMinusBase(const uint8_t *src, const uint8_t *limit) {
} }
} else if (src[1] == 0x87) { } else if (src[1] == 0x87) {
uint8_t t = src[2]; uint8_t t = src[2];
if ((int8_t)t <= (int8_t)0x82u) { if (static_cast<int8_t>(t) <= static_cast<int8_t>(0x82u)) {
return t - (0xa7 - 0x40); return t - (0xa7 - 0x40);
} }
} }
@ -138,10 +138,10 @@ appendCodePointDelta(const uint8_t *cpStart, const uint8_t *cpLimit, int32_t del
ByteSink &sink, Edits *edits) { ByteSink &sink, Edits *edits) {
char buffer[U8_MAX_LENGTH]; char buffer[U8_MAX_LENGTH];
int32_t length; int32_t length;
int32_t cpLength = (int32_t)(cpLimit - cpStart); int32_t cpLength = static_cast<int32_t>(cpLimit - cpStart);
if (cpLength == 1) { if (cpLength == 1) {
// The builder makes ASCII map to ASCII. // The builder makes ASCII map to ASCII.
buffer[0] = (uint8_t)(*cpStart + delta); buffer[0] = static_cast<uint8_t>(*cpStart + delta);
length = 1; length = 1;
} else { } else {
int32_t trail = *(cpLimit-1) + delta; int32_t trail = *(cpLimit-1) + delta;
@ -150,7 +150,7 @@ appendCodePointDelta(const uint8_t *cpStart, const uint8_t *cpLimit, int32_t del
--cpLimit; --cpLimit;
length = 0; length = 0;
do { buffer[length++] = *cpStart++; } while (cpStart < cpLimit); do { buffer[length++] = *cpStart++; } while (cpStart < cpLimit);
buffer[length++] = (uint8_t)trail; buffer[length++] = static_cast<uint8_t>(trail);
} else { } else {
// Decode the code point, add the delta, re-encode. // Decode the code point, add the delta, re-encode.
UChar32 c = codePointFromValidUTF8(cpStart, cpLimit) + delta; UChar32 c = codePointFromValidUTF8(cpStart, cpLimit) + delta;
@ -205,16 +205,16 @@ UBool ReorderingBuffer::init(int32_t destCapacity, UErrorCode &errorCode) {
} }
UBool ReorderingBuffer::equals(const char16_t *otherStart, const char16_t *otherLimit) const { UBool ReorderingBuffer::equals(const char16_t *otherStart, const char16_t *otherLimit) const {
int32_t length=(int32_t)(limit-start); int32_t length = static_cast<int32_t>(limit - start);
return return
length==(int32_t)(otherLimit-otherStart) && length == static_cast<int32_t>(otherLimit - otherStart) &&
0==u_memcmp(start, otherStart, length); 0==u_memcmp(start, otherStart, length);
} }
UBool ReorderingBuffer::equals(const uint8_t *otherStart, const uint8_t *otherLimit) const { UBool ReorderingBuffer::equals(const uint8_t *otherStart, const uint8_t *otherLimit) const {
U_ASSERT((otherLimit - otherStart) <= INT32_MAX); // ensured by caller U_ASSERT((otherLimit - otherStart) <= INT32_MAX); // ensured by caller
int32_t length = (int32_t)(limit - start); int32_t length = static_cast<int32_t>(limit - start);
int32_t otherLength = (int32_t)(otherLimit - otherStart); int32_t otherLength = static_cast<int32_t>(otherLimit - otherStart);
// For equal strings, UTF-8 is at least as long as UTF-16, and at most three times as long. // For equal strings, UTF-8 is at least as long as UTF-16, and at most three times as long.
if (otherLength < length || (otherLength / 3) > length) { if (otherLength < length || (otherLength / 3) > length) {
return false; return false;
@ -284,7 +284,7 @@ UBool ReorderingBuffer::append(const char16_t *s, int32_t length, UBool isNFD,
U16_NEXT(s, i, length, c); U16_NEXT(s, i, length, c);
if(i<length) { if(i<length) {
if (isNFD) { if (isNFD) {
leadCC = Normalizer2Impl::getCCFromYesOrMaybe(impl.getRawNorm16(c)); leadCC = Normalizer2Impl::getCCFromYesOrMaybeYes(impl.getRawNorm16(c));
} else { } else {
leadCC = impl.getCC(impl.getNorm16(c)); leadCC = impl.getCC(impl.getNorm16(c));
} }
@ -304,7 +304,7 @@ UBool ReorderingBuffer::appendZeroCC(UChar32 c, UErrorCode &errorCode) {
} }
remainingCapacity-=cpLength; remainingCapacity-=cpLength;
if(cpLength==1) { if(cpLength==1) {
*limit++=(char16_t)c; *limit++ = static_cast<char16_t>(c);
} else { } else {
limit[0]=U16_LEAD(c); limit[0]=U16_LEAD(c);
limit[1]=U16_TRAIL(c); limit[1]=U16_TRAIL(c);
@ -319,7 +319,7 @@ UBool ReorderingBuffer::appendZeroCC(const char16_t *s, const char16_t *sLimit,
if(s==sLimit) { if(s==sLimit) {
return true; return true;
} }
int32_t length=(int32_t)(sLimit-s); int32_t length = static_cast<int32_t>(sLimit - s);
if(remainingCapacity<length && !resize(length, errorCode)) { if(remainingCapacity<length && !resize(length, errorCode)) {
return false; return false;
} }
@ -350,8 +350,8 @@ void ReorderingBuffer::removeSuffix(int32_t suffixLength) {
} }
UBool ReorderingBuffer::resize(int32_t appendLength, UErrorCode &errorCode) { UBool ReorderingBuffer::resize(int32_t appendLength, UErrorCode &errorCode) {
int32_t reorderStartIndex=(int32_t)(reorderStart-start); int32_t reorderStartIndex = static_cast<int32_t>(reorderStart - start);
int32_t length=(int32_t)(limit-start); int32_t length = static_cast<int32_t>(limit - start);
str.releaseBuffer(length); str.releaseBuffer(length);
int32_t newCapacity=length+appendLength; int32_t newCapacity=length+appendLength;
int32_t doubleCapacity=2*str.getCapacity(); int32_t doubleCapacity=2*str.getCapacity();
@ -392,7 +392,7 @@ uint8_t ReorderingBuffer::previousCC() {
--codePointStart; --codePointStart;
c=U16_GET_SUPPLEMENTARY(c2, c); c=U16_GET_SUPPLEMENTARY(c2, c);
} }
return impl.getCCFromYesOrMaybeCP(c); return impl.getCCFromYesOrMaybeYesCP(c);
} }
// Inserts c somewhere before the last character. // Inserts c somewhere before the last character.
@ -440,15 +440,14 @@ Normalizer2Impl::init(const int32_t *inIndexes, const UCPTrie *inTrie,
minNoNoCompNoMaybeCC = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC]); minNoNoCompNoMaybeCC = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC]);
minNoNoEmpty = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_EMPTY]); minNoNoEmpty = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_EMPTY]);
limitNoNo = static_cast<uint16_t>(inIndexes[IX_LIMIT_NO_NO]); limitNoNo = static_cast<uint16_t>(inIndexes[IX_LIMIT_NO_NO]);
minMaybeNo = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_NO]);
minMaybeNoCombinesFwd = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_NO_COMBINES_FWD]);
minMaybeYes = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_YES]); minMaybeYes = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_YES]);
U_ASSERT((minMaybeYes & 7) == 0); // 8-aligned for noNoDelta bit fields U_ASSERT((minMaybeNo & 7) == 0); // 8-aligned for noNoDelta bit fields
centerNoNoDelta = (minMaybeYes >> DELTA_SHIFT) - MAX_DELTA - 1; centerNoNoDelta = (minMaybeNo >> DELTA_SHIFT) - MAX_DELTA - 1;
normTrie=inTrie; normTrie=inTrie;
extraData=inExtraData;
maybeYesCompositions=inExtraData;
extraData=maybeYesCompositions+((MIN_NORMAL_MAYBE_YES-minMaybeYes)>>OFFSET_SHIFT);
smallFCD=inSmallFCD; smallFCD=inSmallFCD;
} }
@ -486,7 +485,7 @@ Normalizer2Impl::addPropertyStarts(const USetAdder *sa, UErrorCode & /*errorCode
while ((end = ucptrie_getRange(normTrie, start, UCPMAP_RANGE_FIXED_LEAD_SURROGATES, INERT, while ((end = ucptrie_getRange(normTrie, start, UCPMAP_RANGE_FIXED_LEAD_SURROGATES, INERT,
nullptr, nullptr, &value)) >= 0) { nullptr, nullptr, &value)) >= 0) {
sa->add(sa->set, start); sa->add(sa->set, start);
if (start != end && isAlgorithmicNoNo((uint16_t)value) && if (start != end && isAlgorithmicNoNo(static_cast<uint16_t>(value)) &&
(value & Normalizer2Impl::DELTA_TCCC_MASK) > Normalizer2Impl::DELTA_TCCC_1) { (value & Normalizer2Impl::DELTA_TCCC_MASK) > Normalizer2Impl::DELTA_TCCC_1) {
// Range of code points with same-norm16-value algorithmic decompositions. // Range of code points with same-norm16-value algorithmic decompositions.
// They might have different non-zero FCD16 values. // They might have different non-zero FCD16 values.
@ -570,7 +569,7 @@ Normalizer2Impl::decompose(const char16_t *src, const char16_t *limit,
int32_t destLengthEstimate, int32_t destLengthEstimate,
UErrorCode &errorCode) const { UErrorCode &errorCode) const {
if(destLengthEstimate<0 && limit!=nullptr) { if(destLengthEstimate<0 && limit!=nullptr) {
destLengthEstimate=(int32_t)(limit-src); destLengthEstimate = static_cast<int32_t>(limit - src);
} }
dest.remove(); dest.remove();
ReorderingBuffer buffer(*this, dest); ReorderingBuffer buffer(*this, dest);
@ -650,7 +649,7 @@ Normalizer2Impl::decompose(const char16_t *src, const char16_t *limit,
} }
} else { } else {
if(isDecompYes(norm16)) { if(isDecompYes(norm16)) {
uint8_t cc=getCCFromYesOrMaybe(norm16); uint8_t cc=getCCFromYesOrMaybeYes(norm16);
if(prevCC<=cc || cc==0) { if(prevCC<=cc || cc==0) {
prevCC=cc; prevCC=cc;
if(cc<=1) { if(cc<=1) {
@ -702,12 +701,13 @@ UBool Normalizer2Impl::decompose(UChar32 c, uint16_t norm16,
UErrorCode &errorCode) const { UErrorCode &errorCode) const {
// get the decomposition and the lead and trail cc's // get the decomposition and the lead and trail cc's
if (norm16 >= limitNoNo) { if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) { if (isMaybeYesOrNonZeroCC(norm16)) {
return buffer.append(c, getCCFromYesOrMaybe(norm16), errorCode); return buffer.append(c, getCCFromYesOrMaybeYes(norm16), errorCode);
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
c=mapAlgorithmic(c, norm16);
norm16=getRawNorm16(c);
} }
// Maps to an isCompYesAndZeroCC.
c=mapAlgorithmic(c, norm16);
norm16=getRawNorm16(c);
} }
if (norm16 < minYesNo) { if (norm16 < minYesNo) {
// c does not decompose // c does not decompose
@ -718,17 +718,17 @@ UBool Normalizer2Impl::decompose(UChar32 c, uint16_t norm16,
return buffer.appendZeroCC(jamos, jamos+Hangul::decompose(c, jamos), errorCode); return buffer.appendZeroCC(jamos, jamos+Hangul::decompose(c, jamos), errorCode);
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
int32_t length=firstUnit&MAPPING_LENGTH_MASK; int32_t length=firstUnit&MAPPING_LENGTH_MASK;
uint8_t leadCC, trailCC; uint8_t leadCC, trailCC;
trailCC=(uint8_t)(firstUnit>>8); trailCC = static_cast<uint8_t>(firstUnit >> 8);
if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) { if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) {
leadCC=(uint8_t)(*(mapping-1)>>8); leadCC = static_cast<uint8_t>(*(mapping - 1) >> 8);
} else { } else {
leadCC=0; leadCC=0;
} }
return buffer.append((const char16_t *)mapping+1, length, true, leadCC, trailCC, errorCode); return buffer.append(reinterpret_cast<const char16_t*>(mapping) + 1, length, true, leadCC, trailCC, errorCode);
} }
// Dual functionality: // Dual functionality:
@ -787,9 +787,9 @@ Normalizer2Impl::decomposeUTF8(uint32_t options,
} }
// Medium-fast path: Quick check. // Medium-fast path: Quick check.
if (isMaybeOrNonZeroCC(norm16)) { if (isMaybeYesOrNonZeroCC(norm16)) {
// Does not decompose. // Does not decompose.
uint8_t cc = getCCFromYesOrMaybe(norm16); uint8_t cc = getCCFromYesOrMaybeYes(norm16);
if (prevCC <= cc || cc == 0) { if (prevCC <= cc || cc == 0) {
prevCC = cc; prevCC = cc;
if (cc <= 1) { if (cc <= 1) {
@ -836,7 +836,7 @@ Normalizer2Impl::decomposeUTF8(uint32_t options,
} }
// We already know there was a change if the original character decomposed; // We already know there was a change if the original character decomposed;
// otherwise compare. // otherwise compare.
if (isMaybeOrNonZeroCC(norm16) && buffer.equals(prevBoundary, src)) { if (isMaybeYesOrNonZeroCC(norm16) && buffer.equals(prevBoundary, src)) {
if (!ByteSinkUtil::appendUnchanged(prevBoundary, src, if (!ByteSinkUtil::appendUnchanged(prevBoundary, src,
*sink, options, edits, errorCode)) { *sink, options, edits, errorCode)) {
break; break;
@ -867,9 +867,9 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
// Get the decomposition and the lead and trail cc's. // Get the decomposition and the lead and trail cc's.
UChar32 c = U_SENTINEL; UChar32 c = U_SENTINEL;
if (norm16 >= limitNoNo) { if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) { if (isMaybeYesOrNonZeroCC(norm16)) {
// No comp boundaries around this character. // No comp boundaries around this character.
uint8_t cc = getCCFromYesOrMaybe(norm16); uint8_t cc = getCCFromYesOrMaybeYes(norm16);
if (cc == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) { if (cc == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) {
return prevSrc; return prevSrc;
} }
@ -881,14 +881,15 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
return src; return src;
} }
continue; continue;
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
if (stopAt != STOP_AT_LIMIT) {
return prevSrc;
}
c = codePointFromValidUTF8(prevSrc, src);
c = mapAlgorithmic(c, norm16);
norm16 = getRawNorm16(c);
} }
// Maps to an isCompYesAndZeroCC.
if (stopAt != STOP_AT_LIMIT) {
return prevSrc;
}
c = codePointFromValidUTF8(prevSrc, src);
c = mapAlgorithmic(c, norm16);
norm16 = getRawNorm16(c);
} else if (stopAt != STOP_AT_LIMIT && norm16 < minNoNoCompNoMaybeCC) { } else if (stopAt != STOP_AT_LIMIT && norm16 < minNoNoCompNoMaybeCC) {
return prevSrc; return prevSrc;
} }
@ -918,20 +919,20 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
} }
} else { } else {
// The character decomposes, get everything from the variable-length extra data. // The character decomposes, get everything from the variable-length extra data.
const uint16_t *mapping = getMapping(norm16); const uint16_t *mapping = getData(norm16);
uint16_t firstUnit = *mapping; uint16_t firstUnit = *mapping;
int32_t length = firstUnit & MAPPING_LENGTH_MASK; int32_t length = firstUnit & MAPPING_LENGTH_MASK;
uint8_t trailCC = (uint8_t)(firstUnit >> 8); uint8_t trailCC = static_cast<uint8_t>(firstUnit >> 8);
uint8_t leadCC; uint8_t leadCC;
if (firstUnit & MAPPING_HAS_CCC_LCCC_WORD) { if (firstUnit & MAPPING_HAS_CCC_LCCC_WORD) {
leadCC = (uint8_t)(*(mapping-1) >> 8); leadCC = static_cast<uint8_t>(*(mapping - 1) >> 8);
} else { } else {
leadCC = 0; leadCC = 0;
} }
if (leadCC == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) { if (leadCC == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) {
return prevSrc; return prevSrc;
} }
if (!buffer.append((const char16_t *)mapping+1, length, true, leadCC, trailCC, errorCode)) { if (!buffer.append(reinterpret_cast<const char16_t*>(mapping) + 1, length, true, leadCC, trailCC, errorCode)) {
return nullptr; return nullptr;
} }
} }
@ -946,7 +947,7 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
const char16_t * const char16_t *
Normalizer2Impl::getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length) const { Normalizer2Impl::getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length) const {
uint16_t norm16; uint16_t norm16;
if(c<minDecompNoCP || isMaybeOrNonZeroCC(norm16=getNorm16(c))) { if(c<minDecompNoCP || isMaybeYesOrNonZeroCC(norm16=getNorm16(c))) {
// c does not decompose // c does not decompose
return nullptr; return nullptr;
} }
@ -968,9 +969,9 @@ Normalizer2Impl::getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length
return buffer; return buffer;
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getData(norm16);
length=*mapping&MAPPING_LENGTH_MASK; length=*mapping&MAPPING_LENGTH_MASK;
return (const char16_t *)mapping+1; return reinterpret_cast<const char16_t*>(mapping) + 1;
} }
// The capacity of the buffer must be 30=MAPPING_LENGTH_MASK-1 // The capacity of the buffer must be 30=MAPPING_LENGTH_MASK-1
@ -995,7 +996,7 @@ Normalizer2Impl::getRawDecomposition(UChar32 c, char16_t buffer[30], int32_t &le
return buffer; return buffer;
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
int32_t mLength=firstUnit&MAPPING_LENGTH_MASK; // length of normal mapping int32_t mLength=firstUnit&MAPPING_LENGTH_MASK; // length of normal mapping
if(firstUnit&MAPPING_HAS_RAW_MAPPING) { if(firstUnit&MAPPING_HAS_RAW_MAPPING) {
@ -1005,17 +1006,17 @@ Normalizer2Impl::getRawDecomposition(UChar32 c, char16_t buffer[30], int32_t &le
uint16_t rm0=*rawMapping; uint16_t rm0=*rawMapping;
if(rm0<=MAPPING_LENGTH_MASK) { if(rm0<=MAPPING_LENGTH_MASK) {
length=rm0; length=rm0;
return (const char16_t *)rawMapping-rm0; return reinterpret_cast<const char16_t*>(rawMapping) - rm0;
} else { } else {
// Copy the normal mapping and replace its first two code units with rm0. // Copy the normal mapping and replace its first two code units with rm0.
buffer[0]=(char16_t)rm0; buffer[0] = static_cast<char16_t>(rm0);
u_memcpy(buffer+1, (const char16_t *)mapping+1+2, mLength-2); u_memcpy(buffer + 1, reinterpret_cast<const char16_t*>(mapping) + 1 + 2, mLength - 2);
length=mLength-1; length=mLength-1;
return buffer; return buffer;
} }
} else { } else {
length=mLength; length=mLength;
return (const char16_t *)mapping+1; return reinterpret_cast<const char16_t*>(mapping) + 1;
} }
} }
@ -1052,7 +1053,7 @@ void Normalizer2Impl::decomposeAndAppend(const char16_t *src, const char16_t *li
limit=u_strchr(p, 0); limit=u_strchr(p, 0);
} }
if (buffer.append(src, (int32_t)(p - src), false, firstCC, prevCC, errorCode)) { if (buffer.append(src, static_cast<int32_t>(p - src), false, firstCC, prevCC, errorCode)) {
buffer.appendZeroCC(p, limit, errorCode); buffer.appendZeroCC(p, limit, errorCode);
} }
} }
@ -1070,7 +1071,7 @@ UBool Normalizer2Impl::norm16HasDecompBoundaryBefore(uint16_t norm16) const {
return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT; return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT;
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getDataForYesOrNo(norm16);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
// true if leadCC==0 (hasFCDBoundaryBefore()) // true if leadCC==0 (hasFCDBoundaryBefore())
return (firstUnit&MAPPING_HAS_CCC_LCCC_WORD)==0 || (*(mapping-1)&0xff00)==0; return (firstUnit&MAPPING_HAS_CCC_LCCC_WORD)==0 || (*(mapping-1)&0xff00)==0;
@ -1091,14 +1092,15 @@ UBool Normalizer2Impl::norm16HasDecompBoundaryAfter(uint16_t norm16) const {
return true; return true;
} }
if (norm16 >= limitNoNo) { if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) { if (isMaybeYesOrNonZeroCC(norm16)) {
return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT; return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT;
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
return (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1;
} }
// Maps to an isCompYesAndZeroCC.
return (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1;
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
// decomp after-boundary: same as hasFCDBoundaryAfter(), // decomp after-boundary: same as hasFCDBoundaryAfter(),
// fcd16<=1 || trailCC==0 // fcd16<=1 || trailCC==0
@ -1140,13 +1142,13 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
if(trail<COMP_1_TRAIL_LIMIT) { if(trail<COMP_1_TRAIL_LIMIT) {
// trail character is 0..33FF // trail character is 0..33FF
// result entry may have 2 or 3 units // result entry may have 2 or 3 units
key1=(uint16_t)(trail<<1); key1 = static_cast<uint16_t>(trail << 1);
while(key1>(firstUnit=*list)) { while(key1>(firstUnit=*list)) {
list+=2+(firstUnit&COMP_1_TRIPLE); list+=2+(firstUnit&COMP_1_TRIPLE);
} }
if(key1==(firstUnit&COMP_1_TRAIL_MASK)) { if(key1==(firstUnit&COMP_1_TRAIL_MASK)) {
if(firstUnit&COMP_1_TRIPLE) { if(firstUnit&COMP_1_TRIPLE) {
return ((int32_t)list[1]<<16)|list[2]; return (static_cast<int32_t>(list[1]) << 16) | list[2];
} else { } else {
return list[1]; return list[1];
} }
@ -1154,10 +1156,10 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
} else { } else {
// trail character is 3400..10FFFF // trail character is 3400..10FFFF
// result entry has 3 units // result entry has 3 units
key1=(uint16_t)(COMP_1_TRAIL_LIMIT+ key1 = static_cast<uint16_t>(COMP_1_TRAIL_LIMIT +
(((trail>>COMP_1_TRAIL_SHIFT))& (((trail>>COMP_1_TRAIL_SHIFT))&
~COMP_1_TRIPLE)); ~COMP_1_TRIPLE));
uint16_t key2=(uint16_t)(trail<<COMP_2_TRAIL_SHIFT); uint16_t key2 = static_cast<uint16_t>(trail << COMP_2_TRAIL_SHIFT);
uint16_t secondUnit; uint16_t secondUnit;
for(;;) { for(;;) {
if(key1>(firstUnit=*list)) { if(key1>(firstUnit=*list)) {
@ -1170,7 +1172,7 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
list+=3; list+=3;
} }
} else if(key2==(secondUnit&COMP_2_TRAIL_MASK)) { } else if(key2==(secondUnit&COMP_2_TRAIL_MASK)) {
return ((int32_t)(secondUnit&~COMP_2_TRAIL_MASK)<<16)|list[2]; return (static_cast<int32_t>(secondUnit & ~COMP_2_TRAIL_MASK) << 16) | list[2];
} else { } else {
break; break;
} }
@ -1195,7 +1197,7 @@ void Normalizer2Impl::addComposites(const uint16_t *list, UnicodeSet &set) const
compositeAndFwd=list[1]; compositeAndFwd=list[1];
list+=2; list+=2;
} else { } else {
compositeAndFwd=(((int32_t)list[1]&~COMP_2_TRAIL_MASK)<<16)|list[2]; compositeAndFwd = ((static_cast<int32_t>(list[1]) & ~COMP_2_TRAIL_MASK) << 16) | list[2];
list+=3; list+=3;
} }
UChar32 composite=compositeAndFwd>>1; UChar32 composite=compositeAndFwd>>1;
@ -1240,7 +1242,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
for(;;) { for(;;) {
UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, p, limit, c, norm16); UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, p, limit, c, norm16);
cc=getCCFromYesOrMaybe(norm16); cc=getCCFromYesOrMaybeYes(norm16);
if( // this character combines backward and if( // this character combines backward and
isMaybe(norm16) && isMaybe(norm16) &&
// we have seen a starter that combines forward and // we have seen a starter that combines forward and
@ -1252,15 +1254,15 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
// c is a Jamo V/T, see if we can compose it with the previous character. // c is a Jamo V/T, see if we can compose it with the previous character.
if(c<Hangul::JAMO_T_BASE) { if(c<Hangul::JAMO_T_BASE) {
// c is a Jamo Vowel, compose with previous Jamo L and following Jamo T. // c is a Jamo Vowel, compose with previous Jamo L and following Jamo T.
char16_t prev=(char16_t)(*starter-Hangul::JAMO_L_BASE); char16_t prev = static_cast<char16_t>(*starter - Hangul::JAMO_L_BASE);
if(prev<Hangul::JAMO_L_COUNT) { if(prev<Hangul::JAMO_L_COUNT) {
pRemove=p-1; pRemove=p-1;
char16_t syllable=(char16_t) char16_t syllable = static_cast<char16_t>(
(Hangul::HANGUL_BASE+ Hangul::HANGUL_BASE +
(prev*Hangul::JAMO_V_COUNT+(c-Hangul::JAMO_V_BASE))* (prev*Hangul::JAMO_V_COUNT+(c-Hangul::JAMO_V_BASE))*
Hangul::JAMO_T_COUNT); Hangul::JAMO_T_COUNT);
char16_t t; char16_t t;
if(p!=limit && (t=(char16_t)(*p-Hangul::JAMO_T_BASE))<Hangul::JAMO_T_COUNT) { if (p != limit && (t = static_cast<char16_t>(*p - Hangul::JAMO_T_BASE)) < Hangul::JAMO_T_COUNT) {
++p; ++p;
syllable+=t; // The next character was a Jamo T. syllable+=t; // The next character was a Jamo T.
} }
@ -1298,7 +1300,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
starter[0]=U16_LEAD(composite); starter[0]=U16_LEAD(composite);
starter[1]=U16_TRAIL(composite); starter[1]=U16_TRAIL(composite);
} else { } else {
*starter=(char16_t)composite; *starter = static_cast<char16_t>(composite);
// The composite is shorter than the starter, // The composite is shorter than the starter,
// move the intermediate characters forward one. // move the intermediate characters forward one.
starterIsSupplementary=false; starterIsSupplementary=false;
@ -1323,7 +1325,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
*--starter=U16_LEAD(composite); // undo the temporary increment *--starter=U16_LEAD(composite); // undo the temporary increment
} else { } else {
// both are on the BMP // both are on the BMP
*starter=(char16_t)composite; *starter = static_cast<char16_t>(composite);
} }
/* remove the combining mark by moving the following text over it */ /* remove the combining mark by moving the following text over it */
@ -1414,17 +1416,22 @@ Normalizer2Impl::composePair(UChar32 a, UChar32 b) const {
} }
} else { } else {
// 'a' has a compositions list in extraData // 'a' has a compositions list in extraData
list=getMapping(norm16); list=getDataForYesOrNo(norm16);
if(norm16>minYesNo) { // composite 'a' has both mapping & compositions list if(norm16>minYesNo) { // composite 'a' has both mapping & compositions list
list+= // mapping pointer list+= // mapping pointer
1+ // +1 to skip the first unit with the mapping length 1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length (*list&MAPPING_LENGTH_MASK); // + mapping length
} }
} }
} else if(norm16<minMaybeYes || MIN_NORMAL_MAYBE_YES<=norm16) { } else if(norm16<minMaybeNoCombinesFwd || MIN_NORMAL_MAYBE_YES<=norm16) {
return U_SENTINEL; return U_SENTINEL;
} else { } else {
list=getCompositionsListForMaybe(norm16); list=getDataForMaybe(norm16);
if(norm16<minMaybeYes) { // composite 'a' has both mapping & compositions list
list+= // mapping pointer
1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length
}
} }
if(b<0 || 0x10ffff<b) { // combine(list, b) requires a valid code point b if(b<0 || 0x10ffff<b) { // combine(list, b) requires a valid code point b
return U_SENTINEL; return U_SENTINEL;
@ -1502,12 +1509,12 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
} }
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo. // isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping) // The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward) // or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0. // or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties. // It is not a Hangul syllable or Jamo L because those have "yes" properties.
// Medium-fast path: Handle cases that do not require full decomposition and recomposition. // Medium-fast path: Handle cases that do not require full decomposition and recomposition.
if (!isMaybeOrNonZeroCC(norm16)) { // minNoNo <= norm16 < minMaybeYes if (norm16 < minMaybeNo) { // minNoNo <= norm16 < minMaybeNo
if (!doCompose) { if (!doCompose) {
return false; return false;
} }
@ -1534,7 +1541,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) { if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break; break;
} }
const char16_t *mapping = reinterpret_cast<const char16_t *>(getMapping(norm16)); const char16_t *mapping = reinterpret_cast<const char16_t *>(getDataForYesOrNo(norm16));
int32_t length = *mapping++ & MAPPING_LENGTH_MASK; int32_t length = *mapping++ & MAPPING_LENGTH_MASK;
if(!buffer.appendZeroCC(mapping, mapping + length, errorCode)) { if(!buffer.appendZeroCC(mapping, mapping + length, errorCode)) {
break; break;
@ -1562,14 +1569,14 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if(c<Hangul::JAMO_T_BASE) { if(c<Hangul::JAMO_T_BASE) {
// The current character is a Jamo Vowel, // The current character is a Jamo Vowel,
// compose with previous Jamo L and following Jamo T. // compose with previous Jamo L and following Jamo T.
char16_t l = (char16_t)(prev-Hangul::JAMO_L_BASE); char16_t l = static_cast<char16_t>(prev - Hangul::JAMO_L_BASE);
if(l<Hangul::JAMO_L_COUNT) { if(l<Hangul::JAMO_L_COUNT) {
if (!doCompose) { if (!doCompose) {
return false; return false;
} }
int32_t t; int32_t t;
if (src != limit && if (src != limit &&
0 < (t = ((int32_t)*src - Hangul::JAMO_T_BASE)) && 0 < (t = (static_cast<int32_t>(*src) - Hangul::JAMO_T_BASE)) &&
t < Hangul::JAMO_T_COUNT) { t < Hangul::JAMO_T_COUNT) {
// The next character is a Jamo T. // The next character is a Jamo T.
++src; ++src;
@ -1587,7 +1594,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) { if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break; break;
} }
if(!buffer.appendBMP((char16_t)syllable, 0, errorCode)) { if (!buffer.appendBMP(static_cast<char16_t>(syllable), 0, errorCode)) {
break; break;
} }
prevBoundary = src; prevBoundary = src;
@ -1612,7 +1619,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) { if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break; break;
} }
if(!buffer.appendBMP((char16_t)syllable, 0, errorCode)) { if (!buffer.appendBMP(static_cast<char16_t>(syllable), 0, errorCode)) {
break; break;
} }
prevBoundary = src; prevBoundary = src;
@ -1763,7 +1770,7 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
} }
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo. // isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping) // The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward) // or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0. // or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties. // It is not a Hangul syllable or Jamo L because those have "yes" properties.
@ -1784,8 +1791,9 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
} }
} }
if(isMaybeOrNonZeroCC(norm16)) { if (norm16 >= minMaybeNo) {
uint8_t cc=getCCFromYesOrMaybe(norm16); uint16_t fcd16 = getFCD16FromMaybeOrNonZeroCC(norm16);
uint8_t cc = fcd16 >> 8;
if (onlyContiguous /* FCC */ && cc != 0 && if (onlyContiguous /* FCC */ && cc != 0 &&
getTrailCCFromCompYesAndZeroCC(prevNorm16) > cc) { getTrailCCFromCompYesAndZeroCC(prevNorm16) > cc) {
// The [prevBoundary..prevSrc[ character // The [prevBoundary..prevSrc[ character
@ -1806,11 +1814,12 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
if (src == limit) { if (src == limit) {
return src; return src;
} }
uint8_t prevCC = cc; uint8_t prevCC = fcd16;
nextSrc = src; nextSrc = src;
UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, nextSrc, limit, c, norm16); UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, nextSrc, limit, c, norm16);
if (isMaybeOrNonZeroCC(norm16)) { if (norm16 >= minMaybeNo) {
cc = getCCFromYesOrMaybe(norm16); fcd16 = getFCD16FromMaybeOrNonZeroCC(norm16);
cc = fcd16 >> 8;
if (!(prevCC <= cc || cc == 0)) { if (!(prevCC <= cc || cc == 0)) {
break; break;
} }
@ -1845,11 +1854,11 @@ void Normalizer2Impl::composeAndAppend(const char16_t *src, const char16_t *limi
if(src!=firstStarterInSrc) { if(src!=firstStarterInSrc) {
const char16_t *lastStarterInDest=findPreviousCompBoundary(buffer.getStart(), const char16_t *lastStarterInDest=findPreviousCompBoundary(buffer.getStart(),
buffer.getLimit(), onlyContiguous); buffer.getLimit(), onlyContiguous);
int32_t destSuffixLength=(int32_t)(buffer.getLimit()-lastStarterInDest); int32_t destSuffixLength = static_cast<int32_t>(buffer.getLimit() - lastStarterInDest);
UnicodeString middle(lastStarterInDest, destSuffixLength); UnicodeString middle(lastStarterInDest, destSuffixLength);
buffer.removeSuffix(destSuffixLength); buffer.removeSuffix(destSuffixLength);
safeMiddle=middle; safeMiddle=middle;
middle.append(src, (int32_t)(firstStarterInSrc-src)); middle.append(src, static_cast<int32_t>(firstStarterInSrc - src));
const char16_t *middleStart=middle.getBuffer(); const char16_t *middleStart=middle.getBuffer();
compose(middleStart, middleStart+middle.length(), onlyContiguous, compose(middleStart, middleStart+middle.length(), onlyContiguous,
true, buffer, errorCode); true, buffer, errorCode);
@ -1903,12 +1912,12 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
} }
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo. // isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping) // The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward) // or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0. // or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties. // It is not a Hangul syllable or Jamo L because those have "yes" properties.
// Medium-fast path: Handle cases that do not require full decomposition and recomposition. // Medium-fast path: Handle cases that do not require full decomposition and recomposition.
if (!isMaybeOrNonZeroCC(norm16)) { // minNoNo <= norm16 < minMaybeYes if (norm16 < minMaybeNo) { // minNoNo <= norm16 < minMaybeNo
if (sink == nullptr) { if (sink == nullptr) {
return false; return false;
} }
@ -1937,9 +1946,9 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
*sink, options, edits, errorCode)) { *sink, options, edits, errorCode)) {
break; break;
} }
const uint16_t *mapping = getMapping(norm16); const uint16_t *mapping = getDataForYesOrNo(norm16);
int32_t length = *mapping++ & MAPPING_LENGTH_MASK; int32_t length = *mapping++ & MAPPING_LENGTH_MASK;
if (!ByteSinkUtil::appendChange(prevSrc, src, (const char16_t *)mapping, length, if (!ByteSinkUtil::appendChange(prevSrc, src, reinterpret_cast<const char16_t*>(mapping), length,
*sink, edits, errorCode)) { *sink, edits, errorCode)) {
break; break;
} }
@ -1958,7 +1967,7 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
break; break;
} }
if (edits != nullptr) { if (edits != nullptr) {
edits->addReplace((int32_t)(src - prevSrc), 0); edits->addReplace(static_cast<int32_t>(src - prevSrc), 0);
} }
prevBoundary = src; prevBoundary = src;
continue; continue;
@ -1976,7 +1985,7 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
// The current character is a Jamo Vowel, // The current character is a Jamo Vowel,
// compose with previous Jamo L and following Jamo T. // compose with previous Jamo L and following Jamo T.
UChar32 l = prev - Hangul::JAMO_L_BASE; UChar32 l = prev - Hangul::JAMO_L_BASE;
if ((uint32_t)l < Hangul::JAMO_L_COUNT) { if (static_cast<uint32_t>(l) < Hangul::JAMO_L_COUNT) {
if (sink == nullptr) { if (sink == nullptr) {
return false; return false;
} }
@ -2204,20 +2213,20 @@ uint8_t Normalizer2Impl::getPreviousTrailCC(const char16_t *start, const char16_
if (start == p) { if (start == p) {
return 0; return 0;
} }
int32_t i = (int32_t)(p - start); int32_t i = static_cast<int32_t>(p - start);
UChar32 c; UChar32 c;
U16_PREV(start, 0, i, c); U16_PREV(start, 0, i, c);
return (uint8_t)getFCD16(c); return static_cast<uint8_t>(getFCD16(c));
} }
uint8_t Normalizer2Impl::getPreviousTrailCC(const uint8_t *start, const uint8_t *p) const { uint8_t Normalizer2Impl::getPreviousTrailCC(const uint8_t *start, const uint8_t *p) const {
if (start == p) { if (start == p) {
return 0; return 0;
} }
int32_t i = (int32_t)(p - start); int32_t i = static_cast<int32_t>(p - start);
UChar32 c; UChar32 c;
U8_PREV(start, 0, i, c); U8_PREV(start, 0, i, c);
return (uint8_t)getFCD16(c); return static_cast<uint8_t>(getFCD16(c));
} }
// Note: normalizer2impl.cpp r30982 (2011-nov-27) // Note: normalizer2impl.cpp r30982 (2011-nov-27)
@ -2245,7 +2254,7 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
return norm16|(norm16<<8); return norm16|(norm16<<8);
} else if(norm16>=minMaybeYes) { } else if(norm16>=minMaybeYes) {
return 0; return 0;
} else { // isDecompNoAlgorithmic(norm16) } else if(norm16<minMaybeNo) { // isDecompNoAlgorithmic(norm16)
uint16_t deltaTrailCC = norm16 & DELTA_TCCC_MASK; uint16_t deltaTrailCC = norm16 & DELTA_TCCC_MASK;
if (deltaTrailCC <= DELTA_TCCC_1) { if (deltaTrailCC <= DELTA_TCCC_1) {
return deltaTrailCC >> OFFSET_SHIFT; return deltaTrailCC >> OFFSET_SHIFT;
@ -2260,7 +2269,7 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
return 0; return 0;
} }
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
norm16=firstUnit>>8; // tccc norm16=firstUnit>>8; // tccc
if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) { if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) {
@ -2272,6 +2281,23 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
#pragma optimize( "", on ) #pragma optimize( "", on )
#endif #endif
uint16_t Normalizer2Impl::getFCD16FromMaybeOrNonZeroCC(uint16_t norm16) const {
U_ASSERT(norm16 >= minMaybeNo);
if (norm16 >= MIN_NORMAL_MAYBE_YES) {
// combining mark
norm16 = getCCFromNormalYesOrMaybe(norm16);
return norm16 | (norm16<<8);
} else if (norm16 >= minMaybeYes) {
return 0;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping = getDataForMaybe(norm16);
uint16_t firstUnit = *mapping;
// maybeNo has lccc = 0
U_ASSERT((firstUnit & MAPPING_HAS_CCC_LCCC_WORD) == 0 || (*(mapping - 1) & 0xff00) == 0);
return firstUnit >> 8; // tccc
}
// Dual functionality: // Dual functionality:
// buffer!=nullptr: normalize // buffer!=nullptr: normalize
// buffer==nullptr: isNormalized/quickCheck/spanQuickCheckYes // buffer==nullptr: isNormalized/quickCheck/spanQuickCheckYes
@ -2395,7 +2421,7 @@ Normalizer2Impl::makeFCD(const char16_t *src, const char16_t *limit,
* already but is now going to be decomposed. * already but is now going to be decomposed.
* prevSrc is set to after what was copied/appended. * prevSrc is set to after what was copied/appended.
*/ */
buffer->removeSuffix((int32_t)(prevSrc-prevBoundary)); buffer->removeSuffix(static_cast<int32_t>(prevSrc - prevBoundary));
/* /*
* Find the part of the source that needs to be decomposed, * Find the part of the source that needs to be decomposed,
* up to the next safe boundary. * up to the next safe boundary.
@ -2426,11 +2452,11 @@ void Normalizer2Impl::makeFCDAndAppend(const char16_t *src, const char16_t *limi
if(src!=firstBoundaryInSrc) { if(src!=firstBoundaryInSrc) {
const char16_t *lastBoundaryInDest=findPreviousFCDBoundary(buffer.getStart(), const char16_t *lastBoundaryInDest=findPreviousFCDBoundary(buffer.getStart(),
buffer.getLimit()); buffer.getLimit());
int32_t destSuffixLength=(int32_t)(buffer.getLimit()-lastBoundaryInDest); int32_t destSuffixLength = static_cast<int32_t>(buffer.getLimit() - lastBoundaryInDest);
UnicodeString middle(lastBoundaryInDest, destSuffixLength); UnicodeString middle(lastBoundaryInDest, destSuffixLength);
buffer.removeSuffix(destSuffixLength); buffer.removeSuffix(destSuffixLength);
safeMiddle=middle; safeMiddle=middle;
middle.append(src, (int32_t)(firstBoundaryInSrc-src)); middle.append(src, static_cast<int32_t>(firstBoundaryInSrc - src));
const char16_t *middleStart=middle.getBuffer(); const char16_t *middleStart=middle.getBuffer();
makeFCD(middleStart, middleStart+middle.length(), &buffer, errorCode); makeFCD(middleStart, middleStart+middle.length(), &buffer, errorCode);
if(U_FAILURE(errorCode)) { if(U_FAILURE(errorCode)) {
@ -2507,8 +2533,8 @@ void CanonIterData::addToStartSet(UChar32 origin, UChar32 decompLead, UErrorCode
if(U_FAILURE(errorCode)) { if(U_FAILURE(errorCode)) {
return; return;
} }
UChar32 firstOrigin=(UChar32)(canonValue&CANON_VALUE_MASK); UChar32 firstOrigin = static_cast<UChar32>(canonValue & CANON_VALUE_MASK);
canonValue=(canonValue&~CANON_VALUE_MASK)|CANON_HAS_SET|(uint32_t)canonStartSets.size(); canonValue = (canonValue & ~CANON_VALUE_MASK) | CANON_HAS_SET | static_cast<uint32_t>(canonStartSets.size());
umutablecptrie_set(mutableTrie, decompLead, canonValue, &errorCode); umutablecptrie_set(mutableTrie, decompLead, canonValue, &errorCode);
canonStartSets.adoptElement(lpSet.orphan(), errorCode); canonStartSets.adoptElement(lpSet.orphan(), errorCode);
if (U_FAILURE(errorCode)) { if (U_FAILURE(errorCode)) {
@ -2518,7 +2544,7 @@ void CanonIterData::addToStartSet(UChar32 origin, UChar32 decompLead, UErrorCode
set->add(firstOrigin); set->add(firstOrigin);
} }
} else { } else {
set=(UnicodeSet *)canonStartSets[(int32_t)(canonValue&CANON_VALUE_MASK)]; set = static_cast<UnicodeSet*>(canonStartSets[static_cast<int32_t>(canonValue & CANON_VALUE_MASK)]);
} }
set->add(origin); set->add(origin);
} }
@ -2575,9 +2601,11 @@ void InitCanonIterData::doInit(Normalizer2Impl *impl, UErrorCode &errorCode) {
void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, const uint16_t norm16, void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, const uint16_t norm16,
CanonIterData &newData, CanonIterData &newData,
UErrorCode &errorCode) const { UErrorCode &errorCode) const {
if(isInert(norm16) || (minYesNo<=norm16 && norm16<minNoNo)) { if(isInert(norm16) ||
(minYesNo<=norm16 && norm16<minNoNo) ||
(minMaybeNo<=norm16 && norm16<minMaybeYes)) {
// Inert, or 2-way mapping (including Hangul syllable). // Inert, or 2-way mapping (including Hangul syllable).
// We do not write a canonStartSet for any yesNo character. // We do not write a canonStartSet for any yesNo/maybeNo character.
// Composites from 2-way mappings are added at runtime from the // Composites from 2-way mappings are added at runtime from the
// starter's compositions list, and the other characters in // starter's compositions list, and the other characters in
// 2-way mappings get CANON_NOT_SEGMENT_STARTER set because they are // 2-way mappings get CANON_NOT_SEGMENT_STARTER set because they are
@ -2587,7 +2615,7 @@ void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, co
for(UChar32 c=start; c<=end; ++c) { for(UChar32 c=start; c<=end; ++c) {
uint32_t oldValue = umutablecptrie_get(newData.mutableTrie, c); uint32_t oldValue = umutablecptrie_get(newData.mutableTrie, c);
uint32_t newValue=oldValue; uint32_t newValue=oldValue;
if(isMaybeOrNonZeroCC(norm16)) { if(isMaybeYesOrNonZeroCC(norm16)) {
// not a segment starter if it occurs in a decomposition or has cc!=0 // not a segment starter if it occurs in a decomposition or has cc!=0
newValue|=CANON_NOT_SEGMENT_STARTER; newValue|=CANON_NOT_SEGMENT_STARTER;
if(norm16<MIN_NORMAL_MAYBE_YES) { if(norm16<MIN_NORMAL_MAYBE_YES) {
@ -2609,7 +2637,7 @@ void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, co
} }
if (norm16_2 > minYesNo) { if (norm16_2 > minYesNo) {
// c decomposes, get everything from the variable-length extra data // c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16_2); const uint16_t *mapping=getDataForYesOrNo(norm16_2);
uint16_t firstUnit=*mapping; uint16_t firstUnit=*mapping;
int32_t length=firstUnit&MAPPING_LENGTH_MASK; int32_t length=firstUnit&MAPPING_LENGTH_MASK;
if((firstUnit&MAPPING_HAS_CCC_LCCC_WORD)!=0) { if((firstUnit&MAPPING_HAS_CCC_LCCC_WORD)!=0) {
@ -2657,11 +2685,11 @@ UBool Normalizer2Impl::ensureCanonIterData(UErrorCode &errorCode) const {
} }
int32_t Normalizer2Impl::getCanonValue(UChar32 c) const { int32_t Normalizer2Impl::getCanonValue(UChar32 c) const {
return (int32_t)ucptrie_get(fCanonIterData->trie, c); return static_cast<int32_t>(ucptrie_get(fCanonIterData->trie, c));
} }
const UnicodeSet &Normalizer2Impl::getCanonStartSet(int32_t n) const { const UnicodeSet &Normalizer2Impl::getCanonStartSet(int32_t n) const {
return *(const UnicodeSet *)fCanonIterData->canonStartSets[n]; return *static_cast<const UnicodeSet*>(fCanonIterData->canonStartSets[n]);
} }
UBool Normalizer2Impl::isCanonSegmentStarter(UChar32 c) const { UBool Normalizer2Impl::isCanonSegmentStarter(UChar32 c) const {
@ -2684,7 +2712,7 @@ UBool Normalizer2Impl::getCanonStartSet(UChar32 c, UnicodeSet &set) const {
uint16_t norm16=getRawNorm16(c); uint16_t norm16=getRawNorm16(c);
if(norm16==JAMO_L) { if(norm16==JAMO_L) {
UChar32 syllable= UChar32 syllable=
(UChar32)(Hangul::HANGUL_BASE+(c-Hangul::JAMO_L_BASE)*Hangul::JAMO_VT_COUNT); static_cast<UChar32>(Hangul::HANGUL_BASE + (c - Hangul::JAMO_L_BASE) * Hangul::JAMO_VT_COUNT);
set.add(syllable, syllable+Hangul::JAMO_VT_COUNT-1); set.add(syllable, syllable+Hangul::JAMO_VT_COUNT-1);
} else { } else {
addComposites(getCompositionsList(norm16), set); addComposites(getCompositionsList(norm16), set);
@ -2728,7 +2756,7 @@ unorm2_swap(const UDataSwapper *ds,
pInfo->dataFormat[1]==0x72 && pInfo->dataFormat[1]==0x72 &&
pInfo->dataFormat[2]==0x6d && pInfo->dataFormat[2]==0x6d &&
pInfo->dataFormat[3]==0x32 && pInfo->dataFormat[3]==0x32 &&
(1<=formatVersion0 && formatVersion0<=4) (1<=formatVersion0 && formatVersion0<=5)
)) { )) {
udata_printError(ds, "unorm2_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as Normalizer2 data\n", udata_printError(ds, "unorm2_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as Normalizer2 data\n",
pInfo->dataFormat[0], pInfo->dataFormat[1], pInfo->dataFormat[0], pInfo->dataFormat[1],
@ -2747,8 +2775,10 @@ unorm2_swap(const UDataSwapper *ds,
minIndexesLength=Normalizer2Impl::IX_MIN_MAYBE_YES+1; minIndexesLength=Normalizer2Impl::IX_MIN_MAYBE_YES+1;
} else if(formatVersion0==2) { } else if(formatVersion0==2) {
minIndexesLength=Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY+1; minIndexesLength=Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY+1;
} else { } else if(formatVersion0<=4) {
minIndexesLength=Normalizer2Impl::IX_MIN_LCCC_CP+1; minIndexesLength=Normalizer2Impl::IX_MIN_LCCC_CP+1;
} else {
minIndexesLength=Normalizer2Impl::IX_MIN_MAYBE_NO_COMBINES_FWD+1;
} }
if(length>=0) { if(length>=0) {

View File

@ -81,10 +81,10 @@ public:
return 0<=c && c<HANGUL_COUNT && c%JAMO_T_COUNT==0; return 0<=c && c<HANGUL_COUNT && c%JAMO_T_COUNT==0;
} }
static inline UBool isJamoL(UChar32 c) { static inline UBool isJamoL(UChar32 c) {
return (uint32_t)(c-JAMO_L_BASE)<JAMO_L_COUNT; return static_cast<uint32_t>(c - JAMO_L_BASE) < JAMO_L_COUNT;
} }
static inline UBool isJamoV(UChar32 c) { static inline UBool isJamoV(UChar32 c) {
return (uint32_t)(c-JAMO_V_BASE)<JAMO_V_COUNT; return static_cast<uint32_t>(c - JAMO_V_BASE) < JAMO_V_COUNT;
} }
static inline UBool isJamoT(UChar32 c) { static inline UBool isJamoT(UChar32 c) {
int32_t t=c-JAMO_T_BASE; int32_t t=c-JAMO_T_BASE;
@ -103,12 +103,12 @@ public:
c-=HANGUL_BASE; c-=HANGUL_BASE;
UChar32 c2=c%JAMO_T_COUNT; UChar32 c2=c%JAMO_T_COUNT;
c/=JAMO_T_COUNT; c/=JAMO_T_COUNT;
buffer[0]=(char16_t)(JAMO_L_BASE+c/JAMO_V_COUNT); buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT);
buffer[1]=(char16_t)(JAMO_V_BASE+c%JAMO_V_COUNT); buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT);
if(c2==0) { if(c2==0) {
return 2; return 2;
} else { } else {
buffer[2]=(char16_t)(JAMO_T_BASE+c2); buffer[2] = static_cast<char16_t>(JAMO_T_BASE + c2);
return 3; return 3;
} }
} }
@ -123,11 +123,11 @@ public:
UChar32 c2=c%JAMO_T_COUNT; UChar32 c2=c%JAMO_T_COUNT;
if(c2==0) { if(c2==0) {
c/=JAMO_T_COUNT; c/=JAMO_T_COUNT;
buffer[0]=(char16_t)(JAMO_L_BASE+c/JAMO_V_COUNT); buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT);
buffer[1]=(char16_t)(JAMO_V_BASE+c%JAMO_V_COUNT); buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT);
} else { } else {
buffer[0]=(char16_t)(orig-c2); // LV syllable buffer[0] = static_cast<char16_t>(orig - c2); // LV syllable
buffer[1]=(char16_t)(JAMO_T_BASE+c2); buffer[1] = static_cast<char16_t>(JAMO_T_BASE + c2);
} }
} }
private: private:
@ -147,13 +147,13 @@ public:
ReorderingBuffer(const Normalizer2Impl &ni, UnicodeString &dest, UErrorCode &errorCode); ReorderingBuffer(const Normalizer2Impl &ni, UnicodeString &dest, UErrorCode &errorCode);
~ReorderingBuffer() { ~ReorderingBuffer() {
if (start != nullptr) { if (start != nullptr) {
str.releaseBuffer((int32_t)(limit-start)); str.releaseBuffer(static_cast<int32_t>(limit - start));
} }
} }
UBool init(int32_t destCapacity, UErrorCode &errorCode); UBool init(int32_t destCapacity, UErrorCode &errorCode);
UBool isEmpty() const { return start==limit; } UBool isEmpty() const { return start==limit; }
int32_t length() const { return (int32_t)(limit-start); } int32_t length() const { return static_cast<int32_t>(limit - start); }
char16_t *getStart() { return start; } char16_t *getStart() { return start; }
char16_t *getLimit() { return limit; } char16_t *getLimit() { return limit; }
uint8_t getLastCC() const { return lastCC; } uint8_t getLastCC() const { return lastCC; }
@ -163,7 +163,7 @@ public:
UBool append(UChar32 c, uint8_t cc, UErrorCode &errorCode) { UBool append(UChar32 c, uint8_t cc, UErrorCode &errorCode) {
return (c<=0xffff) ? return (c<=0xffff) ?
appendBMP((char16_t)c, cc, errorCode) : appendBMP(static_cast<char16_t>(c), cc, errorCode) :
appendSupplementary(c, cc, errorCode); appendSupplementary(c, cc, errorCode);
} }
UBool append(const char16_t *s, int32_t length, UBool isNFD, UBool append(const char16_t *s, int32_t length, UBool isNFD,
@ -190,12 +190,12 @@ public:
void remove(); void remove();
void removeSuffix(int32_t suffixLength); void removeSuffix(int32_t suffixLength);
void setReorderingLimit(char16_t *newLimit) { void setReorderingLimit(char16_t *newLimit) {
remainingCapacity+=(int32_t)(limit-newLimit); remainingCapacity += static_cast<int32_t>(limit - newLimit);
reorderStart=limit=newLimit; reorderStart=limit=newLimit;
lastCC=0; lastCC=0;
} }
void copyReorderableSuffixTo(UnicodeString &s) const { void copyReorderableSuffixTo(UnicodeString &s) const {
s.setTo(ConstChar16Ptr(reorderStart), (int32_t)(limit-reorderStart)); s.setTo(ConstChar16Ptr(reorderStart), static_cast<int32_t>(limit - reorderStart));
} }
private: private:
/* /*
@ -215,7 +215,7 @@ private:
void insert(UChar32 c, uint8_t cc); void insert(UChar32 c, uint8_t cc);
static void writeCodePoint(char16_t *p, UChar32 c) { static void writeCodePoint(char16_t *p, UChar32 c) {
if(c<=0xffff) { if(c<=0xffff) {
*p=(char16_t)c; *p = static_cast<char16_t>(c);
} else { } else {
p[0]=U16_LEAD(c); p[0]=U16_LEAD(c);
p[1]=U16_TRAIL(c); p[1]=U16_TRAIL(c);
@ -241,7 +241,7 @@ private:
* Low-level implementation of the Unicode Normalization Algorithm. * Low-level implementation of the Unicode Normalization Algorithm.
* For the data structure and details see the documentation at the end of * For the data structure and details see the documentation at the end of
* this normalizer2impl.h and in the design doc at * this normalizer2impl.h and in the design doc at
* https://icu.unicode.org/design/normalization/custom * https://unicode-org.github.io/icu/design/normalization/custom.html
*/ */
class U_COMMON_API Normalizer2Impl : public UObject { class U_COMMON_API Normalizer2Impl : public UObject {
public: public:
@ -271,14 +271,14 @@ public:
UNormalizationCheckResult getCompQuickCheck(uint16_t norm16) const { UNormalizationCheckResult getCompQuickCheck(uint16_t norm16) const {
if(norm16<minNoNo || MIN_YES_YES_WITH_CC<=norm16) { if(norm16<minNoNo || MIN_YES_YES_WITH_CC<=norm16) {
return UNORM_YES; return UNORM_YES;
} else if(minMaybeYes<=norm16) { } else if(minMaybeNo<=norm16) {
return UNORM_MAYBE; return UNORM_MAYBE;
} else { } else {
return UNORM_NO; return UNORM_NO;
} }
} }
UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeYes; } UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; }
UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeYes; } UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeNo; }
UBool isDecompYes(uint16_t norm16) const { return norm16<minYesNo || minMaybeYes<=norm16; } UBool isDecompYes(uint16_t norm16) const { return norm16<minYesNo || minMaybeYes<=norm16; }
uint8_t getCC(uint16_t norm16) const { uint8_t getCC(uint16_t norm16) const {
@ -291,14 +291,14 @@ public:
return getCCFromNoNo(norm16); return getCCFromNoNo(norm16);
} }
static uint8_t getCCFromNormalYesOrMaybe(uint16_t norm16) { static uint8_t getCCFromNormalYesOrMaybe(uint16_t norm16) {
return (uint8_t)(norm16 >> OFFSET_SHIFT); return static_cast<uint8_t>(norm16 >> OFFSET_SHIFT);
} }
static uint8_t getCCFromYesOrMaybe(uint16_t norm16) { static uint8_t getCCFromYesOrMaybeYes(uint16_t norm16) {
return norm16>=MIN_NORMAL_MAYBE_YES ? getCCFromNormalYesOrMaybe(norm16) : 0; return norm16>=MIN_NORMAL_MAYBE_YES ? getCCFromNormalYesOrMaybe(norm16) : 0;
} }
uint8_t getCCFromYesOrMaybeCP(UChar32 c) const { uint8_t getCCFromYesOrMaybeYesCP(UChar32 c) const {
if (c < minCompNoMaybeCP) { return 0; } if (c < minCompNoMaybeCP) { return 0; }
return getCCFromYesOrMaybe(getNorm16(c)); return getCCFromYesOrMaybeYes(getNorm16(c));
} }
/** /**
@ -364,11 +364,13 @@ public:
// 0<=lead<=0xffff // 0<=lead<=0xffff
uint8_t bits=smallFCD[lead>>8]; uint8_t bits=smallFCD[lead>>8];
if(bits==0) { return false; } if(bits==0) { return false; }
return (UBool)((bits>>((lead>>5)&7))&1); return (bits >> ((lead >> 5) & 7)) & 1;
} }
/** Returns the FCD value from the regular normalization data. */ /** Returns the FCD value from the regular normalization data. */
uint16_t getFCD16FromNormData(UChar32 c) const; uint16_t getFCD16FromNormData(UChar32 c) const;
uint16_t getFCD16FromMaybeOrNonZeroCC(uint16_t norm16) const;
/** /**
* Gets the decomposition for one code point. * Gets the decomposition for one code point.
* @param c code point * @param c code point
@ -450,7 +452,13 @@ public:
IX_MIN_LCCC_CP, IX_MIN_LCCC_CP,
IX_RESERVED19, IX_RESERVED19,
IX_COUNT
/** Two-way mappings; each starts with a character that combines backward. */
IX_MIN_MAYBE_NO, // 20
/** Two-way mappings & compositions. */
IX_MIN_MAYBE_NO_COMBINES_FWD,
IX_COUNT // 22
}; };
enum { enum {
@ -541,7 +549,8 @@ public:
uint16_t norm16=getNorm16(c); uint16_t norm16=getNorm16(c);
return isCompYesAndZeroCC(norm16) && return isCompYesAndZeroCC(norm16) &&
(norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 && (norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 &&
(!onlyContiguous || isInert(norm16) || *getMapping(norm16) <= 0x1ff); (!onlyContiguous || isInert(norm16) || *getDataForYesOrNo(norm16) <= 0x1ff);
// The last check fetches the mapping's first unit and checks tccc<=1.
} }
UBool hasFCDBoundaryBefore(UChar32 c) const { return hasDecompBoundaryBefore(c); } UBool hasFCDBoundaryBefore(UChar32 c) const { return hasDecompBoundaryBefore(c); }
@ -551,8 +560,8 @@ private:
friend class InitCanonIterData; friend class InitCanonIterData;
friend class LcccContext; friend class LcccContext;
UBool isMaybe(uint16_t norm16) const { return minMaybeYes<=norm16 && norm16<=JAMO_VT; } UBool isMaybe(uint16_t norm16) const { return minMaybeNo<=norm16 && norm16<=JAMO_VT; }
UBool isMaybeOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; } UBool isMaybeYesOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; }
static UBool isInert(uint16_t norm16) { return norm16==INERT; } static UBool isInert(uint16_t norm16) { return norm16==INERT; }
static UBool isJamoL(uint16_t norm16) { return norm16==JAMO_L; } static UBool isJamoL(uint16_t norm16) { return norm16==JAMO_L; }
static UBool isJamoVT(uint16_t norm16) { return norm16==JAMO_VT; } static UBool isJamoVT(uint16_t norm16) { return norm16==JAMO_VT; }
@ -566,7 +575,7 @@ private:
// return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo; // return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo;
// } // }
// UBool isCompYesOrMaybe(uint16_t norm16) const { // UBool isCompYesOrMaybe(uint16_t norm16) const {
// return norm16<minNoNo || minMaybeYes<=norm16; // return norm16<minNoNo || minMaybeNo<=norm16;
// } // }
// UBool hasZeroCCFromDecompYes(uint16_t norm16) const { // UBool hasZeroCCFromDecompYes(uint16_t norm16) const {
// return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT; // return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
@ -579,12 +588,12 @@ private:
/** /**
* A little faster and simpler than isDecompYesAndZeroCC() but does not include * A little faster and simpler than isDecompYesAndZeroCC() but does not include
* the MaybeYes which combine-forward and have ccc=0. * the MaybeYes which combine-forward and have ccc=0.
* (Standard Unicode 10 normalization does not have such characters.)
*/ */
UBool isMostDecompYesAndZeroCC(uint16_t norm16) const { UBool isMostDecompYesAndZeroCC(uint16_t norm16) const {
return norm16<minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT; return norm16<minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
} }
UBool isDecompNoAlgorithmic(uint16_t norm16) const { return norm16>=limitNoNo; } /** Since formatVersion 5: same as isAlgorithmicNoNo() */
UBool isDecompNoAlgorithmic(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; }
// For use with isCompYes(). // For use with isCompYes().
// Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC. // Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC.
@ -592,9 +601,9 @@ private:
// return norm16>=MIN_YES_YES_WITH_CC ? getCCFromNormalYesOrMaybe(norm16) : 0; // return norm16>=MIN_YES_YES_WITH_CC ? getCCFromNormalYesOrMaybe(norm16) : 0;
// } // }
uint8_t getCCFromNoNo(uint16_t norm16) const { uint8_t getCCFromNoNo(uint16_t norm16) const {
const uint16_t *mapping=getMapping(norm16); const uint16_t *mapping=getDataForYesOrNo(norm16);
if(*mapping&MAPPING_HAS_CCC_LCCC_WORD) { if(*mapping&MAPPING_HAS_CCC_LCCC_WORD) {
return (uint8_t)*(mapping-1); return static_cast<uint8_t>(*(mapping - 1));
} else { } else {
return 0; return 0;
} }
@ -605,7 +614,7 @@ private:
return 0; // yesYes and Hangul LV have ccc=tccc=0 return 0; // yesYes and Hangul LV have ccc=tccc=0
} else { } else {
// For Hangul LVT we harmlessly fetch a firstUnit with tccc=0 here. // For Hangul LVT we harmlessly fetch a firstUnit with tccc=0 here.
return (uint8_t)(*getMapping(norm16)>>8); // tccc from yesNo return static_cast<uint8_t>(*getDataForYesOrNo(norm16) >> 8); // tccc from yesNo
} }
} }
uint8_t getPreviousTrailCC(const char16_t *start, const char16_t *p) const; uint8_t getPreviousTrailCC(const char16_t *start, const char16_t *p) const;
@ -619,28 +628,33 @@ private:
return (norm16>>DELTA_SHIFT)-centerNoNoDelta; return (norm16>>DELTA_SHIFT)-centerNoNoDelta;
} }
// Requires minYesNo<norm16<limitNoNo. const uint16_t *getDataForYesOrNo(uint16_t norm16) const {
const uint16_t *getMapping(uint16_t norm16) const { return extraData+(norm16>>OFFSET_SHIFT); } return extraData+(norm16>>OFFSET_SHIFT);
}
const uint16_t *getDataForMaybe(uint16_t norm16) const {
return extraData+((norm16-minMaybeNo+limitNoNo)>>OFFSET_SHIFT);
}
const uint16_t *getData(uint16_t norm16) const {
if(norm16>=minMaybeNo) {
norm16=norm16-minMaybeNo+limitNoNo;
}
return extraData+(norm16>>OFFSET_SHIFT);
}
const uint16_t *getCompositionsListForDecompYes(uint16_t norm16) const { const uint16_t *getCompositionsListForDecompYes(uint16_t norm16) const {
if(norm16<JAMO_L || MIN_NORMAL_MAYBE_YES<=norm16) { if(norm16<JAMO_L || MIN_NORMAL_MAYBE_YES<=norm16) {
return nullptr; return nullptr;
} else if(norm16<minMaybeYes) {
return getMapping(norm16); // for yesYes; if Jamo L: harmless empty list
} else { } else {
return maybeYesCompositions+norm16-minMaybeYes; // if yesYes: if Jamo L: harmless empty list
return getData(norm16);
} }
} }
const uint16_t *getCompositionsListForComposite(uint16_t norm16) const { const uint16_t *getCompositionsListForComposite(uint16_t norm16) const {
// A composite has both mapping & compositions list. // A composite has both mapping & compositions list.
const uint16_t *list=getMapping(norm16); const uint16_t *list=getData(norm16);
return list+ // mapping pointer return list+ // mapping pointer
1+ // +1 to skip the first unit with the mapping length 1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length (*list&MAPPING_LENGTH_MASK); // + mapping length
} }
const uint16_t *getCompositionsListForMaybe(uint16_t norm16) const {
// minMaybeYes<=norm16<MIN_NORMAL_MAYBE_YES
return maybeYesCompositions+((norm16-minMaybeYes)>>OFFSET_SHIFT);
}
/** /**
* @param c code point must have compositions * @param c code point must have compositions
* @return compositions list pointer * @return compositions list pointer
@ -692,11 +706,13 @@ private:
/** For FCC: Given norm16 HAS_COMP_BOUNDARY_AFTER, does it have tccc<=1? */ /** For FCC: Given norm16 HAS_COMP_BOUNDARY_AFTER, does it have tccc<=1? */
UBool isTrailCC01ForCompBoundaryAfter(uint16_t norm16) const { UBool isTrailCC01ForCompBoundaryAfter(uint16_t norm16) const {
return isInert(norm16) || (isDecompNoAlgorithmic(norm16) ? return isInert(norm16) || (isDecompNoAlgorithmic(norm16) ?
(norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getMapping(norm16) <= 0x1ff); (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getDataForYesOrNo(norm16) <= 0x1ff);
} }
const char16_t *findPreviousCompBoundary(const char16_t *start, const char16_t *p, UBool onlyContiguous) const; const char16_t *findPreviousCompBoundary(const char16_t *start, const char16_t *p,
const char16_t *findNextCompBoundary(const char16_t *p, const char16_t *limit, UBool onlyContiguous) const; UBool onlyContiguous) const;
const char16_t *findNextCompBoundary(const char16_t *p, const char16_t *limit,
UBool onlyContiguous) const;
const char16_t *findPreviousFCDBoundary(const char16_t *start, const char16_t *p) const; const char16_t *findPreviousFCDBoundary(const char16_t *start, const char16_t *p) const;
const char16_t *findNextFCDBoundary(const char16_t *p, const char16_t *limit) const; const char16_t *findNextFCDBoundary(const char16_t *p, const char16_t *limit) const;
@ -723,11 +739,12 @@ private:
uint16_t minNoNoEmpty; uint16_t minNoNoEmpty;
uint16_t limitNoNo; uint16_t limitNoNo;
uint16_t centerNoNoDelta; uint16_t centerNoNoDelta;
uint16_t minMaybeNo;
uint16_t minMaybeNoCombinesFwd;
uint16_t minMaybeYes; uint16_t minMaybeYes;
const UCPTrie *normTrie; const UCPTrie *normTrie;
const uint16_t *maybeYesCompositions; const uint16_t *extraData; // mappings and/or compositions
const uint16_t *extraData; // mappings and/or compositions for yesYes, yesNo & noNo characters
const uint8_t *smallFCD; // [0x100] one bit per 32 BMP code points, set if any FCD!=0 const uint8_t *smallFCD; // [0x100] one bit per 32 BMP code points, set if any FCD!=0
UInitOnce fCanonIterDataInitOnce {}; UInitOnce fCanonIterDataInitOnce {};
@ -785,7 +802,7 @@ unorm_getFCD16(UChar32 c);
/** /**
* Format of Normalizer2 .nrm data files. * Format of Normalizer2 .nrm data files.
* Format version 4.0. * Format version 5.0.
* *
* Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms. * Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms.
* ICU ships with data files for standard Unicode Normalization Forms * ICU ships with data files for standard Unicode Normalization Forms
@ -807,7 +824,7 @@ unorm_getFCD16(UChar32 c);
* Constants are defined as enum values of the Normalizer2Impl class. * Constants are defined as enum values of the Normalizer2Impl class.
* *
* Many details of the data structures are described in the design doc * Many details of the data structures are described in the design doc
* which is at https://icu.unicode.org/design/normalization/custom * which is at https://unicode-org.github.io/icu/design/normalization/custom.html
* *
* int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4; * int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4;
* *
@ -829,7 +846,9 @@ unorm_getFCD16(UChar32 c);
* *
* The next eight indexes are thresholds of 16-bit trie values for ranges of * The next eight indexes are thresholds of 16-bit trie values for ranges of
* values indicating multiple normalization properties. * values indicating multiple normalization properties.
* They are listed here in threshold order, not in the order they are stored in the indexes. * Format version 5 adds the two minMaybeNo* threshold indexes.
* The thresholds are listed here in threshold order,
* not in the order they are stored in the indexes.
* minYesNo=indexes[IX_MIN_YES_NO]; * minYesNo=indexes[IX_MIN_YES_NO];
* minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY]; * minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY];
* minNoNo=indexes[IX_MIN_NO_NO]; * minNoNo=indexes[IX_MIN_NO_NO];
@ -837,6 +856,8 @@ unorm_getFCD16(UChar32 c);
* minNoNoCompNoMaybeCC=indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC]; * minNoNoCompNoMaybeCC=indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC];
* minNoNoEmpty=indexes[IX_MIN_NO_NO_EMPTY]; * minNoNoEmpty=indexes[IX_MIN_NO_NO_EMPTY];
* limitNoNo=indexes[IX_LIMIT_NO_NO]; * limitNoNo=indexes[IX_LIMIT_NO_NO];
* minMaybeNo=indexes[IX_MIN_MAYBE_NO];
* minMaybeNoCombinesFwd=indexes[IX_MIN_MAYBE_NO_COMBINES_FWD];
* minMaybeYes=indexes[IX_MIN_MAYBE_YES]; * minMaybeYes=indexes[IX_MIN_MAYBE_YES];
* See the normTrie description below and the design doc for details. * See the normTrie description below and the design doc for details.
* *
@ -845,13 +866,14 @@ unorm_getFCD16(UChar32 c);
* The trie holds the main normalization data. Each code point is mapped to a 16-bit value. * The trie holds the main normalization data. Each code point is mapped to a 16-bit value.
* Rather than using independent bits in the value (which would require more than 16 bits), * Rather than using independent bits in the value (which would require more than 16 bits),
* information is extracted primarily via range checks. * information is extracted primarily via range checks.
* Except, format version 3 uses bit 0 for hasCompBoundaryAfter(). * Except, format version 3+ uses bit 0 for hasCompBoundaryAfter().
* For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo * For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo
* means that the character has NF*C_QC=Yes and NF*D_QC=No properties, * means that the character has NF*C_QC=Yes and NF*D_QC=No properties,
* which means it has a two-way (round-trip) decomposition mapping. * which means it has a two-way (round-trip) decomposition mapping.
* Values in the range 2<=norm16<limitNoNo are also directly indexes into the extraData * Values in the ranges 2<=norm16<limitNoNo and minMaybeNo<=norm16<minMaybeYes
* are also directly indexes into the extraData
* pointing to mappings, compositions lists, or both. * pointing to mappings, compositions lists, or both.
* Value norm16==INERT (0 in versions 1 & 2, 1 in version 3) * Value norm16==INERT (0 in versions 1 & 2, 1 in version 3+)
* means that the character is normalization-inert, that is, * means that the character is normalization-inert, that is,
* it does not have a mapping, does not participate in composition, has a zero * it does not have a mapping, does not participate in composition, has a zero
* canonical combining class, and forms a boundary where text before it and after it * canonical combining class, and forms a boundary where text before it and after it
@ -870,33 +892,38 @@ unorm_getFCD16(UChar32 c);
* When the lead surrogate unit's value exceeds the quick check minimum during processing, * When the lead surrogate unit's value exceeds the quick check minimum during processing,
* the properties for the full supplementary code point need to be looked up. * the properties for the full supplementary code point need to be looked up.
* *
* uint16_t maybeYesCompositions[MIN_NORMAL_MAYBE_YES-minMaybeYes];
* uint16_t extraData[]; * uint16_t extraData[];
* *
* There is only one byte offset for the end of these two arrays. * The extraData array contains many per-character data sections.
* The split between them is given by the constant and variable mentioned above. * Each section contains mappings and/or composition lists.
* In version 3, the difference must be shifted right by OFFSET_SHIFT. * The norm16 value of each character that has such data is directly an index to
* a section of the extraData array.
* *
* The maybeYesCompositions array contains compositions lists for characters that * In version 3+, the norm16 values must be shifted right by OFFSET_SHIFT
* combine both forward (as starters in composition pairs)
* and backward (as trailing characters in composition pairs).
* Such characters do not occur in Unicode 5.2 but are allowed by
* the Unicode Normalization algorithms.
* If there are no such characters, then minMaybeYes==MIN_NORMAL_MAYBE_YES
* and the maybeYesCompositions array is empty.
* If there are such characters, then minMaybeYes is subtracted from their norm16 values
* to get the index into this array.
*
* The extraData array contains compositions lists for "YesYes" characters,
* followed by mappings and optional compositions lists for "YesNo" characters,
* followed by only mappings for "NoNo" characters.
* (Referring to pairs of NFC/NFD quick check values.)
* The norm16 values of those characters are directly indexes into the extraData array.
* In version 3, the norm16 values must be shifted right by OFFSET_SHIFT
* for accessing extraData. * for accessing extraData.
* *
* The data structures for compositions lists and mappings are described in the design doc. * The data structures for compositions lists and mappings are described in the design doc.
* *
* In version 4 and below, the composition lists for MaybeYes characters were stored before
* the data for other characters.
* This sub-array had a length of MIN_NORMAL_MAYBE_YES-minMaybeYes.
* In version 3 & 4, the difference must be shifted right by OFFSET_SHIFT.
*
* In version 5, the data for MaybeNo and MaybeYes characters is stored after
* the data for other characters.
*
* If there are no MaybeNo and no MaybeYes characters,
* then minMaybeYes==minMaybeNo==MIN_NORMAL_MAYBE_YES.
* If there are such characters, then minMaybeNo is subtracted from their norm16 values
* to get the index into the extraData.
* In version 4 and below, the data index for Yes* and No* characters needs to be
* offset by the length of the MaybeYes data.
* In version 5, the data index for Maybe* characters needs to be offset by limitNoNo.
*
* Version 5 is the first to support MaybeNo characters, and
* adds the minMaybeNo and minMaybeNoCombinesFwd thresholds and
* the corresponding sections of the extraData.
*
* uint8_t smallFCD[0x100]; -- new in format version 2 * uint8_t smallFCD[0x100]; -- new in format version 2
* *
* This is a bit set to help speed up FCD value lookups in the absence of a full * This is a bit set to help speed up FCD value lookups in the absence of a full
@ -936,7 +963,7 @@ unorm_getFCD16(UChar32 c);
* to make room for two bits (three values) indicating whether the tccc is 0, 1, or greater. * to make room for two bits (three values) indicating whether the tccc is 0, 1, or greater.
* See DELTA_TCCC_MASK etc. * See DELTA_TCCC_MASK etc.
* This helps with fetching tccc/FCD values and FCC hasCompBoundaryAfter(). * This helps with fetching tccc/FCD values and FCC hasCompBoundaryAfter().
* minMaybeYes is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly. * minMaybeNo is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly.
* *
* - Algorithmic mappings are only used for mapping to "comp yes and ccc=0" characters, * - Algorithmic mappings are only used for mapping to "comp yes and ccc=0" characters,
* and ASCII characters are mapped algorithmically only to other ASCII characters. * and ASCII characters are mapped algorithmically only to other ASCII characters.
@ -982,6 +1009,23 @@ unorm_getFCD16(UChar32 c);
* gennorm2 now has to reject mappings for surrogate code points. * gennorm2 now has to reject mappings for surrogate code points.
* UTS #46 maps unpaired surrogates to U+FFFD in code rather than via its * UTS #46 maps unpaired surrogates to U+FFFD in code rather than via its
* custom normalization data file. * custom normalization data file.
*
* Changes from format version 4 to format version 5 (ICU 76) ------------------
*
* Unicode 16 adds the first MaybeYes characters which combine both backward and forward,
* taking this formerly theoretical data structure into reality.
*
* Unicode 16 also adds the first characters that have two-way mappings whose first characters
* combine backward. In order for normalization and the quick check to work properly,
* these composite characters also must be marked as NFC_QC=Maybe,
* corresponding to "combines back", although the composites themselves do not combine backward.
* Format version 5 adds two new ranges between "algorithmic NoNo" and MaybeYes,
* with thresholds minMaybeNo and minMaybeNoCombinesFwd,
* and indexes[IX_MIN_MAYBE_NO] and indexes[IX_MIN_MAYBE_NO_COMBINES_FWD],
* and corresponding mappings and composition lists in the extraData.
*
* Format version 5 moves the data for Maybe* characters from the start of the extraData array
* to its end.
*/ */
#endif /* !UCONFIG_NO_NORMALIZATION */ #endif /* !UCONFIG_NO_NORMALIZATION */

View File

@ -120,12 +120,12 @@ PatternProps::isSyntax(UChar32 c) {
if(c<0) { if(c<0) {
return false; return false;
} else if(c<=0xff) { } else if(c<=0xff) {
return (UBool)(latin1[c]>>1)&1; return (latin1[c] >> 1) & 1;
} else if(c<0x2010) { } else if(c<0x2010) {
return false; return false;
} else if(c<=0x3030) { } else if(c<=0x3030) {
uint32_t bits=syntax2000[index2000[(c-0x2000)>>5]]; uint32_t bits=syntax2000[index2000[(c-0x2000)>>5]];
return (UBool)((bits>>(c&0x1f))&1); return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) { } else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c; return c<=0xfd3f || 0xfe45<=c;
} else { } else {
@ -138,12 +138,12 @@ PatternProps::isSyntaxOrWhiteSpace(UChar32 c) {
if(c<0) { if(c<0) {
return false; return false;
} else if(c<=0xff) { } else if(c<=0xff) {
return (UBool)(latin1[c]&1); return latin1[c] & 1;
} else if(c<0x200e) { } else if(c<0x200e) {
return false; return false;
} else if(c<=0x3030) { } else if(c<=0x3030) {
uint32_t bits=syntaxOrWhiteSpace2000[index2000[(c-0x2000)>>5]]; uint32_t bits=syntaxOrWhiteSpace2000[index2000[(c-0x2000)>>5]];
return (UBool)((bits>>(c&0x1f))&1); return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) { } else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c; return c<=0xfd3f || 0xfe45<=c;
} else { } else {
@ -156,7 +156,7 @@ PatternProps::isWhiteSpace(UChar32 c) {
if(c<0) { if(c<0) {
return false; return false;
} else if(c<=0xff) { } else if(c<=0xff) {
return (UBool)(latin1[c]>>2)&1; return (latin1[c] >> 2) & 1;
} else if(0x200e<=c && c<=0x2029) { } else if(0x200e<=c && c<=0x2029) {
return c<=0x200f || 0x2028<=c; return c<=0x200f || 0x2028<=c;
} else { } else {

View File

@ -43,7 +43,7 @@ getASCIIPropertyNameChar(const char *name) {
) {} ) {}
if(c!=0) { if(c!=0) {
return (i<<8)|(uint8_t)uprv_asciitolower((char)c); return (i << 8) | static_cast<uint8_t>(uprv_asciitolower(c));
} else { } else {
return i<<8; return i<<8;
} }
@ -66,7 +66,7 @@ getEBCDICPropertyNameChar(const char *name) {
) {} ) {}
if(c!=0) { if(c!=0) {
return (i<<8)|(uint8_t)uprv_ebcdictolower((char)c); return (i << 8) | static_cast<uint8_t>(uprv_ebcdictolower(c));
} else { } else {
return i<<8; return i<<8;
} }
@ -231,7 +231,7 @@ UBool PropNameData::containsName(BytesTrie &trie, const char *name) {
if(!USTRINGTRIE_HAS_NEXT(result)) { if(!USTRINGTRIE_HAS_NEXT(result)) {
return false; return false;
} }
result=trie.next((uint8_t)c); result = trie.next(static_cast<uint8_t>(c));
} }
return USTRINGTRIE_HAS_VALUE(result); return USTRINGTRIE_HAS_VALUE(result);
} }

File diff suppressed because it is too large Load Diff

View File

@ -102,29 +102,29 @@ _findRow(UPropsVectors *pv, UChar32 rangeStart) {
/* check the vicinity of the last-seen row (start searching with an unrolled loop) */ /* check the vicinity of the last-seen row (start searching with an unrolled loop) */
row=pv->v+prevRow*columns; row=pv->v+prevRow*columns;
if(rangeStart>=(UChar32)row[0]) { if (rangeStart >= static_cast<UChar32>(row[0])) {
if(rangeStart<(UChar32)row[1]) { if (rangeStart < static_cast<UChar32>(row[1])) {
/* same row as last seen */ /* same row as last seen */
return row; return row;
} else if(rangeStart<(UChar32)(row+=columns)[1]) { } else if (rangeStart < static_cast<UChar32>((row += columns)[1])) {
/* next row after the last one */ /* next row after the last one */
pv->prevRow=prevRow+1; pv->prevRow=prevRow+1;
return row; return row;
} else if(rangeStart<(UChar32)(row+=columns)[1]) { } else if (rangeStart < static_cast<UChar32>((row += columns)[1])) {
/* second row after the last one */ /* second row after the last one */
pv->prevRow=prevRow+2; pv->prevRow=prevRow+2;
return row; return row;
} else if((rangeStart-(UChar32)row[1])<10) { } else if ((rangeStart - static_cast<UChar32>(row[1])) < 10) {
/* we are close, continue looping */ /* we are close, continue looping */
prevRow+=2; prevRow+=2;
do { do {
++prevRow; ++prevRow;
row+=columns; row+=columns;
} while(rangeStart>=(UChar32)row[1]); } while (rangeStart >= static_cast<UChar32>(row[1]));
pv->prevRow=prevRow; pv->prevRow=prevRow;
return row; return row;
} }
} else if(rangeStart<(UChar32)pv->v[1]) { } else if (rangeStart < static_cast<UChar32>(pv->v[1])) {
/* the very first row */ /* the very first row */
pv->prevRow=0; pv->prevRow=0;
return pv->v; return pv->v;
@ -135,9 +135,9 @@ _findRow(UPropsVectors *pv, UChar32 rangeStart) {
while(start<limit-1) { while(start<limit-1) {
i=(start+limit)/2; i=(start+limit)/2;
row=pv->v+i*columns; row=pv->v+i*columns;
if(rangeStart<(UChar32)row[0]) { if (rangeStart < static_cast<UChar32>(row[0])) {
limit=i; limit=i;
} else if(rangeStart<(UChar32)row[1]) { } else if (rangeStart < static_cast<UChar32>(row[1])) {
pv->prevRow=i; pv->prevRow=i;
return row; return row;
} else { } else {
@ -194,8 +194,8 @@ upvec_setValue(UPropsVectors *pv,
* input range (only possible for the first and last rows) * input range (only possible for the first and last rows)
* and if their value differs from the input value. * and if their value differs from the input value.
*/ */
splitFirstRow= (UBool)(start!=(UChar32)firstRow[0] && value!=(firstRow[column]&mask)); splitFirstRow = start != static_cast<UChar32>(firstRow[0]) && value != (firstRow[column] & mask);
splitLastRow= (UBool)(limit!=(UChar32)lastRow[1] && value!=(lastRow[column]&mask)); splitLastRow = limit != static_cast<UChar32>(lastRow[1]) && value != (lastRow[column] & mask);
/* split first/last rows if necessary */ /* split first/last rows if necessary */
if(splitFirstRow || splitLastRow) { if(splitFirstRow || splitLastRow) {
@ -312,8 +312,8 @@ upvec_getRow(const UPropsVectors *pv, int32_t rowIndex,
static int32_t U_CALLCONV static int32_t U_CALLCONV
upvec_compareRows(const void *context, const void *l, const void *r) { upvec_compareRows(const void *context, const void *l, const void *r) {
const uint32_t *left=(const uint32_t *)l, *right=(const uint32_t *)r; const uint32_t* left = static_cast<const uint32_t*>(l), *right = static_cast<const uint32_t*>(r);
const UPropsVectors *pv=(const UPropsVectors *)context; const UPropsVectors* pv = static_cast<const UPropsVectors*>(context);
int32_t i, count, columns; int32_t i, count, columns;
count=columns=pv->columns; /* includes start/limit columns */ count=columns=pv->columns; /* includes start/limit columns */

View File

@ -97,12 +97,12 @@ digitToBasic(int32_t digit, UBool uppercase) {
/* 26..35 map to ASCII 0..9 */ /* 26..35 map to ASCII 0..9 */
if(digit<26) { if(digit<26) {
if(uppercase) { if(uppercase) {
return (char)(_CAPITAL_A+digit); return static_cast<char>(_CAPITAL_A + digit);
} else { } else {
return (char)(_SMALL_A+digit); return static_cast<char>(_SMALL_A + digit);
} }
} else { } else {
return (char)((_ZERO_-26)+digit); return static_cast<char>((_ZERO_ - 26) + digit);
} }
} }
@ -353,10 +353,10 @@ u_strToPunycode(const char16_t *src, int32_t srcLength,
} }
if(destLength<destCapacity) { if(destLength<destCapacity) {
dest[destLength]=digitToBasic(q, (UBool)(cpBuffer[j]<0)); dest[destLength] = digitToBasic(q, cpBuffer[j] < 0);
} }
++destLength; ++destLength;
bias=adaptBias(delta, handledCPCount+1, (UBool)(handledCPCount==basicLength)); bias = adaptBias(delta, handledCPCount + 1, handledCPCount == basicLength);
delta=0; delta=0;
++handledCPCount; ++handledCPCount;
} }
@ -421,7 +421,7 @@ u_strFromPunycode(const char16_t *src, int32_t srcLength,
} }
if(j<destCapacity) { if(j<destCapacity) {
dest[j]=(char16_t)b; dest[j] = b;
if(caseFlags!=nullptr) { if(caseFlags!=nullptr) {
caseFlags[j]=IS_BASIC_UPPERCASE(b); caseFlags[j]=IS_BASIC_UPPERCASE(b);
@ -500,7 +500,7 @@ u_strFromPunycode(const char16_t *src, int32_t srcLength,
* where needed instead of in for() loop tail. * where needed instead of in for() loop tail.
*/ */
++destCPCount; ++destCPCount;
bias=adaptBias(i-oldi, destCPCount, (UBool)(oldi==0)); bias = adaptBias(i - oldi, destCPCount, oldi == 0);
/* /*
* i was supposed to wrap around from (incremented) destCPCount to 0, * i was supposed to wrap around from (incremented) destCPCount to 0,

View File

@ -46,11 +46,6 @@
// First, the platform type. Need this for U_PLATFORM. // First, the platform type. Need this for U_PLATFORM.
#include "unicode/platform.h" #include "unicode/platform.h"
#if U_PLATFORM == U_PF_MINGW && defined __STRICT_ANSI__
/* tzset isn't defined in strict ANSI on MinGW. */
#undef __STRICT_ANSI__
#endif
/* /*
* Cygwin with GCC requires inclusion of time.h after the above disabling strict asci mode statement. * Cygwin with GCC requires inclusion of time.h after the above disabling strict asci mode statement.
*/ */
@ -180,8 +175,8 @@ typedef union {
int64_t i64; /* This must be defined first in order to allow the initialization to work. This is a C89 feature. */ int64_t i64; /* This must be defined first in order to allow the initialization to work. This is a C89 feature. */
double d64; double d64;
} BitPatternConversion; } BitPatternConversion;
static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000) }; static const BitPatternConversion gNan = {static_cast<int64_t>(INT64_C(0x7FF8000000000000))};
static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000) }; static const BitPatternConversion gInf = {static_cast<int64_t>(INT64_C(0x7FF0000000000000))};
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
Platform utilities Platform utilities
@ -230,7 +225,7 @@ u_signBit(double d) {
#if U_IS_BIG_ENDIAN #if U_IS_BIG_ENDIAN
hiByte = *(uint8_t *)&d; hiByte = *(uint8_t *)&d;
#else #else
hiByte = *(((uint8_t *)&d) + sizeof(double) - 1); hiByte = *(reinterpret_cast<uint8_t*>(&d) + sizeof(double) - 1);
#endif #endif
return (hiByte & 0x80) != 0; return (hiByte & 0x80) != 0;
} }
@ -347,7 +342,7 @@ uprv_isNaN(double number)
BitPatternConversion convertedNumber; BitPatternConversion convertedNumber;
convertedNumber.d64 = number; convertedNumber.d64 = number;
/* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */ /* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) > gInf.i64); return (convertedNumber.i64 & U_INT64_MAX) > gInf.i64;
#elif U_PLATFORM == U_PF_OS390 #elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number, uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
@ -373,7 +368,7 @@ uprv_isInfinite(double number)
BitPatternConversion convertedNumber; BitPatternConversion convertedNumber;
convertedNumber.d64 = number; convertedNumber.d64 = number;
/* Infinity is exactly 0x7FF0000000000000U. */ /* Infinity is exactly 0x7FF0000000000000U. */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) == gInf.i64); return (convertedNumber.i64 & U_INT64_MAX) == gInf.i64;
#elif U_PLATFORM == U_PF_OS390 #elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number, uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
sizeof(uint32_t)); sizeof(uint32_t));
@ -394,7 +389,7 @@ U_CAPI UBool U_EXPORT2
uprv_isPositiveInfinity(double number) uprv_isPositiveInfinity(double number)
{ {
#if IEEE_754 || U_PLATFORM == U_PF_OS390 #if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number > 0 && uprv_isInfinite(number)); return number > 0 && uprv_isInfinite(number);
#else #else
return uprv_isInfinite(number); return uprv_isInfinite(number);
#endif #endif
@ -404,7 +399,7 @@ U_CAPI UBool U_EXPORT2
uprv_isNegativeInfinity(double number) uprv_isNegativeInfinity(double number)
{ {
#if IEEE_754 || U_PLATFORM == U_PF_OS390 #if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number < 0 && uprv_isInfinite(number)); return number < 0 && uprv_isInfinite(number);
#else #else
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number, uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
@ -749,11 +744,11 @@ static UBool isValidOlsonID(const char *id) {
The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30", The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30",
"GRNLNDST3GRNLNDDT" or similar, so we cannot use it. "GRNLNDST3GRNLNDDT" or similar, so we cannot use it.
The rest of the time it could be an Olson ID. George */ The rest of the time it could be an Olson ID. George */
return (UBool)(id[idx] == 0 return id[idx] == 0
|| uprv_strcmp(id, "PST8PDT") == 0 || uprv_strcmp(id, "PST8PDT") == 0
|| uprv_strcmp(id, "MST7MDT") == 0 || uprv_strcmp(id, "MST7MDT") == 0
|| uprv_strcmp(id, "CST6CDT") == 0 || uprv_strcmp(id, "CST6CDT") == 0
|| uprv_strcmp(id, "EST5EDT") == 0); || uprv_strcmp(id, "EST5EDT") == 0;
} }
/* On some Unix-like OS, 'posix' subdirectory in /* On some Unix-like OS, 'posix' subdirectory in
@ -932,7 +927,7 @@ static UBool compareBinaryFiles(const char* defaultTZFileName, const char* TZFil
*/ */
if (tzInfo->defaultTZBuffer == nullptr) { if (tzInfo->defaultTZBuffer == nullptr) {
rewind(tzInfo->defaultTZFilePtr); rewind(tzInfo->defaultTZFilePtr);
tzInfo->defaultTZBuffer = (char*)uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize); tzInfo->defaultTZBuffer = static_cast<char*>(uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize));
sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzInfo->defaultTZFilePtr); sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzInfo->defaultTZFilePtr);
} }
rewind(file); rewind(file);

View File

@ -90,6 +90,8 @@ typedef size_t uintptr_t;
# define U_NL_LANGINFO_CODESET -1 # define U_NL_LANGINFO_CODESET -1
#elif U_PLATFORM == U_PF_OS400 #elif U_PLATFORM == U_PF_OS400
/* not defined */ /* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined */
#else #else
# define U_NL_LANGINFO_CODESET CODESET # define U_NL_LANGINFO_CODESET CODESET
#endif #endif
@ -103,6 +105,8 @@ typedef size_t uintptr_t;
#endif #endif
#elif U_PLATFORM == U_PF_OS400 #elif U_PLATFORM == U_PF_OS400
/* not defined */ /* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined */
#else #else
# define U_TZSET tzset # define U_TZSET tzset
#endif #endif
@ -141,6 +145,8 @@ typedef size_t uintptr_t;
#endif #endif
#elif U_PLATFORM == U_PF_OS400 #elif U_PLATFORM == U_PF_OS400
/* not defined */ /* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined, (well it is but a loop back to icu) */
#else #else
# define U_TZNAME tzname # define U_TZNAME tzname
#endif #endif
@ -553,7 +559,7 @@ inline int32_t pinCapacity(T *dest, int32_t capacity) {
if (maxInt < destInt) { if (maxInt < destInt) {
// Less than 2GB to the end of the address space. // Less than 2GB to the end of the address space.
// Pin to that to prevent address overflow. // Pin to that to prevent address overflow.
maxInt = (uintptr_t)-1; maxInt = static_cast<uintptr_t>(-1);
} }
# endif # endif

View File

@ -110,7 +110,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules,
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
} }
const RBBIDataHeader *data = (const RBBIDataHeader *)compiledRules; const RBBIDataHeader* data = reinterpret_cast<const RBBIDataHeader*>(compiledRules);
if (data->fLength > ruleLength) { if (data->fLength > ruleLength) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return; return;
@ -553,7 +553,7 @@ int32_t RuleBasedBreakIterator::first() {
* @return The text's past-the-end offset. * @return The text's past-the-end offset.
*/ */
int32_t RuleBasedBreakIterator::last() { int32_t RuleBasedBreakIterator::last() {
int32_t endPos = (int32_t)utext_nativeLength(&fText); int32_t endPos = static_cast<int32_t>(utext_nativeLength(&fText));
UBool endShouldBeBoundary = isBoundary(endPos); // Has side effect of setting iterator position. UBool endShouldBeBoundary = isBoundary(endPos); // Has side effect of setting iterator position.
(void)endShouldBeBoundary; (void)endShouldBeBoundary;
U_ASSERT(endShouldBeBoundary); U_ASSERT(endShouldBeBoundary);
@ -625,7 +625,7 @@ int32_t RuleBasedBreakIterator::following(int32_t startPos) {
// Move requested offset to a code point start. It might be on a trail surrogate, // Move requested offset to a code point start. It might be on a trail surrogate,
// or on a trail byte if the input is UTF-8. Or it may be beyond the end of the text. // or on a trail byte if the input is UTF-8. Or it may be beyond the end of the text.
utext_setNativeIndex(&fText, startPos); utext_setNativeIndex(&fText, startPos);
startPos = (int32_t)utext_getNativeIndex(&fText); startPos = static_cast<int32_t>(utext_getNativeIndex(&fText));
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
fBreakCache->following(startPos, status); fBreakCache->following(startPos, status);
@ -881,7 +881,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
if (accepting == ACCEPTING_UNCONDITIONAL) { if (accepting == ACCEPTING_UNCONDITIONAL) {
// Match found, common case. // Match found, common case.
if (mode != RBBI_START) { if (mode != RBBI_START) {
result = (int32_t)UTEXT_GETNATIVEINDEX(&fText); result = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
} }
fRuleStatusIndex = row->fTagsIdx; // Remember the break status (tag) values. fRuleStatusIndex = row->fTagsIdx; // Remember the break status (tag) values.
} else if (accepting > ACCEPTING_UNCONDITIONAL) { } else if (accepting > ACCEPTING_UNCONDITIONAL) {
@ -905,7 +905,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
U_ASSERT(rule == 0 || rule > ACCEPTING_UNCONDITIONAL); U_ASSERT(rule == 0 || rule > ACCEPTING_UNCONDITIONAL);
U_ASSERT(rule == 0 || rule < fData->fForwardTable->fLookAheadResultsSize); U_ASSERT(rule == 0 || rule < fData->fForwardTable->fLookAheadResultsSize);
if (rule > ACCEPTING_UNCONDITIONAL) { if (rule > ACCEPTING_UNCONDITIONAL) {
int32_t pos = (int32_t)UTEXT_GETNATIVEINDEX(&fText); int32_t pos = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
fLookAheadMatches[rule] = pos; fLookAheadMatches[rule] = pos;
} }
@ -937,7 +937,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
if (result == initialPosition) { if (result == initialPosition) {
utext_setNativeIndex(&fText, initialPosition); utext_setNativeIndex(&fText, initialPosition);
utext_next32(&fText); utext_next32(&fText);
result = (int32_t)utext_getNativeIndex(&fText); result = static_cast<int32_t>(utext_getNativeIndex(&fText));
fRuleStatusIndex = 0; fRuleStatusIndex = 0;
} }
@ -1027,7 +1027,7 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) {
} }
// The state machine is done. Check whether it found a match... // The state machine is done. Check whether it found a match...
result = (int32_t)UTEXT_GETNATIVEINDEX(&fText); result = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
#ifdef RBBI_DEBUG #ifdef RBBI_DEBUG
if (gTrace) { if (gTrace) {
RBBIDebugPrintf("result = %d\n\n", result); RBBIDebugPrintf("result = %d\n\n", result);
@ -1091,7 +1091,7 @@ const uint8_t *RuleBasedBreakIterator::getBinaryRules(uint32_t &length) {
length = 0; length = 0;
if (fData != nullptr) { if (fData != nullptr) {
retPtr = (const uint8_t *)fData->fHeader; retPtr = reinterpret_cast<const uint8_t*>(fData->fHeader);
length = fData->fHeader->fLength; length = fData->fHeader->fLength;
} }
return retPtr; return retPtr;
@ -1187,7 +1187,7 @@ getLanguageBreakEngineFromFactory(UChar32 c, const char* locale)
int32_t i = gLanguageBreakFactories->size(); int32_t i = gLanguageBreakFactories->size();
const LanguageBreakEngine *lbe = nullptr; const LanguageBreakEngine *lbe = nullptr;
while (--i >= 0) { while (--i >= 0) {
LanguageBreakFactory *factory = (LanguageBreakFactory *)(gLanguageBreakFactories->elementAt(i)); LanguageBreakFactory* factory = static_cast<LanguageBreakFactory*>(gLanguageBreakFactories->elementAt(i));
lbe = factory->getEngineFor(c, locale); lbe = factory->getEngineFor(c, locale);
if (lbe != nullptr) { if (lbe != nullptr) {
break; break;
@ -1219,7 +1219,7 @@ RuleBasedBreakIterator::getLanguageBreakEngine(UChar32 c, const char* locale) {
int32_t i = fLanguageBreakEngines->size(); int32_t i = fLanguageBreakEngines->size();
while (--i >= 0) { while (--i >= 0) {
lbe = (const LanguageBreakEngine *)(fLanguageBreakEngines->elementAt(i)); lbe = static_cast<const LanguageBreakEngine*>(fLanguageBreakEngines->elementAt(i));
if (lbe->handles(c, locale)) { if (lbe->handles(c, locale)) {
return lbe; return lbe;
} }

View File

@ -146,7 +146,7 @@ void RuleBasedBreakIterator::DictionaryCache::populateDictionary(int32_t startPo
uint32_t dictStart = fBI->fData->fForwardTable->fDictCategoriesStart; uint32_t dictStart = fBI->fData->fForwardTable->fDictCategoriesStart;
while(U_SUCCESS(status)) { while(U_SUCCESS(status)) {
while((current = (int32_t)UTEXT_GETNATIVEINDEX(text)) < rangeEnd while ((current = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(text))) < rangeEnd
&& (category < dictStart)) { && (category < dictStart)) {
utext_next32(text); // TODO: cleaner loop structure. utext_next32(text); // TODO: cleaner loop structure.
c = utext_current32(text); c = utext_current32(text);
@ -221,7 +221,7 @@ void RuleBasedBreakIterator::BreakCache::reset(int32_t pos, int32_t ruleStatus)
fTextIdx = pos; fTextIdx = pos;
fBufIdx = 0; fBufIdx = 0;
fBoundaries[0] = pos; fBoundaries[0] = pos;
fStatuses[0] = (uint16_t)ruleStatus; fStatuses[0] = static_cast<uint16_t>(ruleStatus);
} }

View File

@ -104,10 +104,10 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
fDontFreeData = false; fDontFreeData = false;
if (data->fFTableLen != 0) { if (data->fFTableLen != 0) {
fForwardTable = (RBBIStateTable *)((char *)data + fHeader->fFTable); fForwardTable = reinterpret_cast<const RBBIStateTable*>(reinterpret_cast<const char*>(data) + fHeader->fFTable);
} }
if (data->fRTableLen != 0) { if (data->fRTableLen != 0) {
fReverseTable = (RBBIStateTable *)((char *)data + fHeader->fRTable); fReverseTable = reinterpret_cast<const RBBIStateTable*>(reinterpret_cast<const char*>(data) + fHeader->fRTable);
} }
fTrie = ucptrie_openFromBinary(UCPTRIE_TYPE_FAST, fTrie = ucptrie_openFromBinary(UCPTRIE_TYPE_FAST,
@ -130,7 +130,7 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
fRuleString = UnicodeString::fromUTF8(StringPiece(fRuleSource, fHeader->fRuleSourceLen)); fRuleString = UnicodeString::fromUTF8(StringPiece(fRuleSource, fHeader->fRuleSourceLen));
U_ASSERT(data->fRuleSourceLen > 0); U_ASSERT(data->fRuleSourceLen > 0);
fRuleStatusTable = (int32_t *)((char *)data + fHeader->fStatusTable); fRuleStatusTable = reinterpret_cast<const int32_t*>(reinterpret_cast<const char*>(data) + fHeader->fStatusTable);
fStatusMaxIdx = data->fStatusTableLen / sizeof(int32_t); fStatusMaxIdx = data->fStatusTableLen / sizeof(int32_t);
fRefCount = 1; fRefCount = 1;

View File

@ -103,7 +103,7 @@ RBBIRuleBuilder::~RBBIRuleBuilder() {
int i; int i;
for (i=0; ; i++) { for (i=0; ; i++) {
RBBINode *n = (RBBINode *)fUSetNodes->elementAt(i); RBBINode* n = static_cast<RBBINode*>(fUSetNodes->elementAt(i));
if (n==nullptr) { if (n==nullptr) {
break; break;
} }
@ -182,12 +182,12 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() {
} }
#endif #endif
RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize); LocalMemory<RBBIDataHeader> data(static_cast<RBBIDataHeader*>(uprv_malloc(totalSize)));
if (data == nullptr) { if (data.isNull()) {
*fStatus = U_MEMORY_ALLOCATION_ERROR; *fStatus = U_MEMORY_ALLOCATION_ERROR;
return nullptr; return nullptr;
} }
uprv_memset(data, 0, totalSize); uprv_memset(data.getAlias(), 0, totalSize);
data->fMagic = 0xb1a0; data->fMagic = 0xb1a0;
@ -213,23 +213,23 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() {
uprv_memset(data->fReserved, 0, sizeof(data->fReserved)); uprv_memset(data->fReserved, 0, sizeof(data->fReserved));
fForwardTable->exportTable((uint8_t *)data + data->fFTable); fForwardTable->exportTable(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fFTable);
fForwardTable->exportSafeTable((uint8_t *)data + data->fRTable); fForwardTable->exportSafeTable(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fRTable);
fSetBuilder->serializeTrie ((uint8_t *)data + data->fTrie); fSetBuilder->serializeTrie(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fTrie);
int32_t *ruleStatusTable = (int32_t *)((uint8_t *)data + data->fStatusTable); int32_t* ruleStatusTable = reinterpret_cast<int32_t*>(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fStatusTable);
for (i=0; i<fRuleStatusVals->size(); i++) { for (i=0; i<fRuleStatusVals->size(); i++) {
ruleStatusTable[i] = fRuleStatusVals->elementAti(i); ruleStatusTable[i] = fRuleStatusVals->elementAti(i);
} }
u_strToUTF8WithSub((char *)data+data->fRuleSource, rulesSize, &rulesLengthInUTF8, u_strToUTF8WithSub(reinterpret_cast<char*>(data.getAlias()) + data->fRuleSource, rulesSize, &rulesLengthInUTF8,
fStrippedRules.getBuffer(), fStrippedRules.length(), fStrippedRules.getBuffer(), fStrippedRules.length(),
0xfffd, nullptr, fStatus); 0xfffd, nullptr, fStatus);
if (U_FAILURE(*fStatus)) { if (U_FAILURE(*fStatus)) {
return nullptr; return nullptr;
} }
return data; return data.orphan();
} }

View File

@ -748,7 +748,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
// First check whether we've already cached a set for this string. // First check whether we've already cached a set for this string.
// If so, just use the cached set in the new node. // If so, just use the cached set in the new node.
// delete any set provided by the caller, since we own it. // delete any set provided by the caller, since we own it.
el = (RBBISetTableEl *)uhash_get(fSetTable, &s); el = static_cast<RBBISetTableEl*>(uhash_get(fSetTable, &s));
if (el != nullptr) { if (el != nullptr) {
delete setToAdopt; delete setToAdopt;
node->fLeftChild = el->val; node->fLeftChild = el->val;
@ -794,7 +794,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
// //
// Add the new set to the set hash table. // Add the new set to the set hash table.
// //
el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl)); el = static_cast<RBBISetTableEl*>(uprv_malloc(sizeof(RBBISetTableEl)));
UnicodeString *tkey = new UnicodeString(s); UnicodeString *tkey = new UnicodeString(s);
if (tkey == nullptr || el == nullptr || setToAdopt == nullptr) { if (tkey == nullptr || el == nullptr || setToAdopt == nullptr) {
// Delete to avoid memory leak // Delete to avoid memory leak
@ -864,7 +864,7 @@ UChar32 RBBIRuleScanner::nextCharLL() {
UChar32 ch; UChar32 ch;
if (fNextIndex >= fRB->fRules.length()) { if (fNextIndex >= fRB->fRules.length()) {
return (UChar32)-1; return static_cast<UChar32>(-1);
} }
ch = fRB->fRules.char32At(fNextIndex); ch = fRB->fRules.char32At(fNextIndex);
if (U_IS_SURROGATE(ch)) { if (U_IS_SURROGATE(ch)) {
@ -939,7 +939,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
} }
} }
if (c.fChar == (UChar32)-1) { if (c.fChar == static_cast<UChar32>(-1)) {
return; return;
} }
if (fQuoteMode) { if (fQuoteMode) {
@ -958,7 +958,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
int32_t commentStart = fScanIndex; int32_t commentStart = fScanIndex;
for (;;) { for (;;) {
c.fChar = nextCharLL(); c.fChar = nextCharLL();
if (c.fChar == (UChar32)-1 || // EOF if (c.fChar == static_cast<UChar32>(-1) || // EOF
c.fChar == chCR || c.fChar == chCR ||
c.fChar == chLF || c.fChar == chLF ||
c.fChar == chNEL || c.fChar == chNEL ||
@ -968,7 +968,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
fRB->fStrippedRules.setCharAt(i, u' '); fRB->fStrippedRules.setCharAt(i, u' ');
} }
} }
if (c.fChar == (UChar32)-1) { if (c.fChar == static_cast<UChar32>(-1)) {
return; return;
} }
@ -1065,14 +1065,14 @@ void RBBIRuleScanner::parse() {
// Table row specified "escaped P" and the char is either 'p' or 'P'. // Table row specified "escaped P" and the char is either 'p' or 'P'.
break; break;
} }
if (tableEl->fCharClass == 252 && fC.fChar == (UChar32)-1) { if (tableEl->fCharClass == 252 && fC.fChar == static_cast<UChar32>(-1)) {
// Table row specified eof and we hit eof on the input. // Table row specified eof and we hit eof on the input.
break; break;
} }
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class && if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
fC.fEscaped == false && // char is not escaped && fC.fEscaped == false && // char is not escaped &&
fC.fChar != (UChar32)-1) { // char is not EOF fC.fChar != static_cast<UChar32>(-1)) { // char is not EOF
U_ASSERT((tableEl->fCharClass-128) < UPRV_LENGTHOF(fRuleSets)); U_ASSERT((tableEl->fCharClass-128) < UPRV_LENGTHOF(fRuleSets));
if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) { if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) {
// Table row specified a character class, or set of characters, // Table row specified a character class, or set of characters,
@ -1090,7 +1090,7 @@ void RBBIRuleScanner::parse() {
// We've found the row of the state table that matches the current input // We've found the row of the state table that matches the current input
// character from the rules string. // character from the rules string.
// Perform any action specified by this row in the state table. // Perform any action specified by this row in the state table.
if (doParseActions((int32_t)tableEl->fAction) == false) { if (doParseActions(static_cast<int32_t>(tableEl->fAction)) == false) {
// Break out of the state machine loop if the // Break out of the state machine loop if the
// the action signalled some kind of error, or // the action signalled some kind of error, or
// the action was to exit, occurs on normal end-of-rules-input. // the action was to exit, occurs on normal end-of-rules-input.

View File

@ -120,7 +120,7 @@ void RBBISetBuilder::buildRanges() {
// //
int ni; int ni;
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni); usetNode = static_cast<RBBINode*>(this->fRB->fUSetNodes->elementAt(ni));
if (usetNode==nullptr) { if (usetNode==nullptr) {
break; break;
} }
@ -251,7 +251,7 @@ void RBBISetBuilder::buildRanges() {
UnicodeString eofString(u"eof"); UnicodeString eofString(u"eof");
UnicodeString bofString(u"bof"); UnicodeString bofString(u"bof");
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni); usetNode = static_cast<RBBINode*>(this->fRB->fUSetNodes->elementAt(ni));
if (usetNode==nullptr) { if (usetNode==nullptr) {
break; break;
} }
@ -369,7 +369,7 @@ void RBBISetBuilder::addValToSets(UVector *sets, uint32_t val) {
int32_t ix; int32_t ix;
for (ix=0; ix<sets->size(); ix++) { for (ix=0; ix<sets->size(); ix++) {
RBBINode *usetNode = (RBBINode *)sets->elementAt(ix); RBBINode* usetNode = static_cast<RBBINode*>(sets->elementAt(ix));
addValToSet(usetNode, val); addValToSet(usetNode, val);
} }
} }
@ -380,7 +380,7 @@ void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
*fStatus = U_MEMORY_ALLOCATION_ERROR; *fStatus = U_MEMORY_ALLOCATION_ERROR;
return; return;
} }
leafNode->fVal = (unsigned short)val; leafNode->fVal = static_cast<unsigned short>(val);
if (usetNode->fLeftChild == nullptr) { if (usetNode->fLeftChild == nullptr) {
usetNode->fLeftChild = leafNode; usetNode->fLeftChild = leafNode;
leafNode->fParent = usetNode; leafNode->fParent = usetNode;
@ -441,7 +441,7 @@ UBool RBBISetBuilder::sawBOF() const {
//------------------------------------------------------------------------ //------------------------------------------------------------------------
UChar32 RBBISetBuilder::getFirstChar(int32_t category) const { UChar32 RBBISetBuilder::getFirstChar(int32_t category) const {
RangeDescriptor *rlRange; RangeDescriptor *rlRange;
UChar32 retVal = (UChar32)-1; UChar32 retVal = static_cast<UChar32>(-1);
for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) {
if (rlRange->fNum == category) { if (rlRange->fNum == category) {
retVal = rlRange->fStartChar; retVal = rlRange->fStartChar;
@ -674,7 +674,7 @@ void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
bool RangeDescriptor::isDictionaryRange() { bool RangeDescriptor::isDictionaryRange() {
static const char16_t *dictionary = u"dictionary"; static const char16_t *dictionary = u"dictionary";
for (int32_t i=0; i<fIncludesSets->size(); i++) { for (int32_t i=0; i<fIncludesSets->size(); i++) {
RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i); RBBINode* usetNode = static_cast<RBBINode*>(fIncludesSets->elementAt(i));
RBBINode *setRef = usetNode->fParent; RBBINode *setRef = usetNode->fParent;
if (setRef != nullptr) { if (setRef != nullptr) {
RBBINode *varRef = setRef->fParent; RBBINode *varRef = setRef->fParent;

View File

@ -41,7 +41,7 @@ U_CDECL_END
U_NAMESPACE_BEGIN U_NAMESPACE_BEGIN
RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status) RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status)
:fRules(rules), fRuleScanner(rs), ffffString(char16_t(0xffff)) : fRules(rules), fRuleScanner(rs), ffffString(static_cast<char16_t>(0xffff))
{ {
fHashTable = nullptr; fHashTable = nullptr;
fCachedSetLookup = nullptr; fCachedSetLookup = nullptr;
@ -76,9 +76,9 @@ const UnicodeString *RBBISymbolTable::lookup(const UnicodeString& s) const
RBBINode *exprNode; RBBINode *exprNode;
RBBINode *usetNode; RBBINode *usetNode;
const UnicodeString *retString; const UnicodeString *retString;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const RBBISymbolTable *This = const_cast<RBBISymbolTable*>(this); // cast off const
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &s); el = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &s));
if (el == nullptr) { if (el == nullptr) {
return nullptr; return nullptr;
} }
@ -119,7 +119,7 @@ const UnicodeString *RBBISymbolTable::lookup(const UnicodeString& s) const
const UnicodeFunctor *RBBISymbolTable::lookupMatcher(UChar32 ch) const const UnicodeFunctor *RBBISymbolTable::lookupMatcher(UChar32 ch) const
{ {
UnicodeSet *retVal = nullptr; UnicodeSet *retVal = nullptr;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const RBBISymbolTable *This = const_cast<RBBISymbolTable*>(this); // cast off const
if (ch == 0xffff) { if (ch == 0xffff) {
retVal = fCachedSetLookup; retVal = fCachedSetLookup;
This->fCachedSetLookup = nullptr; This->fCachedSetLookup = nullptr;
@ -170,7 +170,7 @@ RBBINode *RBBISymbolTable::lookupNode(const UnicodeString &key) const{
RBBINode *retNode = nullptr; RBBINode *retNode = nullptr;
RBBISymbolTableEntry *el; RBBISymbolTableEntry *el;
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key); el = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &key));
if (el != nullptr) { if (el != nullptr) {
retNode = el->val; retNode = el->val;
} }
@ -190,7 +190,7 @@ void RBBISymbolTable::addEntry (const UnicodeString &key, RBBINode *
if (U_FAILURE(err)) { if (U_FAILURE(err)) {
return; return;
} }
e = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key); e = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &key));
if (e != nullptr) { if (e != nullptr) {
err = U_BRK_VARIABLE_REDFINITION; err = U_BRK_VARIABLE_REDFINITION;
return; return;

View File

@ -51,7 +51,7 @@ RBBITableBuilder::RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode, UEr
RBBITableBuilder::~RBBITableBuilder() { RBBITableBuilder::~RBBITableBuilder() {
int i; int i;
for (i=0; i<fDStates->size(); i++) { for (i=0; i<fDStates->size(); i++) {
delete (RBBIStateDescriptor *)fDStates->elementAt(i); delete static_cast<RBBIStateDescriptor*>(fDStates->elementAt(i));
} }
delete fDStates; delete fDStates;
delete fSafeTable; delete fSafeTable;
@ -361,8 +361,8 @@ void RBBITableBuilder::calcFollowPos(RBBINode *n) {
UVector *LastPosOfLeftChild = n->fLeftChild->fLastPosSet; UVector *LastPosOfLeftChild = n->fLeftChild->fLastPosSet;
for (ix=0; ix<(uint32_t)LastPosOfLeftChild->size(); ix++) { for (ix = 0; ix < static_cast<uint32_t>(LastPosOfLeftChild->size()); ix++) {
i = (RBBINode *)LastPosOfLeftChild->elementAt(ix); i = static_cast<RBBINode*>(LastPosOfLeftChild->elementAt(ix));
setAdd(i->fFollowPos, n->fRightChild->fFirstPosSet); setAdd(i->fFollowPos, n->fRightChild->fFirstPosSet);
} }
} }
@ -373,8 +373,8 @@ void RBBITableBuilder::calcFollowPos(RBBINode *n) {
RBBINode *i; // again, n and i are the names from Aho's description. RBBINode *i; // again, n and i are the names from Aho's description.
uint32_t ix; uint32_t ix;
for (ix=0; ix<(uint32_t)n->fLastPosSet->size(); ix++) { for (ix = 0; ix < static_cast<uint32_t>(n->fLastPosSet->size()); ix++) {
i = (RBBINode *)n->fLastPosSet->elementAt(ix); i = static_cast<RBBINode*>(n->fLastPosSet->elementAt(ix));
setAdd(i->fFollowPos, n->fFirstPosSet); setAdd(i->fFollowPos, n->fFirstPosSet);
} }
} }
@ -445,7 +445,7 @@ void RBBITableBuilder::calcChainedFollowPos(RBBINode *tree, RBBINode *endMarkNod
int32_t startNodeIx; int32_t startNodeIx;
for (endNodeIx=0; endNodeIx<leafNodes.size(); endNodeIx++) { for (endNodeIx=0; endNodeIx<leafNodes.size(); endNodeIx++) {
RBBINode *endNode = (RBBINode *)leafNodes.elementAt(endNodeIx); RBBINode* endNode = static_cast<RBBINode*>(leafNodes.elementAt(endNodeIx));
// Identify leaf nodes that correspond to overall rule match positions. // Identify leaf nodes that correspond to overall rule match positions.
// These include the endMarkNode in their followPos sets. // These include the endMarkNode in their followPos sets.
@ -465,7 +465,7 @@ void RBBITableBuilder::calcChainedFollowPos(RBBINode *tree, RBBINode *endMarkNod
// with the same char class as our ending node. // with the same char class as our ending node.
RBBINode *startNode; RBBINode *startNode;
for (startNodeIx = 0; startNodeIx<matchStartNodes.size(); startNodeIx++) { for (startNodeIx = 0; startNodeIx<matchStartNodes.size(); startNodeIx++) {
startNode = (RBBINode *)matchStartNodes.elementAt(startNodeIx); startNode = static_cast<RBBINode*>(matchStartNodes.elementAt(startNodeIx));
if (startNode->fType != RBBINode::leafChar) { if (startNode->fType != RBBINode::leafChar) {
continue; continue;
} }
@ -525,7 +525,7 @@ void RBBITableBuilder::bofFixup() {
RBBINode *startNode; RBBINode *startNode;
int startNodeIx; int startNodeIx;
for (startNodeIx = 0; startNodeIx<matchStartNodes->size(); startNodeIx++) { for (startNodeIx = 0; startNodeIx<matchStartNodes->size(); startNodeIx++) {
startNode = (RBBINode *)matchStartNodes->elementAt(startNodeIx); startNode = static_cast<RBBINode*>(matchStartNodes->elementAt(startNodeIx));
if (startNode->fType != RBBINode::leafChar) { if (startNode->fType != RBBINode::leafChar) {
continue; continue;
} }
@ -605,7 +605,7 @@ void RBBITableBuilder::buildStateTable() {
int32_t tx; int32_t tx;
for (tx=1; tx<fDStates->size(); tx++) { for (tx=1; tx<fDStates->size(); tx++) {
RBBIStateDescriptor *temp; RBBIStateDescriptor *temp;
temp = (RBBIStateDescriptor *)fDStates->elementAt(tx); temp = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(tx));
if (temp->fMarked == false) { if (temp->fMarked == false) {
T = temp; T = temp;
break; break;
@ -628,7 +628,7 @@ void RBBITableBuilder::buildStateTable() {
RBBINode *p; RBBINode *p;
int32_t px; int32_t px;
for (px=0; px<T->fPositions->size(); px++) { for (px=0; px<T->fPositions->size(); px++) {
p = (RBBINode *)T->fPositions->elementAt(px); p = static_cast<RBBINode*>(T->fPositions->elementAt(px));
if ((p->fType == RBBINode::leafChar) && (p->fVal == a)) { if ((p->fType == RBBINode::leafChar) && (p->fVal == a)) {
if (U == nullptr) { if (U == nullptr) {
U = new UVector(*fStatus); U = new UVector(*fStatus);
@ -649,7 +649,7 @@ void RBBITableBuilder::buildStateTable() {
int ix; int ix;
for (ix=0; ix<fDStates->size(); ix++) { for (ix=0; ix<fDStates->size(); ix++) {
RBBIStateDescriptor *temp2; RBBIStateDescriptor *temp2;
temp2 = (RBBIStateDescriptor *)fDStates->elementAt(ix); temp2 = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(ix));
if (setEquals(U, temp2->fPositions)) { if (setEquals(U, temp2->fPositions)) {
delete U; delete U;
U = temp2->fPositions; U = temp2->fPositions;
@ -705,7 +705,7 @@ void RBBITableBuilder::mapLookAheadRules() {
fLookAheadRuleMap->setSize(fRB->fScanner->numRules() + 1); fLookAheadRuleMap->setSize(fRB->fScanner->numRules() + 1);
for (int32_t n=0; n<fDStates->size(); n++) { for (int32_t n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
int32_t laSlotForState = 0; int32_t laSlotForState = 0;
// Establish the look-ahead slot for this state, if the state covers // Establish the look-ahead slot for this state, if the state covers
@ -789,9 +789,9 @@ void RBBITableBuilder::flagAcceptingStates() {
} }
for (i=0; i<endMarkerNodes.size(); i++) { for (i=0; i<endMarkerNodes.size(); i++) {
endMarker = (RBBINode *)endMarkerNodes.elementAt(i); endMarker = static_cast<RBBINode*>(endMarkerNodes.elementAt(i));
for (n=0; n<fDStates->size(); n++) { for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
if (sd->fPositions->indexOf(endMarker) >= 0) { if (sd->fPositions->indexOf(endMarker) >= 0) {
// Any non-zero value for fAccepting means this is an accepting node. // Any non-zero value for fAccepting means this is an accepting node.
// The value is what will be returned to the user as the break status. // The value is what will be returned to the user as the break status.
@ -837,11 +837,11 @@ void RBBITableBuilder::flagLookAheadStates() {
return; return;
} }
for (i=0; i<lookAheadNodes.size(); i++) { for (i=0; i<lookAheadNodes.size(); i++) {
lookAheadNode = (RBBINode *)lookAheadNodes.elementAt(i); lookAheadNode = static_cast<RBBINode*>(lookAheadNodes.elementAt(i));
U_ASSERT(lookAheadNode->fType == RBBINode::NodeType::lookAhead); U_ASSERT(lookAheadNode->fType == RBBINode::NodeType::lookAhead);
for (n=0; n<fDStates->size(); n++) { for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
int32_t positionsIdx = sd->fPositions->indexOf(lookAheadNode); int32_t positionsIdx = sd->fPositions->indexOf(lookAheadNode);
if (positionsIdx >= 0) { if (positionsIdx >= 0) {
U_ASSERT(lookAheadNode == sd->fPositions->elementAt(positionsIdx)); U_ASSERT(lookAheadNode == sd->fPositions->elementAt(positionsIdx));
@ -882,10 +882,10 @@ void RBBITableBuilder::flagTaggedStates() {
return; return;
} }
for (i=0; i<tagNodes.size(); i++) { // For each tag node t (all of 'em) for (i=0; i<tagNodes.size(); i++) { // For each tag node t (all of 'em)
tagNode = (RBBINode *)tagNodes.elementAt(i); tagNode = static_cast<RBBINode*>(tagNodes.elementAt(i));
for (n=0; n<fDStates->size(); n++) { // For each state s (row in the state table) for (n=0; n<fDStates->size(); n++) { // For each state s (row in the state table)
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t
sortedAdd(&sd->fTagVals, tagNode->fVal); sortedAdd(&sd->fTagVals, tagNode->fVal);
} }
@ -923,12 +923,12 @@ void RBBITableBuilder::mergeRuleStatusVals() {
// We will need this as a default, for rule sets with no explicit tagging. // We will need this as a default, for rule sets with no explicit tagging.
if (fRB->fRuleStatusVals->size() == 0) { if (fRB->fRuleStatusVals->size() == 0) {
fRB->fRuleStatusVals->addElement(1, *fStatus); // Num of statuses in group fRB->fRuleStatusVals->addElement(1, *fStatus); // Num of statuses in group
fRB->fRuleStatusVals->addElement((int32_t)0, *fStatus); // and our single status of zero fRB->fRuleStatusVals->addElement(static_cast<int32_t>(0), *fStatus); // and our single status of zero
} }
// For each state // For each state
for (n=0; n<fDStates->size(); n++) { for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
UVector *thisStatesTagValues = sd->fTagVals; UVector *thisStatesTagValues = sd->fTagVals;
if (thisStatesTagValues == nullptr) { if (thisStatesTagValues == nullptr) {
// No tag values are explicitly associated with this state. // No tag values are explicitly associated with this state.
@ -1154,9 +1154,9 @@ bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) {
uint16_t table_base = 0; uint16_t table_base = 0;
uint16_t table_dupl = 1; uint16_t table_dupl = 1;
for (int32_t state=0; state<numStates; state++) { for (int32_t state=0; state<numStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
table_base = (uint16_t)sd->fDtran->elementAti(categories->first); table_base = static_cast<uint16_t>(sd->fDtran->elementAti(categories->first));
table_dupl = (uint16_t)sd->fDtran->elementAti(categories->second); table_dupl = static_cast<uint16_t>(sd->fDtran->elementAti(categories->second));
if (table_base != table_dupl) { if (table_base != table_dupl) {
break; break;
} }
@ -1176,7 +1176,7 @@ bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) {
void RBBITableBuilder::removeColumn(int32_t column) { void RBBITableBuilder::removeColumn(int32_t column) {
int32_t numStates = fDStates->size(); int32_t numStates = fDStates->size();
for (int32_t state=0; state<numStates; state++) { for (int32_t state=0; state<numStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
U_ASSERT(column < sd->fDtran->size()); U_ASSERT(column < sd->fDtran->size());
sd->fDtran->removeElementAt(column); sd->fDtran->removeElementAt(column);
} }
@ -1190,9 +1190,9 @@ bool RBBITableBuilder::findDuplicateState(IntPair *states) {
int32_t numCols = fRB->fSetBuilder->getNumCharCategories(); int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
for (; states->first<numStates-1; states->first++) { for (; states->first<numStates-1; states->first++) {
RBBIStateDescriptor *firstSD = (RBBIStateDescriptor *)fDStates->elementAt(states->first); RBBIStateDescriptor* firstSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(states->first));
for (states->second=states->first+1; states->second<numStates; states->second++) { for (states->second=states->first+1; states->second<numStates; states->second++) {
RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(states->second); RBBIStateDescriptor* duplSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(states->second));
if (firstSD->fAccepting != duplSD->fAccepting || if (firstSD->fAccepting != duplSD->fAccepting ||
firstSD->fLookAhead != duplSD->fLookAhead || firstSD->fLookAhead != duplSD->fLookAhead ||
firstSD->fTagsIdx != duplSD->fTagsIdx) { firstSD->fTagsIdx != duplSD->fTagsIdx) {
@ -1252,14 +1252,14 @@ void RBBITableBuilder::removeState(IntPair duplStates) {
U_ASSERT(keepState < duplState); U_ASSERT(keepState < duplState);
U_ASSERT(duplState < fDStates->size()); U_ASSERT(duplState < fDStates->size());
RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(duplState); RBBIStateDescriptor* duplSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(duplState));
fDStates->removeElementAt(duplState); fDStates->removeElementAt(duplState);
delete duplSD; delete duplSD;
int32_t numStates = fDStates->size(); int32_t numStates = fDStates->size();
int32_t numCols = fRB->fSetBuilder->getNumCharCategories(); int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
for (int32_t state=0; state<numStates; ++state) { for (int32_t state=0; state<numStates; ++state) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
for (int32_t col=0; col<numCols; col++) { for (int32_t col=0; col<numCols; col++) {
int32_t existingVal = sd->fDtran->elementAti(col); int32_t existingVal = sd->fDtran->elementAti(col);
int32_t newVal = existingVal; int32_t newVal = existingVal;
@ -1283,7 +1283,7 @@ void RBBITableBuilder::removeSafeState(IntPair duplStates) {
// and will auto-delete the removed element. // and will auto-delete the removed element.
int32_t numStates = fSafeTable->size(); int32_t numStates = fSafeTable->size();
for (int32_t state=0; state<numStates; ++state) { for (int32_t state=0; state<numStates; ++state) {
UnicodeString *sd = (UnicodeString *)fSafeTable->elementAt(state); UnicodeString* sd = static_cast<UnicodeString*>(fSafeTable->elementAt(state));
int32_t numCols = sd->length(); int32_t numCols = sd->length();
for (int32_t col=0; col<numCols; col++) { for (int32_t col=0; col<numCols; col++) {
int32_t existingVal = sd->charAt(col); int32_t existingVal = sd->charAt(col);
@ -1357,7 +1357,7 @@ bool RBBITableBuilder::use8BitsForTable() const {
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void RBBITableBuilder::exportTable(void *where) { void RBBITableBuilder::exportTable(void *where) {
RBBIStateTable *table = (RBBIStateTable *)where; RBBIStateTable* table = static_cast<RBBIStateTable*>(where);
uint32_t state; uint32_t state;
int col; int col;
@ -1390,13 +1390,13 @@ void RBBITableBuilder::exportTable(void *where) {
} }
for (state=0; state<table->fNumStates; state++) { for (state=0; state<table->fNumStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state); RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen); RBBIStateTableRow* row = reinterpret_cast<RBBIStateTableRow*>(table->fTableData + state * table->fRowLen);
if (use8BitsForTable()) { if (use8BitsForTable()) {
U_ASSERT (sd->fAccepting <= 255); U_ASSERT (sd->fAccepting <= 255);
U_ASSERT (sd->fLookAhead <= 255); U_ASSERT (sd->fLookAhead <= 255);
U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255); U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255);
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row; RBBIStateTableRow8* r8 = reinterpret_cast<RBBIStateTableRow8*>(row);
r8->fAccepting = sd->fAccepting; r8->fAccepting = sd->fAccepting;
r8->fLookAhead = sd->fLookAhead; r8->fLookAhead = sd->fLookAhead;
r8->fTagsIdx = sd->fTagsIdx; r8->fTagsIdx = sd->fTagsIdx;
@ -1472,8 +1472,8 @@ void RBBITableBuilder::buildSafeReverseTable(UErrorCode &status) {
} }
} }
if (wantedEndState == endState) { if (wantedEndState == endState) {
safePairs.append((char16_t)c1); safePairs.append(static_cast<char16_t>(c1));
safePairs.append((char16_t)c2); safePairs.append(static_cast<char16_t>(c2));
// printf("(%d, %d) ", c1, c2); // printf("(%d, %d) ", c1, c2);
} }
} }
@ -1579,7 +1579,7 @@ bool RBBITableBuilder::use8BitsForSafeTable() const {
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void RBBITableBuilder::exportSafeTable(void *where) { void RBBITableBuilder::exportSafeTable(void *where) {
RBBIStateTable *table = (RBBIStateTable *)where; RBBIStateTable* table = static_cast<RBBIStateTable*>(where);
uint32_t state; uint32_t state;
int col; int col;
@ -1604,10 +1604,10 @@ void RBBITableBuilder::exportSafeTable(void *where) {
} }
for (state=0; state<table->fNumStates; state++) { for (state=0; state<table->fNumStates; state++) {
UnicodeString *rowString = (UnicodeString *)fSafeTable->elementAt(state); UnicodeString* rowString = static_cast<UnicodeString*>(fSafeTable->elementAt(state));
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen); RBBIStateTableRow* row = reinterpret_cast<RBBIStateTableRow*>(table->fTableData + state * table->fRowLen);
if (use8BitsForSafeTable()) { if (use8BitsForSafeTable()) {
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row; RBBIStateTableRow8* r8 = reinterpret_cast<RBBIStateTableRow8*>(row);
r8->fAccepting = 0; r8->fAccepting = 0;
r8->fLookAhead = 0; r8->fLookAhead = 0;
r8->fTagsIdx = 0; r8->fTagsIdx = 0;

View File

@ -49,7 +49,7 @@ ResourceBundle::constructForLocale(const UnicodeString& path,
} }
else { else {
UnicodeString nullTerminatedPath(path); UnicodeString nullTerminatedPath(path);
nullTerminatedPath.append((char16_t)0); nullTerminatedPath.append(static_cast<char16_t>(0));
fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error); fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error);
} }
} }

View File

@ -139,7 +139,7 @@ UChar32 RuleCharacterIterator::_current() const {
return buf->char32At(bufPos); return buf->char32At(bufPos);
} else { } else {
int i = pos.getIndex(); int i = pos.getIndex();
return (i < text.length()) ? text.char32At(i) : (UChar32)DONE; return (i < text.length()) ? text.char32At(i) : static_cast<UChar32>(DONE);
} }
} }

View File

@ -424,7 +424,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
return handleDefault(key, actualReturn, status); return handleDefault(key, actualReturn, status);
} }
ICUService* ncthis = (ICUService*)this; // cast away semantic const ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
CacheEntry* result = nullptr; CacheEntry* result = nullptr;
{ {
@ -462,7 +462,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
if (factory != nullptr) { if (factory != nullptr) {
for (int32_t i = 0; i < limit; ++i) { for (int32_t i = 0; i < limit; ++i) {
if (factory == (const ICUServiceFactory*)factories->elementAt(i)) { if (factory == static_cast<const ICUServiceFactory*>(factories->elementAt(i))) {
startIndex = i + 1; startIndex = i + 1;
break; break;
} }
@ -478,7 +478,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
do { do {
currentDescriptor.remove(); currentDescriptor.remove();
key.currentDescriptor(currentDescriptor); key.currentDescriptor(currentDescriptor);
result = (CacheEntry*)serviceCache->get(currentDescriptor); result = static_cast<CacheEntry*>(serviceCache->get(currentDescriptor));
if (result != nullptr) { if (result != nullptr) {
break; break;
} }
@ -490,7 +490,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
int32_t index = startIndex; int32_t index = startIndex;
while (index < limit) { while (index < limit) {
ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(index++); ICUServiceFactory* f = static_cast<ICUServiceFactory*>(factories->elementAt(index++));
LocalPointer<UObject> service(f->create(key, this, status)); LocalPointer<UObject> service(f->create(key, this, status));
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
return nullptr; return nullptr;
@ -543,7 +543,7 @@ outerEnd:
if (cacheDescriptorList.isValid()) { if (cacheDescriptorList.isValid()) {
for (int32_t i = cacheDescriptorList->size(); --i >= 0;) { for (int32_t i = cacheDescriptorList->size(); --i >= 0;) {
UnicodeString* desc = (UnicodeString*)cacheDescriptorList->elementAt(i); UnicodeString* desc = static_cast<UnicodeString*>(cacheDescriptorList->elementAt(i));
serviceCache->put(*desc, result, status); serviceCache->put(*desc, result, status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -558,7 +558,7 @@ outerEnd:
if (actualReturn != nullptr) { if (actualReturn != nullptr) {
// strip null prefix // strip null prefix
if (result->actualDescriptor.indexOf((char16_t)0x2f) == 0) { // U+002f=slash (/) if (result->actualDescriptor.indexOf(static_cast<char16_t>(0x2f)) == 0) { // U+002f=slash (/)
actualReturn->remove(); actualReturn->remove();
actualReturn->append(result->actualDescriptor, actualReturn->append(result->actualDescriptor,
1, 1,
@ -618,7 +618,7 @@ ICUService::getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorC
break; break;
} }
const UnicodeString* id = (const UnicodeString*)e->key.pointer; const UnicodeString* id = static_cast<const UnicodeString*>(e->key.pointer);
if (fallbackKey != nullptr) { if (fallbackKey != nullptr) {
if (!fallbackKey->isFallbackOf(*id)) { if (!fallbackKey->isFallbackOf(*id)) {
continue; continue;
@ -644,14 +644,14 @@ ICUService::getVisibleIDMap(UErrorCode& status) const {
// must only be called when lock is already held // must only be called when lock is already held
ICUService* ncthis = (ICUService*)this; // cast away semantic const ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
if (idCache == nullptr) { if (idCache == nullptr) {
ncthis->idCache = new Hashtable(status); ncthis->idCache = new Hashtable(status);
if (idCache == nullptr) { if (idCache == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; status = U_MEMORY_ALLOCATION_ERROR;
} else if (factories != nullptr) { } else if (factories != nullptr) {
for (int32_t pos = factories->size(); --pos >= 0;) { for (int32_t pos = factories->size(); --pos >= 0;) {
ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(pos); ICUServiceFactory* f = static_cast<ICUServiceFactory*>(factories->elementAt(pos));
f->updateVisibleIDs(*idCache, status); f->updateVisibleIDs(*idCache, status);
} }
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -679,7 +679,7 @@ ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const
Mutex mutex(&lock); Mutex mutex(&lock);
const Hashtable* map = getVisibleIDMap(status); const Hashtable* map = getVisibleIDMap(status);
if (map != nullptr) { if (map != nullptr) {
ICUServiceFactory* f = (ICUServiceFactory*)map->get(id); ICUServiceFactory* f = static_cast<ICUServiceFactory*>(map->get(id));
if (f != nullptr) { if (f != nullptr) {
f->getDisplayName(id, locale, result); f->getDisplayName(id, locale, result);
return result; return result;
@ -691,7 +691,7 @@ ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const
while (fallbackKey != nullptr && fallbackKey->fallback()) { while (fallbackKey != nullptr && fallbackKey->fallback()) {
UnicodeString us; UnicodeString us;
fallbackKey->currentID(us); fallbackKey->currentID(us);
f = (ICUServiceFactory*)map->get(us); f = static_cast<ICUServiceFactory*>(map->get(us));
if (f != nullptr) { if (f != nullptr) {
f->getDisplayName(id, locale, result); f->getDisplayName(id, locale, result);
delete fallbackKey; delete fallbackKey;
@ -727,7 +727,7 @@ ICUService::getDisplayNames(UVector& result,
result.removeAllElements(); result.removeAllElements();
result.setDeleter(userv_deleteStringPair); result.setDeleter(userv_deleteStringPair);
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
ICUService* ncthis = (ICUService*)this; // cast away semantic const ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
Mutex mutex(&lock); Mutex mutex(&lock);
if (dnCache != nullptr && dnCache->locale != locale) { if (dnCache != nullptr && dnCache->locale != locale) {
@ -749,8 +749,8 @@ ICUService::getDisplayNames(UVector& result,
int32_t pos = UHASH_FIRST; int32_t pos = UHASH_FIRST;
const UHashElement* entry = nullptr; const UHashElement* entry = nullptr;
while ((entry = m->nextElement(pos)) != nullptr) { while ((entry = m->nextElement(pos)) != nullptr) {
const UnicodeString* id = (const UnicodeString*)entry->key.pointer; const UnicodeString* id = static_cast<const UnicodeString*>(entry->key.pointer);
ICUServiceFactory* f = (ICUServiceFactory*)entry->value.pointer; ICUServiceFactory* f = static_cast<ICUServiceFactory*>(entry->value.pointer);
UnicodeString dname; UnicodeString dname;
f->getDisplayName(*id, locale, dname); f->getDisplayName(*id, locale, dname);
if (dname.isBogus()) { if (dname.isBogus()) {
@ -776,11 +776,11 @@ ICUService::getDisplayNames(UVector& result,
int32_t pos = UHASH_FIRST; int32_t pos = UHASH_FIRST;
const UHashElement *entry = nullptr; const UHashElement *entry = nullptr;
while ((entry = dnCache->cache.nextElement(pos)) != nullptr) { while ((entry = dnCache->cache.nextElement(pos)) != nullptr) {
const UnicodeString* id = (const UnicodeString*)entry->value.pointer; const UnicodeString* id = static_cast<const UnicodeString*>(entry->value.pointer);
if (matchKey != nullptr && !matchKey->isFallbackOf(*id)) { if (matchKey != nullptr && !matchKey->isFallbackOf(*id)) {
continue; continue;
} }
const UnicodeString* dn = (const UnicodeString*)entry->key.pointer; const UnicodeString* dn = static_cast<const UnicodeString*>(entry->key.pointer);
StringPair* sp = StringPair::create(*id, *dn, status); StringPair* sp = StringPair::create(*id, *dn, status);
result.adoptElement(sp, status); result.adoptElement(sp, status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {

View File

@ -76,7 +76,7 @@ LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
const UHashElement* elem = nullptr; const UHashElement* elem = nullptr;
int32_t pos = UHASH_FIRST; int32_t pos = UHASH_FIRST;
while ((elem = supported->nextElement(pos)) != nullptr) { while ((elem = supported->nextElement(pos)) != nullptr) {
const UnicodeString& id = *((const UnicodeString*)elem->key.pointer); const UnicodeString& id = *static_cast<const UnicodeString*>(elem->key.pointer);
if (!visible) { if (!visible) {
result.remove(id); result.remove(id);
} else { } else {

View File

@ -179,7 +179,7 @@ private:
length = other._ids.size(); length = other._ids.size();
for(i = 0; i < length; ++i) { for(i = 0; i < length; ++i) {
LocalPointer<UnicodeString> clonedId(((UnicodeString *)other._ids.elementAt(i))->clone(), status); LocalPointer<UnicodeString> clonedId(static_cast<UnicodeString*>(other._ids.elementAt(i))->clone(), status);
_ids.adoptElement(clonedId.orphan(), status); _ids.adoptElement(clonedId.orphan(), status);
} }
@ -228,7 +228,7 @@ public:
virtual const UnicodeString* snext(UErrorCode& status) override { virtual const UnicodeString* snext(UErrorCode& status) override {
if (upToDate(status) && (_pos < _ids.size())) { if (upToDate(status) && (_pos < _ids.size())) {
return (const UnicodeString*)_ids[_pos++]; return static_cast<const UnicodeString*>(_ids[_pos++]);
} }
return nullptr; return nullptr;
} }
@ -263,7 +263,7 @@ const UnicodeString&
ICULocaleService::validateFallbackLocale() const ICULocaleService::validateFallbackLocale() const
{ {
const Locale& loc = Locale::getDefault(); const Locale& loc = Locale::getDefault();
ICULocaleService* ncThis = (ICULocaleService*)this; ICULocaleService* ncThis = const_cast<ICULocaleService*>(this);
static UMutex llock; static UMutex llock;
{ {
Mutex mutex(&llock); Mutex mutex(&llock);

View File

@ -56,7 +56,7 @@ ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
listeners = lpListeners.orphan(); listeners = lpListeners.orphan();
} else { } else {
for (int i = 0, e = listeners->size(); i < e; ++i) { for (int i = 0, e = listeners->size(); i < e; ++i) {
const EventListener* el = (const EventListener*)(listeners->elementAt(i)); const EventListener* el = static_cast<const EventListener*>(listeners->elementAt(i));
if (l == el) { if (l == el) {
return; return;
} }
@ -88,7 +88,7 @@ ICUNotifier::removeListener(const EventListener *l, UErrorCode& status)
if (listeners != nullptr) { if (listeners != nullptr) {
// identity equality check // identity equality check
for (int i = 0, e = listeners->size(); i < e; ++i) { for (int i = 0, e = listeners->size(); i < e; ++i) {
const EventListener* el = (const EventListener*)listeners->elementAt(i); const EventListener* el = static_cast<const EventListener*>(listeners->elementAt(i));
if (l == el) { if (l == el) {
listeners->removeElementAt(i); listeners->removeElementAt(i);
if (listeners->size() == 0) { if (listeners->size() == 0) {
@ -109,7 +109,7 @@ ICUNotifier::notifyChanged()
Mutex lmx(&notifyLock); Mutex lmx(&notifyLock);
if (listeners != nullptr) { if (listeners != nullptr) {
for (int i = 0, e = listeners->size(); i < e; ++i) { for (int i = 0, e = listeners->size(); i < e; ++i) {
EventListener* el = (EventListener*)listeners->elementAt(i); EventListener* el = static_cast<EventListener*>(listeners->elementAt(i));
notifyListener(*el); notifyListener(*el);
} }
} }

View File

@ -61,8 +61,8 @@ ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, co
// who made this change? -- dlf // who made this change? -- dlf
char pkg[20]; char pkg[20];
int32_t length; int32_t length;
length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV); length = _bundleName.extract(0, INT32_MAX, pkg, static_cast<int32_t>(sizeof(pkg)), US_INV);
if(length>=(int32_t)sizeof(pkg)) { if (length >= static_cast<int32_t>(sizeof(pkg))) {
return nullptr; return nullptr;
} }
return new ResourceBundle(pkg, loc, status); return new ResourceBundle(pkg, loc, status);

View File

@ -73,7 +73,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
const char16_t *patternBuffer = pattern.getBuffer(); const char16_t *patternBuffer = pattern.getBuffer();
int32_t patternLength = pattern.length(); int32_t patternLength = pattern.length();
// Reserve the first char for the number of arguments. // Reserve the first char for the number of arguments.
compiledPattern.setTo((char16_t)0); compiledPattern.setTo(static_cast<char16_t>(0));
int32_t textLength = 0; int32_t textLength = 0;
int32_t maxArg = -1; int32_t maxArg = -1;
UBool inQuote = false; UBool inQuote = false;
@ -98,7 +98,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
} else if (!inQuote && c == OPEN_BRACE) { } else if (!inQuote && c == OPEN_BRACE) {
if (textLength > 0) { if (textLength > 0) {
compiledPattern.setCharAt(compiledPattern.length() - textLength - 1, compiledPattern.setCharAt(compiledPattern.length() - textLength - 1,
(char16_t)(ARG_NUM_LIMIT + textLength)); static_cast<char16_t>(ARG_NUM_LIMIT + textLength));
textLength = 0; textLength = 0;
} }
int32_t argNumber; int32_t argNumber;
@ -129,7 +129,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
if (argNumber > maxArg) { if (argNumber > maxArg) {
maxArg = argNumber; maxArg = argNumber;
} }
compiledPattern.append((char16_t)argNumber); compiledPattern.append(static_cast<char16_t>(argNumber));
continue; continue;
} // else: c is part of literal text } // else: c is part of literal text
// Append c and track the literal-text segment length. // Append c and track the literal-text segment length.
@ -144,14 +144,14 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
} }
if (textLength > 0) { if (textLength > 0) {
compiledPattern.setCharAt(compiledPattern.length() - textLength - 1, compiledPattern.setCharAt(compiledPattern.length() - textLength - 1,
(char16_t)(ARG_NUM_LIMIT + textLength)); static_cast<char16_t>(ARG_NUM_LIMIT + textLength));
} }
int32_t argCount = maxArg + 1; int32_t argCount = maxArg + 1;
if (argCount < min || max < argCount) { if (argCount < min || max < argCount) {
errorCode = U_ILLEGAL_ARGUMENT_ERROR; errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return false; return false;
} }
compiledPattern.setCharAt(0, (char16_t)argCount); compiledPattern.setCharAt(0, static_cast<char16_t>(argCount));
return true; return true;
} }

View File

@ -328,7 +328,7 @@ StringTrieBuilder::registerNode(Node *newNode, UErrorCode &errorCode) {
const UHashElement *old=uhash_find(nodes, newNode); const UHashElement *old=uhash_find(nodes, newNode);
if(old!=nullptr) { if(old!=nullptr) {
delete newNode; delete newNode;
return (Node *)old->key.pointer; return static_cast<Node*>(old->key.pointer);
} }
// If uhash_puti() returns a non-zero value from an equivalent, previously // If uhash_puti() returns a non-zero value from an equivalent, previously
// registered node, then uhash_find() failed to find that and we will leak newNode. // registered node, then uhash_find() failed to find that and we will leak newNode.
@ -352,7 +352,7 @@ StringTrieBuilder::registerFinalValue(int32_t value, UErrorCode &errorCode) {
FinalValueNode key(value); FinalValueNode key(value);
const UHashElement *old=uhash_find(nodes, &key); const UHashElement *old=uhash_find(nodes, &key);
if(old!=nullptr) { if(old!=nullptr) {
return (Node *)old->key.pointer; return static_cast<Node*>(old->key.pointer);
} }
Node *newNode=new FinalValueNode(value); Node *newNode=new FinalValueNode(value);
if(newNode==nullptr) { if(newNode==nullptr) {
@ -375,12 +375,12 @@ StringTrieBuilder::registerFinalValue(int32_t value, UErrorCode &errorCode) {
int32_t int32_t
StringTrieBuilder::hashNode(const void *node) { StringTrieBuilder::hashNode(const void *node) {
return ((const Node *)node)->hashCode(); return static_cast<const Node*>(node)->hashCode();
} }
UBool UBool
StringTrieBuilder::equalNodes(const void *left, const void *right) { StringTrieBuilder::equalNodes(const void *left, const void *right) {
return *(const Node *)left==*(const Node *)right; return *static_cast<const Node*>(left) == *static_cast<const Node*>(right);
} }
bool bool

View File

@ -304,7 +304,7 @@ ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode) UPRV_N
if ((pBiDi!=nullptr) && (reorderingMode >= UBIDI_REORDER_DEFAULT) if ((pBiDi!=nullptr) && (reorderingMode >= UBIDI_REORDER_DEFAULT)
&& (reorderingMode < UBIDI_REORDER_COUNT)) { && (reorderingMode < UBIDI_REORDER_COUNT)) {
pBiDi->reorderingMode = reorderingMode; pBiDi->reorderingMode = reorderingMode;
pBiDi->isInverse = (UBool)(reorderingMode == UBIDI_REORDER_INVERSE_NUMBERS_AS_L); pBiDi->isInverse = reorderingMode == UBIDI_REORDER_INVERSE_NUMBERS_AS_L;
} }
} }
@ -381,7 +381,7 @@ firstL_R_AL(UBiDi *pBiDi) {
for(i=0; i<length; ) { for(i=0; i<length; ) {
/* i is incremented by U16_NEXT */ /* i is incremented by U16_NEXT */
U16_NEXT(text, i, length, uchar); U16_NEXT(text, i, length, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar); dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(result==ON) { if(result==ON) {
if(dirProp==L || dirProp==R || dirProp==AL) { if(dirProp==L || dirProp==R || dirProp==AL) {
result=dirProp; result=dirProp;
@ -436,13 +436,13 @@ getDirProps(UBiDi *pBiDi) {
UBool isDefaultLevel=IS_DEFAULT_LEVEL(pBiDi->paraLevel); UBool isDefaultLevel=IS_DEFAULT_LEVEL(pBiDi->paraLevel);
/* for inverse BiDi, the default para level is set to RTL if there is a /* for inverse BiDi, the default para level is set to RTL if there is a
strong R or AL character at either end of the text */ strong R or AL character at either end of the text */
UBool isDefaultLevelInverse=isDefaultLevel && (UBool) UBool isDefaultLevelInverse = isDefaultLevel && static_cast<UBool>(
(pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT || pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL); pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL);
int32_t lastArabicPos=-1; int32_t lastArabicPos=-1;
int32_t controlCount=0; int32_t controlCount=0;
UBool removeBiDiControls = (UBool)(pBiDi->reorderingOptions & UBool removeBiDiControls =
UBIDI_OPTION_REMOVE_CONTROLS); static_cast<UBool>(pBiDi->reorderingOptions & UBIDI_OPTION_REMOVE_CONTROLS);
enum State { enum State {
NOT_SEEKING_STRONG, /* 0: not contextual paraLevel, not after FSI */ NOT_SEEKING_STRONG, /* 0: not contextual paraLevel, not after FSI */
@ -676,7 +676,7 @@ bracketInit(UBiDi *pBiDi, BracketData *bd) {
bd->isoRuns[0].level=GET_PARALEVEL(pBiDi, 0); bd->isoRuns[0].level=GET_PARALEVEL(pBiDi, 0);
UBiDiLevel t = GET_PARALEVEL(pBiDi, 0) & 1; UBiDiLevel t = GET_PARALEVEL(pBiDi, 0) & 1;
bd->isoRuns[0].lastStrong = bd->isoRuns[0].lastBase = t; bd->isoRuns[0].lastStrong = bd->isoRuns[0].lastBase = t;
bd->isoRuns[0].contextDir = (UBiDiDirection)t; bd->isoRuns[0].contextDir = static_cast<UBiDiDirection>(t);
bd->isoRuns[0].contextPos=0; bd->isoRuns[0].contextPos=0;
if(pBiDi->openingsMemory) { if(pBiDi->openingsMemory) {
bd->openings=pBiDi->openingsMemory; bd->openings=pBiDi->openingsMemory;
@ -696,7 +696,7 @@ bracketProcessB(BracketData *bd, UBiDiLevel level) {
bd->isoRuns[0].limit=0; bd->isoRuns[0].limit=0;
bd->isoRuns[0].level=level; bd->isoRuns[0].level=level;
bd->isoRuns[0].lastStrong=bd->isoRuns[0].lastBase=level&1; bd->isoRuns[0].lastStrong=bd->isoRuns[0].lastBase=level&1;
bd->isoRuns[0].contextDir=(UBiDiDirection)(level&1); bd->isoRuns[0].contextDir = static_cast<UBiDiDirection>(level & 1);
bd->isoRuns[0].contextPos=0; bd->isoRuns[0].contextPos=0;
} }
@ -713,8 +713,8 @@ bracketProcessBoundary(BracketData *bd, int32_t lastCcPos,
pLastIsoRun->limit=pLastIsoRun->start; pLastIsoRun->limit=pLastIsoRun->start;
pLastIsoRun->level=embeddingLevel; pLastIsoRun->level=embeddingLevel;
pLastIsoRun->lastStrong=pLastIsoRun->lastBase=contextLevel&1; pLastIsoRun->lastStrong=pLastIsoRun->lastBase=contextLevel&1;
pLastIsoRun->contextDir=(UBiDiDirection)(contextLevel&1); pLastIsoRun->contextDir = static_cast<UBiDiDirection>(contextLevel & 1);
pLastIsoRun->contextPos=(UBiDiDirection)lastCcPos; pLastIsoRun->contextPos = static_cast<UBiDiDirection>(lastCcPos);
} }
/* LRI or RLI */ /* LRI or RLI */
@ -729,7 +729,7 @@ bracketProcessLRI_RLI(BracketData *bd, UBiDiLevel level) {
pLastIsoRun->start=pLastIsoRun->limit=lastLimit; pLastIsoRun->start=pLastIsoRun->limit=lastLimit;
pLastIsoRun->level=level; pLastIsoRun->level=level;
pLastIsoRun->lastStrong=pLastIsoRun->lastBase=level&1; pLastIsoRun->lastStrong=pLastIsoRun->lastBase=level&1;
pLastIsoRun->contextDir=(UBiDiDirection)(level&1); pLastIsoRun->contextDir = static_cast<UBiDiDirection>(level & 1);
pLastIsoRun->contextPos=0; pLastIsoRun->contextPos=0;
} }
@ -803,7 +803,7 @@ bracketProcessClosing(BracketData *bd, int32_t openIdx, int32_t position) {
UBool stable; UBool stable;
DirProp newProp; DirProp newProp;
pOpening=&bd->openings[openIdx]; pOpening=&bd->openings[openIdx];
direction=(UBiDiDirection)(pLastIsoRun->level&1); direction = static_cast<UBiDiDirection>(pLastIsoRun->level & 1);
stable=true; /* assume stable until proved otherwise */ stable=true; /* assume stable until proved otherwise */
/* The stable flag is set when brackets are paired and their /* The stable flag is set when brackets are paired and their
@ -896,7 +896,7 @@ bracketProcessChar(BracketData *bd, int32_t position) {
break; break;
} }
pLastIsoRun->lastBase=ON; pLastIsoRun->lastBase=ON;
pLastIsoRun->contextDir=(UBiDiDirection)newProp; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
level=bd->pBiDi->levels[position]; level=bd->pBiDi->levels[position];
if(level&UBIDI_LEVEL_OVERRIDE) { /* X4, X5 */ if(level&UBIDI_LEVEL_OVERRIDE) { /* X4, X5 */
@ -944,14 +944,14 @@ bracketProcessChar(BracketData *bd, int32_t position) {
dirProps[position]=newProp; dirProps[position]=newProp;
pLastIsoRun->lastBase=newProp; pLastIsoRun->lastBase=newProp;
pLastIsoRun->lastStrong=newProp; pLastIsoRun->lastStrong=newProp;
pLastIsoRun->contextDir=(UBiDiDirection)newProp; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
} }
else if(dirProp<=R || dirProp==AL) { else if(dirProp<=R || dirProp==AL) {
newProp= static_cast<DirProp>(DIR_FROM_STRONG(dirProp)); newProp= static_cast<DirProp>(DIR_FROM_STRONG(dirProp));
pLastIsoRun->lastBase=dirProp; pLastIsoRun->lastBase=dirProp;
pLastIsoRun->lastStrong=dirProp; pLastIsoRun->lastStrong=dirProp;
pLastIsoRun->contextDir=(UBiDiDirection)newProp; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
} }
else if(dirProp==EN) { else if(dirProp==EN) {
@ -960,7 +960,7 @@ bracketProcessChar(BracketData *bd, int32_t position) {
newProp=L; /* W7 */ newProp=L; /* W7 */
if(!bd->isNumbersSpecial) if(!bd->isNumbersSpecial)
dirProps[position]=ENL; dirProps[position]=ENL;
pLastIsoRun->contextDir=(UBiDiDirection)L; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(L);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
} }
else { else {
@ -969,14 +969,14 @@ bracketProcessChar(BracketData *bd, int32_t position) {
dirProps[position]=AN; /* W2 */ dirProps[position]=AN; /* W2 */
else else
dirProps[position]=ENR; dirProps[position]=ENR;
pLastIsoRun->contextDir=(UBiDiDirection)R; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(R);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
} }
} }
else if(dirProp==AN) { else if(dirProp==AN) {
newProp=R; /* N0 */ newProp=R; /* N0 */
pLastIsoRun->lastBase=AN; pLastIsoRun->lastBase=AN;
pLastIsoRun->contextDir=(UBiDiDirection)R; pLastIsoRun->contextDir = static_cast<UBiDiDirection>(R);
pLastIsoRun->contextPos=position; pLastIsoRun->contextPos=position;
} }
else if(dirProp==NSM) { else if(dirProp==NSM) {
@ -1177,10 +1177,10 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
levels[i]=previousLevel; levels[i]=previousLevel;
if (dirProp==LRE || dirProp==LRO) if (dirProp==LRE || dirProp==LRO)
/* least greater even level */ /* least greater even level */
newLevel=(UBiDiLevel)((embeddingLevel+2)&~(UBIDI_LEVEL_OVERRIDE|1)); newLevel = static_cast<UBiDiLevel>((embeddingLevel + 2) & ~(UBIDI_LEVEL_OVERRIDE | 1));
else else
/* least greater odd level */ /* least greater odd level */
newLevel=(UBiDiLevel)((NO_OVERRIDE(embeddingLevel)+1)|1); newLevel = static_cast<UBiDiLevel>((NO_OVERRIDE(embeddingLevel) + 1) | 1);
if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 && if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 &&
overflowEmbeddingCount==0) { overflowEmbeddingCount==0) {
lastCcPos=i; lastCcPos=i;
@ -1213,7 +1213,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
if(stackLast>0 && stack[stackLast]<ISOLATE) { /* not an isolate entry */ if(stackLast>0 && stack[stackLast]<ISOLATE) { /* not an isolate entry */
lastCcPos=i; lastCcPos=i;
stackLast--; stackLast--;
embeddingLevel=(UBiDiLevel)stack[stackLast]; embeddingLevel = static_cast<UBiDiLevel>(stack[stackLast]);
} }
break; break;
case LRI: case LRI:
@ -1229,10 +1229,10 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
/* (X5a, X5b) */ /* (X5a, X5b) */
if(dirProp==LRI) if(dirProp==LRI)
/* least greater even level */ /* least greater even level */
newLevel=(UBiDiLevel)((embeddingLevel+2)&~(UBIDI_LEVEL_OVERRIDE|1)); newLevel = static_cast<UBiDiLevel>((embeddingLevel + 2) & ~(UBIDI_LEVEL_OVERRIDE | 1));
else else
/* least greater odd level */ /* least greater odd level */
newLevel=(UBiDiLevel)((NO_OVERRIDE(embeddingLevel)+1)|1); newLevel = static_cast<UBiDiLevel>((NO_OVERRIDE(embeddingLevel) + 1) | 1);
if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 && if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 &&
overflowEmbeddingCount==0) { overflowEmbeddingCount==0) {
flags|=DIRPROP_FLAG(dirProp); flags|=DIRPROP_FLAG(dirProp);
@ -1276,7 +1276,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
} else } else
/* make it WS so that it is handled by adjustWSLevels() */ /* make it WS so that it is handled by adjustWSLevels() */
dirProps[i]=WS; dirProps[i]=WS;
embeddingLevel=(UBiDiLevel)stack[stackLast]&~ISOLATE; embeddingLevel = static_cast<UBiDiLevel>(stack[stackLast]) & ~ISOLATE;
flags|=(DIRPROP_FLAG(ON)|DIRPROP_FLAG_LR(embeddingLevel)); flags|=(DIRPROP_FLAG(ON)|DIRPROP_FLAG_LR(embeddingLevel));
previousLevel=embeddingLevel; previousLevel=embeddingLevel;
levels[i]=NO_OVERRIDE(embeddingLevel); levels[i]=NO_OVERRIDE(embeddingLevel);
@ -1315,7 +1315,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
previousLevel=embeddingLevel; previousLevel=embeddingLevel;
levels[i]=embeddingLevel; levels[i]=embeddingLevel;
if(!bracketProcessChar(&bracketData, i)) if(!bracketProcessChar(&bracketData, i))
return (UBiDiDirection)-1; return static_cast<UBiDiDirection>(-1);
/* the dirProp may have been changed in bracketProcessChar() */ /* the dirProp may have been changed in bracketProcessChar() */
flags|=DIRPROP_FLAG(dirProps[i]); flags|=DIRPROP_FLAG(dirProps[i]);
break; break;
@ -1386,7 +1386,7 @@ checkExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
} else { } else {
// Treat explicit level 0 as a wildcard for the paragraph level. // Treat explicit level 0 as a wildcard for the paragraph level.
// Avoid making the caller guess what the paragraph level would be. // Avoid making the caller guess what the paragraph level would be.
level = (UBiDiLevel)currentParaLevel; level = static_cast<UBiDiLevel>(currentParaLevel);
levels[i] = level | overrideFlag; levels[i] = level | overrideFlag;
} }
} else { } else {
@ -1868,7 +1868,7 @@ processPropertySeq(UBiDi *pBiDi, LevState *pLevState, uint8_t _prop,
int32_t start0, k; int32_t start0, k;
start0=start; /* save original start position */ start0=start; /* save original start position */
oldStateSeq=(uint8_t)pLevState->state; oldStateSeq = static_cast<uint8_t>(pLevState->state);
cell=(*pImpTab)[oldStateSeq][_prop]; cell=(*pImpTab)[oldStateSeq][_prop];
pLevState->state=GET_STATE(cell); /* isolate the new state */ pLevState->state=GET_STATE(cell); /* isolate the new state */
actionSeq=(*pImpAct)[GET_ACTION(cell)]; /* isolate the action */ actionSeq=(*pImpAct)[GET_ACTION(cell)]; /* isolate the action */
@ -2076,7 +2076,7 @@ lastL_R_AL(UBiDi *pBiDi) {
for(i=length; i>0; ) { for(i=length; i>0; ) {
/* i is decremented by U16_PREV */ /* i is decremented by U16_PREV */
U16_PREV(text, 0, i, uchar); U16_PREV(text, 0, i, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar); dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(dirProp==L) { if(dirProp==L) {
return DirProp_L; return DirProp_L;
} }
@ -2104,7 +2104,7 @@ firstL_R_AL_EN_AN(UBiDi *pBiDi) {
for(i=0; i<length; ) { for(i=0; i<length; ) {
/* i is incremented by U16_NEXT */ /* i is incremented by U16_NEXT */
U16_NEXT(text, i, length, uchar); U16_NEXT(text, i, length, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar); dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(dirProp==L) { if(dirProp==L) {
return DirProp_L; return DirProp_L;
} }
@ -2142,18 +2142,18 @@ resolveImplicitLevels(UBiDi *pBiDi,
* actions) and different levels state tables (maybe very similar to the * actions) and different levels state tables (maybe very similar to the
* LTR corresponding ones. * LTR corresponding ones.
*/ */
inverseRTL=(UBool) inverseRTL =
((start<pBiDi->lastArabicPos) && (GET_PARALEVEL(pBiDi, start) & 1) && static_cast<UBool>((start < pBiDi->lastArabicPos) && (GET_PARALEVEL(pBiDi, start) & 1) &&
(pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT || (pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL)); pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL));
/* initialize for property and levels state tables */ /* initialize for property and levels state tables */
levState.startL2EN=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */ levState.startL2EN=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
levState.lastStrongRTL=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */ levState.lastStrongRTL=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
levState.runStart=start; levState.runStart=start;
levState.runLevel=pBiDi->levels[start]; levState.runLevel=pBiDi->levels[start];
levState.pImpTab=(const ImpTab*)((pBiDi->pImpTabPair)->pImpTab)[levState.runLevel&1]; levState.pImpTab = static_cast<const ImpTab*>(((pBiDi->pImpTabPair)->pImpTab)[levState.runLevel & 1]);
levState.pImpAct=(const ImpAct*)((pBiDi->pImpTabPair)->pImpAct)[levState.runLevel&1]; levState.pImpAct = static_cast<const ImpAct*>(((pBiDi->pImpTabPair)->pImpAct)[levState.runLevel & 1]);
if(start==0 && pBiDi->proLength>0) { if(start==0 && pBiDi->proLength>0) {
DirProp lastStrong=lastL_R_AL(pBiDi); DirProp lastStrong=lastL_R_AL(pBiDi);
if(lastStrong!=DirProp_ON) { if(lastStrong!=DirProp_ON) {
@ -2391,8 +2391,8 @@ setParaRunsOnly(UBiDi *pBiDi, const char16_t *text, int32_t length,
goto cleanup3; goto cleanup3;
} }
visualMap=runsOnlyMemory; visualMap=runsOnlyMemory;
visualText=(char16_t *)&visualMap[length]; visualText = reinterpret_cast<char16_t*>(&visualMap[length]);
saveLevels=(UBiDiLevel *)&visualText[length]; saveLevels = reinterpret_cast<UBiDiLevel*>(&visualText[length]);
saveOptions=pBiDi->reorderingOptions; saveOptions=pBiDi->reorderingOptions;
if(saveOptions & UBIDI_OPTION_INSERT_MARKS) { if(saveOptions & UBIDI_OPTION_INSERT_MARKS) {
pBiDi->reorderingOptions&=~UBIDI_OPTION_INSERT_MARKS; pBiDi->reorderingOptions&=~UBIDI_OPTION_INSERT_MARKS;

View File

@ -51,7 +51,7 @@ _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32
(void)end; (void)end;
(void)value; (void)value;
/* add the start code point to the USet */ /* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context; const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start); sa->add(sa->set, start);
return true; return true;
} }
@ -139,7 +139,7 @@ ubidi_getClass(UChar32 c) {
U_CFUNC UBool U_CFUNC UBool
ubidi_isMirrored(UChar32 c) { ubidi_isMirrored(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c); uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT); return UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
} }
static UChar32 static UChar32
@ -183,13 +183,13 @@ ubidi_getMirror(UChar32 c) {
U_CFUNC UBool U_CFUNC UBool
ubidi_isBidiControl(UChar32 c) { ubidi_isBidiControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c); uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT); return UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT);
} }
U_CFUNC UBool U_CFUNC UBool
ubidi_isJoinControl(UChar32 c) { ubidi_isJoinControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c); uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT); return UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT);
} }
U_CFUNC UJoiningType U_CFUNC UJoiningType

File diff suppressed because it is too large Load Diff

View File

@ -233,7 +233,7 @@ updateSrc(UBiDiTransform *pTransform, const char16_t *newSrc, uint32_t newLength
uprv_free(pTransform->src); uprv_free(pTransform->src);
pTransform->src = nullptr; pTransform->src = nullptr;
} }
pTransform->src = (char16_t *)uprv_malloc(newSize * sizeof(char16_t)); pTransform->src = static_cast<char16_t*>(uprv_malloc(newSize * sizeof(char16_t)));
if (pTransform->src == nullptr) { if (pTransform->src == nullptr) {
*pErrorCode = U_MEMORY_ALLOCATION_ERROR; *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
//pTransform->srcLength = pTransform->srcSize = 0; //pTransform->srcLength = pTransform->srcSize = 0;
@ -499,7 +499,7 @@ ubiditransform_transform(UBiDiTransform *pBiDiTransform,
/* Checking for U_SUCCESS() within the loop to bail out on first failure. */ /* Checking for U_SUCCESS() within the loop to bail out on first failure. */
for (action = pBiDiTransform->pActiveScheme->actions; *action && U_SUCCESS(*pErrorCode); action++) { for (action = pBiDiTransform->pActiveScheme->actions; *action && U_SUCCESS(*pErrorCode); action++) {
if ((*action)(pBiDiTransform, pErrorCode)) { if ((*action)(pBiDiTransform, pErrorCode)) {
if (action + 1) { if (action[1] != nullptr) {
updateSrc(pBiDiTransform, pBiDiTransform->dest, *pBiDiTransform->pDestLength, updateSrc(pBiDiTransform, pBiDiTransform->dest, *pBiDiTransform->pDestLength,
*pBiDiTransform->pDestLength, pErrorCode); *pBiDiTransform->pDestLength, pErrorCode);
} }

View File

@ -501,7 +501,10 @@ ubidi_writeReordered(UBiDi *pBiDi,
destSize-=runLength; destSize-=runLength;
if((pBiDi->isInverse) && if((pBiDi->isInverse) &&
(/*run<runCount-1 &&*/ dirProps[logicalStart+runLength-1]!=L)) { (/*run<runCount-1 &&*/
runLength > 0 && // doWriteForward may return 0 if src
// only include bidi control chars
dirProps[logicalStart+runLength-1]!=L)) {
markFlag |= LRM_AFTER; markFlag |= LRM_AFTER;
} }
if (markFlag & LRM_AFTER) { if (markFlag & LRM_AFTER) {
@ -632,7 +635,10 @@ ubidi_writeReordered(UBiDi *pBiDi,
} }
destSize-=runLength; destSize-=runLength;
if(/*run>0 &&*/ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) { if(/*run>0 &&*/
runLength > 0 && // doWriteForward may return 0 if src
// only include bidi control chars
!(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) {
if(destSize>0) { if(destSize>0) {
*dest++=RLM_CHAR; *dest++=RLM_CHAR;
} }

View File

@ -38,7 +38,7 @@
static UBool U_CALLCONV static UBool U_CALLCONV
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 /*end*/, uint32_t /*value*/) { _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 /*end*/, uint32_t /*value*/) {
/* add the start code point to the USet */ /* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context; const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start); sa->add(sa->set, start);
return true; return true;
} }
@ -696,17 +696,17 @@ getDotType(UChar32 c) {
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
ucase_isSoftDotted(UChar32 c) { ucase_isSoftDotted(UChar32 c) {
return (UBool)(getDotType(c)==UCASE_SOFT_DOTTED); return getDotType(c)==UCASE_SOFT_DOTTED;
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
ucase_isCaseSensitive(UChar32 c) { ucase_isCaseSensitive(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c); uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
if(!UCASE_HAS_EXCEPTION(props)) { if(!UCASE_HAS_EXCEPTION(props)) {
return (UBool)((props&UCASE_SENSITIVE)!=0); return (props&UCASE_SENSITIVE)!=0;
} else { } else {
const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props); const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
return (UBool)((*pe&UCASE_EXC_SENSITIVE)!=0); return (*pe&UCASE_EXC_SENSITIVE)!=0;
} }
} }
@ -1623,12 +1623,12 @@ ucase_toFullFolding(UChar32 c,
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
u_isULowercase(UChar32 c) { u_isULowercase(UChar32 c) {
return (UBool)(UCASE_LOWER==ucase_getType(c)); return UCASE_LOWER==ucase_getType(c);
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
u_isUUppercase(UChar32 c) { u_isUUppercase(UChar32 c) {
return (UBool)(UCASE_UPPER==ucase_getType(c)); return UCASE_UPPER==ucase_getType(c);
} }
/* Transforms the Unicode character to its lower case equivalent.*/ /* Transforms the Unicode character to its lower case equivalent.*/

File diff suppressed because it is too large Load Diff

View File

@ -160,12 +160,12 @@ appendResult(int32_t cpLength, int32_t result, const char16_t *s,
} }
// See unicode/utf8.h U8_APPEND_UNSAFE(). // See unicode/utf8.h U8_APPEND_UNSAFE().
inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); } inline uint8_t getTwoByteLead(UChar32 c) { return static_cast<uint8_t>((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); } inline uint8_t getTwoByteTrail(UChar32 c) { return static_cast<uint8_t>((c & 0x3f) | 0x80); }
UChar32 U_CALLCONV UChar32 U_CALLCONV
utf8_caseContextIterator(void *context, int8_t dir) { utf8_caseContextIterator(void *context, int8_t dir) {
UCaseContext *csc=(UCaseContext *)context; UCaseContext* csc = static_cast<UCaseContext*>(context);
UChar32 c; UChar32 c;
if(dir<0) { if(dir<0) {
@ -234,7 +234,7 @@ void toLower(int32_t caseLocale, uint32_t options,
if (d == 0) { continue; } if (d == 0) { continue; }
ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev, ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
sink, options, edits, errorCode); sink, options, edits, errorCode);
char ascii = (char)(lead + d); char ascii = static_cast<char>(lead + d);
sink.Append(&ascii, 1); sink.Append(&ascii, 1);
if (edits != nullptr) { if (edits != nullptr) {
edits->addReplace(1, 1); edits->addReplace(1, 1);
@ -342,7 +342,7 @@ void toUpper(int32_t caseLocale, uint32_t options,
if (d == 0) { continue; } if (d == 0) { continue; }
ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev, ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
sink, options, edits, errorCode); sink, options, edits, errorCode);
char ascii = (char)(lead + d); char ascii = static_cast<char>(lead + d);
sink.Append(&ascii, 1); sink.Append(&ascii, 1);
if (edits != nullptr) { if (edits != nullptr) {
edits->addReplace(1, 1); edits->addReplace(1, 1);
@ -747,14 +747,14 @@ void toUpper(uint32_t options,
int32_t i2 = i + 2; int32_t i2 = i + 2;
if ((data & HAS_EITHER_DIALYTIKA) != 0) { if ((data & HAS_EITHER_DIALYTIKA) != 0) {
change |= (i2 + 2) > nextIndex || change |= (i2 + 2) > nextIndex ||
src[i2] != (uint8_t)u8"\u0308"[0] || src[i2] != static_cast<uint8_t>(u8"\u0308"[0]) ||
src[i2 + 1] != (uint8_t)u8"\u0308"[1]; src[i2 + 1] != static_cast<uint8_t>(u8"\u0308"[1]);
i2 += 2; i2 += 2;
} }
if (addTonos) { if (addTonos) {
change |= (i2 + 2) > nextIndex || change |= (i2 + 2) > nextIndex ||
src[i2] != (uint8_t)u8"\u0301"[0] || src[i2] != static_cast<uint8_t>(u8"\u0301"[0]) ||
src[i2 + 1] != (uint8_t)u8"\u0301"[1]; src[i2 + 1] != static_cast<uint8_t>(u8"\u0301"[1]);
i2 += 2; i2 += 2;
} }
int32_t oldLength = nextIndex - i; int32_t oldLength = nextIndex - i;
@ -867,14 +867,14 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
// Get the string length. // Get the string length.
if (srcLength == -1) { if (srcLength == -1) {
srcLength = (int32_t)uprv_strlen((const char *)src); srcLength = static_cast<int32_t>(uprv_strlen(src));
} }
if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) { if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
edits->reset(); edits->reset();
} }
stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
(const uint8_t *)src, srcLength, sink, edits, errorCode); reinterpret_cast<const uint8_t*>(src), srcLength, sink, edits, errorCode);
sink.Flush(); sink.Flush();
if (U_SUCCESS(errorCode)) { if (U_SUCCESS(errorCode)) {
if (edits != nullptr) { if (edits != nullptr) {
@ -904,7 +904,7 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
/* get the string length */ /* get the string length */
if(srcLength==-1) { if(srcLength==-1) {
srcLength=(int32_t)uprv_strlen((const char *)src); srcLength = static_cast<int32_t>(uprv_strlen(src));
} }
/* check for overlapping source and destination */ /* check for overlapping source and destination */
@ -923,7 +923,7 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
dest, destCapacity, dest, destCapacity,
[&](ByteSink& sink, UErrorCode& status) { [&](ByteSink& sink, UErrorCode& status) {
stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
(const uint8_t *)src, srcLength, sink, edits, status); reinterpret_cast<const uint8_t*>(src), srcLength, sink, edits, status);
}, },
errorCode); errorCode);
if (U_SUCCESS(errorCode) && edits != nullptr) { if (U_SUCCESS(errorCode) && edits != nullptr) {

View File

@ -107,7 +107,7 @@ ucasemap_utf8ToTitle(UCaseMap *csm,
return 0; return 0;
} }
UText utext=UTEXT_INITIALIZER; UText utext=UTEXT_INITIALIZER;
utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode); utext_openUTF8(&utext, src, srcLength, pErrorCode);
if (U_FAILURE(*pErrorCode)) { if (U_FAILURE(*pErrorCode)) {
return 0; return 0;
} }

View File

@ -23,6 +23,7 @@
#include "unicode/utypes.h" #include "unicode/utypes.h"
#include "unicode/uchar.h" #include "unicode/uchar.h"
#include "unicode/ucptrie.h"
#include "unicode/uscript.h" #include "unicode/uscript.h"
#include "unicode/udata.h" #include "unicode/udata.h"
#include "uassert.h" #include "uassert.h"
@ -67,9 +68,9 @@ _enumTypeValue(const void *context, uint32_t value) {
static UBool U_CALLCONV static UBool U_CALLCONV
_enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) { _enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
/* just cast the value to UCharCategory */ /* just cast the value to UCharCategory */
return ((struct _EnumTypeCallback *)context)-> return static_cast<const _EnumTypeCallback*>(context)->
enumRange(((struct _EnumTypeCallback *)context)->context, enumRange(static_cast<const _EnumTypeCallback*>(context)->context,
start, end+1, (UCharCategory)value); start, end + 1, static_cast<UCharCategory>(value));
} }
U_CAPI void U_EXPORT2 U_CAPI void U_EXPORT2
@ -90,7 +91,7 @@ U_CAPI UBool U_EXPORT2
u_islower(UChar32 c) { u_islower(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER); return GET_CATEGORY(props)==U_LOWERCASE_LETTER;
} }
/* Checks if ch is an upper case letter.*/ /* Checks if ch is an upper case letter.*/
@ -98,7 +99,7 @@ U_CAPI UBool U_EXPORT2
u_isupper(UChar32 c) { u_isupper(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER); return GET_CATEGORY(props)==U_UPPERCASE_LETTER;
} }
/* Checks if ch is a title case letter; usually upper case letters.*/ /* Checks if ch is a title case letter; usually upper case letters.*/
@ -106,7 +107,7 @@ U_CAPI UBool U_EXPORT2
u_istitle(UChar32 c) { u_istitle(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER); return GET_CATEGORY(props)==U_TITLECASE_LETTER;
} }
/* Checks if ch is a decimal digit. */ /* Checks if ch is a decimal digit. */
@ -114,7 +115,7 @@ U_CAPI UBool U_EXPORT2
u_isdigit(UChar32 c) { u_isdigit(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER); return GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER;
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
@ -130,7 +131,7 @@ u_isxdigit(UChar32 c) {
} }
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER); return GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER;
} }
/* Checks if the Unicode character is a letter.*/ /* Checks if the Unicode character is a letter.*/
@ -138,7 +139,7 @@ U_CAPI UBool U_EXPORT2
u_isalpha(UChar32 c) { u_isalpha(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0); return (CAT_MASK(props)&U_GC_L_MASK)!=0;
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
@ -151,7 +152,7 @@ U_CAPI UBool U_EXPORT2
u_isalnum(UChar32 c) { u_isalnum(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0); return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0;
} }
/** /**
@ -160,7 +161,7 @@ u_isalnum(UChar32 c) {
*/ */
U_CFUNC UBool U_CFUNC UBool
u_isalnumPOSIX(UChar32 c) { u_isalnumPOSIX(UChar32 c) {
return (UBool)(u_isUAlphabetic(c) || u_isdigit(c)); return u_isUAlphabetic(c) || u_isdigit(c);
} }
/* Checks if ch is a unicode character with assigned character type.*/ /* Checks if ch is a unicode character with assigned character type.*/
@ -168,7 +169,7 @@ U_CAPI UBool U_EXPORT2
u_isdefined(UChar32 c) { u_isdefined(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)!=0); return GET_CATEGORY(props)!=0;
} }
/* Checks if the Unicode character is a base form character that can take a diacritic.*/ /* Checks if the Unicode character is a base form character that can take a diacritic.*/
@ -176,7 +177,7 @@ U_CAPI UBool U_EXPORT2
u_isbase(UChar32 c) { u_isbase(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0); return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0;
} }
/* Checks if the Unicode character is a control character.*/ /* Checks if the Unicode character is a control character.*/
@ -184,7 +185,7 @@ U_CAPI UBool U_EXPORT2
u_iscntrl(UChar32 c) { u_iscntrl(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0); return (CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0;
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
@ -205,14 +206,14 @@ U_CAPI UBool U_EXPORT2
u_isspace(UChar32 c) { u_isspace(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c)); return (CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c);
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
u_isJavaSpaceChar(UChar32 c) { u_isJavaSpaceChar(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0); return (CAT_MASK(props)&U_GC_Z_MASK)!=0;
} }
/* Checks if the Unicode character is a whitespace character.*/ /* Checks if the Unicode character is a whitespace character.*/
@ -220,11 +221,9 @@ U_CAPI UBool U_EXPORT2
u_isWhitespace(UChar32 c) { u_isWhitespace(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)( return ((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
((CAT_MASK(props)&U_GC_Z_MASK)!=0 && c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */ IS_THAT_ASCII_CONTROL_SPACE(c);
IS_THAT_ASCII_CONTROL_SPACE(c)
);
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
@ -235,7 +234,7 @@ u_isblank(UChar32 c) {
/* Zs */ /* Zs */
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR); return GET_CATEGORY(props)==U_SPACE_SEPARATOR;
} }
} }
@ -250,7 +249,7 @@ u_isprint(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
/* comparing ==0 returns false for the categories mentioned */ /* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0); return (CAT_MASK(props)&U_GC_C_MASK)==0;
} }
/** /**
@ -266,7 +265,7 @@ u_isprintPOSIX(UChar32 c) {
* The only cntrl character in graph+blank is TAB (in blank). * The only cntrl character in graph+blank is TAB (in blank).
* Here we implement (blank-TAB)=Zs instead of calling u_isblank(). * Here we implement (blank-TAB)=Zs instead of calling u_isblank().
*/ */
return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c)); return (GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c);
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
@ -274,9 +273,9 @@ u_isgraph(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
/* comparing ==0 returns false for the categories mentioned */ /* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)& return (CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK)) (U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0); ==0;
} }
/** /**
@ -292,16 +291,16 @@ u_isgraphPOSIX(UChar32 c) {
GET_PROPS(c, props); GET_PROPS(c, props);
/* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */ /* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
/* comparing ==0 returns false for the categories mentioned */ /* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)& return (CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK)) (U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0); ==0;
} }
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
u_ispunct(UChar32 c) { u_ispunct(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0); return (CAT_MASK(props)&U_GC_P_MASK)!=0;
} }
/*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/ /*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/
@ -312,7 +311,7 @@ u_isIDIgnorable(UChar32 c) {
} else { } else {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR); return GET_CATEGORY(props)==U_FORMAT_CHAR;
} }
} }
@ -321,7 +320,7 @@ U_CAPI UBool U_EXPORT2
u_isJavaIDStart(UChar32 c) { u_isJavaIDStart(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0); return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0;
} }
/*Checks if the Unicode character can be a Java identifier part other than starting the /*Checks if the Unicode character can be a Java identifier part other than starting the
@ -331,14 +330,13 @@ U_CAPI UBool U_EXPORT2
u_isJavaIDPart(UChar32 c) { u_isJavaIDPart(UChar32 c) {
uint32_t props; uint32_t props;
GET_PROPS(c, props); GET_PROPS(c, props);
return (UBool)( return (CAT_MASK(props)&
(CAT_MASK(props)&
(U_GC_ND_MASK|U_GC_NL_MASK| (U_GC_ND_MASK|U_GC_NL_MASK|
U_GC_L_MASK| U_GC_L_MASK|
U_GC_SC_MASK|U_GC_PC_MASK| U_GC_SC_MASK|U_GC_PC_MASK|
U_GC_MC_MASK|U_GC_MN_MASK) U_GC_MC_MASK|U_GC_MN_MASK)
)!=0 || )!=0 ||
u_isIDIgnorable(c)); u_isIDIgnorable(c);
} }
U_CAPI int32_t U_EXPORT2 U_CAPI int32_t U_EXPORT2
@ -515,6 +513,8 @@ uprv_getMaxValues(int32_t column) {
return indexes[UPROPS_MAX_VALUES_INDEX]; return indexes[UPROPS_MAX_VALUES_INDEX];
case 2: case 2:
return indexes[UPROPS_MAX_VALUES_2_INDEX]; return indexes[UPROPS_MAX_VALUES_2_INDEX];
case UPROPS_MAX_VALUES_OTHER_INDEX:
return indexes[column];
default: default:
return 0; return 0;
} }
@ -524,8 +524,8 @@ U_CAPI void U_EXPORT2
u_charAge(UChar32 c, UVersionInfo versionArray) { u_charAge(UChar32 c, UVersionInfo versionArray) {
if(versionArray!=nullptr) { if(versionArray!=nullptr) {
uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT; uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT;
versionArray[0]=(uint8_t)(version>>4); versionArray[0]=(uint8_t)(version>>2);
versionArray[1]=(uint8_t)(version&0xf); versionArray[1]=(uint8_t)(version&3);
versionArray[2]=versionArray[3]=0; versionArray[2]=versionArray[3]=0;
} }
} }
@ -540,7 +540,7 @@ uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
return USCRIPT_INVALID_CODE; return USCRIPT_INVALID_CODE;
} }
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK; uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX); uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) { if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
return (UScriptCode)codeOrIndex; return (UScriptCode)codeOrIndex;
} else if(scriptX<UPROPS_SCRIPT_X_WITH_INHERITED) { } else if(scriptX<UPROPS_SCRIPT_X_WITH_INHERITED) {
@ -555,7 +555,7 @@ uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
uscript_hasScript(UChar32 c, UScriptCode sc) UPRV_NO_SANITIZE_UNDEFINED { uscript_hasScript(UChar32 c, UScriptCode sc) UPRV_NO_SANITIZE_UNDEFINED {
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK; uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX); uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) { if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
return sc==(UScriptCode)codeOrIndex; return sc==(UScriptCode)codeOrIndex;
} }
@ -587,7 +587,7 @@ uscript_getScriptExtensions(UChar32 c,
return 0; return 0;
} }
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK; uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX); uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) { if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
if(capacity==0) { if(capacity==0) {
*pErrorCode=U_BUFFER_OVERFLOW_ERROR; *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
@ -618,7 +618,15 @@ uscript_getScriptExtensions(UChar32 c,
U_CAPI UBlockCode U_EXPORT2 U_CAPI UBlockCode U_EXPORT2
ublock_getCode(UChar32 c) { ublock_getCode(UChar32 c) {
return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT); // We store Block values indexed by the code point shifted right 4 bits
// and use a "small" UCPTrie=CodePointTrie for minimal data size.
// This works because blocks have xxx0..xxxF ranges.
uint32_t c4 = c; // unsigned so that shifting right does not worry the compiler
// Shift unless out of range, in which case we fetch the trie's error value.
if (c4 <= 0x10ffff) {
c4 >>= 4;
}
return (UBlockCode)ucptrie_get(&block_trie, c4);
} }
/* property starts for UnicodeSet ------------------------------------------- */ /* property starts for UnicodeSet ------------------------------------------- */
@ -626,7 +634,7 @@ ublock_getCode(UChar32 c) {
static UBool U_CALLCONV static UBool U_CALLCONV
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) { _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
/* add the start code point to the USet */ /* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context; const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start); sa->add(sa->set, start);
(void)end; (void)end;
(void)value; (void)value;
@ -706,3 +714,18 @@ upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
/* add the start code point of each same-value range of the properties vectors trie */ /* add the start code point of each same-value range of the properties vectors trie */
utrie2_enum(&propsVectorsTrie, nullptr, _enumPropertyStartsRange, sa); utrie2_enum(&propsVectorsTrie, nullptr, _enumPropertyStartsRange, sa);
} }
U_CFUNC void U_EXPORT2
ublock_addPropertyStarts(const USetAdder *sa, UErrorCode & /*errorCode*/) {
// Add the start code point of each same-value range of the trie.
// We store Block values indexed by the code point shifted right 4 bits;
// see ublock_getCode().
UChar32 start = 0, end;
uint32_t value;
while (start < 0x11000 && // limit: (max code point + 1) >> 4
(end = ucptrie_getRange(&block_trie, start, UCPMAP_RANGE_NORMAL, 0,
nullptr, nullptr, &value)) >= 0) {
sa->add(sa->set, start << 4);
start = end + 1;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -297,7 +297,7 @@ UCharsTrie::findUniqueValueFromBranch(const char16_t *pos, int32_t length,
++pos; // ignore a comparison unit ++pos; // ignore a comparison unit
// handle its value // handle its value
int32_t node=*pos++; int32_t node=*pos++;
UBool isFinal=(UBool)(node>>15); UBool isFinal = static_cast<UBool>(node >> 15);
node&=0x7fff; node&=0x7fff;
int32_t value=readValue(pos, node); int32_t value=readValue(pos, node);
pos=skipValue(pos, node); pos=skipValue(pos, node);
@ -339,7 +339,7 @@ UCharsTrie::findUniqueValue(const char16_t *pos, UBool haveUniqueValue, int32_t
pos+=node-kMinLinearMatch+1; // Ignore the match units. pos+=node-kMinLinearMatch+1; // Ignore the match units.
node=*pos++; node=*pos++;
} else { } else {
UBool isFinal=(UBool)(node>>15); UBool isFinal = static_cast<UBool>(node >> 15);
int32_t value; int32_t value;
if(isFinal) { if(isFinal) {
value=readValue(pos, node&0x7fff); value=readValue(pos, node&0x7fff);

View File

@ -75,7 +75,7 @@ UCharsTrieElement::setTo(const UnicodeString &s, int32_t val,
return; return;
} }
stringOffset=strings.length(); stringOffset=strings.length();
strings.append((char16_t)length); strings.append(static_cast<char16_t>(length));
value=val; value=val;
strings.append(s); strings.append(s);
} }
@ -186,7 +186,7 @@ UCharsTrieBuilder::buildUChars(UStringTrieBuildOption buildOption, UErrorCode &e
errorCode=U_MEMORY_ALLOCATION_ERROR; errorCode=U_MEMORY_ALLOCATION_ERROR;
return; return;
} }
uprv_sortArray(elements, elementsLength, (int32_t)sizeof(UCharsTrieElement), uprv_sortArray(elements, elementsLength, static_cast<int32_t>(sizeof(UCharsTrieElement)),
compareElementStrings, &strings, compareElementStrings, &strings,
false, // need not be a stable sort false, // need not be a stable sort
&errorCode); &errorCode);
@ -351,7 +351,7 @@ UCharsTrieBuilder::write(int32_t unit) {
int32_t newLength=ucharsLength+1; int32_t newLength=ucharsLength+1;
if(ensureCapacity(newLength)) { if(ensureCapacity(newLength)) {
ucharsLength=newLength; ucharsLength=newLength;
uchars[ucharsCapacity-ucharsLength]=(char16_t)unit; uchars[ucharsCapacity - ucharsLength] = static_cast<char16_t>(unit);
} }
return ucharsLength; return ucharsLength;
} }
@ -379,19 +379,19 @@ UCharsTrieBuilder::writeValueAndFinal(int32_t i, UBool isFinal) {
char16_t intUnits[3]; char16_t intUnits[3];
int32_t length; int32_t length;
if(i<0 || i>UCharsTrie::kMaxTwoUnitValue) { if(i<0 || i>UCharsTrie::kMaxTwoUnitValue) {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitValueLead); intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitValueLead);
intUnits[1]=(char16_t)((uint32_t)i>>16); intUnits[1] = static_cast<char16_t>(static_cast<uint32_t>(i) >> 16);
intUnits[2]=(char16_t)i; intUnits[2] = static_cast<char16_t>(i);
length=3; length=3;
// } else if(i<=UCharsTrie::kMaxOneUnitValue) { // } else if(i<=UCharsTrie::kMaxOneUnitValue) {
// intUnits[0]=(char16_t)(i); // intUnits[0]=(char16_t)(i);
// length=1; // length=1;
} else { } else {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitValueLead+(i>>16)); intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitValueLead + (i >> 16));
intUnits[1]=(char16_t)i; intUnits[1] = static_cast<char16_t>(i);
length=2; length=2;
} }
intUnits[0]=(char16_t)(intUnits[0]|(isFinal<<15)); intUnits[0] = static_cast<char16_t>(intUnits[0] | (isFinal << 15));
return write(intUnits, length); return write(intUnits, length);
} }
@ -403,19 +403,19 @@ UCharsTrieBuilder::writeValueAndType(UBool hasValue, int32_t value, int32_t node
char16_t intUnits[3]; char16_t intUnits[3];
int32_t length; int32_t length;
if(value<0 || value>UCharsTrie::kMaxTwoUnitNodeValue) { if(value<0 || value>UCharsTrie::kMaxTwoUnitNodeValue) {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitNodeValueLead); intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitNodeValueLead);
intUnits[1]=(char16_t)((uint32_t)value>>16); intUnits[1] = static_cast<char16_t>(static_cast<uint32_t>(value) >> 16);
intUnits[2]=(char16_t)value; intUnits[2] = static_cast<char16_t>(value);
length=3; length=3;
} else if(value<=UCharsTrie::kMaxOneUnitNodeValue) { } else if(value<=UCharsTrie::kMaxOneUnitNodeValue) {
intUnits[0]=(char16_t)((value+1)<<6); intUnits[0] = static_cast<char16_t>((value + 1) << 6);
length=1; length=1;
} else { } else {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitNodeValueLead+((value>>10)&0x7fc0)); intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitNodeValueLead + ((value >> 10) & 0x7fc0));
intUnits[1]=(char16_t)value; intUnits[1] = static_cast<char16_t>(value);
length=2; length=2;
} }
intUnits[0]|=(char16_t)node; intUnits[0] |= static_cast<char16_t>(node);
return write(intUnits, length); return write(intUnits, length);
} }
@ -429,14 +429,14 @@ UCharsTrieBuilder::writeDeltaTo(int32_t jumpTarget) {
char16_t intUnits[3]; char16_t intUnits[3];
int32_t length; int32_t length;
if(i<=UCharsTrie::kMaxTwoUnitDelta) { if(i<=UCharsTrie::kMaxTwoUnitDelta) {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitDeltaLead+(i>>16)); intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitDeltaLead + (i >> 16));
length=1; length=1;
} else { } else {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitDeltaLead); intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitDeltaLead);
intUnits[1]=(char16_t)(i>>16); intUnits[1] = static_cast<char16_t>(i >> 16);
length=2; length=2;
} }
intUnits[length++]=(char16_t)i; intUnits[length++] = static_cast<char16_t>(i);
return write(intUnits, length); return write(intUnits, length);
} }

View File

@ -114,7 +114,7 @@ UCharsTrie::Iterator::next(UErrorCode &errorCode) {
pos=uchars_+stack_->elementAti(stackSize-2); pos=uchars_+stack_->elementAti(stackSize-2);
stack_->setSize(stackSize-2); stack_->setSize(stackSize-2);
str_.truncate(length&0xffff); str_.truncate(length&0xffff);
length=(int32_t)((uint32_t)length>>16); length = static_cast<int32_t>(static_cast<uint32_t>(length) >> 16);
if(length>1) { if(length>1) {
pos=branchNext(pos, length, errorCode); pos=branchNext(pos, length, errorCode);
if(pos==nullptr) { if(pos==nullptr) {
@ -138,7 +138,7 @@ UCharsTrie::Iterator::next(UErrorCode &errorCode) {
skipValue_=false; skipValue_=false;
} else { } else {
// Deliver value for the string so far. // Deliver value for the string so far.
UBool isFinal=(UBool)(node>>15); UBool isFinal = static_cast<UBool>(node >> 15);
if(isFinal) { if(isFinal) {
value_=readValue(pos, node&0x7fff); value_=readValue(pos, node&0x7fff);
} else { } else {
@ -187,7 +187,7 @@ UCharsTrie::Iterator::branchNext(const char16_t *pos, int32_t length, UErrorCode
while(length>kMaxBranchLinearSubNodeLength) { while(length>kMaxBranchLinearSubNodeLength) {
++pos; // ignore the comparison unit ++pos; // ignore the comparison unit
// Push state for the greater-or-equal edge. // Push state for the greater-or-equal edge.
stack_->addElement((int32_t)(skipDelta(pos)-uchars_), errorCode); stack_->addElement(static_cast<int32_t>(skipDelta(pos) - uchars_), errorCode);
stack_->addElement(((length-(length>>1))<<16)|str_.length(), errorCode); stack_->addElement(((length-(length>>1))<<16)|str_.length(), errorCode);
// Follow the less-than edge. // Follow the less-than edge.
length>>=1; length>>=1;
@ -197,10 +197,10 @@ UCharsTrie::Iterator::branchNext(const char16_t *pos, int32_t length, UErrorCode
// Read the first (key, value) pair. // Read the first (key, value) pair.
char16_t trieUnit=*pos++; char16_t trieUnit=*pos++;
int32_t node=*pos++; int32_t node=*pos++;
UBool isFinal=(UBool)(node>>15); UBool isFinal = static_cast<UBool>(node >> 15);
int32_t value=readValue(pos, node&=0x7fff); int32_t value=readValue(pos, node&=0x7fff);
pos=skipValue(pos, node); pos=skipValue(pos, node);
stack_->addElement((int32_t)(pos-uchars_), errorCode); stack_->addElement(static_cast<int32_t>(pos - uchars_), errorCode);
stack_->addElement(((length-1)<<16)|str_.length(), errorCode); stack_->addElement(((length-1)<<16)|str_.length(), errorCode);
str_.append(trieUnit); str_.append(trieUnit);
if(isFinal) { if(isFinal) {

View File

@ -172,7 +172,7 @@ UCharCharacterIterator::nextPostInc() {
UBool UBool
UCharCharacterIterator::hasNext() { UCharCharacterIterator::hasNext() {
return (UBool)(pos < end ? true : false); return pos < end;
} }
char16_t char16_t
@ -186,7 +186,7 @@ UCharCharacterIterator::previous() {
UBool UBool
UCharCharacterIterator::hasPrevious() { UCharCharacterIterator::hasPrevious() {
return (UBool)(pos > begin ? true : false); return pos > begin;
} }
UChar32 UChar32

View File

@ -108,8 +108,8 @@ strcmpAfterPrefix(const char *s1, const char *s2, int32_t *pPrefixLength) {
s1+=pl; s1+=pl;
s2+=pl; s2+=pl;
for(;;) { for(;;) {
int32_t c1=(uint8_t)*s1++; int32_t c1 = static_cast<uint8_t>(*s1++);
int32_t c2=(uint8_t)*s2++; int32_t c2 = static_cast<uint8_t>(*s2++);
cmp=c1-c2; cmp=c1-c2;
if(cmp!=0 || c1==0) { /* different or done */ if(cmp!=0 || c1==0) { /* different or done */
break; break;
@ -271,7 +271,7 @@ offsetTOCLookupFn(const UDataMemory *pData,
static uint32_t U_CALLCONV pointerTOCEntryCount(const UDataMemory *pData) { static uint32_t U_CALLCONV pointerTOCEntryCount(const UDataMemory *pData) {
const PointerTOC *toc = (PointerTOC *)pData->toc; const PointerTOC *toc = (PointerTOC *)pData->toc;
return (uint32_t)((toc != nullptr) ? (toc->count) : 0); return toc != nullptr ? toc->count : 0;
} }
static const DataHeader * U_CALLCONV pointerTOCLookupFn(const UDataMemory *pData, static const DataHeader * U_CALLCONV pointerTOCLookupFn(const UDataMemory *pData,

View File

@ -916,7 +916,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
* s<sourceLimit before converterSawEndOfInput is checked * s<sourceLimit before converterSawEndOfInput is checked
*/ */
converterSawEndOfInput= converterSawEndOfInput=
(UBool)(U_SUCCESS(*err) && static_cast<UBool>(U_SUCCESS(*err) &&
pArgs->flush && pArgs->source==pArgs->sourceLimit && pArgs->flush && pArgs->source==pArgs->sourceLimit &&
cnv->fromUChar32==0); cnv->fromUChar32==0);
} else { } else {
@ -941,7 +941,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
for(;;) { for(;;) {
/* update offsets if we write any */ /* update offsets if we write any */
if(offsets!=nullptr) { if(offsets!=nullptr) {
int32_t length=(int32_t)(pArgs->target-t); int32_t length = static_cast<int32_t>(pArgs->target - t);
if(length>0) { if(length>0) {
_updateOffsets(offsets, length, sourceIndex, errorInputLength); _updateOffsets(offsets, length, sourceIndex, errorInputLength);
@ -956,7 +956,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
} }
if(sourceIndex>=0) { if(sourceIndex>=0) {
sourceIndex+=(int32_t)(pArgs->source-s); sourceIndex += static_cast<int32_t>(pArgs->source - s);
} }
} }
@ -1066,10 +1066,10 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
U_ASSERT(cnv->preFromULength==0); U_ASSERT(cnv->preFromULength==0);
length=(int32_t)(pArgs->sourceLimit-pArgs->source); length = static_cast<int32_t>(pArgs->sourceLimit - pArgs->source);
if(length>0) { if(length>0) {
u_memcpy(cnv->preFromU, pArgs->source, length); u_memcpy(cnv->preFromU, pArgs->source, length);
cnv->preFromULength=(int8_t)-length; cnv->preFromULength = static_cast<int8_t>(-length);
} }
pArgs->source=realSource; pArgs->source=realSource;
@ -1089,7 +1089,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
codePoint=cnv->fromUChar32; codePoint=cnv->fromUChar32;
errorInputLength=0; errorInputLength=0;
U16_APPEND_UNSAFE(cnv->invalidUCharBuffer, errorInputLength, codePoint); U16_APPEND_UNSAFE(cnv->invalidUCharBuffer, errorInputLength, codePoint);
cnv->invalidUCharLength=(int8_t)errorInputLength; cnv->invalidUCharLength = static_cast<int8_t>(errorInputLength);
/* set the converter state to deal with the next character */ /* set the converter state to deal with the next character */
cnv->fromUChar32=0; cnv->fromUChar32=0;
@ -1134,7 +1134,7 @@ ucnv_outputOverflowFromUnicode(UConverter *cnv,
offsets=nullptr; offsets=nullptr;
} }
overflow=(char *)cnv->charErrorBuffer; overflow = reinterpret_cast<char*>(cnv->charErrorBuffer);
length=cnv->charErrorBufferLength; length=cnv->charErrorBufferLength;
i=0; i=0;
while(i<length) { while(i<length) {
@ -1146,7 +1146,7 @@ ucnv_outputOverflowFromUnicode(UConverter *cnv,
overflow[j++]=overflow[i++]; overflow[j++]=overflow[i++];
} while(i<length); } while(i<length);
cnv->charErrorBufferLength=(int8_t)j; cnv->charErrorBufferLength = static_cast<int8_t>(j);
*target=t; *target=t;
if(offsets!=nullptr) { if(offsets!=nullptr) {
*pOffsets=offsets; *pOffsets=offsets;
@ -1361,7 +1361,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
* s<sourceLimit before converterSawEndOfInput is checked * s<sourceLimit before converterSawEndOfInput is checked
*/ */
converterSawEndOfInput= converterSawEndOfInput=
(UBool)(U_SUCCESS(*err) && static_cast<UBool>(U_SUCCESS(*err) &&
pArgs->flush && pArgs->source==pArgs->sourceLimit && pArgs->flush && pArgs->source==pArgs->sourceLimit &&
cnv->toULength==0); cnv->toULength==0);
} else { } else {
@ -1386,7 +1386,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
for(;;) { for(;;) {
/* update offsets if we write any */ /* update offsets if we write any */
if(offsets!=nullptr) { if(offsets!=nullptr) {
int32_t length=(int32_t)(pArgs->target-t); int32_t length = static_cast<int32_t>(pArgs->target - t);
if(length>0) { if(length>0) {
_updateOffsets(offsets, length, sourceIndex, errorInputLength); _updateOffsets(offsets, length, sourceIndex, errorInputLength);
@ -1401,7 +1401,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
} }
if(sourceIndex>=0) { if(sourceIndex>=0) {
sourceIndex+=(int32_t)(pArgs->source-s); sourceIndex += static_cast<int32_t>(pArgs->source - s);
} }
} }
@ -1513,10 +1513,10 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
U_ASSERT(cnv->preToULength==0); U_ASSERT(cnv->preToULength==0);
length=(int32_t)(pArgs->sourceLimit-pArgs->source); length = static_cast<int32_t>(pArgs->sourceLimit - pArgs->source);
if(length>0) { if(length>0) {
uprv_memcpy(cnv->preToU, pArgs->source, length); uprv_memcpy(cnv->preToU, pArgs->source, length);
cnv->preToULength=(int8_t)-length; cnv->preToULength = static_cast<int8_t>(-length);
} }
pArgs->source=realSource; pArgs->source=realSource;
@ -1592,7 +1592,7 @@ ucnv_outputOverflowToUnicode(UConverter *cnv,
overflow[j++]=overflow[i++]; overflow[j++]=overflow[i++];
} while(i<length); } while(i<length);
cnv->UCharErrorBufferLength=(int8_t)j; cnv->UCharErrorBufferLength = static_cast<int8_t>(j);
*target=t; *target=t;
if(offsets!=nullptr) { if(offsets!=nullptr) {
*pOffsets=offsets; *pOffsets=offsets;
@ -2437,7 +2437,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter,
false, false,
true, true,
pErrorCode); pErrorCode);
targetLength=(int32_t)(myTarget-target); targetLength = static_cast<int32_t>(myTarget - target);
} }
/* /*
@ -2460,7 +2460,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter,
false, false,
true, true,
pErrorCode); pErrorCode);
targetLength+=(int32_t)(myTarget-targetBuffer); targetLength += static_cast<int32_t>(myTarget - targetBuffer);
} while(*pErrorCode==U_BUFFER_OVERFLOW_ERROR); } while(*pErrorCode==U_BUFFER_OVERFLOW_ERROR);
/* done with preflighting, set warnings and errors as appropriate */ /* done with preflighting, set warnings and errors as appropriate */
@ -2684,7 +2684,7 @@ ucnv_fixFileSeparator(const UConverter *cnv,
U_CAPI UBool U_EXPORT2 U_CAPI UBool U_EXPORT2
ucnv_isAmbiguous(const UConverter *cnv) { ucnv_isAmbiguous(const UConverter *cnv) {
return (UBool)(ucnv_getAmbiguous(cnv)!=nullptr); return ucnv_getAmbiguous(cnv)!=nullptr;
} }
U_CAPI void U_EXPORT2 U_CAPI void U_EXPORT2

File diff suppressed because it is too large Load Diff

View File

@ -231,7 +231,7 @@ static void
ucnv_flushAvailableConverterCache() { ucnv_flushAvailableConverterCache() {
gAvailableConverterCount = 0; gAvailableConverterCount = 0;
if (gAvailableConverters) { if (gAvailableConverters) {
uprv_free((char **)gAvailableConverters); uprv_free(const_cast<char**>(gAvailableConverters));
gAvailableConverters = nullptr; gAvailableConverters = nullptr;
} }
gAvailableConvertersInitOnce.reset(); gAvailableConvertersInitOnce.reset();
@ -270,7 +270,7 @@ static UBool U_CALLCONV
isCnvAcceptable(void * /*context*/, isCnvAcceptable(void * /*context*/,
const char * /*type*/, const char * /*name*/, const char * /*type*/, const char * /*name*/,
const UDataInfo *pInfo) { const UDataInfo *pInfo) {
return (UBool)( return
pInfo->size>=20 && pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
pInfo->charsetFamily==U_CHARSET_FAMILY && pInfo->charsetFamily==U_CHARSET_FAMILY &&
@ -279,7 +279,7 @@ isCnvAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x6e && pInfo->dataFormat[1]==0x6e &&
pInfo->dataFormat[2]==0x76 && pInfo->dataFormat[2]==0x76 &&
pInfo->dataFormat[3]==0x74 && pInfo->dataFormat[3]==0x74 &&
pInfo->formatVersion[0]==6); /* Everything will be version 6 */ pInfo->formatVersion[0]==6; /* Everything will be version 6 */
} }
/** /**
@ -289,15 +289,15 @@ static UConverterSharedData*
ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCode *status) ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCode *status)
{ {
/* UDataInfo info; -- necessary only if some converters have different formatVersion */ /* UDataInfo info; -- necessary only if some converters have different formatVersion */
const uint8_t *raw = (const uint8_t *)udata_getMemory(pData); const uint8_t* raw = static_cast<const uint8_t*>(udata_getMemory(pData));
const UConverterStaticData *source = (const UConverterStaticData *) raw; const UConverterStaticData* source = reinterpret_cast<const UConverterStaticData*>(raw);
UConverterSharedData *data; UConverterSharedData *data;
UConverterType type = (UConverterType)source->conversionType; UConverterType type = static_cast<UConverterType>(source->conversionType);
if(U_FAILURE(*status)) if(U_FAILURE(*status))
return nullptr; return nullptr;
if( (uint16_t)type >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES || if (static_cast<uint16_t>(type) >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES ||
converterData[type] == nullptr || converterData[type] == nullptr ||
!converterData[type]->isReferenceCounted || !converterData[type]->isReferenceCounted ||
converterData[type]->referenceCounter != 1 || converterData[type]->referenceCounter != 1 ||
@ -307,7 +307,7 @@ ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCo
return nullptr; return nullptr;
} }
data = (UConverterSharedData *)uprv_malloc(sizeof(UConverterSharedData)); data = static_cast<UConverterSharedData*>(uprv_malloc(sizeof(UConverterSharedData)));
if(data == nullptr) { if(data == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR; *status = U_MEMORY_ALLOCATION_ERROR;
return nullptr; return nullptr;
@ -397,7 +397,7 @@ getAlgorithmicTypeFromName(const char *realName)
lastMid = UINT32_MAX; lastMid = UINT32_MAX;
for (;;) { for (;;) {
mid = (uint32_t)((start + limit) / 2); mid = (start + limit) / 2;
if (lastMid == mid) { /* Have we moved? */ if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */ break; /* We haven't moved, and it wasn't found. */
} }
@ -491,7 +491,7 @@ ucnv_getSharedConverterData(const char *name)
{ {
UConverterSharedData *rc; UConverterSharedData *rc;
rc = (UConverterSharedData*)uhash_get(SHARED_DATA_HASHTABLE, name); rc = static_cast<UConverterSharedData*>(uhash_get(SHARED_DATA_HASHTABLE, name));
UCNV_DEBUG_LOG("get",name,rc); UCNV_DEBUG_LOG("get",name,rc);
return rc; return rc;
} }
@ -682,8 +682,8 @@ parseConverterOptions(const char *inName,
if(c==0) { if(c==0) {
pArgs->options=(pPieces->options&=~UCNV_OPTION_VERSION); pArgs->options=(pPieces->options&=~UCNV_OPTION_VERSION);
return; return;
} else if((uint8_t)(c-'0')<10) { } else if (static_cast<uint8_t>(c - '0') < 10) {
pArgs->options=pPieces->options=(pPieces->options&~UCNV_OPTION_VERSION)|(uint32_t)(c-'0'); pArgs->options = pPieces->options = (pPieces->options & ~UCNV_OPTION_VERSION) | static_cast<uint32_t>(c - '0');
++inName; ++inName;
} }
} else if(uprv_strncmp(inName, "swaplfnl", 8)==0) { } else if(uprv_strncmp(inName, "swaplfnl", 8)==0) {
@ -909,7 +909,7 @@ ucnv_createAlgorithmicConverter(UConverter *myUConverter,
stackArgs.options = options; stackArgs.options = options;
stackArgs.locale=locale; stackArgs.locale=locale;
cnv = ucnv_createConverterFromSharedData( cnv = ucnv_createConverterFromSharedData(
myUConverter, (UConverterSharedData *)sharedData, myUConverter, const_cast<UConverterSharedData*>(sharedData),
&stackArgs, err); &stackArgs, err);
UTRACE_EXIT_PTR_STATUS(cnv, *err); UTRACE_EXIT_PTR_STATUS(cnv, *err);
@ -1112,7 +1112,7 @@ static void U_CALLCONV initAvailableConvertersList(UErrorCode &errCode) {
} }
/* We can't have more than "*converterTable" converters to open */ /* We can't have more than "*converterTable" converters to open */
gAvailableConverters = (const char **) uprv_malloc(allConverterCount * sizeof(char*)); gAvailableConverters = static_cast<const char**>(uprv_malloc(allConverterCount * sizeof(char*)));
if (!gAvailableConverters) { if (!gAvailableConverters) {
errCode = U_MEMORY_ALLOCATION_ERROR; errCode = U_MEMORY_ALLOCATION_ERROR;
return; return;
@ -1440,7 +1440,7 @@ ucnv_swap(const UDataSwapper *ds,
MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0 MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0
) { ) {
mbcsHeaderLength=mbcsHeader.options&MBCS_OPT_LENGTH_MASK; mbcsHeaderLength=mbcsHeader.options&MBCS_OPT_LENGTH_MASK;
noFromU=(UBool)((mbcsHeader.options&MBCS_OPT_NO_FROM_U)!=0); noFromU = (mbcsHeader.options & MBCS_OPT_NO_FROM_U) != 0;
} else { } else {
udata_printError(ds, "ucnv_swap(): unsupported _MBCSHeader.version %d.%d\n", udata_printError(ds, "ucnv_swap(): unsupported _MBCSHeader.version %d.%d\n",
inMBCSHeader->version[0], inMBCSHeader->version[1]); inMBCSHeader->version[0], inMBCSHeader->version[1]);

View File

@ -368,7 +368,7 @@ getTrail:
/*look ahead to find the trail surrogate*/ /*look ahead to find the trail surrogate*/
if(source < sourceLimit) { if(source < sourceLimit) {
/* test the following code unit */ /* test the following code unit */
char16_t trail=(char16_t) *source; char16_t trail = *source;
if(U16_IS_TRAIL(trail)) { if(U16_IS_TRAIL(trail)) {
source++; source++;
sourceChar=U16_GET_SUPPLEMENTARY(sourceChar, trail); sourceChar=U16_GET_SUPPLEMENTARY(sourceChar, trail);

View File

@ -41,8 +41,8 @@ ucnv_extFindToU(const uint32_t *toUSection, int32_t length, uint8_t byte) {
int32_t i, start, limit; int32_t i, start, limit;
/* check the input byte against the lowest and highest section bytes */ /* check the input byte against the lowest and highest section bytes */
start=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[0]); start = static_cast<int32_t>(UCNV_EXT_TO_U_GET_BYTE(toUSection[0]));
limit=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[length-1]); limit = static_cast<int32_t>(UCNV_EXT_TO_U_GET_BYTE(toUSection[length - 1]));
if(byte<start || limit<byte) { if(byte<start || limit<byte) {
return 0; /* the byte is out of range */ return 0; /* the byte is out of range */
} }
@ -180,9 +180,9 @@ ucnv_extMatchToU(const int32_t *cx, int8_t sisoState,
/* match pre[] then src[] */ /* match pre[] then src[] */
if(i<preLength) { if(i<preLength) {
b=(uint8_t)pre[i++]; b = static_cast<uint8_t>(pre[i++]);
} else if(j<srcLength) { } else if(j<srcLength) {
b=(uint8_t)src[j++]; b = static_cast<uint8_t>(src[j++]);
} else { } else {
/* all input consumed, partial match */ /* all input consumed, partial match */
if(flush || (length=(i+j))>UCNV_EXT_MAX_BYTES) { if(flush || (length=(i+j))>UCNV_EXT_MAX_BYTES) {
@ -206,7 +206,7 @@ ucnv_extMatchToU(const int32_t *cx, int8_t sisoState,
} else { } else {
if(UCNV_EXT_TO_U_IS_PARTIAL(value)) { if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
/* partial match, continue */ /* partial match, continue */
idx=(int32_t)UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value); idx = static_cast<int32_t>(UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value));
} else { } else {
if( (UCNV_EXT_TO_U_IS_ROUNDTRIP(value) || if( (UCNV_EXT_TO_U_IS_ROUNDTRIP(value) ||
TO_U_USE_FALLBACK(useFallback)) && TO_U_USE_FALLBACK(useFallback)) &&
@ -572,7 +572,7 @@ ucnv_extMatchFromU(const int32_t *cx,
if(UCNV_EXT_TO_U_IS_PARTIAL(value)) { if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
/* partial match, enter the loop below */ /* partial match, enter the loop below */
idx=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value); idx = static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value));
/* initialize */ /* initialize */
fromUTableUChars=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_UCHARS_INDEX, char16_t); fromUTableUChars=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_UCHARS_INDEX, char16_t);
@ -627,7 +627,7 @@ ucnv_extMatchFromU(const int32_t *cx,
value=fromUSectionValues[idx]; value=fromUSectionValues[idx];
if(UCNV_EXT_FROM_U_IS_PARTIAL(value)) { if(UCNV_EXT_FROM_U_IS_PARTIAL(value)) {
/* partial match, continue */ /* partial match, continue */
idx=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value); idx = static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value));
} else { } else {
if(extFromUUseMapping(useFallback, value, firstCP)) { if(extFromUUseMapping(useFallback, value, firstCP)) {
/* full match, stop with result */ /* full match, stop with result */
@ -679,7 +679,7 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
int32_t length, prevLength; int32_t length, prevLength;
length=UCNV_EXT_FROM_U_GET_LENGTH(value); length=UCNV_EXT_FROM_U_GET_LENGTH(value);
value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value); value = UCNV_EXT_FROM_U_GET_DATA(value);
/* output the result */ /* output the result */
if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) { if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
@ -692,13 +692,13 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
uint8_t *p=buffer+1; /* reserve buffer[0] for shiftByte below */ uint8_t *p=buffer+1; /* reserve buffer[0] for shiftByte below */
switch(length) { switch(length) {
case 3: case 3:
*p++=(uint8_t)(value>>16); *p++ = static_cast<uint8_t>(value >> 16);
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*p++=(uint8_t)(value>>8); *p++ = static_cast<uint8_t>(value >> 8);
U_FALLTHROUGH; U_FALLTHROUGH;
case 1: case 1:
*p++=(uint8_t)value; *p++ = static_cast<uint8_t>(value);
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
break; /* will never occur */ break; /* will never occur */
@ -716,11 +716,11 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
if(prevLength>1 && length==1) { if(prevLength>1 && length==1) {
/* change from double-byte mode to single-byte */ /* change from double-byte mode to single-byte */
shiftByte=(uint8_t)UCNV_SI; shiftByte = static_cast<uint8_t>(UCNV_SI);
cnv->fromUnicodeStatus=1; cnv->fromUnicodeStatus=1;
} else if(prevLength==1 && length>1) { } else if(prevLength==1 && length>1) {
/* change from single-byte mode to double-byte */ /* change from single-byte mode to double-byte */
shiftByte=(uint8_t)UCNV_SO; shiftByte = static_cast<uint8_t>(UCNV_SO);
cnv->fromUnicodeStatus=2; cnv->fromUnicodeStatus=2;
} else { } else {
shiftByte=0; shiftByte=0;
@ -737,7 +737,7 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
} }
} }
ucnv_fromUWriteBytes(cnv, (const char *)result, length, ucnv_fromUWriteBytes(cnv, reinterpret_cast<const char*>(result), length,
target, targetLimit, target, targetLimit,
offsets, srcIndex, offsets, srcIndex,
pErrorCode); pErrorCode);
@ -830,7 +830,7 @@ ucnv_extSimpleMatchFromU(const int32_t *cx,
isRoundtrip=UCNV_EXT_FROM_U_IS_ROUNDTRIP(value); isRoundtrip=UCNV_EXT_FROM_U_IS_ROUNDTRIP(value);
length=UCNV_EXT_FROM_U_GET_LENGTH(value); length=UCNV_EXT_FROM_U_GET_LENGTH(value);
value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value); value = UCNV_EXT_FROM_U_GET_DATA(value);
if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) { if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
*pValue=value; *pValue=value;
@ -1018,7 +1018,7 @@ ucnv_extGetUnicodeSetString(const UConverterSharedData *sharedData,
ucnv_extGetUnicodeSetString( ucnv_extGetUnicodeSetString(
sharedData, cx, sa, which, minLength, sharedData, cx, sa, which, minLength,
firstCP, s, length+1, firstCP, s, length+1,
(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value), static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value)),
pErrorCode); pErrorCode);
} else if(extSetUseMapping(which, minLength, value)) { } else if(extSetUseMapping(which, minLength, value)) {
sa->addString(sa->set, s, length+1); sa->addString(sa->set, s, length+1);

View File

@ -205,7 +205,7 @@ static UBool U_CALLCONV
isAcceptable(void * /*context*/, isAcceptable(void * /*context*/,
const char * /*type*/, const char * /*name*/, const char * /*type*/, const char * /*name*/,
const UDataInfo *pInfo) { const UDataInfo *pInfo) {
return (UBool)( return
pInfo->size>=20 && pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
pInfo->charsetFamily==U_CHARSET_FAMILY && pInfo->charsetFamily==U_CHARSET_FAMILY &&
@ -213,7 +213,7 @@ isAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x76 && pInfo->dataFormat[1]==0x76 &&
pInfo->dataFormat[2]==0x41 && pInfo->dataFormat[2]==0x41 &&
pInfo->dataFormat[3]==0x6c && pInfo->dataFormat[3]==0x6c &&
pInfo->formatVersion[0]==3); pInfo->formatVersion[0]==3;
} }
static UBool U_CALLCONV ucnv_io_cleanup() static UBool U_CALLCONV ucnv_io_cleanup()
@ -244,8 +244,8 @@ static void U_CALLCONV initAliasData(UErrorCode &errCode) {
return; return;
} }
sectionSizes = (const uint32_t *)udata_getMemory(data); sectionSizes = static_cast<const uint32_t*>(udata_getMemory(data));
table = (const uint16_t *)sectionSizes; table = reinterpret_cast<const uint16_t*>(sectionSizes);
tableStart = sectionSizes[0]; tableStart = sectionSizes[0];
if (tableStart < minTocLength) { if (tableStart < minTocLength) {
@ -289,10 +289,10 @@ static void U_CALLCONV initAliasData(UErrorCode &errCode) {
currOffset += gMainTable.taggedAliasListsSize; currOffset += gMainTable.taggedAliasListsSize;
if (gMainTable.optionTableSize > 0 if (gMainTable.optionTableSize > 0
&& ((const UConverterAliasOptions *)(table + currOffset))->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT) && reinterpret_cast<const UConverterAliasOptions*>(table + currOffset)->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
{ {
/* Faster table */ /* Faster table */
gMainTable.optionTable = (const UConverterAliasOptions *)(table + currOffset); gMainTable.optionTable = reinterpret_cast<const UConverterAliasOptions*>(table + currOffset);
} }
else { else {
/* Smaller table, or I can't handle this normalization mode! /* Smaller table, or I can't handle this normalization mode!
@ -321,7 +321,7 @@ isAlias(const char *alias, UErrorCode *pErrorCode) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return false; return false;
} }
return (UBool)(*alias!=0); return *alias != 0;
} }
static uint32_t getTagNumber(const char *tagname) { static uint32_t getTagNumber(const char *tagname) {
@ -574,7 +574,7 @@ findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode)
lastMid = UINT32_MAX; lastMid = UINT32_MAX;
for (;;) { for (;;) {
mid = (uint32_t)((start + limit) / 2); mid = (start + limit) / 2;
if (lastMid == mid) { /* Have we moved? */ if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */ break; /* We haven't moved, and it wasn't found. */
} }
@ -601,8 +601,8 @@ findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode)
/* State whether the canonical converter name contains an option. /* State whether the canonical converter name contains an option.
This information is contained in this list in order to maintain backward & forward compatibility. */ This information is contained in this list in order to maintain backward & forward compatibility. */
if (containsOption) { if (containsOption) {
UBool containsCnvOptionInfo = (UBool)gMainTable.optionTable->containsCnvOptionInfo; UBool containsCnvOptionInfo = static_cast<UBool>(gMainTable.optionTable->containsCnvOptionInfo);
*containsOption = (UBool)((containsCnvOptionInfo *containsOption = static_cast<UBool>((containsCnvOptionInfo
&& ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0)) && ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0))
|| !containsCnvOptionInfo); || !containsCnvOptionInfo);
} }
@ -939,7 +939,7 @@ static uint16_t
ucnv_io_countStandards(UErrorCode *pErrorCode) { ucnv_io_countStandards(UErrorCode *pErrorCode) {
if (haveAliasData(pErrorCode)) { if (haveAliasData(pErrorCode)) {
/* Don't include the empty list */ /* Don't include the empty list */
return (uint16_t)(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS); return static_cast<uint16_t>(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
} }
return 0; return 0;
@ -1130,8 +1130,9 @@ io_compareRows(const void *context, const void *left, const void *right) {
TempAliasTable *tempTable=(TempAliasTable *)context; TempAliasTable *tempTable=(TempAliasTable *)context;
const char *chars=tempTable->chars; const char *chars=tempTable->chars;
return (int32_t)uprv_strcmp(tempTable->stripForCompare(strippedLeft, chars+2*((const TempRow *)left)->strIndex), return static_cast<int32_t>(uprv_strcmp(
tempTable->stripForCompare(strippedRight, chars+2*((const TempRow *)right)->strIndex)); tempTable->stripForCompare(strippedLeft, chars + 2 * static_cast<const TempRow*>(left)->strIndex),
tempTable->stripForCompare(strippedRight, chars + 2 * static_cast<const TempRow*>(right)->strIndex)));
} }
U_CAPI int32_t U_EXPORT2 U_CAPI int32_t U_EXPORT2

View File

@ -633,7 +633,7 @@ _LMBCSOpenWorker(UConverter* _this,
UErrorCode* err, UErrorCode* err,
ulmbcs_byte_t OptGroup) ulmbcs_byte_t OptGroup)
{ {
UConverterDataLMBCS * extraInfo = (UConverterDataLMBCS*)uprv_malloc (sizeof (UConverterDataLMBCS)); UConverterDataLMBCS* extraInfo = static_cast<UConverterDataLMBCS*>(uprv_malloc(sizeof(UConverterDataLMBCS)));
_this->extraInfo = extraInfo; _this->extraInfo = extraInfo;
if(extraInfo != nullptr) if(extraInfo != nullptr)
{ {

View File

@ -236,10 +236,10 @@ _UTF16BEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
/* output length bytes with overflow (length>targetCapacity>0) */ /* output length bytes with overflow (length>targetCapacity>0) */
ucnv_fromUWriteBytes(cnv, ucnv_fromUWriteBytes(cnv,
overflow, length, overflow, length,
(char **)&target, pArgs->targetLimit, &target, pArgs->targetLimit,
&offsets, sourceIndex, &offsets, sourceIndex,
pErrorCode); pErrorCode);
targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target); targetCapacity = static_cast<uint32_t>(pArgs->targetLimit - target);
} }
if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) { if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) {
@ -248,7 +248,7 @@ _UTF16BEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
/* write back the updated pointers */ /* write back the updated pointers */
pArgs->source=source; pArgs->source=source;
pArgs->target=(char *)target; pArgs->target = target;
pArgs->offsets=offsets; pArgs->offsets=offsets;
} }
@ -840,7 +840,7 @@ _UTF16LEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
&target, pArgs->targetLimit, &target, pArgs->targetLimit,
&offsets, sourceIndex, &offsets, sourceIndex,
pErrorCode); pErrorCode);
targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target); targetCapacity = static_cast<uint32_t>(pArgs->targetLimit - target);
} }
if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) { if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) {

View File

@ -49,8 +49,8 @@ U_CFUNC void ucnv_fromUnicode_UTF8_OFFSETS_LOGIC(UConverterFromUnicodeArgs *args
#define MAXIMUM_UCS2 0x0000FFFF #define MAXIMUM_UCS2 0x0000FFFF
static const uint32_t offsetsFromUTF8[5] = {0, static const uint32_t offsetsFromUTF8[5] = {0,
(uint32_t) 0x00000000, (uint32_t) 0x00003080, (uint32_t) 0x000E2080, static_cast<uint32_t>(0x00000000), static_cast<uint32_t>(0x00003080),
(uint32_t) 0x03C82080 static_cast<uint32_t>(0x000E2080), static_cast<uint32_t>(0x03C82080)
}; };
static UBool hasCESU8Data(const UConverter *cnv) static UBool hasCESU8Data(const UConverter *cnv)
@ -58,7 +58,7 @@ static UBool hasCESU8Data(const UConverter *cnv)
#if UCONFIG_ONLY_HTML_CONVERSION #if UCONFIG_ONLY_HTML_CONVERSION
return false; return false;
#else #else
return (UBool)(cnv->sharedData == &_CESU8Data); return cnv->sharedData == &_CESU8Data;
#endif #endif
} }
U_CDECL_BEGIN U_CDECL_BEGIN
@ -571,7 +571,7 @@ static UChar32 U_CALLCONV ucnv_getNextUChar_UTF8(UConverterToUnicodeArgs *args,
return 0xffff; return 0xffff;
} }
myByte = (uint8_t)*(source++); myByte = *(source++);
if (U8_IS_SINGLE(myByte)) if (U8_IS_SINGLE(myByte))
{ {
args->source = (const char *)source; args->source = (const char *)source;

View File

@ -338,7 +338,7 @@ packDiff(int32_t diff) {
*/ */
result|=BOCU1_TRAIL_TO_BYTE(diff)<<16; result|=BOCU1_TRAIL_TO_BYTE(diff)<<16;
result|=((uint32_t)BOCU1_START_POS_4)<<24; result |= static_cast<uint32_t>(BOCU1_START_POS_4) << 24;
} }
} else { } else {
/* two- to four-byte negative differences */ /* two- to four-byte negative differences */
@ -405,13 +405,13 @@ _Bocu1FromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
cnv=pArgs->converter; cnv=pArgs->converter;
source=pArgs->source; source=pArgs->source;
sourceLimit=pArgs->sourceLimit; sourceLimit=pArgs->sourceLimit;
target=(uint8_t *)pArgs->target; target = reinterpret_cast<uint8_t*>(pArgs->target);
targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target); targetCapacity = static_cast<int32_t>(pArgs->targetLimit - pArgs->target);
offsets=pArgs->offsets; offsets=pArgs->offsets;
/* get the converter state from UConverter */ /* get the converter state from UConverter */
c=cnv->fromUChar32; c=cnv->fromUChar32;
prev=(int32_t)cnv->fromUnicodeStatus; prev = static_cast<int32_t>(cnv->fromUnicodeStatus);
if(prev==0) { if(prev==0) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
@ -428,7 +428,7 @@ _Bocu1FromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
fastSingle: fastSingle:
/* fast loop for single-byte differences */ /* fast loop for single-byte differences */
/* use only one loop counter variable, targetCapacity, not also source */ /* use only one loop counter variable, targetCapacity, not also source */
diff=(int32_t)(sourceLimit-source); diff = static_cast<int32_t>(sourceLimit - source);
if(targetCapacity>diff) { if(targetCapacity>diff) {
targetCapacity=diff; targetCapacity=diff;
} }
@ -437,7 +437,7 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(uint8_t)c; *target++ = static_cast<uint8_t>(c);
*offsets++=nextSourceIndex++; *offsets++=nextSourceIndex++;
++source; ++source;
--targetCapacity; --targetCapacity;
@ -445,7 +445,7 @@ fastSingle:
diff=c-prev; diff=c-prev;
if(DIFF_IS_SINGLE(diff)) { if(DIFF_IS_SINGLE(diff)) {
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
*target++=(uint8_t)PACK_SINGLE_DIFF(diff); *target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
*offsets++=nextSourceIndex++; *offsets++=nextSourceIndex++;
++source; ++source;
--targetCapacity; --targetCapacity;
@ -455,7 +455,7 @@ fastSingle:
} }
} }
/* restore real values */ /* restore real values */
targetCapacity=(int32_t)((const uint8_t *)pArgs->targetLimit-target); targetCapacity = static_cast<int32_t>(reinterpret_cast<const uint8_t*>(pArgs->targetLimit) - target);
sourceIndex=nextSourceIndex; /* wrong if offsets==nullptr but does not matter */ sourceIndex=nextSourceIndex; /* wrong if offsets==nullptr but does not matter */
/* regular loop for all cases */ /* regular loop for all cases */
@ -473,7 +473,7 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(uint8_t)c; *target++ = static_cast<uint8_t>(c);
*offsets++=sourceIndex; *offsets++=sourceIndex;
--targetCapacity; --targetCapacity;
@ -510,7 +510,7 @@ getTrail:
diff=c-prev; diff=c-prev;
prev=BOCU1_PREV(c); prev=BOCU1_PREV(c);
if(DIFF_IS_SINGLE(diff)) { if(DIFF_IS_SINGLE(diff)) {
*target++=(uint8_t)PACK_SINGLE_DIFF(diff); *target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
*offsets++=sourceIndex; *offsets++=sourceIndex;
--targetCapacity; --targetCapacity;
sourceIndex=nextSourceIndex; sourceIndex=nextSourceIndex;
@ -531,8 +531,8 @@ getTrail:
NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m); NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m);
diff+=BOCU1_START_NEG_2; diff+=BOCU1_START_NEG_2;
} }
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
*target++=(uint8_t)BOCU1_TRAIL_TO_BYTE(m); *target++ = static_cast<uint8_t>(BOCU1_TRAIL_TO_BYTE(m));
*offsets++=sourceIndex; *offsets++=sourceIndex;
*offsets++=sourceIndex; *offsets++=sourceIndex;
targetCapacity-=2; targetCapacity-=2;
@ -549,18 +549,18 @@ getTrail:
switch(length) { switch(length) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 4: case 4:
*target++=(uint8_t)(diff>>24); *target++ = static_cast<uint8_t>(diff >> 24);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
case 3: case 3:
*target++=(uint8_t)(diff>>16); *target++ = static_cast<uint8_t>(diff >> 16);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*target++=(uint8_t)(diff>>8); *target++ = static_cast<uint8_t>(diff >> 8);
*offsets++=sourceIndex; *offsets++=sourceIndex;
/* case 1: handled above */ /* case 1: handled above */
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
@ -584,34 +584,34 @@ getTrail:
switch(length) { switch(length) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 3: case 3:
*charErrorBuffer++=(uint8_t)(diff>>16); *charErrorBuffer++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*charErrorBuffer++=(uint8_t)(diff>>8); *charErrorBuffer++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH; U_FALLTHROUGH;
case 1: case 1:
*charErrorBuffer=(uint8_t)diff; *charErrorBuffer = static_cast<uint8_t>(diff);
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
/* will never occur */ /* will never occur */
break; break;
} }
cnv->charErrorBufferLength=(int8_t)length; cnv->charErrorBufferLength = static_cast<int8_t>(length);
/* now output what fits into the regular target */ /* now output what fits into the regular target */
diff>>=8*length; /* length was reduced by targetCapacity */ diff>>=8*length; /* length was reduced by targetCapacity */
switch(targetCapacity) { switch(targetCapacity) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 3: case 3:
*target++=(uint8_t)(diff>>16); *target++ = static_cast<uint8_t>(diff >> 16);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*target++=(uint8_t)(diff>>8); *target++ = static_cast<uint8_t>(diff >> 8);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
case 1: case 1:
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
*offsets++=sourceIndex; *offsets++=sourceIndex;
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
@ -634,11 +634,11 @@ getTrail:
/* set the converter state back into UConverter */ /* set the converter state back into UConverter */
cnv->fromUChar32= c<0 ? -c : 0; cnv->fromUChar32= c<0 ? -c : 0;
cnv->fromUnicodeStatus=(uint32_t)prev; cnv->fromUnicodeStatus = static_cast<uint32_t>(prev);
/* write back the updated pointers */ /* write back the updated pointers */
pArgs->source=source; pArgs->source=source;
pArgs->target=(char *)target; pArgs->target = reinterpret_cast<char*>(target);
pArgs->offsets=offsets; pArgs->offsets=offsets;
} }
@ -663,12 +663,12 @@ _Bocu1FromUnicode(UConverterFromUnicodeArgs *pArgs,
cnv=pArgs->converter; cnv=pArgs->converter;
source=pArgs->source; source=pArgs->source;
sourceLimit=pArgs->sourceLimit; sourceLimit=pArgs->sourceLimit;
target=(uint8_t *)pArgs->target; target = reinterpret_cast<uint8_t*>(pArgs->target);
targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target); targetCapacity = static_cast<int32_t>(pArgs->targetLimit - pArgs->target);
/* get the converter state from UConverter */ /* get the converter state from UConverter */
c=cnv->fromUChar32; c=cnv->fromUChar32;
prev=(int32_t)cnv->fromUnicodeStatus; prev = static_cast<int32_t>(cnv->fromUnicodeStatus);
if(prev==0) { if(prev==0) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
@ -681,7 +681,7 @@ _Bocu1FromUnicode(UConverterFromUnicodeArgs *pArgs,
fastSingle: fastSingle:
/* fast loop for single-byte differences */ /* fast loop for single-byte differences */
/* use only one loop counter variable, targetCapacity, not also source */ /* use only one loop counter variable, targetCapacity, not also source */
diff=(int32_t)(sourceLimit-source); diff = static_cast<int32_t>(sourceLimit - source);
if(targetCapacity>diff) { if(targetCapacity>diff) {
targetCapacity=diff; targetCapacity=diff;
} }
@ -690,12 +690,12 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(uint8_t)c; *target++ = static_cast<uint8_t>(c);
} else { } else {
diff=c-prev; diff=c-prev;
if(DIFF_IS_SINGLE(diff)) { if(DIFF_IS_SINGLE(diff)) {
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
*target++=(uint8_t)PACK_SINGLE_DIFF(diff); *target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
} else { } else {
break; break;
} }
@ -704,7 +704,7 @@ fastSingle:
--targetCapacity; --targetCapacity;
} }
/* restore real values */ /* restore real values */
targetCapacity=(int32_t)((const uint8_t *)pArgs->targetLimit-target); targetCapacity = static_cast<int32_t>(reinterpret_cast<const uint8_t*>(pArgs->targetLimit) - target);
/* regular loop for all cases */ /* regular loop for all cases */
while(source<sourceLimit) { while(source<sourceLimit) {
@ -720,7 +720,7 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(uint8_t)c; *target++ = static_cast<uint8_t>(c);
--targetCapacity; --targetCapacity;
continue; continue;
} }
@ -753,7 +753,7 @@ getTrail:
diff=c-prev; diff=c-prev;
prev=BOCU1_PREV(c); prev=BOCU1_PREV(c);
if(DIFF_IS_SINGLE(diff)) { if(DIFF_IS_SINGLE(diff)) {
*target++=(uint8_t)PACK_SINGLE_DIFF(diff); *target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
--targetCapacity; --targetCapacity;
if(c<0x3000) { if(c<0x3000) {
goto fastSingle; goto fastSingle;
@ -772,8 +772,8 @@ getTrail:
NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m); NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m);
diff+=BOCU1_START_NEG_2; diff+=BOCU1_START_NEG_2;
} }
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
*target++=(uint8_t)BOCU1_TRAIL_TO_BYTE(m); *target++ = static_cast<uint8_t>(BOCU1_TRAIL_TO_BYTE(m));
targetCapacity-=2; targetCapacity-=2;
} else { } else {
int32_t length; /* will be 2..4 */ int32_t length; /* will be 2..4 */
@ -787,14 +787,14 @@ getTrail:
switch(length) { switch(length) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 4: case 4:
*target++=(uint8_t)(diff>>24); *target++ = static_cast<uint8_t>(diff >> 24);
U_FALLTHROUGH; U_FALLTHROUGH;
case 3: case 3:
*target++=(uint8_t)(diff>>16); *target++ = static_cast<uint8_t>(diff >> 16);
/* case 2: handled above */ /* case 2: handled above */
*target++=(uint8_t)(diff>>8); *target++ = static_cast<uint8_t>(diff >> 8);
/* case 1: handled above */ /* case 1: handled above */
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
/* will never occur */ /* will never occur */
@ -816,32 +816,32 @@ getTrail:
switch(length) { switch(length) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 3: case 3:
*charErrorBuffer++=(uint8_t)(diff>>16); *charErrorBuffer++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*charErrorBuffer++=(uint8_t)(diff>>8); *charErrorBuffer++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH; U_FALLTHROUGH;
case 1: case 1:
*charErrorBuffer=(uint8_t)diff; *charErrorBuffer = static_cast<uint8_t>(diff);
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
/* will never occur */ /* will never occur */
break; break;
} }
cnv->charErrorBufferLength=(int8_t)length; cnv->charErrorBufferLength = static_cast<int8_t>(length);
/* now output what fits into the regular target */ /* now output what fits into the regular target */
diff>>=8*length; /* length was reduced by targetCapacity */ diff>>=8*length; /* length was reduced by targetCapacity */
switch(targetCapacity) { switch(targetCapacity) {
/* each branch falls through to the next one */ /* each branch falls through to the next one */
case 3: case 3:
*target++=(uint8_t)(diff>>16); *target++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH; U_FALLTHROUGH;
case 2: case 2:
*target++=(uint8_t)(diff>>8); *target++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH; U_FALLTHROUGH;
case 1: case 1:
*target++=(uint8_t)diff; *target++ = static_cast<uint8_t>(diff);
U_FALLTHROUGH; U_FALLTHROUGH;
default: default:
/* will never occur */ /* will never occur */
@ -863,11 +863,11 @@ getTrail:
/* set the converter state back into UConverter */ /* set the converter state back into UConverter */
cnv->fromUChar32= c<0 ? -c : 0; cnv->fromUChar32= c<0 ? -c : 0;
cnv->fromUnicodeStatus=(uint32_t)prev; cnv->fromUnicodeStatus = static_cast<uint32_t>(prev);
/* write back the updated pointers */ /* write back the updated pointers */
pArgs->source=source; pArgs->source=source;
pArgs->target=(char *)target; pArgs->target = reinterpret_cast<char*>(target);
} }
/* BOCU-1-to-Unicode conversion functions ----------------------------------- */ /* BOCU-1-to-Unicode conversion functions ----------------------------------- */
@ -887,11 +887,11 @@ decodeBocu1LeadByte(int32_t b) {
/* positive difference */ /* positive difference */
if(b<BOCU1_START_POS_3) { if(b<BOCU1_START_POS_3) {
/* two bytes */ /* two bytes */
diff=((int32_t)b-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1; diff = (b - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
count=1; count=1;
} else if(b<BOCU1_START_POS_4) { } else if(b<BOCU1_START_POS_4) {
/* three bytes */ /* three bytes */
diff=((int32_t)b-BOCU1_START_POS_3)*BOCU1_TRAIL_COUNT*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_2+1; diff = (b - BOCU1_START_POS_3) * BOCU1_TRAIL_COUNT * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_2 + 1;
count=2; count=2;
} else { } else {
/* four bytes */ /* four bytes */
@ -902,11 +902,11 @@ decodeBocu1LeadByte(int32_t b) {
/* negative difference */ /* negative difference */
if(b>=BOCU1_START_NEG_3) { if(b>=BOCU1_START_NEG_3) {
/* two bytes */ /* two bytes */
diff=((int32_t)b-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1; diff = (b - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
count=1; count=1;
} else if(b>BOCU1_MIN) { } else if(b>BOCU1_MIN) {
/* three bytes */ /* three bytes */
diff=((int32_t)b-BOCU1_START_NEG_3)*BOCU1_TRAIL_COUNT*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_2; diff = (b - BOCU1_START_NEG_3) * BOCU1_TRAIL_COUNT * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_2;
count=2; count=2;
} else { } else {
/* four bytes */ /* four bytes */
@ -916,7 +916,7 @@ decodeBocu1LeadByte(int32_t b) {
} }
/* return the state for decoding the trail byte(s) */ /* return the state for decoding the trail byte(s) */
return ((uint32_t)diff<<2)|count; return (static_cast<uint32_t>(diff) << 2) | count;
} }
/** /**
@ -970,14 +970,14 @@ _Bocu1ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
/* set up the local pointers */ /* set up the local pointers */
cnv=pArgs->converter; cnv=pArgs->converter;
source=(const uint8_t *)pArgs->source; source = reinterpret_cast<const uint8_t*>(pArgs->source);
sourceLimit=(const uint8_t *)pArgs->sourceLimit; sourceLimit = reinterpret_cast<const uint8_t*>(pArgs->sourceLimit);
target=pArgs->target; target=pArgs->target;
targetLimit=pArgs->targetLimit; targetLimit=pArgs->targetLimit;
offsets=pArgs->offsets; offsets=pArgs->offsets;
/* get the converter state from UConverter */ /* get the converter state from UConverter */
prev=(int32_t)cnv->toUnicodeStatus; prev = static_cast<int32_t>(cnv->toUnicodeStatus);
if(prev==0) { if(prev==0) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
@ -1000,8 +1000,8 @@ _Bocu1ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
fastSingle: fastSingle:
/* fast loop for single-byte differences */ /* fast loop for single-byte differences */
/* use count as the only loop counter variable */ /* use count as the only loop counter variable */
diff=(int32_t)(sourceLimit-source); diff = static_cast<int32_t>(sourceLimit - source);
count=(int32_t)(pArgs->targetLimit-target); count = static_cast<int32_t>(pArgs->targetLimit - target);
if(count>diff) { if(count>diff) {
count=diff; count=diff;
} }
@ -1009,7 +1009,7 @@ fastSingle:
if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) { if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) {
c=prev+(c-BOCU1_MIDDLE); c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) { if(c<0x3000) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
*offsets++=nextSourceIndex++; *offsets++=nextSourceIndex++;
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
} else { } else {
@ -1019,7 +1019,7 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
*offsets++=nextSourceIndex++; *offsets++=nextSourceIndex++;
} else { } else {
break; break;
@ -1043,7 +1043,7 @@ fastSingle:
/* Write a code point directly from a single-byte difference. */ /* Write a code point directly from a single-byte difference. */
c=prev+(c-BOCU1_MIDDLE); c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) { if(c<0x3000) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex; *offsets++=sourceIndex;
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
sourceIndex=nextSourceIndex; sourceIndex=nextSourceIndex;
@ -1057,22 +1057,22 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex; *offsets++=sourceIndex;
sourceIndex=nextSourceIndex; sourceIndex=nextSourceIndex;
continue; continue;
} else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) { } else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) {
/* Optimize two-byte case. */ /* Optimize two-byte case. */
if(c>=BOCU1_MIDDLE) { if(c>=BOCU1_MIDDLE) {
diff=((int32_t)c-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1; diff = (c - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
} else { } else {
diff=((int32_t)c-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1; diff = (c - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
} }
/* trail byte */ /* trail byte */
++nextSourceIndex; ++nextSourceIndex;
c=decodeBocu1TrailByte(1, *source++); c=decodeBocu1TrailByte(1, *source++);
if(c<0 || (uint32_t)(c=prev+diff+c)>0x10ffff) { if (c < 0 || static_cast<uint32_t>(c = prev + diff + c) > 0x10ffff) {
bytes[0]=source[-2]; bytes[0]=source[-2];
bytes[1]=source[-1]; bytes[1]=source[-1];
byteIndex=2; byteIndex=2;
@ -1090,7 +1090,7 @@ fastSingle:
* with the partial difference value from the lead byte and * with the partial difference value from the lead byte and
* with the number of trail bytes. * with the number of trail bytes.
*/ */
bytes[0]=(uint8_t)c; bytes[0] = static_cast<uint8_t>(c);
byteIndex=1; byteIndex=1;
diff=decodeBocu1LeadByte(c); diff=decodeBocu1LeadByte(c);
@ -1116,7 +1116,7 @@ getTrail:
/* final trail byte, deliver a code point */ /* final trail byte, deliver a code point */
byteIndex=0; byteIndex=0;
c=prev+diff; c=prev+diff;
if((uint32_t)c>0x10ffff) { if (static_cast<uint32_t>(c) > 0x10ffff) {
*pErrorCode=U_ILLEGAL_CHAR_FOUND; *pErrorCode=U_ILLEGAL_CHAR_FOUND;
goto endloop; goto endloop;
} }
@ -1128,7 +1128,7 @@ getTrail:
/* calculate the next prev and output c */ /* calculate the next prev and output c */
prev=BOCU1_PREV(c); prev=BOCU1_PREV(c);
if(c<=0xffff) { if(c<=0xffff) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex; *offsets++=sourceIndex;
} else { } else {
/* output surrogate pair */ /* output surrogate pair */
@ -1156,13 +1156,13 @@ endloop:
cnv->mode=0; cnv->mode=0;
} else { } else {
/* set the converter state back into UConverter */ /* set the converter state back into UConverter */
cnv->toUnicodeStatus=(uint32_t)prev; cnv->toUnicodeStatus = static_cast<uint32_t>(prev);
cnv->mode=(int32_t)((uint32_t)diff<<2)|count; cnv->mode = static_cast<int32_t>(static_cast<uint32_t>(diff) << 2) | count;
} }
cnv->toULength=byteIndex; cnv->toULength=byteIndex;
/* write back the updated pointers */ /* write back the updated pointers */
pArgs->source=(const char *)source; pArgs->source = reinterpret_cast<const char*>(source);
pArgs->target=target; pArgs->target=target;
pArgs->offsets=offsets; pArgs->offsets=offsets;
} }
@ -1189,13 +1189,13 @@ _Bocu1ToUnicode(UConverterToUnicodeArgs *pArgs,
/* set up the local pointers */ /* set up the local pointers */
cnv=pArgs->converter; cnv=pArgs->converter;
source=(const uint8_t *)pArgs->source; source = reinterpret_cast<const uint8_t*>(pArgs->source);
sourceLimit=(const uint8_t *)pArgs->sourceLimit; sourceLimit = reinterpret_cast<const uint8_t*>(pArgs->sourceLimit);
target=pArgs->target; target=pArgs->target;
targetLimit=pArgs->targetLimit; targetLimit=pArgs->targetLimit;
/* get the converter state from UConverter */ /* get the converter state from UConverter */
prev=(int32_t)cnv->toUnicodeStatus; prev = static_cast<int32_t>(cnv->toUnicodeStatus);
if(prev==0) { if(prev==0) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
@ -1214,8 +1214,8 @@ _Bocu1ToUnicode(UConverterToUnicodeArgs *pArgs,
fastSingle: fastSingle:
/* fast loop for single-byte differences */ /* fast loop for single-byte differences */
/* use count as the only loop counter variable */ /* use count as the only loop counter variable */
diff=(int32_t)(sourceLimit-source); diff = static_cast<int32_t>(sourceLimit - source);
count=(int32_t)(pArgs->targetLimit-target); count = static_cast<int32_t>(pArgs->targetLimit - target);
if(count>diff) { if(count>diff) {
count=diff; count=diff;
} }
@ -1223,7 +1223,7 @@ fastSingle:
if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) { if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) {
c=prev+(c-BOCU1_MIDDLE); c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) { if(c<0x3000) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
} else { } else {
break; break;
@ -1232,7 +1232,7 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
} else { } else {
break; break;
} }
@ -1253,7 +1253,7 @@ fastSingle:
/* Write a code point directly from a single-byte difference. */ /* Write a code point directly from a single-byte difference. */
c=prev+(c-BOCU1_MIDDLE); c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) { if(c<0x3000) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
prev=BOCU1_SIMPLE_PREV(c); prev=BOCU1_SIMPLE_PREV(c);
goto fastSingle; goto fastSingle;
} }
@ -1265,19 +1265,19 @@ fastSingle:
if(c!=0x20) { if(c!=0x20) {
prev=BOCU1_ASCII_PREV; prev=BOCU1_ASCII_PREV;
} }
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
continue; continue;
} else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) { } else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) {
/* Optimize two-byte case. */ /* Optimize two-byte case. */
if(c>=BOCU1_MIDDLE) { if(c>=BOCU1_MIDDLE) {
diff=((int32_t)c-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1; diff = (c - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
} else { } else {
diff=((int32_t)c-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1; diff = (c - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
} }
/* trail byte */ /* trail byte */
c=decodeBocu1TrailByte(1, *source++); c=decodeBocu1TrailByte(1, *source++);
if(c<0 || (uint32_t)(c=prev+diff+c)>0x10ffff) { if (c < 0 || static_cast<uint32_t>(c = prev + diff + c) > 0x10ffff) {
bytes[0]=source[-2]; bytes[0]=source[-2];
bytes[1]=source[-1]; bytes[1]=source[-1];
byteIndex=2; byteIndex=2;
@ -1294,7 +1294,7 @@ fastSingle:
* with the partial difference value from the lead byte and * with the partial difference value from the lead byte and
* with the number of trail bytes. * with the number of trail bytes.
*/ */
bytes[0]=(uint8_t)c; bytes[0] = static_cast<uint8_t>(c);
byteIndex=1; byteIndex=1;
diff=decodeBocu1LeadByte(c); diff=decodeBocu1LeadByte(c);
@ -1319,7 +1319,7 @@ getTrail:
/* final trail byte, deliver a code point */ /* final trail byte, deliver a code point */
byteIndex=0; byteIndex=0;
c=prev+diff; c=prev+diff;
if((uint32_t)c>0x10ffff) { if (static_cast<uint32_t>(c) > 0x10ffff) {
*pErrorCode=U_ILLEGAL_CHAR_FOUND; *pErrorCode=U_ILLEGAL_CHAR_FOUND;
goto endloop; goto endloop;
} }
@ -1331,7 +1331,7 @@ getTrail:
/* calculate the next prev and output c */ /* calculate the next prev and output c */
prev=BOCU1_PREV(c); prev=BOCU1_PREV(c);
if(c<=0xffff) { if(c<=0xffff) {
*target++=(char16_t)c; *target++ = static_cast<char16_t>(c);
} else { } else {
/* output surrogate pair */ /* output surrogate pair */
*target++=U16_LEAD(c); *target++=U16_LEAD(c);
@ -1354,13 +1354,13 @@ endloop:
cnv->mode=0; cnv->mode=0;
} else { } else {
/* set the converter state back into UConverter */ /* set the converter state back into UConverter */
cnv->toUnicodeStatus=(uint32_t)prev; cnv->toUnicodeStatus = static_cast<uint32_t>(prev);
cnv->mode=((uint32_t)diff<<2)|count; cnv->mode = (static_cast<uint32_t>(diff) << 2) | count;
} }
cnv->toULength=byteIndex; cnv->toULength=byteIndex;
/* write back the updated pointers */ /* write back the updated pointers */
pArgs->source=(const char *)source; pArgs->source = reinterpret_cast<const char*>(source);
pArgs->target=target; pArgs->target=target;
} }

View File

@ -345,7 +345,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
uint32_t targetUniChar = 0x0000; uint32_t targetUniChar = 0x0000;
UChar32 mySourceChar = 0x0000; UChar32 mySourceChar = 0x0000;
UConverterDataHZ *myConverterData=(UConverterDataHZ*)args->converter->extraInfo; UConverterDataHZ *myConverterData=(UConverterDataHZ*)args->converter->extraInfo;
UBool isTargetUCharDBCS = (UBool) myConverterData->isTargetUCharDBCS; UBool isTargetUCharDBCS = myConverterData->isTargetUCharDBCS;
UBool oldIsTargetUCharDBCS; UBool oldIsTargetUCharDBCS;
int len =0; int len =0;
const char* escSeq=nullptr; const char* escSeq=nullptr;
@ -363,7 +363,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
targetUniChar = missingCharMarker; targetUniChar = missingCharMarker;
if (myTargetIndex < targetLength){ if (myTargetIndex < targetLength){
mySourceChar = (char16_t) mySource[mySourceIndex++]; mySourceChar = mySource[mySourceIndex++];
oldIsTargetUCharDBCS = isTargetUCharDBCS; oldIsTargetUCharDBCS = isTargetUCharDBCS;
@ -389,7 +389,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
} }
} }
if (targetUniChar != missingCharMarker){ if (targetUniChar != missingCharMarker){
myConverterData->isTargetUCharDBCS = isTargetUCharDBCS = (UBool)(targetUniChar>0x00FF); myConverterData->isTargetUCharDBCS = isTargetUCharDBCS = targetUniChar > 0x00FF;
if(oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isEscapeAppended ){ if(oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isEscapeAppended ){
/*Shifting from a double byte to single byte mode*/ /*Shifting from a double byte to single byte mode*/
if(!isTargetUCharDBCS){ if(!isTargetUCharDBCS){

View File

@ -174,7 +174,7 @@ isPNJConsonant(UChar32 c) {
if (c < 0xa00 || 0xa50 <= c) { if (c < 0xa00 || 0xa50 <= c) {
return false; return false;
} else { } else {
return (UBool)(pnjMap[c - 0xa00] & 1); return pnjMap[c - 0xa00] & 1;
} }
} }
@ -183,7 +183,7 @@ isPNJBindiTippi(UChar32 c) {
if (c < 0xa00 || 0xa50 <= c) { if (c < 0xa00 || 0xa50 <= c) {
return false; return false;
} else { } else {
return (UBool)(pnjMap[c - 0xa00] >> 1); return pnjMap[c - 0xa00] >> 1;
} }
} }
U_CDECL_BEGIN U_CDECL_BEGIN
@ -1484,7 +1484,7 @@ UConverter_toUnicode_ISCII_OFFSETS_LOGIC(UConverterToUnicodeArgs *args, UErrorCo
*/ */
*err = U_INVALID_CHAR_FOUND; *err = U_INVALID_CHAR_FOUND;
CALLBACK: CALLBACK:
args->converter->toUBytes[0] = (uint8_t) sourceChar; args->converter->toUBytes[0] = sourceChar;
args->converter->toULength = 1; args->converter->toULength = 1;
break; break;
} }

View File

@ -381,7 +381,7 @@ ucnv_Latin1FromUTF8(UConverterFromUnicodeArgs *pFromUArgs,
b=*source++; b=*source++;
if(U8_IS_SINGLE(b)) { if(U8_IS_SINGLE(b)) {
/* convert ASCII */ /* convert ASCII */
*target++=(uint8_t)b; *target++ = b;
--targetCapacity; --targetCapacity;
} else if( /* handle U+0080..U+00FF inline */ } else if( /* handle U+0080..U+00FF inline */
b>=0xc2 && b<=0xc3 && b>=0xc2 && b<=0xc3 &&

File diff suppressed because it is too large Load Diff

View File

@ -883,8 +883,8 @@ static int8_t
getWindow(const uint32_t offsets[8], uint32_t c) { getWindow(const uint32_t offsets[8], uint32_t c) {
int i; int i;
for(i=0; i<8; ++i) { for(i=0; i<8; ++i) {
if((uint32_t)(c-offsets[i])<=0x7f) { if (c - offsets[i] <= 0x7f) {
return (int8_t)(i); return static_cast<int8_t>(i);
} }
} }
return -1; return -1;
@ -893,9 +893,9 @@ getWindow(const uint32_t offsets[8], uint32_t c) {
/* is the character in the dynamic window starting at the offset, or in the direct-encoded range? */ /* is the character in the dynamic window starting at the offset, or in the direct-encoded range? */
static UBool static UBool
isInOffsetWindowOrDirect(uint32_t offset, uint32_t c) { isInOffsetWindowOrDirect(uint32_t offset, uint32_t c) {
return (UBool)(c<=offset+0x7f && return c<=offset+0x7f &&
(c>=offset || (c<=0x7f && (c>=offset || (c<=0x7f &&
(c>=0x20 || (1UL<<c)&0x2601)))); (c>=0x20 || (1UL<<c)&0x2601)));
/* binary 0010 0110 0000 0001, /* binary 0010 0110 0000 0001,
check for b==0xd || b==0xa || b==9 || b==0 */ check for b==0xd || b==0xa || b==9 || b==0 */
} }
@ -963,7 +963,7 @@ getDynamicOffset(uint32_t c, uint32_t *pOffset) {
int i; int i;
for(i=0; i<7; ++i) { for(i=0; i<7; ++i) {
if((uint32_t)(c-fixedOffsets[i])<=0x7f) { if (c - fixedOffsets[i] <= 0x7f) {
*pOffset=fixedOffsets[i]; *pOffset=fixedOffsets[i];
return 0xf9+i; return 0xf9+i;
} }
@ -973,16 +973,16 @@ getDynamicOffset(uint32_t c, uint32_t *pOffset) {
/* No dynamic window for US-ASCII. */ /* No dynamic window for US-ASCII. */
return -1; return -1;
} else if(c<0x3400 || } else if(c<0x3400 ||
(uint32_t)(c-0x10000)<(0x14000-0x10000) || c - 0x10000 < 0x14000 - 0x10000 ||
(uint32_t)(c-0x1d000)<=(0x1ffff-0x1d000) c - 0x1d000 <= 0x1ffff - 0x1d000
) { ) {
/* This character is in a code range for a "small", i.e., reasonably windowable, script. */ /* This character is in a code range for a "small", i.e., reasonably windowable, script. */
*pOffset=c&0x7fffff80; *pOffset=c&0x7fffff80;
return (int)(c>>7); return static_cast<int>(c >> 7);
} else if(0xe000<=c && c!=0xfeff && c<0xfff0) { } else if(0xe000<=c && c!=0xfeff && c<0xfff0) {
/* For these characters we need to take the gapOffset into account. */ /* For these characters we need to take the gapOffset into account. */
*pOffset=c&0x7fffff80; *pOffset=c&0x7fffff80;
return (int)((c-gapOffset)>>7); return static_cast<int>((c - gapOffset) >> 7);
} else { } else {
return -1; return -1;
} }
@ -1208,8 +1208,8 @@ getTrailSingle:
c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80; c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80;
length=3; length=3;
goto outputBytes; goto outputBytes;
} else if((uint32_t)(c-0x3400)<(0xd800-0x3400) && } else if ((c - 0x3400) < (0xd800 - 0x3400) &&
(source>=sourceLimit || (uint32_t)(*source-0x3400)<(0xd800-0x3400)) (source >= sourceLimit || (uint32_t)(*source - 0x3400) < (0xd800 - 0x3400))
) { ) {
/* /*
* this character is not compressible (a BMP ideograph or similar); * this character is not compressible (a BMP ideograph or similar);
@ -1248,7 +1248,7 @@ getTrailSingle:
c=*source++; c=*source++;
++nextSourceIndex; ++nextSourceIndex;
if((uint32_t)(c-0x3400)<(0xd800-0x3400)) { if ((c - 0x3400) < (0xd800 - 0x3400)) {
/* not compressible, write character directly */ /* not compressible, write character directly */
if(targetCapacity>=2) { if(targetCapacity>=2) {
*target++=(uint8_t)(c>>8); *target++=(uint8_t)(c>>8);
@ -1262,10 +1262,10 @@ getTrailSingle:
length=2; length=2;
goto outputBytes; goto outputBytes;
} }
} else if((uint32_t)(c-0x3400)>=(0xf300-0x3400) /* c<0x3400 || c>=0xf300 */) { } else if (c - 0x3400 >= 0xf300 - 0x3400 /* c<0x3400 || c>=0xf300 */) {
/* compress BMP character if the following one is not an uncompressible ideograph */ /* compress BMP character if the following one is not an uncompressible ideograph */
if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) { if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) {
if(((uint32_t)(c-0x30)<10 || (uint32_t)(c-0x61)<26 || (uint32_t)(c-0x41)<26)) { if (c - 0x30 < 10 || c - 0x61 < 26 || c - 0x41 < 26) {
/* ASCII digit or letter */ /* ASCII digit or letter */
isSingleByteMode=true; isSingleByteMode=true;
c|=((uint32_t)(UC0+dynamicWindow)<<8)|c; c|=((uint32_t)(UC0+dynamicWindow)<<8)|c;
@ -1691,8 +1691,8 @@ getTrailSingle:
c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80; c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80;
length=3; length=3;
goto outputBytes; goto outputBytes;
} else if((uint32_t)(c-0x3400)<(0xd800-0x3400) && } else if (c - 0x3400 < 0xd800 - 0x3400 &&
(source>=sourceLimit || (uint32_t)(*source-0x3400)<(0xd800-0x3400)) (source >= sourceLimit || static_cast<uint32_t>(*source - 0x3400) < 0xd800 - 0x3400)
) { ) {
/* /*
* this character is not compressible (a BMP ideograph or similar); * this character is not compressible (a BMP ideograph or similar);
@ -1729,7 +1729,7 @@ getTrailSingle:
} }
c=*source++; c=*source++;
if((uint32_t)(c-0x3400)<(0xd800-0x3400)) { if (c - 0x3400 < 0xd800 - 0x3400) {
/* not compressible, write character directly */ /* not compressible, write character directly */
if(targetCapacity>=2) { if(targetCapacity>=2) {
*target++=(uint8_t)(c>>8); *target++=(uint8_t)(c>>8);
@ -1739,10 +1739,10 @@ getTrailSingle:
length=2; length=2;
goto outputBytes; goto outputBytes;
} }
} else if((uint32_t)(c-0x3400)>=(0xf300-0x3400) /* c<0x3400 || c>=0xf300 */) { } else if (c - 0x3400 >= 0xf300 - 0x3400 /* c<0x3400 || c>=0xf300 */) {
/* compress BMP character if the following one is not an uncompressible ideograph */ /* compress BMP character if the following one is not an uncompressible ideograph */
if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) { if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) {
if(((uint32_t)(c-0x30)<10 || (uint32_t)(c-0x61)<26 || (uint32_t)(c-0x41)<26)) { if (c - 0x30 < 10 || c - 0x61 < 26 || c - 0x41 < 26) {
/* ASCII digit or letter */ /* ASCII digit or letter */
isSingleByteMode=true; isSingleByteMode=true;
c|=((uint32_t)(UC0+dynamicWindow)<<8)|c; c|=((uint32_t)(UC0+dynamicWindow)<<8)|c;

View File

@ -377,7 +377,7 @@ ucnvsel_swap(const UDataSwapper *ds,
} }
/* check data format and format version */ /* check data format and format version */
const UDataInfo *pInfo = (const UDataInfo *)((const char *)inData + 4); const UDataInfo* pInfo = reinterpret_cast<const UDataInfo*>(static_cast<const char*>(inData) + 4);
if(!( if(!(
pInfo->dataFormat[0] == 0x43 && /* dataFormat="CSel" */ pInfo->dataFormat[0] == 0x43 && /* dataFormat="CSel" */
pInfo->dataFormat[1] == 0x53 && pInfo->dataFormat[1] == 0x53 &&
@ -407,11 +407,11 @@ ucnvsel_swap(const UDataSwapper *ds,
} }
} }
const uint8_t *inBytes = (const uint8_t *)inData + headerSize; const uint8_t* inBytes = static_cast<const uint8_t*>(inData) + headerSize;
uint8_t *outBytes = (uint8_t *)outData + headerSize; uint8_t* outBytes = static_cast<uint8_t*>(outData) + headerSize;
/* read the indexes */ /* read the indexes */
const int32_t *inIndexes = (const int32_t *)inBytes; const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexes[16]; int32_t indexes[16];
int32_t i; int32_t i;
for(i = 0; i < 16; ++i) { for(i = 0; i < 16; ++i) {

Some files were not shown because too many files have changed in this diff Show More