41 template <
typename Char>
63 template<
typename Char>
67 static const signed char kHexValue[
'g'];
69 template<
typename Char>
75 template <
typename Char>
83 const signed char URIUnescape::kHexValue[] = {
84 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
85 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
87 -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
88 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90 -1, 10, 11, 12, 13, 14, 15 };
93 template<
typename Char>
98 index = search.
Search(GetCharVector<Char>(source), 0);
99 if (index < 0)
return source;
101 return UnescapeSlow<Char>(isolate, source, index);
105 template <
typename Char>
108 bool one_byte =
true;
109 int length =
string->length();
111 int unescaped_length = 0;
114 for (
int i = start_index; i < length; unescaped_length++) {
116 if (UnescapeChar(vector, i, length, &step) >
124 ASSERT(start_index < length);
125 Handle<String> first_part =
128 int dest_position = 0;
129 Handle<String> second_part;
132 Handle<SeqOneByteString> dest =
136 Vector<const Char> vector = GetCharVector<Char>(string);
137 for (
int i = start_index; i < length; dest_position++) {
139 dest->SeqOneByteStringSet(dest_position,
140 UnescapeChar(vector, i, length, &step));
145 Handle<SeqTwoByteString> dest =
149 Vector<const Char> vector = GetCharVector<Char>(string);
150 for (
int i = start_index; i < length; dest_position++) {
152 dest->SeqTwoByteStringSet(dest_position,
153 UnescapeChar(vector, i, length, &step));
163 if (character1 >
'f')
return -1;
164 int hi = kHexValue[character1];
165 if (hi == -1)
return -1;
166 if (character2 >
'f')
return -1;
167 int lo = kHexValue[character2];
168 if (lo == -1)
return -1;
169 return (hi << 4) +
lo;
173 template <
typename Char>
174 int URIUnescape::UnescapeChar(Vector<const Char> vector,
181 if (character ==
'%' &&
183 vector[i + 1] ==
'u' &&
184 (hi = TwoDigitHex(vector[i + 2],
185 vector[i + 3])) != -1 &&
186 (lo = TwoDigitHex(vector[i + 4],
187 vector[i + 5])) != -1) {
189 return (hi << 8) +
lo;
190 }
else if (character ==
'%' &&
192 (lo = TwoDigitHex(vector[i + 1],
193 vector[i + 2])) != -1) {
205 template<
typename Char>
209 static const char kHexChars[17];
210 static const char kNotEscaped[256];
212 static bool IsNotEscaped(
uint16_t c) {
return kNotEscaped[c] != 0; }
216 const char URIEscape::kHexChars[] =
"0123456789ABCDEF";
230 const char URIEscape::kNotEscaped[] = {
231 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
233 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,
234 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
235 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
236 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
237 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
238 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
249 template<
typename Char>
252 int escaped_length = 0;
253 int length =
string->length();
257 for (
int i = 0; i < length; i++) {
261 }
else if (IsNotEscaped(c)) {
274 if (escaped_length == length)
return string;
279 int dest_position = 0;
283 for (
int i = 0; i < length; i++) {
286 dest->SeqOneByteStringSet(dest_position,
'%');
287 dest->SeqOneByteStringSet(dest_position+1,
'u');
288 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]);
289 dest->SeqOneByteStringSet(dest_position+3, kHexChars[(c >> 8) & 0xf]);
290 dest->SeqOneByteStringSet(dest_position+4, kHexChars[(c >> 4) & 0xf]);
291 dest->SeqOneByteStringSet(dest_position+5, kHexChars[c & 0xf]);
293 }
else if (IsNotEscaped(c)) {
294 dest->SeqOneByteStringSet(dest_position, c);
297 dest->SeqOneByteStringSet(dest_position,
'%');
298 dest->SeqOneByteStringSet(dest_position+1, kHexChars[c >> 4]);
299 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c & 0xf]);
Vector< const uint8_t > GetCharVector(Handle< String > string)
static Handle< String > Unescape(Isolate *isolate, Handle< String > source)
int Search(Vector< const SubjectChar > subject, int index)
#define ASSERT(condition)
#define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value)
Handle< SeqTwoByteString > NewRawTwoByteString(int length, PretenureFlag pretenure=NOT_TENURED)
Vector< const uc16 > ToUC16Vector()
static Handle< String > Escape(Isolate *isolate, Handle< String > string)
#define STATIC_ASCII_VECTOR(x)
Handle< String > NewProperSubString(Handle< String > str, int begin, int end)
INLINE(static HeapObject *EnsureDoubleAligned(Heap *heap, HeapObject *object, int size))
Handle< SeqOneByteString > NewRawOneByteString(int length, PretenureFlag pretenure=NOT_TENURED)
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Handle< String > NewConsString(Handle< String > left, Handle< String > right)
static const int kMaxLength
Vector< const uint8_t > ToOneByteVector()
static const int32_t kMaxOneByteCharCode