From 7f0d04161b1b8c4d7995c7a3d9dd3c3a44d3c56e Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Jul 2015 12:19:19 -0700 Subject: [PATCH] Use ICU to lowercase words to hyphenate. Previously, the standard C tolower() function was used, which didn't support any characters beyond the basic ASCII letters. Bug: 22506121 Change-Id: Ibb81121caa29be44fbb59aa98891e9faafc57592 --- engine/src/flutter/libs/minikin/Hyphenator.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index c50b3861af..3eb151b9e0 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -16,9 +16,9 @@ #include #include -#include #include #include +#include // HACK: for reading pattern file #include @@ -95,8 +95,19 @@ void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t hyphenateSoft(result, word, len); return; } - // TODO: use locale-sensitive case folding from ICU. - c = tolower(c); + // TODO: This uses ICU's simple character to character lowercasing, which ignores + // the locale, and ignores cases when lowercasing a character results in more than + // one character. It should be fixed to consider the locale (in order for it to work + // correctly for Turkish and Azerbaijani), as well as support one-to-many, and + // many-to-many case conversions (including non-BMP cases). + if (c < 0x00C0) { // U+00C0 is the lowest uppercase non-ASCII character + // Convert uppercase ASCII to lowercase ASCII, but keep other characters as-is + if (0x0041 <= c && c <= 0x005A) { + c += 0x0020; + } + } else { + c = u_tolower(c); + } } auto search = node->succ.find(c); if (search != node->succ.end()) {