2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "CharacterClass.h"
33 namespace JSC
{ namespace WREC
{
35 const CharacterClass
& CharacterClass::newline() {
36 static const UChar asciiNewlines
[2] = { '\n', '\r' };
37 static const UChar unicodeNewlines
[2] = { 0x2028, 0x2029 };
38 static const CharacterClass charClass
= {
48 const CharacterClass
& CharacterClass::digits() {
49 static const CharacterRange asciiDigitsRange
[1] = { { '0', '9' } };
50 static const CharacterClass charClass
= {
60 const CharacterClass
& CharacterClass::spaces() {
61 static const UChar asciiSpaces
[1] = { ' ' };
62 static const CharacterRange asciiSpacesRange
[1] = { { '\t', '\r' } };
63 static const UChar unicodeSpaces
[8] = { 0x00a0, 0x1680, 0x180e, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000 };
64 static const CharacterRange unicodeSpacesRange
[1] = { { 0x2000, 0x200a } };
65 static const CharacterClass charClass
= {
69 unicodeSpacesRange
, 1,
75 const CharacterClass
& CharacterClass::wordchar() {
76 static const UChar asciiWordchar
[1] = { '_' };
77 static const CharacterRange asciiWordcharRange
[3] = { { '0', '9' }, { 'A', 'Z' }, { 'a', 'z' } };
78 static const CharacterClass charClass
= {
80 asciiWordcharRange
, 3,
88 const CharacterClass
& CharacterClass::nondigits() {
89 static const CharacterRange asciiNondigitsRange
[2] = { { 0, '0' - 1 }, { '9' + 1, 0x7f } };
90 static const CharacterRange unicodeNondigitsRange
[1] = { { 0x0080, 0xffff } };
91 static const CharacterClass charClass
= {
93 asciiNondigitsRange
, 2,
95 unicodeNondigitsRange
, 1,
101 const CharacterClass
& CharacterClass::nonspaces() {
102 static const CharacterRange asciiNonspacesRange
[3] = { { 0, '\t' - 1 }, { '\r' + 1, ' ' - 1 }, { ' ' + 1, 0x7f } };
103 static const CharacterRange unicodeNonspacesRange
[9] = {
114 static const CharacterClass charClass
= {
116 asciiNonspacesRange
, 3,
118 unicodeNonspacesRange
, 9,
124 const CharacterClass
& CharacterClass::nonwordchar() {
125 static const UChar asciiNonwordchar
[1] = { '`' };
126 static const CharacterRange asciiNonwordcharRange
[4] = { { 0, '0' - 1 }, { '9' + 1, 'A' - 1 }, { 'Z' + 1, '_' - 1 }, { 'z' + 1, 0x7f } };
127 static const CharacterRange unicodeNonwordcharRange
[1] = { { 0x0080, 0xffff } };
128 static const CharacterClass charClass
= {
130 asciiNonwordcharRange
, 4,
132 unicodeNonwordcharRange
, 1,
138 } } // namespace JSC::WREC
140 #endif // ENABLE(WREC)