| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/parser/CSSParserTokenRange.h" | 5 #include "core/css/parser/CSSParserTokenRange.h" |
| 6 | 6 |
| 7 #include "wtf/StaticConstructors.h" | 7 #include "wtf/StaticConstructors.h" |
| 8 #include "wtf/text/StringBuilder.h" | 8 #include "wtf/text/StringBuilder.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 if (first == &staticEOFToken) | 21 if (first == &staticEOFToken) |
| 22 first = m_last; | 22 first = m_last; |
| 23 if (last == &staticEOFToken) | 23 if (last == &staticEOFToken) |
| 24 last = m_last; | 24 last = m_last; |
| 25 ASSERT(first <= last); | 25 ASSERT(first <= last); |
| 26 return CSSParserTokenRange(first, last); | 26 return CSSParserTokenRange(first, last); |
| 27 } | 27 } |
| 28 | 28 |
| 29 CSSParserTokenRange CSSParserTokenRange::consumeBlock() | 29 CSSParserTokenRange CSSParserTokenRange::consumeBlock() |
| 30 { | 30 { |
| 31 ASSERT(peek().blockType() == CSSParserToken::BlockStart); | 31 ASSERT(peek().getBlockType() == CSSParserToken::BlockStart); |
| 32 const CSSParserToken* start = &peek() + 1; | 32 const CSSParserToken* start = &peek() + 1; |
| 33 unsigned nestingLevel = 0; | 33 unsigned nestingLevel = 0; |
| 34 do { | 34 do { |
| 35 const CSSParserToken& token = consume(); | 35 const CSSParserToken& token = consume(); |
| 36 if (token.blockType() == CSSParserToken::BlockStart) | 36 if (token.getBlockType() == CSSParserToken::BlockStart) |
| 37 nestingLevel++; | 37 nestingLevel++; |
| 38 else if (token.blockType() == CSSParserToken::BlockEnd) | 38 else if (token.getBlockType() == CSSParserToken::BlockEnd) |
| 39 nestingLevel--; | 39 nestingLevel--; |
| 40 } while (nestingLevel && m_first < m_last); | 40 } while (nestingLevel && m_first < m_last); |
| 41 | 41 |
| 42 if (nestingLevel) | 42 if (nestingLevel) |
| 43 return makeSubRange(start, m_first); // Ended at EOF | 43 return makeSubRange(start, m_first); // Ended at EOF |
| 44 return makeSubRange(start, m_first - 1); | 44 return makeSubRange(start, m_first - 1); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CSSParserTokenRange::consumeComponentValue() | 47 void CSSParserTokenRange::consumeComponentValue() |
| 48 { | 48 { |
| 49 // FIXME: This is going to do multiple passes over large sections of a style
sheet. | 49 // FIXME: This is going to do multiple passes over large sections of a style
sheet. |
| 50 // We should consider optimising this by precomputing where each block ends. | 50 // We should consider optimising this by precomputing where each block ends. |
| 51 unsigned nestingLevel = 0; | 51 unsigned nestingLevel = 0; |
| 52 do { | 52 do { |
| 53 const CSSParserToken& token = consume(); | 53 const CSSParserToken& token = consume(); |
| 54 if (token.blockType() == CSSParserToken::BlockStart) | 54 if (token.getBlockType() == CSSParserToken::BlockStart) |
| 55 nestingLevel++; | 55 nestingLevel++; |
| 56 else if (token.blockType() == CSSParserToken::BlockEnd) | 56 else if (token.getBlockType() == CSSParserToken::BlockEnd) |
| 57 nestingLevel--; | 57 nestingLevel--; |
| 58 } while (nestingLevel && m_first < m_last); | 58 } while (nestingLevel && m_first < m_last); |
| 59 } | 59 } |
| 60 | 60 |
| 61 String CSSParserTokenRange::serialize() const | 61 String CSSParserTokenRange::serialize() const |
| 62 { | 62 { |
| 63 // We're supposed to insert comments between certain pairs of token types | 63 // We're supposed to insert comments between certain pairs of token types |
| 64 // as per spec, but since this is currently only used for @supports CSSOM | 64 // as per spec, but since this is currently only used for @supports CSSOM |
| 65 // we just get these cases wrong and avoid the additional complexity. | 65 // we just get these cases wrong and avoid the additional complexity. |
| 66 StringBuilder builder; | 66 StringBuilder builder; |
| 67 for (const CSSParserToken* it = m_first; it < m_last; ++it) | 67 for (const CSSParserToken* it = m_first; it < m_last; ++it) |
| 68 it->serialize(builder); | 68 it->serialize(builder); |
| 69 return builder.toString(); | 69 return builder.toString(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |