Bug 1157277 - Part 2: Add functions to handle non-BMP ToLowerCase/ToUpperCase. r=till
authorTooru Fujisawa <arai_a@mac.com>
Wed, 20 Jul 2016 14:11:35 +0900
changeset 389947 de1cf380b1d55c91ce5bd7c07f917510fa98a55e
parent 389946 0a822e7f78cbb140a6172b134ba05b4c0a83e6e4
child 389948 4e952735e78954dffc362bc6b8e5b3b4f6147313
push id23566
push usertkuo@mozilla.com
push dateWed, 20 Jul 2016 10:57:43 +0000
reviewerstill
bugs1157277
milestone50.0a1
Bug 1157277 - Part 2: Add functions to handle non-BMP ToLowerCase/ToUpperCase. r=till
js/src/vm/Unicode.h
--- a/js/src/vm/Unicode.h
+++ b/js/src/vm/Unicode.h
@@ -230,16 +230,60 @@ CanUpperCase(char16_t ch)
 inline bool
 CanLowerCase(char16_t ch)
 {
     if (ch < 128)
         return ch >= 'A' && ch <= 'Z';
     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;
     uint16_t reverse1;
     uint16_t reverse2;
     uint16_t reverse3;
 };