| 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 14 matching lines...) Expand all Loading... |
| 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() |
| 35 : m_isStarted(false) |
| 35 { | 36 { |
| 36 } | 37 } |
| 37 | 38 |
| 38 void HTMLSourceTracker::start(SegmentedString& currentInput, HTMLTokenizer* toke
nizer, HTMLToken& token) | 39 void HTMLSourceTracker::start(SegmentedString& currentInput, HTMLTokenizer* toke
nizer, HTMLToken& token) |
| 39 { | 40 { |
| 40 if (token.type() == HTMLToken::Uninitialized) { | 41 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) { |
| 41 m_previousSource.clear(); | 42 m_previousSource.clear(); |
| 42 if (tokenizer->numberOfBufferedCharacters()) | 43 if (tokenizer->numberOfBufferedCharacters()) |
| 43 m_previousSource = tokenizer->bufferedCharacters(); | 44 m_previousSource = tokenizer->bufferedCharacters(); |
| 44 } else | 45 } else |
| 45 m_previousSource.append(m_currentSource); | 46 m_previousSource.append(m_currentSource); |
| 46 | 47 |
| 48 m_isStarted = true; |
| 47 m_currentSource = currentInput; | 49 m_currentSource = currentInput; |
| 48 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - m_previou
sSource.length()); | 50 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - m_previou
sSource.length()); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void HTMLSourceTracker::end(SegmentedString& currentInput, HTMLTokenizer* tokeni
zer, HTMLToken& token) | 53 void HTMLSourceTracker::end(SegmentedString& currentInput, HTMLTokenizer* tokeni
zer, HTMLToken& token) |
| 52 { | 54 { |
| 55 m_isStarted = false; |
| 56 |
| 53 m_cachedSourceForToken = String(); | 57 m_cachedSourceForToken = String(); |
| 54 | 58 |
| 55 // FIXME: This work should really be done by the HTMLTokenizer. | 59 // FIXME: This work should really be done by the HTMLTokenizer. |
| 56 token.end(currentInput.numberOfCharactersConsumed() - tokenizer->numberOfBuf
feredCharacters()); | 60 token.end(currentInput.numberOfCharactersConsumed() - tokenizer->numberOfBuf
feredCharacters()); |
| 57 } | 61 } |
| 58 | 62 |
| 59 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) | 63 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) |
| 60 { | 64 { |
| 61 if (!m_cachedSourceForToken.isEmpty()) | 65 if (!m_cachedSourceForToken.isEmpty()) |
| 62 return m_cachedSourceForToken; | 66 return m_cachedSourceForToken; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 82 ASSERT(!m_currentSource.isEmpty()); | 86 ASSERT(!m_currentSource.isEmpty()); |
| 83 source.append(m_currentSource.currentChar()); | 87 source.append(m_currentSource.currentChar()); |
| 84 m_currentSource.advance(); | 88 m_currentSource.advance(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 m_cachedSourceForToken = source.toString(); | 91 m_cachedSourceForToken = source.toString(); |
| 88 return m_cachedSourceForToken; | 92 return m_cachedSourceForToken; |
| 89 } | 93 } |
| 90 | 94 |
| 91 } | 95 } |
| OLD | NEW |