V8 Project
v8::internal::URIEscape Class Reference
+ Inheritance diagram for v8::internal::URIEscape:
+ Collaboration diagram for v8::internal::URIEscape:

Public Member Functions

template<typename Char >
MaybeHandle< StringEscape (Isolate *isolate, Handle< String > string)
 

Static Public Member Functions

template<typename Char >
static MUST_USE_RESULT MaybeHandle< StringEscape (Isolate *isolate, Handle< String > string)
 

Static Private Member Functions

static bool IsNotEscaped (uint16_t c)
 

Static Private Attributes

static const char kHexChars [17] = "0123456789ABCDEF"
 
static const char kNotEscaped [256]
 

Detailed Description

Definition at line 175 of file runtime-uri.cc.

Member Function Documentation

◆ Escape() [1/2]

template<typename Char >
static MUST_USE_RESULT MaybeHandle<String> v8::internal::URIEscape::Escape ( Isolate isolate,
Handle< String string 
)
static

◆ Escape() [2/2]

template<typename Char >
MaybeHandle<String> v8::internal::URIEscape::Escape ( Isolate isolate,
Handle< String string 
)

Definition at line 218 of file runtime-uri.cc.

218  {
219  DCHECK(string->IsFlat());
220  int escaped_length = 0;
221  int length = string->length();
222 
223  {
224  DisallowHeapAllocation no_allocation;
225  Vector<const Char> vector = GetCharVector<Char>(string);
226  for (int i = 0; i < length; i++) {
227  uint16_t c = vector[i];
228  if (c >= 256) {
229  escaped_length += 6;
230  } else if (IsNotEscaped(c)) {
231  escaped_length++;
232  } else {
233  escaped_length += 3;
234  }
235 
236  // We don't allow strings that are longer than a maximal length.
237  DCHECK(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
238  if (escaped_length > String::kMaxLength) break; // Provoke exception.
239  }
240  }
241 
242  // No length change implies no change. Return original string if no change.
243  if (escaped_length == length) return string;
244 
245  Handle<SeqOneByteString> dest;
247  isolate, dest, isolate->factory()->NewRawOneByteString(escaped_length),
248  String);
249  int dest_position = 0;
250 
251  {
252  DisallowHeapAllocation no_allocation;
253  Vector<const Char> vector = GetCharVector<Char>(string);
254  for (int i = 0; i < length; i++) {
255  uint16_t c = vector[i];
256  if (c >= 256) {
257  dest->SeqOneByteStringSet(dest_position, '%');
258  dest->SeqOneByteStringSet(dest_position + 1, 'u');
259  dest->SeqOneByteStringSet(dest_position + 2, kHexChars[c >> 12]);
260  dest->SeqOneByteStringSet(dest_position + 3, kHexChars[(c >> 8) & 0xf]);
261  dest->SeqOneByteStringSet(dest_position + 4, kHexChars[(c >> 4) & 0xf]);
262  dest->SeqOneByteStringSet(dest_position + 5, kHexChars[c & 0xf]);
263  dest_position += 6;
264  } else if (IsNotEscaped(c)) {
265  dest->SeqOneByteStringSet(dest_position, c);
266  dest_position++;
267  } else {
268  dest->SeqOneByteStringSet(dest_position, '%');
269  dest->SeqOneByteStringSet(dest_position + 1, kHexChars[c >> 4]);
270  dest->SeqOneByteStringSet(dest_position + 2, kHexChars[c & 0xf]);
271  dest_position += 3;
272  }
273  }
274  }
275 
276  return dest;
277 }
static const int kMaxLength
Definition: objects.h:8820
static bool IsNotEscaped(uint16_t c)
Definition: runtime-uri.cc:185
static const char kHexChars[17]
Definition: runtime-uri.cc:182
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)
Definition: isolate.h:135
#define DCHECK(condition)
Definition: logging.h:205
unsigned short uint16_t
Definition: unicode.cc:23
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110

References ASSIGN_RETURN_ON_EXCEPTION, DCHECK, v8::internal::Isolate::factory(), IsNotEscaped(), kHexChars, and v8::internal::String::kMaxLength.

+ Here is the call graph for this function:

◆ IsNotEscaped()

static bool v8::internal::URIEscape::IsNotEscaped ( uint16_t  c)
inlinestaticprivate

Definition at line 185 of file runtime-uri.cc.

185 { return kNotEscaped[c] != 0; }
static const char kNotEscaped[256]
Definition: runtime-uri.cc:183

References kNotEscaped.

Referenced by Escape().

+ Here is the caller graph for this function:

Member Data Documentation

◆ kHexChars

const char v8::internal::URIEscape::kHexChars = "0123456789ABCDEF"
staticprivate

Definition at line 182 of file runtime-uri.cc.

Referenced by Escape().

◆ kNotEscaped

const char v8::internal::URIEscape::kNotEscaped
staticprivate
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Definition at line 183 of file runtime-uri.cc.

Referenced by IsNotEscaped().


The documentation for this class was generated from the following file: