| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 static bool IsDigit(uc16 c) { | 437 static bool IsDigit(uc16 c) { |
| 438 return ('0' <= c && c <= '9'); | 438 return ('0' <= c && c <= '9'); |
| 439 } | 439 } |
| 440 | 440 |
| 441 | 441 |
| 442 static bool NotDigit(uc16 c) { | 442 static bool NotDigit(uc16 c) { |
| 443 return !IsDigit(c); | 443 return !IsDigit(c); |
| 444 } | 444 } |
| 445 | 445 |
| 446 | 446 |
| 447 static bool IsWhiteSpace(uc16 c) { | 447 static bool IsWhiteSpaceOrLineTerminator(uc16 c) { |
| 448 switch (c) { | 448 // According to ECMA 5.1, 15.10.2.12 the CharacterClassEscape \s includes |
| 449 case 0x09: | 449 // WhiteSpace (7.2) and LineTerminator (7.3) values. |
| 450 case 0x0A: | 450 return v8::internal::WhiteSpaceOrLineTerminator::Is(c); |
| 451 case 0x0B: | |
| 452 case 0x0C: | |
| 453 case 0x0d: | |
| 454 case 0x20: | |
| 455 case 0xA0: | |
| 456 case 0x2028: | |
| 457 case 0x2029: | |
| 458 case 0xFEFF: | |
| 459 return true; | |
| 460 default: | |
| 461 return unibrow::Space::Is(c); | |
| 462 } | |
| 463 } | 451 } |
| 464 | 452 |
| 465 | 453 |
| 466 static bool NotWhiteSpace(uc16 c) { | 454 static bool NotWhiteSpaceNorLineTermiantor(uc16 c) { |
| 467 return !IsWhiteSpace(c); | 455 return !IsWhiteSpaceOrLineTerminator(c); |
| 468 } | 456 } |
| 469 | 457 |
| 470 | 458 |
| 471 static bool NotWord(uc16 c) { | 459 static bool NotWord(uc16 c) { |
| 472 return !IsRegExpWord(c); | 460 return !IsRegExpWord(c); |
| 473 } | 461 } |
| 474 | 462 |
| 475 | 463 |
| 476 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 464 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
| 477 Zone zone(CcTest::i_isolate()); | 465 Zone zone(CcTest::i_isolate()); |
| 478 ZoneList<CharacterRange>* ranges = | 466 ZoneList<CharacterRange>* ranges = |
| 479 new(&zone) ZoneList<CharacterRange>(2, &zone); | 467 new(&zone) ZoneList<CharacterRange>(2, &zone); |
| 480 CharacterRange::AddClassEscape(c, ranges, &zone); | 468 CharacterRange::AddClassEscape(c, ranges, &zone); |
| 481 for (unsigned i = 0; i < (1 << 16); i++) { | 469 for (unsigned i = 0; i < (1 << 16); i++) { |
| 482 bool in_class = false; | 470 bool in_class = false; |
| 483 for (int j = 0; !in_class && j < ranges->length(); j++) { | 471 for (int j = 0; !in_class && j < ranges->length(); j++) { |
| 484 CharacterRange& range = ranges->at(j); | 472 CharacterRange& range = ranges->at(j); |
| 485 in_class = (range.from() <= i && i <= range.to()); | 473 in_class = (range.from() <= i && i <= range.to()); |
| 486 } | 474 } |
| 487 CHECK_EQ(pred(i), in_class); | 475 CHECK_EQ(pred(i), in_class); |
| 488 } | 476 } |
| 489 } | 477 } |
| 490 | 478 |
| 491 | 479 |
| 492 TEST(CharacterClassEscapes) { | 480 TEST(CharacterClassEscapes) { |
| 493 v8::internal::V8::Initialize(NULL); | 481 v8::internal::V8::Initialize(NULL); |
| 494 TestCharacterClassEscapes('.', IsRegExpNewline); | 482 TestCharacterClassEscapes('.', IsRegExpNewline); |
| 495 TestCharacterClassEscapes('d', IsDigit); | 483 TestCharacterClassEscapes('d', IsDigit); |
| 496 TestCharacterClassEscapes('D', NotDigit); | 484 TestCharacterClassEscapes('D', NotDigit); |
| 497 TestCharacterClassEscapes('s', IsWhiteSpace); | 485 TestCharacterClassEscapes('s', IsWhiteSpaceOrLineTerminator); |
| 498 TestCharacterClassEscapes('S', NotWhiteSpace); | 486 TestCharacterClassEscapes('S', NotWhiteSpaceNorLineTermiantor); |
| 499 TestCharacterClassEscapes('w', IsRegExpWord); | 487 TestCharacterClassEscapes('w', IsRegExpWord); |
| 500 TestCharacterClassEscapes('W', NotWord); | 488 TestCharacterClassEscapes('W', NotWord); |
| 501 } | 489 } |
| 502 | 490 |
| 503 | 491 |
| 504 static RegExpNode* Compile(const char* input, | 492 static RegExpNode* Compile(const char* input, |
| 505 bool multiline, | 493 bool multiline, |
| 506 bool is_ascii, | 494 bool is_ascii, |
| 507 Zone* zone) { | 495 Zone* zone) { |
| 508 V8::Initialize(NULL); | 496 V8::Initialize(NULL); |
| (...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 ZoneList<CharacterRange> first_only(4, &zone); | 1796 ZoneList<CharacterRange> first_only(4, &zone); |
| 1809 ZoneList<CharacterRange> second_only(4, &zone); | 1797 ZoneList<CharacterRange> second_only(4, &zone); |
| 1810 ZoneList<CharacterRange> both(4, &zone); | 1798 ZoneList<CharacterRange> both(4, &zone); |
| 1811 } | 1799 } |
| 1812 | 1800 |
| 1813 | 1801 |
| 1814 TEST(Graph) { | 1802 TEST(Graph) { |
| 1815 V8::Initialize(NULL); | 1803 V8::Initialize(NULL); |
| 1816 Execute("\\b\\w+\\b", false, true, true); | 1804 Execute("\\b\\w+\\b", false, true, true); |
| 1817 } | 1805 } |
| OLD | NEW |