]>
Commit | Line | Data |
---|---|---|
4e4e5a6f A |
1 | /* |
2 | * Copyright (C) 2010 University of Szeged | |
3 | * Copyright (C) 2010 Renata Hodovan (hodovan@inf.u-szeged.hu) | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY | |
16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR | |
19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
22 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
23 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
28 | #include "UString.h" | |
29 | ||
30 | #ifndef RegExpKey_h | |
31 | #define RegExpKey_h | |
32 | ||
33 | namespace JSC { | |
34 | ||
35 | struct RegExpKey { | |
36 | int flagsValue; | |
37 | RefPtr<UString::Rep> pattern; | |
38 | ||
39 | RegExpKey() | |
40 | : flagsValue(0) | |
41 | { | |
42 | } | |
43 | ||
44 | RegExpKey(int flags) | |
45 | : flagsValue(flags) | |
46 | { | |
47 | } | |
48 | ||
49 | RegExpKey(int flags, const UString& pattern) | |
50 | : flagsValue(flags) | |
51 | , pattern(pattern.rep()) | |
52 | { | |
53 | } | |
54 | ||
55 | RegExpKey(int flags, const PassRefPtr<UString::Rep> pattern) | |
56 | : flagsValue(flags) | |
57 | , pattern(pattern) | |
58 | { | |
59 | } | |
60 | ||
61 | RegExpKey(const UString& flags, const UString& pattern) | |
62 | : pattern(pattern.rep()) | |
63 | { | |
64 | flagsValue = getFlagsValue(flags); | |
65 | } | |
66 | ||
67 | int getFlagsValue(const UString flags) | |
68 | { | |
69 | flagsValue = 0; | |
70 | if (flags.find('g') != UString::NotFound) | |
71 | flagsValue += 4; | |
72 | if (flags.find('i') != UString::NotFound) | |
73 | flagsValue += 2; | |
74 | if (flags.find('m') != UString::NotFound) | |
75 | flagsValue += 1; | |
76 | return flagsValue; | |
77 | } | |
78 | }; | |
79 | } // namespace JSC | |
80 | ||
81 | namespace WTF { | |
82 | template<typename T> struct DefaultHash; | |
83 | template<typename T> struct RegExpHash; | |
84 | ||
85 | inline bool operator==(const JSC::RegExpKey& a, const JSC::RegExpKey& b) | |
86 | { | |
87 | if (a.flagsValue != b.flagsValue) | |
88 | return false; | |
89 | if (!a.pattern) | |
90 | return !b.pattern; | |
91 | if (!b.pattern) | |
92 | return false; | |
93 | return equal(a.pattern.get(), b.pattern.get()); | |
94 | } | |
95 | ||
96 | template<> struct RegExpHash<JSC::RegExpKey> { | |
97 | static unsigned hash(const JSC::RegExpKey& key) { return key.pattern->hash(); } | |
98 | static bool equal(const JSC::RegExpKey& a, const JSC::RegExpKey& b) { return a == b; } | |
99 | static const bool safeToCompareToEmptyOrDeleted = false; | |
100 | }; | |
101 | ||
102 | template<> struct DefaultHash<JSC::RegExpKey> { | |
103 | typedef RegExpHash<JSC::RegExpKey> Hash; | |
104 | }; | |
105 | ||
106 | template<> struct HashTraits<JSC::RegExpKey> : GenericHashTraits<JSC::RegExpKey> { | |
107 | static void constructDeletedValue(JSC::RegExpKey& slot) { slot.flagsValue = -1; } | |
108 | static bool isDeletedValue(const JSC::RegExpKey& value) { return value.flagsValue == -1; } | |
109 | }; | |
110 | } // namespace WTF | |
111 | ||
112 | #endif // RegExpKey_h |