Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 | 48 |
| 49 // Provide a common interface to getting a character at a certain | 49 // Provide a common interface to getting a character at a certain |
| 50 // index from a char* or a String object. | 50 // index from a char* or a String object. |
| 51 static inline int GetChar(const char* str, int index) { | 51 static inline int GetChar(const char* str, int index) { |
| 52 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); | 52 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); |
| 53 return str[index]; | 53 return str[index]; |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 static inline int GetChar(String* str, int index) { | 57 static inline int GetChar(String* str, int index) { |
| 58 return str->Get(index); | 58 StringShape shape(str); |
| 59 return str->Get(shape, index); | |
| 59 } | 60 } |
| 60 | 61 |
| 61 | 62 |
| 62 static inline int GetLength(const char* str) { | 63 static inline int GetLength(const char* str) { |
| 63 return strlen(str); | 64 return strlen(str); |
| 64 } | 65 } |
| 65 | 66 |
| 66 | 67 |
| 67 static inline int GetLength(String* str) { | 68 static inline int GetLength(String* str) { |
| 68 return str->length(); | 69 return str->length(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 | 72 |
| 72 static inline const char* GetCString(const char* str, int index) { | 73 static inline const char* GetCString(const char* str, int index) { |
| 73 return str + index; | 74 return str + index; |
| 74 } | 75 } |
| 75 | 76 |
| 76 | 77 |
| 77 static inline const char* GetCString(String* str, int index) { | 78 static inline const char* GetCString(String* str, int index) { |
| 78 char* result = NewArray<char>(str->length() + 1); | 79 StringShape shape(str); |
| 79 for (int i = index; i < str->length(); i++) { | 80 int length = str->length(shape); |
| 80 if (str->Get(i) <= 127) { | 81 char* result = NewArray<char>(length + 1); |
| 81 result[i - index] = static_cast<char>(str->Get(i)); | 82 for (int i = index; i < length; i++) { |
| 83 uc16 c = str->Get(shape, i); | |
| 84 if (c <= 127) { | |
| 85 result[i - index] = static_cast<char>(c); | |
| 82 } else { | 86 } else { |
| 83 result[i - index] = 127; // Force number parsing to fail. | 87 result[i - index] = 127; // Force number parsing to fail. |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 result[str->length() - index] = '\0'; | 90 result[length - index] = '\0'; |
| 87 return result; | 91 return result; |
| 88 } | 92 } |
| 89 | 93 |
| 90 | 94 |
| 91 static inline void ReleaseCString(const char* original, const char* str) { | 95 static inline void ReleaseCString(const char* original, const char* str) { |
| 92 } | 96 } |
| 93 | 97 |
| 94 | 98 |
| 95 static inline void ReleaseCString(String* original, const char* str) { | 99 static inline void ReleaseCString(String* original, const char* str) { |
| 96 DeleteArray(const_cast<char *>(str)); | 100 DeleteArray(const_cast<char *>(str)); |
| 97 } | 101 } |
| 98 | 102 |
| 99 | 103 |
| 100 static inline bool IsSpace(const char* str, int index) { | 104 static inline bool IsSpace(const char* str, int index) { |
| 101 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); | 105 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); |
| 102 return Scanner::kIsWhiteSpace.get(str[index]); | 106 return Scanner::kIsWhiteSpace.get(str[index]); |
| 103 } | 107 } |
| 104 | 108 |
| 105 | 109 |
| 106 static inline bool IsSpace(String* str, int index) { | 110 static inline bool IsSpace(String* str, int index) { |
| 107 return Scanner::kIsWhiteSpace.get(str->Get(index)); | 111 StringShape shape(str); |
| 112 return Scanner::kIsWhiteSpace.get(str->Get(shape, index)); | |
| 108 } | 113 } |
| 109 | 114 |
| 110 | 115 |
| 111 static inline bool SubStringEquals(const char* str, | 116 static inline bool SubStringEquals(const char* str, |
| 112 int index, | 117 int index, |
| 113 const char* other) { | 118 const char* other) { |
| 114 return strncmp(str + index, other, strlen(other)) != 0; | 119 return strncmp(str + index, other, strlen(other)) != 0; |
| 115 } | 120 } |
| 116 | 121 |
| 117 | 122 |
| 118 static inline bool SubStringEquals(String* str, int index, const char* other) { | 123 static inline bool SubStringEquals(String* str, int index, const char* other) { |
| 124 StringShape shape(str); | |
| 119 HandleScope scope; | 125 HandleScope scope; |
| 120 int len = strlen(other); | 126 int len = strlen(other); |
|
Mads Ager (chromium)
2008/11/03 08:45:49
Introduced other_len and str_len?
| |
| 121 int end = index + len < str->length() ? index + len : str->length(); | 127 int end = index + len < str->length(shape) ? index + len : str->length(shape); |
| 122 Handle<String> slice = | 128 Handle<String> slice = |
| 123 Factory::NewStringSlice(Handle<String>(str), index, end); | 129 Factory::NewStringSlice(Handle<String>(str), shape, index, end); |
| 124 return slice->IsEqualTo(Vector<const char>(other, len)); | 130 return slice->IsEqualTo(Vector<const char>(other, len)); |
| 125 } | 131 } |
| 126 | 132 |
| 127 | 133 |
| 128 // Check if a string should be parsed as an octal number. The string | 134 // Check if a string should be parsed as an octal number. The string |
| 129 // can be either a char* or a String*. | 135 // can be either a char* or a String*. |
| 130 template<class S> | 136 template<class S> |
| 131 static bool ShouldParseOctal(S* s, int i) { | 137 static bool ShouldParseOctal(S* s, int i) { |
| 132 int index = i; | 138 int index = i; |
| 133 int len = GetLength(s); | 139 int len = GetLength(s); |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 // Allocate result and fill in the parts. | 699 // Allocate result and fill in the parts. |
| 694 StringBuilder builder(result_size + 1); | 700 StringBuilder builder(result_size + 1); |
| 695 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 701 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
| 696 if (decimal_pos > 0) builder.AddCharacter('.'); | 702 if (decimal_pos > 0) builder.AddCharacter('.'); |
| 697 builder.AddSubstring(decimal_buffer, decimal_pos); | 703 builder.AddSubstring(decimal_buffer, decimal_pos); |
| 698 return builder.Finalize(); | 704 return builder.Finalize(); |
| 699 } | 705 } |
| 700 | 706 |
| 701 | 707 |
| 702 } } // namespace v8::internal | 708 } } // namespace v8::internal |
| OLD | NEW |