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.
26 #ifndef CharacterClassConstructor_h
27 #define CharacterClassConstructor_h
29 #include <wtf/Platform.h>
33 #include "CharacterClass.h"
34 #include <wtf/AlwaysInline.h>
35 #include <wtf/Vector.h>
36 #include <wtf/unicode/Unicode.h>
38 namespace JSC
{ namespace WREC
{
40 class CharacterClassConstructor
{
42 CharacterClassConstructor(bool isCaseInsensitive
)
44 , m_isPendingDash(false)
45 , m_isCaseInsensitive(isCaseInsensitive
)
46 , m_isUpsideDown(false)
52 // We need to flush prior to an escaped hyphen to prevent it as being treated as indicating
53 // a range, e.g. [a\-c] we flush prior to adding the hyphen so that this is not treated as
54 // [a-c]. However, we do not want to flush if we have already seen a non escaped hyphen -
55 // e.g. [+-\-] should be treated the same as [+--], producing a range that will also match
57 void flushBeforeEscapedHyphen()
64 void append(const CharacterClass
& other
);
66 bool isUpsideDown() { return m_isUpsideDown
; }
68 ALWAYS_INLINE CharacterClass
charClass()
70 CharacterClass newCharClass
= {
71 m_matches
.begin(), m_matches
.size(),
72 m_ranges
.begin(), m_ranges
.size(),
73 m_matchesUnicode
.begin(), m_matchesUnicode
.size(),
74 m_rangesUnicode
.begin(), m_rangesUnicode
.size(),
81 void addSorted(Vector
<UChar
>& matches
, UChar ch
);
82 void addSortedRange(Vector
<CharacterRange
>& ranges
, UChar lo
, UChar hi
);
86 bool m_isCaseInsensitive
;
89 Vector
<UChar
> m_matches
;
90 Vector
<CharacterRange
> m_ranges
;
91 Vector
<UChar
> m_matchesUnicode
;
92 Vector
<CharacterRange
> m_rangesUnicode
;
95 } } // namespace JSC::WREC
97 #endif // ENABLE(WREC)
99 #endif // CharacterClassConstructor_h