OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/scanner-character-streams.h" | 7 #include "src/scanner-character-streams.h" |
8 | 8 |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return BufferSeekForward(delta); | 123 return BufferSeekForward(delta); |
124 } | 124 } |
125 | 125 |
126 | 126 |
127 // ---------------------------------------------------------------------------- | 127 // ---------------------------------------------------------------------------- |
128 // GenericStringUtf16CharacterStream | 128 // GenericStringUtf16CharacterStream |
129 | 129 |
130 | 130 |
131 GenericStringUtf16CharacterStream::GenericStringUtf16CharacterStream( | 131 GenericStringUtf16CharacterStream::GenericStringUtf16CharacterStream( |
132 Handle<String> data, size_t start_position, size_t end_position) | 132 Handle<String> data, size_t start_position, size_t end_position) |
133 : string_(data), length_(end_position) { | 133 : string_(data), length_(end_position), bookmark_(start_position) { |
134 DCHECK(end_position >= start_position); | 134 DCHECK(end_position >= start_position); |
135 pos_ = start_position; | 135 pos_ = start_position; |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 GenericStringUtf16CharacterStream::~GenericStringUtf16CharacterStream() { } | 139 GenericStringUtf16CharacterStream::~GenericStringUtf16CharacterStream() { } |
140 | 140 |
141 | 141 |
| 142 bool GenericStringUtf16CharacterStream::SetBookmark() { |
| 143 bookmark_ = pos_; |
| 144 return true; |
| 145 } |
| 146 |
| 147 |
| 148 bool GenericStringUtf16CharacterStream::CanResetToBookmark() { return true; } |
| 149 |
| 150 bool GenericStringUtf16CharacterStream::ResetToBookmark() { |
| 151 pos_ = bookmark_; |
| 152 buffer_cursor_ = buffer_; |
| 153 buffer_end_ = buffer_ + FillBuffer(pos_); |
| 154 return true; |
| 155 } |
| 156 |
| 157 |
142 size_t GenericStringUtf16CharacterStream::BufferSeekForward(size_t delta) { | 158 size_t GenericStringUtf16CharacterStream::BufferSeekForward(size_t delta) { |
143 size_t old_pos = pos_; | 159 size_t old_pos = pos_; |
144 pos_ = Min(pos_ + delta, length_); | 160 pos_ = Min(pos_ + delta, length_); |
145 ReadBlock(); | 161 ReadBlock(); |
146 return pos_ - old_pos; | 162 return pos_ - old_pos; |
147 } | 163 } |
148 | 164 |
149 | 165 |
150 size_t GenericStringUtf16CharacterStream::FillBuffer(size_t from_pos) { | 166 size_t GenericStringUtf16CharacterStream::FillBuffer(size_t from_pos) { |
151 if (from_pos >= length_) return 0; | 167 if (from_pos >= length_) return 0; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 456 } |
441 | 457 |
442 | 458 |
443 // ---------------------------------------------------------------------------- | 459 // ---------------------------------------------------------------------------- |
444 // ExternalTwoByteStringUtf16CharacterStream | 460 // ExternalTwoByteStringUtf16CharacterStream |
445 | 461 |
446 ExternalTwoByteStringUtf16CharacterStream:: | 462 ExternalTwoByteStringUtf16CharacterStream:: |
447 ~ExternalTwoByteStringUtf16CharacterStream() { } | 463 ~ExternalTwoByteStringUtf16CharacterStream() { } |
448 | 464 |
449 | 465 |
450 ExternalTwoByteStringUtf16CharacterStream | 466 ExternalTwoByteStringUtf16CharacterStream:: |
451 ::ExternalTwoByteStringUtf16CharacterStream( | 467 ExternalTwoByteStringUtf16CharacterStream( |
452 Handle<ExternalTwoByteString> data, | 468 Handle<ExternalTwoByteString> data, int start_position, |
453 int start_position, | |
454 int end_position) | 469 int end_position) |
455 : Utf16CharacterStream(), | 470 : Utf16CharacterStream(), |
456 source_(data), | 471 source_(data), |
457 raw_data_(data->GetTwoByteData(start_position)) { | 472 raw_data_(data->GetTwoByteData(start_position)), |
| 473 bookmark_(-1) { |
458 buffer_cursor_ = raw_data_, | 474 buffer_cursor_ = raw_data_, |
459 buffer_end_ = raw_data_ + (end_position - start_position); | 475 buffer_end_ = raw_data_ + (end_position - start_position); |
460 pos_ = start_position; | 476 pos_ = start_position; |
461 } | 477 } |
462 | 478 |
| 479 |
| 480 bool ExternalTwoByteStringUtf16CharacterStream::SetBookmark() { |
| 481 bookmark_ = pos_; |
| 482 return true; |
| 483 } |
| 484 |
| 485 |
| 486 bool ExternalTwoByteStringUtf16CharacterStream::CanResetToBookmark() { |
| 487 return (bookmark_ != -1); |
| 488 } |
| 489 |
| 490 |
| 491 bool ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { |
| 492 if (bookmark_ != -1) { |
| 493 pos_ = bookmark_; |
| 494 buffer_cursor_ = raw_data_ + bookmark_; |
| 495 return true; |
| 496 } else { |
| 497 return false; |
| 498 } |
| 499 } |
463 } } // namespace v8::internal | 500 } } // namespace v8::internal |
OLD | NEW |