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 StringShape shape(str); | 58 return str->Get(index); |
59 return str->Get(shape, index); | |
60 } | 59 } |
61 | 60 |
62 | 61 |
63 static inline int GetLength(const char* str) { | 62 static inline int GetLength(const char* str) { |
64 return strlen(str); | 63 return strlen(str); |
65 } | 64 } |
66 | 65 |
67 | 66 |
68 static inline int GetLength(String* str) { | 67 static inline int GetLength(String* str) { |
69 return str->length(); | 68 return str->length(); |
70 } | 69 } |
71 | 70 |
72 | 71 |
73 static inline const char* GetCString(const char* str, int index) { | 72 static inline const char* GetCString(const char* str, int index) { |
74 return str + index; | 73 return str + index; |
75 } | 74 } |
76 | 75 |
77 | 76 |
78 static inline const char* GetCString(String* str, int index) { | 77 static inline const char* GetCString(String* str, int index) { |
79 StringShape shape(str); | 78 int length = str->length(); |
80 int length = str->length(shape); | |
81 char* result = NewArray<char>(length + 1); | 79 char* result = NewArray<char>(length + 1); |
82 for (int i = index; i < length; i++) { | 80 for (int i = index; i < length; i++) { |
83 uc16 c = str->Get(shape, i); | 81 uc16 c = str->Get(i); |
84 if (c <= 127) { | 82 if (c <= 127) { |
85 result[i - index] = static_cast<char>(c); | 83 result[i - index] = static_cast<char>(c); |
86 } else { | 84 } else { |
87 result[i - index] = 127; // Force number parsing to fail. | 85 result[i - index] = 127; // Force number parsing to fail. |
88 } | 86 } |
89 } | 87 } |
90 result[length - index] = '\0'; | 88 result[length - index] = '\0'; |
91 return result; | 89 return result; |
92 } | 90 } |
93 | 91 |
94 | 92 |
95 static inline void ReleaseCString(const char* original, const char* str) { | 93 static inline void ReleaseCString(const char* original, const char* str) { |
96 } | 94 } |
97 | 95 |
98 | 96 |
99 static inline void ReleaseCString(String* original, const char* str) { | 97 static inline void ReleaseCString(String* original, const char* str) { |
100 DeleteArray(const_cast<char *>(str)); | 98 DeleteArray(const_cast<char *>(str)); |
101 } | 99 } |
102 | 100 |
103 | 101 |
104 static inline bool IsSpace(const char* str, int index) { | 102 static inline bool IsSpace(const char* str, int index) { |
105 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); | 103 ASSERT(index >= 0 && index < static_cast<int>(strlen(str))); |
106 return Scanner::kIsWhiteSpace.get(str[index]); | 104 return Scanner::kIsWhiteSpace.get(str[index]); |
107 } | 105 } |
108 | 106 |
109 | 107 |
110 static inline bool IsSpace(String* str, int index) { | 108 static inline bool IsSpace(String* str, int index) { |
111 StringShape shape(str); | 109 return Scanner::kIsWhiteSpace.get(str->Get(index)); |
112 return Scanner::kIsWhiteSpace.get(str->Get(shape, index)); | |
113 } | 110 } |
114 | 111 |
115 | 112 |
116 static inline bool SubStringEquals(const char* str, | 113 static inline bool SubStringEquals(const char* str, |
117 int index, | 114 int index, |
118 const char* other) { | 115 const char* other) { |
119 return strncmp(str + index, other, strlen(other)) != 0; | 116 return strncmp(str + index, other, strlen(other)) != 0; |
120 } | 117 } |
121 | 118 |
122 | 119 |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 // Allocate result and fill in the parts. | 698 // Allocate result and fill in the parts. |
702 StringBuilder builder(result_size + 1); | 699 StringBuilder builder(result_size + 1); |
703 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 700 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
704 if (decimal_pos > 0) builder.AddCharacter('.'); | 701 if (decimal_pos > 0) builder.AddCharacter('.'); |
705 builder.AddSubstring(decimal_buffer, decimal_pos); | 702 builder.AddSubstring(decimal_buffer, decimal_pos); |
706 return builder.Finalize(); | 703 return builder.Finalize(); |
707 } | 704 } |
708 | 705 |
709 | 706 |
710 } } // namespace v8::internal | 707 } } // namespace v8::internal |
OLD | NEW |