From 63fc6a63c8046081099aa1dadf9155398a498163 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Tue, 2 Jul 2013 00:07:47 -0700 Subject: [PATCH] string_bytes: export GetExternalParts The method is useful elsewhere when needing to check if external and grab data. --- src/string_bytes.cc | 5 +++-- src/string_bytes.h | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 64a2937..492c135 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -230,12 +230,13 @@ size_t hex_decode(char* buf, } -bool GetExternalParts(Handle val, const char** data, size_t* len) { +bool StringBytes::GetExternalParts(Handle val, + const char** data, + size_t* len) { if (Buffer::HasInstance(val)) { *data = Buffer::Data(val); *len = Buffer::Length(val); return true; - } assert(val->IsString()); diff --git a/src/string_bytes.h b/src/string_bytes.h index 7d861ff..aa32aea 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -44,6 +44,12 @@ class StringBytes { // very much slower for UTF-8 static size_t Size(v8::Handle val, enum encoding enc); + // If the string is external then assign external properties to data and len, + // then return true. If not return false. + static bool GetExternalParts(v8::Handle val, + const char** data, + size_t* len); + // Write the bytes from the string or buffer into the char* // returns the number of bytes written, which will always be // <= buflen. Use StorageSize/Size first to know how much -- 2.7.4