Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Adam Barth. All Rights Reserved. | 2 * Copyright (C) 2010 Adam Barth. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/html/parser/HTMLSourceTracker.h" | 27 #include "core/html/parser/HTMLSourceTracker.h" |
| 28 | 28 |
| 29 #include "core/html/parser/HTMLTokenizer.h" | 29 #include "core/html/parser/HTMLTokenizer.h" |
| 30 #include "wtf/text/StringBuilder.h" | 30 #include "wtf/text/StringBuilder.h" |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 HTMLSourceTracker::HTMLSourceTracker() | 34 HTMLSourceTracker::HTMLSourceTracker() : m_isStarted(false) |
|
abarth-chromium
2014/07/01 14:44:09
The : m_isStarted goes on the next line (indented
| |
| 35 { | 35 { |
| 36 } | 36 } |
| 37 | 37 |
| 38 void HTMLSourceTracker::start(SegmentedString& currentInput, HTMLTokenizer* toke nizer, HTMLToken& token) | 38 void HTMLSourceTracker::start(SegmentedString& currentInput, HTMLTokenizer* toke nizer, HTMLToken& token) |
| 39 { | 39 { |
| 40 if (token.type() == HTMLToken::Uninitialized) { | 40 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) { |
| 41 m_previousSource.clear(); | 41 m_previousSource.clear(); |
| 42 if (tokenizer->numberOfBufferedCharacters()) | 42 if (tokenizer->numberOfBufferedCharacters()) |
| 43 m_previousSource = tokenizer->bufferedCharacters(); | 43 m_previousSource = tokenizer->bufferedCharacters(); |
| 44 } else | 44 } else |
| 45 m_previousSource.append(m_currentSource); | 45 m_previousSource.append(m_currentSource); |
| 46 | 46 |
| 47 m_isStarted = true; | |
| 47 m_currentSource = currentInput; | 48 m_currentSource = currentInput; |
| 48 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - m_previou sSource.length()); | 49 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - m_previou sSource.length()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void HTMLSourceTracker::end(SegmentedString& currentInput, HTMLTokenizer* tokeni zer, HTMLToken& token) | 52 void HTMLSourceTracker::end(SegmentedString& currentInput, HTMLTokenizer* tokeni zer, HTMLToken& token) |
| 52 { | 53 { |
| 54 m_isStarted = false; | |
| 55 | |
| 53 m_cachedSourceForToken = String(); | 56 m_cachedSourceForToken = String(); |
| 54 | 57 |
| 55 // FIXME: This work should really be done by the HTMLTokenizer. | 58 // FIXME: This work should really be done by the HTMLTokenizer. |
| 56 token.end(currentInput.numberOfCharactersConsumed() - tokenizer->numberOfBuf feredCharacters()); | 59 token.end(currentInput.numberOfCharactersConsumed() - tokenizer->numberOfBuf feredCharacters()); |
| 57 } | 60 } |
| 58 | 61 |
| 59 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) | 62 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) |
| 60 { | 63 { |
| 61 if (!m_cachedSourceForToken.isEmpty()) | 64 if (!m_cachedSourceForToken.isEmpty()) |
| 62 return m_cachedSourceForToken; | 65 return m_cachedSourceForToken; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 82 ASSERT(!m_currentSource.isEmpty()); | 85 ASSERT(!m_currentSource.isEmpty()); |
| 83 source.append(m_currentSource.currentChar()); | 86 source.append(m_currentSource.currentChar()); |
| 84 m_currentSource.advance(); | 87 m_currentSource.advance(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 m_cachedSourceForToken = source.toString(); | 90 m_cachedSourceForToken = source.toString(); |
| 88 return m_cachedSourceForToken; | 91 return m_cachedSourceForToken; |
| 89 } | 92 } |
| 90 | 93 |
| 91 } | 94 } |
| OLD | NEW |