Skip to content

Commit 0d0625a

Browse files
committed
NFC improvements and fixes
1 parent ce93998 commit 0d0625a

File tree

4 files changed

+236
-226
lines changed

4 files changed

+236
-226
lines changed

lib/inc/sys_string/impl/unicode/algorithms.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ namespace sysstr
962962
{
963963
auto status = get_nfc_qc_status(*cur);
964964

965+
check_again:
965966
if (status == nfc_qc_status::bad)
966967
{
967968
for (++cur; ; ++cur)
@@ -988,15 +989,19 @@ namespace sysstr
988989
return write_unsafe<OutEnc>(*first, dest);
989990
status = get_nfc_qc_status(*cur);
990991
if (status != nfc_qc_status::stable)
991-
break;
992+
goto check_again;
992993
write_unsafe<OutEnc>(*first, dest);
993994
++first;
994995
}
995996
}
996997
else
997998
{
998999
if (++cur == last)
999-
return convert_slow(buffer, first, cur, dest);
1000+
{
1001+
for ( ; first != last; ++first)
1002+
dest = write_unsafe<OutEnc>(*first, dest);
1003+
return dest;
1004+
}
10001005
}
10011006
}
10021007
}

lib/inc/sys_string/impl/unicode/mappings.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ namespace sysstr::util::unicode
224224
using entry_type = std::array<uint16_t, 16>;
225225
using value_type = uint16_t;
226226

227-
static const std::array<entry_type, 891> entries;
227+
static const std::array<entry_type, 899> entries;
228228

229-
static const std::array<value_type, 496> values;
229+
static const std::array<value_type, 503> values;
230230

231231
public:
232232

@@ -255,7 +255,7 @@ namespace sysstr::util::unicode
255255
}
256256
if (res & 0x1000)
257257
{
258-
uint32_t shifted_ccc = uint32_t(res) << 21;
258+
uint32_t shifted_ccc = uint32_t(res & 0xFF) << 21;
259259
uint32_t val = uint32_t(src) | shifted_ccc;
260260
*dest = val;
261261
return ++dest;
@@ -373,8 +373,9 @@ namespace sysstr::util::unicode
373373

374374
if (res & 0x1000)
375375
{
376-
bool is_ccc_zero = uint8_t(res) == 0;
377-
return nfc_qc_status(0 + is_ccc_zero);
376+
int is_ccc_zero = uint8_t(res) == 0;
377+
int is_nfc_qc_yes = !(res >> 8);
378+
return nfc_qc_status(0 + (is_nfc_qc_yes << is_ccc_zero));
378379
}
379380

380381
size_t value_offset = ((size_t(c) - res) & 0x0FFF);
@@ -384,12 +385,12 @@ namespace sysstr::util::unicode
384385

385386
uint16_t comp_idx = value & 0xFFF;
386387
if (comp_idx == 0xFFF)
387-
return nfc_qc_status(1 + is_nfc_qc_yes);
388+
return nfc_qc_status(0 + (is_nfc_qc_yes << 1));
388389

389390
auto * comps = compositions + comp_idx;
390391
bool is_ccc_zero = !(comps[0] & (uint32_t(0xFF) << 21));
391392

392-
return nfc_qc_status(0 + is_nfc_qc_yes + is_ccc_zero);
393+
return nfc_qc_status(0 + (is_nfc_qc_yes << is_ccc_zero));
393394
}
394395
};
395396

0 commit comments

Comments
 (0)