summaryrefslogtreecommitdiff
path: root/src/string_bytes.h
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-07-30 14:26:11 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-07-30 14:32:47 +0200
commitdce26ccea16455179ca538f32d2779cfbf20c51b (patch)
treee94e848a9bd89ea7c2f6e45d8d230edba01abdbf /src/string_bytes.h
parent4881a6a9a3b4e466f852ab9b3a084f7c4a55d8b5 (diff)
downloadandroid-node-v8-dce26ccea16455179ca538f32d2779cfbf20c51b.tar.gz
android-node-v8-dce26ccea16455179ca538f32d2779cfbf20c51b.tar.bz2
android-node-v8-dce26ccea16455179ca538f32d2779cfbf20c51b.zip
string_bytes: add StringBytes::IsValidString()
Performs a quick, non-exhaustive check on the input string to see if it's compatible with the specified string encoding. Curently it only checks that hex strings have a length that is a multiple of two.
Diffstat (limited to 'src/string_bytes.h')
-rw-r--r--src/string_bytes.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/string_bytes.h b/src/string_bytes.h
index 05d9277d0e..8071a494ae 100644
--- a/src/string_bytes.h
+++ b/src/string_bytes.h
@@ -36,6 +36,11 @@ using v8::Value;
class StringBytes {
public:
+ // Does the string match the encoding? Quick but non-exhaustive.
+ // Example: a HEX string must have a length that's a multiple of two.
+ // FIXME(bnoordhuis) IsMaybeValidString()? Naming things is hard...
+ static bool IsValidString(Handle<String> string, enum encoding enc);
+
// Fast, but can be 2 bytes oversized for Base64, and
// as much as triple UTF-8 strings <= 65536 chars in length
static size_t StorageSize(Handle<Value> val, enum encoding enc);