diff options
| author | Sam Varshavchik | 2021-03-06 20:30:50 -0500 |
|---|---|---|
| committer | Sam Varshavchik | 2021-03-06 20:30:50 -0500 |
| commit | 08dde41fd2b1b8c6a9a7297f020d02086ebb58bb (patch) | |
| tree | 4c3a75ad40788c39bfd5c26aad8e75e7164bbc08 | |
| parent | 6a7e117fcc2447b2a2fb5dcbb8b9d00b01d835a6 (diff) | |
| download | courier-libs-08dde41fd2b1b8c6a9a7297f020d02086ebb58bb.tar.bz2 | |
courier-unicode: fix unicode_bidi_embed
| -rw-r--r-- | unicode/ChangeLog | 5 | ||||
| -rw-r--r-- | unicode/biditest2.C | 74 | ||||
| -rw-r--r-- | unicode/unicode_bidi.c | 4 |
3 files changed, 75 insertions, 8 deletions
diff --git a/unicode/ChangeLog b/unicode/ChangeLog index 35cffe6..e1563f1 100644 --- a/unicode/ChangeLog +++ b/unicode/ChangeLog @@ -1,3 +1,8 @@ +2021-03-06 Sam Varshavchik <mrsam@courier-mta.com> + + * unicode_bidi.c (unicode_bidi_needs_embed): Make its return code + what its documentation says its return code is. + 2021-02-24 Sam Varshavchik <mrsam@courier-mta.com> * Implement unicode_bidi_needs_embed(), unicode_bidi_cleaned_size(), diff --git a/unicode/biditest2.C b/unicode/biditest2.C index a14b3ea..7129805 100644 --- a/unicode/biditest2.C +++ b/unicode/biditest2.C @@ -606,38 +606,38 @@ void direction_test() U"Hello", UNICODE_BIDI_LR, 1, - true, + false, }, { U" ", UNICODE_BIDI_LR, 0, - true, + false, }, { U"", UNICODE_BIDI_LR, 0, - true, + false, }, { U"שלום", UNICODE_BIDI_RL, 1, - true, + false, }, { U"Helloש", UNICODE_BIDI_LR, 1, - true, + false, }, { U"Hello" + std::u32string{unicode::literals::LRO} + U"ש", UNICODE_BIDI_LR, 1, - false, + true, }, }; @@ -666,6 +666,67 @@ void direction_test() } } +void direction_test2() +{ + static const struct { + std::u32string str; + std::vector<unicode_bidi_level_t> directions; + unicode_bidi_level_t direction; + bool needs_embed; + } tests[]={ + { + U"Hello world!", + {UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR, + UNICODE_BIDI_LR}, + UNICODE_BIDI_LR, + false, + }, + { + U"Hello world!", + {UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL, + UNICODE_BIDI_RL}, + UNICODE_BIDI_LR, + true, + }, + }; + + for (const auto &t:tests) + { + if (t.str.size() != t.directions.size()) + { + std::cerr << "direction_test2 bad data\n"; + exit(1); + } + + if (unicode::bidi_needs_embed(t.str, t.directions, &t.direction) + != t.needs_embed) + { + std::cerr << "direction-test2 failed\n"; + exit(1); + } + } +} + int main(int argc, char **argv) { DEBUGDUMP=fopen("/dev/null", "w"); @@ -680,5 +741,6 @@ int main(int argc, char **argv) latin_test(); character_test(); direction_test(); + direction_test2(); return 0; } diff --git a/unicode/unicode_bidi.c b/unicode/unicode_bidi.c index 772f9fe..89eb147 100644 --- a/unicode/unicode_bidi.c +++ b/unicode/unicode_bidi.c @@ -2334,7 +2334,7 @@ int unicode_bidi_needs_embed(const char32_t *string, nn=unicode_bidi_cleanup(string_cpy, levels_cpy, n, 0, NULL, NULL); - ret=0; + ret=1; if (n == nn && (paragraph_level == NULL || direction.direction == *paragraph_level)) { @@ -2345,7 +2345,7 @@ int unicode_bidi_needs_embed(const char32_t *string, memcmp(levels_cpy, levels, n * sizeof(unicode_bidi_level_t)) == 0) { - ret=1; + ret=0; } } free(string_cpy); |
