| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/css/CSSVariableData.h" |
| 7 |
| 8 #include "core/css/parser/CSSParserTokenRange.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 template<typename CharacterType> void CSSVariableData::copyStringsAndUpdateToken
s(const CSSParserTokenRange& range) |
| 13 { |
| 14 CSSParserTokenRange localRange = range; |
| 15 String baseString = localRange.scope()->string(); |
| 16 const CharacterType* stringStart = baseString.getCharacters<CharacterType>()
; |
| 17 const CharacterType* stringEnd = stringStart + baseString.length(); |
| 18 |
| 19 const CharacterType* maxOffset = nullptr; |
| 20 const CharacterType* minOffset = nullptr; |
| 21 |
| 22 while (!localRange.atEnd()) { |
| 23 CSSParserToken token = localRange.consume(); |
| 24 const CharacterType* tokenLocation = static_cast<const CharacterType*>(t
oken.m_valueDataCharRaw); |
| 25 if (tokenLocation > stringStart && tokenLocation < stringEnd) { |
| 26 if (!minOffset) |
| 27 minOffset = tokenLocation; |
| 28 maxOffset = tokenLocation + token.m_valueLength; |
| 29 } else { |
| 30 String escapedString(tokenLocation, token.m_valueLength); |
| 31 m_stringPool.append(escapedString); |
| 32 token.m_valueDataCharRaw = escapedString.getCharacters<CharacterType
>(); |
| 33 } |
| 34 m_tokens.append(token); |
| 35 } |
| 36 if (minOffset) { |
| 37 m_string = String(minOffset, maxOffset - minOffset); |
| 38 const CharacterType* newStringStart = m_string.getCharacters<CharacterTy
pe>(); |
| 39 for (CSSParserToken& token : m_tokens) { |
| 40 const CharacterType* tokenLocation = static_cast<const CharacterType
*>(token.m_valueDataCharRaw); |
| 41 if (tokenLocation > stringStart && tokenLocation < stringEnd) |
| 42 token.m_valueDataCharRaw = newStringStart + (tokenLocation - min
Offset); |
| 43 } |
| 44 } |
| 45 } |
| 46 |
| 47 CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, bool needsVar
iableResolution) |
| 48 : m_needsVariableResolution(needsVariableResolution) |
| 49 { |
| 50 if (range.scope()->string().is8Bit()) |
| 51 copyStringsAndUpdateTokens<LChar>(range); |
| 52 else |
| 53 copyStringsAndUpdateTokens<UChar>(range); |
| 54 } |
| 55 |
| 56 } // namespace blink |
| OLD | NEW |