OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5819 | 5819 |
5820 // Negative length means the to the end of the string. | 5820 // Negative length means the to the end of the string. |
5821 if (length < 0) length = kMaxInt - offset; | 5821 if (length < 0) length = kMaxInt - offset; |
5822 | 5822 |
5823 // Compute the size of the UTF-8 string. Start at the specified offset. | 5823 // Compute the size of the UTF-8 string. Start at the specified offset. |
5824 Access<StringInputBuffer> buffer( | 5824 Access<StringInputBuffer> buffer( |
5825 heap->isolate()->objects_string_input_buffer()); | 5825 heap->isolate()->objects_string_input_buffer()); |
5826 buffer->Reset(offset, this); | 5826 buffer->Reset(offset, this); |
5827 int character_position = offset; | 5827 int character_position = offset; |
5828 int utf8_bytes = 0; | 5828 int utf8_bytes = 0; |
5829 while (buffer->has_more()) { | 5829 while (buffer->has_more() && character_position++ < offset + length) { |
5830 uint16_t character = buffer->GetNext(); | 5830 uint16_t character = buffer->GetNext(); |
5831 if (character_position < offset + length) { | 5831 utf8_bytes += unibrow::Utf8::Length(character); |
5832 utf8_bytes += unibrow::Utf8::Length(character); | |
5833 } | |
5834 character_position++; | |
5835 } | 5832 } |
5836 | 5833 |
5837 if (length_return) { | 5834 if (length_return) { |
5838 *length_return = utf8_bytes; | 5835 *length_return = utf8_bytes; |
5839 } | 5836 } |
5840 | 5837 |
5841 char* result = NewArray<char>(utf8_bytes + 1); | 5838 char* result = NewArray<char>(utf8_bytes + 1); |
5842 | 5839 |
5843 // Convert the UTF-16 string to a UTF-8 buffer. Start at the specified offset. | 5840 // Convert the UTF-16 string to a UTF-8 buffer. Start at the specified offset. |
5844 buffer->Rewind(); | 5841 buffer->Rewind(); |
5845 buffer->Seek(offset); | 5842 buffer->Seek(offset); |
5846 character_position = offset; | 5843 character_position = offset; |
5847 int utf8_byte_position = 0; | 5844 int utf8_byte_position = 0; |
5848 while (buffer->has_more()) { | 5845 while (buffer->has_more() && character_position++ < offset + length) { |
5849 uint16_t character = buffer->GetNext(); | 5846 uint16_t character = buffer->GetNext(); |
5850 if (character_position < offset + length) { | 5847 if (allow_nulls == DISALLOW_NULLS && character == 0) { |
5851 if (allow_nulls == DISALLOW_NULLS && character == 0) { | 5848 character = ' '; |
5852 character = ' '; | |
5853 } | |
5854 utf8_byte_position += | |
5855 unibrow::Utf8::Encode(result + utf8_byte_position, character); | |
5856 } | 5849 } |
5857 character_position++; | 5850 utf8_byte_position += |
| 5851 unibrow::Utf8::Encode(result + utf8_byte_position, character); |
5858 } | 5852 } |
5859 result[utf8_byte_position] = 0; | 5853 result[utf8_byte_position] = 0; |
5860 return SmartArrayPointer<char>(result); | 5854 return SmartArrayPointer<char>(result); |
5861 } | 5855 } |
5862 | 5856 |
5863 | 5857 |
5864 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, | 5858 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, |
5865 RobustnessFlag robust_flag, | 5859 RobustnessFlag robust_flag, |
5866 int* length_return) { | 5860 int* length_return) { |
5867 return ToCString(allow_nulls, robust_flag, 0, -1, length_return); | 5861 return ToCString(allow_nulls, robust_flag, 0, -1, length_return); |
(...skipping 6653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12521 if (break_point_objects()->IsUndefined()) return 0; | 12515 if (break_point_objects()->IsUndefined()) return 0; |
12522 // Single break point. | 12516 // Single break point. |
12523 if (!break_point_objects()->IsFixedArray()) return 1; | 12517 if (!break_point_objects()->IsFixedArray()) return 1; |
12524 // Multiple break points. | 12518 // Multiple break points. |
12525 return FixedArray::cast(break_point_objects())->length(); | 12519 return FixedArray::cast(break_point_objects())->length(); |
12526 } | 12520 } |
12527 #endif // ENABLE_DEBUGGER_SUPPORT | 12521 #endif // ENABLE_DEBUGGER_SUPPORT |
12528 | 12522 |
12529 | 12523 |
12530 } } // namespace v8::internal | 12524 } } // namespace v8::internal |
OLD | NEW |