| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 | 3 |
| 4 This library is free software; you can redistribute it and/or | 4 This library is free software; you can redistribute it and/or |
| 5 modify it under the terms of the GNU Library General Public | 5 modify it under the terms of the GNU Library General Public |
| 6 License as published by the Free Software Foundation; either | 6 License as published by the Free Software Foundation; either |
| 7 version 2 of the License, or (at your option) any later version. | 7 version 2 of the License, or (at your option) any later version. |
| 8 | 8 |
| 9 This library is distributed in the hope that it will be useful, | 9 This library is distributed in the hope that it will be useful, |
| 10 but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 current_line_ = 0; | 50 current_line_ = 0; |
| 51 substrings_.Clear(); | 51 substrings_.Clear(); |
| 52 closed_ = false; | 52 closed_ = false; |
| 53 empty_ = true; | 53 empty_ = true; |
| 54 fast_path_flags_ = kNoFastPath; | 54 fast_path_flags_ = kNoFastPath; |
| 55 advance_func_ = &SegmentedString::AdvanceEmpty; | 55 advance_func_ = &SegmentedString::AdvanceEmpty; |
| 56 advance_and_update_line_number_func_ = &SegmentedString::AdvanceEmpty; | 56 advance_and_update_line_number_func_ = &SegmentedString::AdvanceEmpty; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SegmentedString::Append(const SegmentedSubstring& s) { | 59 void SegmentedString::Append(const SegmentedSubstring& s) { |
| 60 ASSERT(!closed_); | 60 DCHECK(!closed_); |
| 61 if (!s.length()) | 61 if (!s.length()) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 if (!current_string_.length()) { | 64 if (!current_string_.length()) { |
| 65 number_of_characters_consumed_prior_to_current_string_ += | 65 number_of_characters_consumed_prior_to_current_string_ += |
| 66 current_string_.NumberOfCharactersConsumed(); | 66 current_string_.NumberOfCharactersConsumed(); |
| 67 current_string_ = s; | 67 current_string_ = s; |
| 68 UpdateAdvanceFunctionPointers(); | 68 UpdateAdvanceFunctionPointers(); |
| 69 } else { | 69 } else { |
| 70 substrings_.push_back(s); | 70 substrings_.push_back(s); |
| 71 } | 71 } |
| 72 empty_ = false; | 72 empty_ = false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void SegmentedString::Push(UChar c) { | 75 void SegmentedString::Push(UChar c) { |
| 76 ASSERT(c); | 76 DCHECK(c); |
| 77 | 77 |
| 78 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, | 78 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, |
| 79 // however it will fail if the SegmentedSubstring is empty, or | 79 // however it will fail if the SegmentedSubstring is empty, or |
| 80 // when we prepended some text while consuming a SegmentedSubstring by | 80 // when we prepended some text while consuming a SegmentedSubstring by |
| 81 // document.write(). | 81 // document.write(). |
| 82 if (current_string_.PushIfPossible(c)) { | 82 if (current_string_.PushIfPossible(c)) { |
| 83 current_char_ = c; | 83 current_char_ = c; |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 Prepend(SegmentedString(String(&c, 1)), PrependType::kUnconsume); | 87 Prepend(SegmentedString(String(&c, 1)), PrependType::kUnconsume); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SegmentedString::Prepend(const SegmentedSubstring& s, PrependType type) { | 90 void SegmentedString::Prepend(const SegmentedSubstring& s, PrependType type) { |
| 91 ASSERT(!s.NumberOfCharactersConsumed()); | 91 DCHECK(!s.NumberOfCharactersConsumed()); |
| 92 if (!s.length()) | 92 if (!s.length()) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 // FIXME: We're also ASSERTing that s is a fresh SegmentedSubstring. | 95 // FIXME: We're also ASSERTing that s is a fresh SegmentedSubstring. |
| 96 // The assumption is sufficient for our current use, but we might | 96 // The assumption is sufficient for our current use, but we might |
| 97 // need to handle the more elaborate cases in the future. | 97 // need to handle the more elaborate cases in the future. |
| 98 number_of_characters_consumed_prior_to_current_string_ += | 98 number_of_characters_consumed_prior_to_current_string_ += |
| 99 current_string_.NumberOfCharactersConsumed(); | 99 current_string_.NumberOfCharactersConsumed(); |
| 100 if (type == PrependType::kUnconsume) | 100 if (type == PrependType::kUnconsume) |
| 101 number_of_characters_consumed_prior_to_current_string_ -= s.length(); | 101 number_of_characters_consumed_prior_to_current_string_ -= s.length(); |
| 102 if (!current_string_.length()) { | 102 if (!current_string_.length()) { |
| 103 current_string_ = s; | 103 current_string_ = s; |
| 104 UpdateAdvanceFunctionPointers(); | 104 UpdateAdvanceFunctionPointers(); |
| 105 } else { | 105 } else { |
| 106 // Shift our m_currentString into our list. | 106 // Shift our m_currentString into our list. |
| 107 substrings_.push_front(current_string_); | 107 substrings_.push_front(current_string_); |
| 108 current_string_ = s; | 108 current_string_ = s; |
| 109 UpdateAdvanceFunctionPointers(); | 109 UpdateAdvanceFunctionPointers(); |
| 110 } | 110 } |
| 111 empty_ = false; | 111 empty_ = false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void SegmentedString::Close() { | 114 void SegmentedString::Close() { |
| 115 // Closing a stream twice is likely a coding mistake. | 115 // Closing a stream twice is likely a coding mistake. |
| 116 ASSERT(!closed_); | 116 DCHECK(!closed_); |
| 117 closed_ = true; | 117 closed_ = true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SegmentedString::Append(const SegmentedString& s) { | 120 void SegmentedString::Append(const SegmentedString& s) { |
| 121 ASSERT(!closed_); | 121 DCHECK(!closed_); |
| 122 | 122 |
| 123 Append(s.current_string_); | 123 Append(s.current_string_); |
| 124 if (s.IsComposite()) { | 124 if (s.IsComposite()) { |
| 125 Deque<SegmentedSubstring>::const_iterator it = s.substrings_.begin(); | 125 Deque<SegmentedSubstring>::const_iterator it = s.substrings_.begin(); |
| 126 Deque<SegmentedSubstring>::const_iterator e = s.substrings_.end(); | 126 Deque<SegmentedSubstring>::const_iterator e = s.substrings_.end(); |
| 127 for (; it != e; ++it) | 127 for (; it != e; ++it) |
| 128 Append(*it); | 128 Append(*it); |
| 129 } | 129 } |
| 130 current_char_ = | 130 current_char_ = |
| 131 current_string_.length() ? current_string_.GetCurrentChar() : 0; | 131 current_string_.length() ? current_string_.GetCurrentChar() : 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 DecrementAndCheckLength(); | 188 DecrementAndCheckLength(); |
| 189 current_char_ = current_string_.IncrementAndGetCurrentChar8(); | 189 current_char_ = current_string_.IncrementAndGetCurrentChar8(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void SegmentedString::Advance16() { | 192 void SegmentedString::Advance16() { |
| 193 DecrementAndCheckLength(); | 193 DecrementAndCheckLength(); |
| 194 current_char_ = current_string_.IncrementAndGetCurrentChar16(); | 194 current_char_ = current_string_.IncrementAndGetCurrentChar16(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void SegmentedString::AdvanceAndUpdateLineNumber8() { | 197 void SegmentedString::AdvanceAndUpdateLineNumber8() { |
| 198 ASSERT(current_string_.GetCurrentChar() == current_char_); | 198 DCHECK_EQ(current_string_.GetCurrentChar(), current_char_); |
| 199 if (current_char_ == '\n') { | 199 if (current_char_ == '\n') { |
| 200 ++current_line_; | 200 ++current_line_; |
| 201 number_of_characters_consumed_prior_to_current_line_ = | 201 number_of_characters_consumed_prior_to_current_line_ = |
| 202 NumberOfCharactersConsumed() + 1; | 202 NumberOfCharactersConsumed() + 1; |
| 203 } | 203 } |
| 204 DecrementAndCheckLength(); | 204 DecrementAndCheckLength(); |
| 205 current_char_ = current_string_.IncrementAndGetCurrentChar8(); | 205 current_char_ = current_string_.IncrementAndGetCurrentChar8(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void SegmentedString::AdvanceAndUpdateLineNumber16() { | 208 void SegmentedString::AdvanceAndUpdateLineNumber16() { |
| 209 ASSERT(current_string_.GetCurrentChar() == current_char_); | 209 DCHECK_EQ(current_string_.GetCurrentChar(), current_char_); |
| 210 if (current_char_ == '\n') { | 210 if (current_char_ == '\n') { |
| 211 ++current_line_; | 211 ++current_line_; |
| 212 number_of_characters_consumed_prior_to_current_line_ = | 212 number_of_characters_consumed_prior_to_current_line_ = |
| 213 NumberOfCharactersConsumed() + 1; | 213 NumberOfCharactersConsumed() + 1; |
| 214 } | 214 } |
| 215 DecrementAndCheckLength(); | 215 DecrementAndCheckLength(); |
| 216 current_char_ = current_string_.IncrementAndGetCurrentChar16(); | 216 current_char_ = current_string_.IncrementAndGetCurrentChar16(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void SegmentedString::AdvanceSlowCase() { | 219 void SegmentedString::AdvanceSlowCase() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 fast_path_flags_ = kNoFastPath; | 253 fast_path_flags_ = kNoFastPath; |
| 254 advance_func_ = &SegmentedString::AdvanceEmpty; | 254 advance_func_ = &SegmentedString::AdvanceEmpty; |
| 255 advance_and_update_line_number_func_ = &SegmentedString::AdvanceEmpty; | 255 advance_and_update_line_number_func_ = &SegmentedString::AdvanceEmpty; |
| 256 } | 256 } |
| 257 | 257 |
| 258 current_char_ = | 258 current_char_ = |
| 259 current_string_.length() ? current_string_.GetCurrentChar() : 0; | 259 current_string_.length() ? current_string_.GetCurrentChar() : 0; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void SegmentedString::AdvanceEmpty() { | 262 void SegmentedString::AdvanceEmpty() { |
| 263 ASSERT(!current_string_.length() && !IsComposite()); | 263 DCHECK(!current_string_.length()); |
| 264 DCHECK(!IsComposite()); |
| 264 current_char_ = 0; | 265 current_char_ = 0; |
| 265 } | 266 } |
| 266 | 267 |
| 267 void SegmentedString::UpdateSlowCaseFunctionPointers() { | 268 void SegmentedString::UpdateSlowCaseFunctionPointers() { |
| 268 fast_path_flags_ = kNoFastPath; | 269 fast_path_flags_ = kNoFastPath; |
| 269 advance_func_ = &SegmentedString::AdvanceSlowCase; | 270 advance_func_ = &SegmentedString::AdvanceSlowCase; |
| 270 advance_and_update_line_number_func_ = | 271 advance_and_update_line_number_func_ = |
| 271 &SegmentedString::AdvanceAndUpdateLineNumberSlowCase; | 272 &SegmentedString::AdvanceAndUpdateLineNumberSlowCase; |
| 272 } | 273 } |
| 273 | 274 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 284 void SegmentedString::SetCurrentPosition(OrdinalNumber line, | 285 void SegmentedString::SetCurrentPosition(OrdinalNumber line, |
| 285 OrdinalNumber column_aftre_prolog, | 286 OrdinalNumber column_aftre_prolog, |
| 286 int prolog_length) { | 287 int prolog_length) { |
| 287 current_line_ = line.ZeroBasedInt(); | 288 current_line_ = line.ZeroBasedInt(); |
| 288 number_of_characters_consumed_prior_to_current_line_ = | 289 number_of_characters_consumed_prior_to_current_line_ = |
| 289 NumberOfCharactersConsumed() + prolog_length - | 290 NumberOfCharactersConsumed() + prolog_length - |
| 290 column_aftre_prolog.ZeroBasedInt(); | 291 column_aftre_prolog.ZeroBasedInt(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |