OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/regexp-parser.h" | 5 #include "src/regexp/regexp-parser.h" |
6 | 6 |
7 #include "src/char-predicates-inl.h" | 7 #include "src/char-predicates-inl.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 return true; | 831 return true; |
832 } | 832 } |
833 } | 833 } |
834 Reset(start); | 834 Reset(start); |
835 } | 835 } |
836 return result; | 836 return result; |
837 } | 837 } |
838 | 838 |
839 ZoneList<CharacterRange>* RegExpParser::ParsePropertyClass() { | 839 ZoneList<CharacterRange>* RegExpParser::ParsePropertyClass() { |
840 #ifdef V8_I18N_SUPPORT | 840 #ifdef V8_I18N_SUPPORT |
841 ZoneList<char> property_name(0, zone()); | 841 char property_name[3]; |
| 842 memset(property_name, 0, sizeof(property_name)); |
842 if (current() == '{') { | 843 if (current() == '{') { |
843 for (Advance(); IsAlpha(current()); Advance()) { | 844 Advance(); |
844 property_name.Add(static_cast<char>(current()), zone()); | 845 if (current() < 'A' || current() > 'Z') return nullptr; |
| 846 property_name[0] = static_cast<char>(current()); |
| 847 Advance(); |
| 848 if (current() >= 'a' && current() <= 'z') { |
| 849 property_name[1] = static_cast<char>(current()); |
| 850 Advance(); |
845 } | 851 } |
846 if (current() != '}') return nullptr; | 852 if (current() != '}') return nullptr; |
847 } else if (IsAlpha(current())) { | 853 } else if (current() >= 'A' && current() <= 'Z') { |
848 property_name.Add(static_cast<char>(current()), zone()); | 854 property_name[0] = static_cast<char>(current()); |
849 } else { | 855 } else { |
850 return nullptr; | 856 return nullptr; |
851 } | 857 } |
852 Advance(); | 858 Advance(); |
853 property_name.Add(0, zone()); // null-terminate string. | |
854 | 859 |
855 // Property names are defined in unicode database files. For aliases of | 860 int32_t category = |
856 // these property names, see PropertyValueAliases.txt. | 861 u_getPropertyValueEnum(UCHAR_GENERAL_CATEGORY_MASK, property_name); |
857 UProperty kPropertyClasses[] = { | 862 if (category == UCHAR_INVALID_CODE) return nullptr; |
858 // General_Category (gc) found in PropertyValueAliases.txt | |
859 UCHAR_GENERAL_CATEGORY_MASK, | |
860 // Script (sc) found in Scripts.txt | |
861 UCHAR_SCRIPT, | |
862 }; | |
863 | 863 |
864 for (int i = 0; i < arraysize(kPropertyClasses); i++) { | 864 USet* set = uset_openEmpty(); |
865 UProperty property_class = kPropertyClasses[i]; | 865 UErrorCode ec = U_ZERO_ERROR; |
866 int32_t category = u_getPropertyValueEnum( | 866 uset_applyIntPropertyValue(set, UCHAR_GENERAL_CATEGORY_MASK, category, &ec); |
867 property_class, property_name.ToConstVector().start()); | 867 ZoneList<CharacterRange>* ranges = nullptr; |
868 if (category == UCHAR_INVALID_CODE) continue; | 868 if (ec == U_ZERO_ERROR && !uset_isEmpty(set)) { |
869 | 869 uset_removeAllStrings(set); |
870 USet* set = uset_openEmpty(); | 870 int item_count = uset_getItemCount(set); |
871 UErrorCode ec = U_ZERO_ERROR; | 871 ranges = new (zone()) ZoneList<CharacterRange>(item_count, zone()); |
872 uset_applyIntPropertyValue(set, property_class, category, &ec); | 872 int item_result = 0; |
873 ZoneList<CharacterRange>* ranges = nullptr; | 873 for (int i = 0; i < item_count; i++) { |
874 if (ec == U_ZERO_ERROR && !uset_isEmpty(set)) { | 874 uc32 start = 0; |
875 uset_removeAllStrings(set); | 875 uc32 end = 0; |
876 int item_count = uset_getItemCount(set); | 876 item_result += uset_getItem(set, i, &start, &end, nullptr, 0, &ec); |
877 ranges = new (zone()) ZoneList<CharacterRange>(item_count, zone()); | 877 ranges->Add(CharacterRange::Range(start, end), zone()); |
878 int item_result = 0; | |
879 for (int i = 0; i < item_count; i++) { | |
880 uc32 start = 0; | |
881 uc32 end = 0; | |
882 item_result += uset_getItem(set, i, &start, &end, nullptr, 0, &ec); | |
883 ranges->Add(CharacterRange::Range(start, end), zone()); | |
884 } | |
885 DCHECK_EQ(U_ZERO_ERROR, ec); | |
886 DCHECK_EQ(0, item_result); | |
887 } | 878 } |
888 uset_close(set); | 879 DCHECK_EQ(U_ZERO_ERROR, ec); |
889 return ranges; | 880 DCHECK_EQ(0, item_result); |
890 } | 881 } |
| 882 uset_close(set); |
| 883 return ranges; |
| 884 #else // V8_I18N_SUPPORT |
| 885 return nullptr; |
891 #endif // V8_I18N_SUPPORT | 886 #endif // V8_I18N_SUPPORT |
892 | |
893 return nullptr; | |
894 } | 887 } |
895 | 888 |
896 bool RegExpParser::ParseUnlimitedLengthHexNumber(int max_value, uc32* value) { | 889 bool RegExpParser::ParseUnlimitedLengthHexNumber(int max_value, uc32* value) { |
897 uc32 x = 0; | 890 uc32 x = 0; |
898 int d = HexValue(current()); | 891 int d = HexValue(current()); |
899 if (d < 0) { | 892 if (d < 0) { |
900 return false; | 893 return false; |
901 } | 894 } |
902 while (d >= 0) { | 895 while (d >= 0) { |
903 x = x * 16 + d; | 896 x = x * 16 + d; |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 return false; | 1443 return false; |
1451 } | 1444 } |
1452 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), | 1445 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), |
1453 zone()); | 1446 zone()); |
1454 LAST(ADD_TERM); | 1447 LAST(ADD_TERM); |
1455 return true; | 1448 return true; |
1456 } | 1449 } |
1457 | 1450 |
1458 } // namespace internal | 1451 } // namespace internal |
1459 } // namespace v8 | 1452 } // namespace v8 |
OLD | NEW |