| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) | |
| 3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | |
| 4 * | |
| 5 * This library is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU Library General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This library is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 * Library General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU Library General Public License | |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 18 * Boston, MA 02110-1301, USA. | |
| 19 */ | |
| 20 | |
| 21 #ifndef CSSParserString_h | |
| 22 #define CSSParserString_h | |
| 23 | |
| 24 #include "wtf/Allocator.h" | |
| 25 #include "wtf/text/AtomicString.h" | |
| 26 #include "wtf/text/StringView.h" | |
| 27 #include "wtf/text/WTFString.h" | |
| 28 | |
| 29 namespace blink { | |
| 30 | |
| 31 struct CSSParserString { | |
| 32 STACK_ALLOCATED(); | |
| 33 void init(const LChar* characters, unsigned length) | |
| 34 { | |
| 35 m_data.characters8 = characters; | |
| 36 m_length = length; | |
| 37 m_is8Bit = true; | |
| 38 } | |
| 39 | |
| 40 void init(const UChar* characters, unsigned length) | |
| 41 { | |
| 42 m_data.characters16 = characters; | |
| 43 m_length = length; | |
| 44 m_is8Bit = false; | |
| 45 } | |
| 46 | |
| 47 void initRaw(const void* charactersRaw, unsigned length, bool is8Bit) | |
| 48 { | |
| 49 m_data.charactersRaw = charactersRaw; | |
| 50 m_length = length; | |
| 51 m_is8Bit = is8Bit; | |
| 52 } | |
| 53 | |
| 54 void init(const String& string) | |
| 55 { | |
| 56 m_length = string.length(); | |
| 57 if (string.isNull()) { | |
| 58 m_data.characters8 = 0; | |
| 59 m_is8Bit = true; | |
| 60 return; | |
| 61 } | |
| 62 if (string.is8Bit()) { | |
| 63 m_data.characters8 = const_cast<LChar*>(string.characters8()); | |
| 64 m_is8Bit = true; | |
| 65 } else { | |
| 66 m_data.characters16 = const_cast<UChar*>(string.characters16()); | |
| 67 m_is8Bit = false; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 bool is8Bit() const { return m_is8Bit; } | |
| 72 const LChar* characters8() const { ASSERT(is8Bit()); return m_data.character
s8; } | |
| 73 const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.charact
ers16; } | |
| 74 | |
| 75 unsigned length() const { return m_length; } | |
| 76 | |
| 77 UChar operator[](unsigned i) const | |
| 78 { | |
| 79 ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); | |
| 80 if (is8Bit()) | |
| 81 return m_data.characters8[i]; | |
| 82 return m_data.characters16[i]; | |
| 83 } | |
| 84 | |
| 85 template<unsigned matchLength> | |
| 86 bool equalIgnoringASCIICase(const char (&match)[matchLength]) const | |
| 87 { | |
| 88 if (matchLength - 1 != length()) | |
| 89 return false; | |
| 90 return is8Bit() ? WTF::equalIgnoringASCIICase(characters8(), match, leng
th()) : WTF::equalIgnoringASCIICase(characters16(), match, length()); | |
| 91 } | |
| 92 | |
| 93 // TODO(esprehn): Remove both of these implicit operators, they're very expe
nsive. | |
| 94 operator String() const { return is8Bit() ? String(m_data.characters8, m_len
gth) : StringImpl::create8BitIfPossible(m_data.characters16, m_length); } | |
| 95 operator AtomicString() const { return is8Bit() ? AtomicString(m_data.charac
ters8, m_length) : AtomicString(m_data.characters16, m_length); } | |
| 96 | |
| 97 operator StringView() const { return is8Bit() ? StringView(m_data.characters
8, m_length) : StringView(m_data.characters16, m_length); } | |
| 98 | |
| 99 union { | |
| 100 const LChar* characters8; | |
| 101 const UChar* characters16; | |
| 102 const void* charactersRaw; | |
| 103 } m_data; | |
| 104 unsigned m_length; | |
| 105 bool m_is8Bit; | |
| 106 }; | |
| 107 | |
| 108 } // namespace blink | |
| 109 | |
| 110 #endif | |
| OLD | NEW |