From 8f916449f4dc2505f12357919dad1f6bf8858993 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Wed, 20 Jul 2016 14:11:35 +0900 Subject: [PATCH] Bug 1157277 - Part 2: Add functions to handle non-BMP ToLowerCase/ToUpperCase. r=till --- js/src/vm/Unicode.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/js/src/vm/Unicode.h b/js/src/vm/Unicode.h index 698d34a17c77..caaa7923d66a 100644 --- a/js/src/vm/Unicode.h +++ b/js/src/vm/Unicode.h @@ -235,6 +235,50 @@ CanLowerCase(char16_t ch) return CharInfo(ch).lowerCase != 0; } +#define CHECK_RANGE(FROM, TO, LEAD, TRAIL_FROM, TRAIL_TO, DIFF) \ + if (lead == LEAD && trail >= TRAIL_FROM && trail <= TRAIL_TO) \ + return true; + +inline bool +CanUpperCaseNonBMP(char16_t lead, char16_t trail) +{ + FOR_EACH_NON_BMP_UPPERCASE(CHECK_RANGE) + return false; +} + +inline bool +CanLowerCaseNonBMP(char16_t lead, char16_t trail) +{ + FOR_EACH_NON_BMP_LOWERCASE(CHECK_RANGE) + return false; +} + +#undef CHECK_RANGE + +inline char16_t +ToUpperCaseNonBMPTrail(char16_t lead, char16_t trail) +{ +#define CALC_TRAIL(FROM, TO, LEAD, TRAIL_FROM, TRAIL_TO, DIFF) \ + if (lead == LEAD && trail >= TRAIL_FROM && trail <= TRAIL_TO) \ + return trail + DIFF; + FOR_EACH_NON_BMP_UPPERCASE(CALC_TRAIL) +#undef CALL_TRAIL + + return trail; +} + +inline char16_t +ToLowerCaseNonBMPTrail(char16_t lead, char16_t trail) +{ +#define CALC_TRAIL(FROM, TO, LEAD, TRAIL_FROM, TRAIL_TO, DIFF) \ + if (lead == LEAD && trail >= TRAIL_FROM && trail <= TRAIL_TO) \ + return trail + DIFF; + FOR_EACH_NON_BMP_LOWERCASE(CALC_TRAIL) +#undef CALL_TRAIL + + return trail; +} + class FoldingInfo { public: uint16_t folding;