Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 void InputBuffer<R, I, s>::Reset(I input) { | 233 void InputBuffer<R, I, s>::Reset(I input) { |
| 234 Reset(0, input); | 234 Reset(0, input); |
| 235 } | 235 } |
| 236 | 236 |
| 237 template <class R, class I, unsigned s> | 237 template <class R, class I, unsigned s> |
| 238 void InputBuffer<R, I, s>::Seek(unsigned position) { | 238 void InputBuffer<R, I, s>::Seek(unsigned position) { |
| 239 offset_ = position; | 239 offset_ = position; |
| 240 buffer_ = R::ReadBlock(input_, util_buffer_, s, &remaining_, &offset_); | 240 buffer_ = R::ReadBlock(input_, util_buffer_, s, &remaining_, &offset_); |
| 241 } | 241 } |
| 242 | 242 |
| 243 template <unsigned s> | 243 Utf8DecoderBase::Utf8DecoderBase() |
| 244 Utf8InputBuffer<s>::Utf8InputBuffer(const char* data, unsigned length) | 244 : unbuffered_start_(NULL), |
| 245 : InputBuffer<Utf8, Buffer<const char*>, s>(Buffer<const char*>(data, | 245 utf16_length_(0), |
| 246 length)) { | 246 last_byte_of_buffer_unused_(false) {} |
| 247 | |
| 248 Utf8DecoderBase::Utf8DecoderBase(uint16_t* buffer, | |
| 249 unsigned buffer_length, | |
| 250 const uint8_t* stream, | |
| 251 unsigned stream_length) { | |
| 252 Reset(buffer, buffer_length, stream, stream_length); | |
| 253 } | |
| 254 | |
| 255 template<unsigned kBufferSize> | |
| 256 Utf8Decoder<kBufferSize>::Utf8Decoder(const char* stream, unsigned length) | |
| 257 : Utf8DecoderBase(buffer_, | |
| 258 kBufferSize, | |
| 259 reinterpret_cast<const uint8_t*>(stream), | |
| 260 length) { | |
| 261 } | |
| 262 | |
| 263 template<unsigned kBufferSize> | |
| 264 void Utf8Decoder<kBufferSize>::Reset(const char* stream, unsigned length) { | |
| 265 Utf8DecoderBase::Reset(buffer_, | |
| 266 kBufferSize, | |
| 267 reinterpret_cast<const uint8_t*>(stream), | |
| 268 length); | |
| 269 } | |
| 270 | |
| 271 template <unsigned kBufferSize> | |
| 272 unsigned Utf8Decoder<kBufferSize>::WriteUtf16(uint16_t* data, | |
| 273 unsigned length) const { | |
| 274 ASSERT(length > 0); | |
| 275 if (length > utf16_length_) length = utf16_length_; | |
| 276 // memcpy everything in buffer. | |
| 277 unsigned buffer_length = | |
| 278 last_byte_of_buffer_unused_ ? kBufferSize - 1 : kBufferSize; | |
| 279 unsigned memcpy_length = length <= buffer_length ? length : buffer_length; | |
| 280 memcpy(data, buffer_, memcpy_length*sizeof(uint16_t)); | |
| 281 if (length <= buffer_length) | |
| 282 return length; | |
|
Yang
2012/12/20 09:20:27
no line break here.
| |
| 283 ASSERT(unbuffered_start_ != NULL); | |
| 284 // Copy the rest the slow way. | |
| 285 WriteUtf16Slow(unbuffered_start_, | |
| 286 data + buffer_length, | |
| 287 length - buffer_length); | |
| 288 return length; | |
| 247 } | 289 } |
| 248 | 290 |
| 249 } // namespace unibrow | 291 } // namespace unibrow |
| 250 | 292 |
| 251 #endif // V8_UNICODE_INL_H_ | 293 #endif // V8_UNICODE_INL_H_ |
| OLD | NEW |