fix isRTL bug

Signed-off-by: sunyaozu <sunyaozu@huawei.com>
This commit is contained in:
sunyaozu 2022-01-27 10:56:54 +08:00
parent a37fadde32
commit 39779764a9
2 changed files with 14 additions and 2 deletions

View File

@ -52,6 +52,7 @@ ohos_shared_library("preferred_language") {
config("intl_util_config") {
include_dirs = [
"include",
"//third_party/icu/icu4c/source",
"//third_party/icu/icu4c/source/common",
"//third_party/icu/icu4c/source/i18n",
@ -62,7 +63,6 @@ config("intl_util_config") {
ohos_shared_library("intl_util") {
public_configs = [ ":intl_util_config" ]
include_dirs = [
"include",
"//utils/native/base/include",
"//third_party/libxml2/include",
"//third_party/libphonenumber/cpp/src",

View File

@ -13,11 +13,20 @@
* limitations under the License.
*/
#include "character.h"
#include <set>
#include "unicode/unistr.h"
namespace OHOS {
namespace Global {
namespace I18n {
static std::set<UCharDirection> RTLDirectionSet = {
U_RIGHT_TO_LEFT,
U_RIGHT_TO_LEFT_ARABIC,
U_RIGHT_TO_LEFT_EMBEDDING,
U_RIGHT_TO_LEFT_OVERRIDE,
U_RIGHT_TO_LEFT_ISOLATE
};
bool IsDigit(const std::string &character)
{
icu::UnicodeString unicodeString(character.c_str());
@ -44,7 +53,10 @@ bool IsRTLCharacter(const std::string &character)
icu::UnicodeString unicodeString(character.c_str());
UChar32 char32 = unicodeString.char32At(0);
UCharDirection direction = u_charDirection(char32);
return direction == UCharDirection::U_RIGHT_TO_LEFT;
if (RTLDirectionSet.find(direction) != RTLDirectionSet.end()) {
return true;
}
return false;
}
bool IsIdeoGraphic(const std::string &character)