summaryrefslogtreecommitdiff
path: root/src/string_bytes.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-06-29 07:16:46 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-07-06 17:44:44 +0200
commit8985bb8bfd0c4b9fa8dcf001306f1cf7e6c886b4 (patch)
tree471fb455d8bc258fb5b2aa745c48fe3020dc61a1 /src/string_bytes.cc
parent110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea (diff)
downloadandroid-node-v8-8985bb8bfd0c4b9fa8dcf001306f1cf7e6c886b4.tar.gz
android-node-v8-8985bb8bfd0c4b9fa8dcf001306f1cf7e6c886b4.tar.bz2
android-node-v8-8985bb8bfd0c4b9fa8dcf001306f1cf7e6c886b4.zip
string_bytes: stop using String::AsciiValue
Debug builds of V8 now actively check that the string only contains ASCII characters (i.e. doesn't contain bytes with the high bit set.)
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r--src/string_bytes.cc32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc
index fcea165fed..d389959fe7 100644
--- a/src/string_bytes.cc
+++ b/src/string_bytes.cc
@@ -124,7 +124,8 @@ static inline size_t base64_decoded_size_fast(size_t size) {
return size;
}
-static inline size_t base64_decoded_size(const char* src, size_t size) {
+template <typename TypeName>
+size_t base64_decoded_size(const TypeName* src, size_t size) {
if (size == 0)
return 0;
@@ -159,14 +160,15 @@ static const int unbase64_table[] =
#define unbase64(x) unbase64_table[(uint8_t)(x)]
-static inline size_t base64_decode(char* buf,
- size_t len,
- const char* src,
- const size_t srcLen) {
+template <typename TypeName>
+size_t base64_decode(char* buf,
+ size_t len,
+ const TypeName* src,
+ const size_t srcLen) {
char a, b, c, d;
char* dst = buf;
char* dstEnd = buf + len;
- const char* srcEnd = src + srcLen;
+ const TypeName* srcEnd = src + srcLen;
while (src < srcEnd && dst < dstEnd) {
int remaining = srcEnd - src;
@@ -202,7 +204,8 @@ static inline size_t base64_decode(char* buf,
//// HEX ////
-static inline unsigned hex2bin(char c) {
+template <typename TypeName>
+unsigned hex2bin(TypeName c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
@@ -210,10 +213,11 @@ static inline unsigned hex2bin(char c) {
}
-static inline size_t hex_decode(char* buf,
- size_t len,
- const char* src,
- const size_t srcLen) {
+template <typename TypeName>
+size_t hex_decode(char* buf,
+ size_t len,
+ const TypeName* src,
+ const size_t srcLen) {
size_t i;
for (i = 0; i < len && i * 2 + 1 < srcLen; ++i) {
unsigned a = hex2bin(src[i * 2 + 0]);
@@ -305,7 +309,7 @@ size_t StringBytes::Write(char* buf,
if (is_extern) {
base64_decode(buf, buflen, data, len);
} else {
- String::AsciiValue value(str);
+ String::Value value(str);
len = base64_decode(buf, buflen, *value, value.length());
}
if (chars_written != NULL) {
@@ -317,7 +321,7 @@ size_t StringBytes::Write(char* buf,
if (is_extern) {
hex_decode(buf, buflen, data, len);
} else {
- String::AsciiValue value(str);
+ String::Value value(str);
len = hex_decode(buf, buflen, *value, value.length());
}
if (chars_written != NULL) {
@@ -411,7 +415,7 @@ size_t StringBytes::Size(Handle<Value> val, enum encoding encoding) {
break;
case BASE64: {
- String::AsciiValue value(str);
+ String::Value value(str);
data_size = base64_decoded_size(*value, value.length());
break;
}