Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: src/regexp/regexp-parser.cc

Issue 2502933002: [regexp] implement latest spec draft for property class. (Closed)
Patch Set: fix test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/regexp-property-blocks.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 static_cast<UPropertyNameChoice>(U_LONG_PROPERTY_NAME + i)); 1075 static_cast<UPropertyNameChoice>(U_LONG_PROPERTY_NAME + i));
1076 if (long_name == NULL) break; 1076 if (long_name == NULL) break;
1077 if (strcmp(property_value_name, long_name) == 0) return true; 1077 if (strcmp(property_value_name, long_name) == 0) return true;
1078 } 1078 }
1079 return false; 1079 return false;
1080 } 1080 }
1081 1081
1082 bool LookupPropertyValueName(UProperty property, 1082 bool LookupPropertyValueName(UProperty property,
1083 const char* property_value_name, bool negate, 1083 const char* property_value_name, bool negate,
1084 ZoneList<CharacterRange>* result, Zone* zone) { 1084 ZoneList<CharacterRange>* result, Zone* zone) {
1085 UProperty property_for_lookup = property;
1086 if (property_for_lookup == UCHAR_SCRIPT_EXTENSIONS) {
1087 // For the property Script_Extensions, we have to do the property value
1088 // name lookup as if the property is Script.
jungshik at Google 2016/11/17 22:27:49 Filed http://bugs.icu-project.org/trac/ticket/1285
Yang 2016/11/18 06:07:13 Thanks.
1089 property_for_lookup = UCHAR_SCRIPT;
1090 }
1085 int32_t property_value = 1091 int32_t property_value =
1086 u_getPropertyValueEnum(property, property_value_name); 1092 u_getPropertyValueEnum(property_for_lookup, property_value_name);
1087 if (property_value == UCHAR_INVALID_CODE) return false; 1093 if (property_value == UCHAR_INVALID_CODE) return false;
1088 1094
1089 // We require the property name to match exactly to one of the property value 1095 // We require the property name to match exactly to one of the property value
1090 // aliases. However, u_getPropertyValueEnum uses loose matching. 1096 // aliases. However, u_getPropertyValueEnum uses loose matching.
1091 if (!IsExactPropertyValueAlias(property_value_name, property, 1097 if (!IsExactPropertyValueAlias(property_value_name, property_for_lookup,
1092 property_value)) { 1098 property_value)) {
1093 return false; 1099 return false;
1094 } 1100 }
1095 1101
1096 USet* set = uset_openEmpty(); 1102 USet* set = uset_openEmpty();
jungshik at Google 2016/11/17 22:27:49 Not for this CL, but I wonder if there is any reas
Yang 2016/11/18 06:07:13 No reason. It's just the first one I came across.
1097 UErrorCode ec = U_ZERO_ERROR; 1103 UErrorCode ec = U_ZERO_ERROR;
1098 uset_applyIntPropertyValue(set, property, property_value, &ec); 1104 uset_applyIntPropertyValue(set, property, property_value, &ec);
1099 bool success = ec == U_ZERO_ERROR && !uset_isEmpty(set); 1105 bool success = ec == U_ZERO_ERROR && !uset_isEmpty(set);
1100 1106
1101 if (success) { 1107 if (success) {
1102 uset_removeAllStrings(set); 1108 uset_removeAllStrings(set);
1103 if (negate) uset_complement(set); 1109 if (negate) uset_complement(set);
1104 int item_count = uset_getItemCount(set); 1110 int item_count = uset_getItemCount(set);
1105 int item_result = 0; 1111 int item_result = 0;
1106 for (int i = 0; i < item_count; i++) { 1112 for (int i = 0; i < item_count; i++) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 if (property >= UCHAR_BINARY_LIMIT) return false; 1195 if (property >= UCHAR_BINARY_LIMIT) return false;
1190 if (!IsExactPropertyAlias(name, property)) return false; 1196 if (!IsExactPropertyAlias(name, property)) return false;
1191 return LookupPropertyValueName(property, negate ? "N" : "Y", false, result, 1197 return LookupPropertyValueName(property, negate ? "N" : "Y", false, result,
1192 zone()); 1198 zone());
1193 } else { 1199 } else {
1194 // Both property name and value name are specified. Attempt to interpret 1200 // Both property name and value name are specified. Attempt to interpret
1195 // the property name as enumerated property. 1201 // the property name as enumerated property.
1196 const char* property_name = first_part.ToConstVector().start(); 1202 const char* property_name = first_part.ToConstVector().start();
1197 const char* value_name = second_part.ToConstVector().start(); 1203 const char* value_name = second_part.ToConstVector().start();
1198 UProperty property = u_getPropertyEnum(property_name); 1204 UProperty property = u_getPropertyEnum(property_name);
1199 if (property < UCHAR_INT_START) return false;
1200 if (property >= UCHAR_INT_LIMIT) return false;
1201 if (!IsExactPropertyAlias(property_name, property)) return false; 1205 if (!IsExactPropertyAlias(property_name, property)) return false;
1206 if (property == UCHAR_GENERAL_CATEGORY) {
1207 // We want to allow aggregate value names such as "Letter".
1208 property = UCHAR_GENERAL_CATEGORY_MASK;
1209 } else if (property != UCHAR_SCRIPT &&
1210 property != UCHAR_SCRIPT_EXTENSIONS) {
1211 return false;
1212 }
1202 return LookupPropertyValueName(property, value_name, negate, result, 1213 return LookupPropertyValueName(property, value_name, negate, result,
1203 zone()); 1214 zone());
1204 } 1215 }
1205 } 1216 }
1206 1217
1207 #else // V8_I18N_SUPPORT 1218 #else // V8_I18N_SUPPORT
1208 1219
1209 bool RegExpParser::ParsePropertyClass(ZoneList<CharacterRange>* result, 1220 bool RegExpParser::ParsePropertyClass(ZoneList<CharacterRange>* result,
1210 bool negate) { 1221 bool negate) {
1211 return false; 1222 return false;
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 return false; 1798 return false;
1788 } 1799 }
1789 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), 1800 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom),
1790 zone()); 1801 zone());
1791 LAST(ADD_TERM); 1802 LAST(ADD_TERM);
1792 return true; 1803 return true;
1793 } 1804 }
1794 1805
1795 } // namespace internal 1806 } // namespace internal
1796 } // namespace v8 1807 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/regexp-property-blocks.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698