diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-04-24 12:54:20 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-09 06:25:05 +0000 |
commit | 19e7c0d2b5a807e194be1d65b16041f48136c9be (patch) | |
tree | 4d6df4cf5e84e4fc6bcad63c4aa07222fc0c36bc /util/unicode | |
parent | f6b96bc34749e4478e75c081bbd0af406cd737b5 (diff) |
QChar/QString: centralize case folding in qchar.cpp
There are (at least) two implementations of the low-level case-folding
algorithm, one of which (for QChar::toLower()) seems to be wrong (it
doesn't deal with special cases which expand to more than one code
point).
The algoithm hidden in QString and entangled with the QString
detaching code makes reusing the code much harder.
At the same time, the dependency of the algorithm on the unicode
tables makes exposing a non-allocating result type in the public API
hard. std::u16string would be an alternative if we can assure that all
implementations use SSO with at least four characters.
So, for the time being, leave this as internal API for use in an
upcoming QStringView::toLower() as well as case-insensitive hashing.
Change-Id: Iabb2611846f6176776aa20e634f44d8464f3305c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'util/unicode')
-rw-r--r-- | util/unicode/main.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index e89d4e4706..3d66af911c 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -2581,6 +2581,7 @@ static QByteArray createSpecialCaseMap() out += "static const unsigned short specialCaseMap[] = {\n" " 0x0, // placeholder"; int i = 1; + int maxN = 0; while (i < specialCaseMap.size()) { out += "\n "; int n = specialCaseMap.at(i); @@ -2589,9 +2590,12 @@ static QByteArray createSpecialCaseMap() out += ","; } i += n + 1; + maxN = std::max(maxN, n); } out.chop(1); - out += "\n};\n\n"; + out += "\n};\n\nconst unsigned int MaxSpecialCaseLength = "; + out += QByteArray::number(maxN); + out += ";\n\n\n"; qDebug(" memory usage: %ld bytes", specialCaseMap.size()*sizeof(unsigned short)); |