diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-30 14:26:11 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-30 14:32:47 +0200 |
commit | dce26ccea16455179ca538f32d2779cfbf20c51b (patch) | |
tree | e94e848a9bd89ea7c2f6e45d8d230edba01abdbf /src/string_bytes.cc | |
parent | 4881a6a9a3b4e466f852ab9b3a084f7c4a55d8b5 (diff) | |
download | android-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.cc')
-rw-r--r-- | src/string_bytes.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index a2ee589bfa..e4a34fee0e 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -257,6 +257,13 @@ size_t StringBytes::Write(char* buf, } +bool StringBytes::IsValidString(Handle<String> string, enum encoding enc) { + if (enc == HEX && string->Length() % 2 != 0) return false; + // TODO(bnoordhuis) Add BASE64 check? + return true; +} + + // Quick and dirty size calculation // Will always be at least big enough, but may have some extra // UTF8 can be as much as 3x the size, Base64 can have 1-2 extra bytes |