From 54cc7212df320f1e489edf8dbeabb167a71cbe67 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Thu, 2 Jun 2016 10:55:36 -0600 Subject: buffer: introduce latin1 encoding term When node began using the OneByte API (f150d56) it also switched to officially supporting ISO-8859-1. Though at the time no new encoding string was introduced. Introduce the new encoding string 'latin1' to be more explicit. The previous 'binary' and documented as an alias to 'latin1'. While many tests have switched to use 'latin1', there are still plenty that do both 'binary' and 'latin1' checks side-by-side to ensure there is no regression. PR-URL: https://github.com/nodejs/node/pull/7111 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/string_bytes.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/string_bytes.cc') diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 8a327deac2..6454e11323 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -271,6 +271,7 @@ size_t StringBytes::Write(Isolate* isolate, switch (encoding) { case ASCII: + case LATIN1: case BINARY: if (is_extern && str->IsOneByte()) { memcpy(buf, data, nbytes); @@ -376,15 +377,17 @@ size_t StringBytes::StorageSize(Isolate* isolate, size_t data_size = 0; bool is_buffer = Buffer::HasInstance(val); - if (is_buffer && (encoding == BUFFER || encoding == BINARY)) { + if (is_buffer && + (encoding == BUFFER || encoding == BINARY || encoding == LATIN1)) { return Buffer::Length(val); } Local str = val->ToString(isolate); switch (encoding) { - case BINARY: case ASCII: + case LATIN1: + case BINARY: data_size = str->Length(); break; @@ -425,7 +428,8 @@ size_t StringBytes::Size(Isolate* isolate, size_t data_size = 0; bool is_buffer = Buffer::HasInstance(val); - if (is_buffer && (encoding == BUFFER || encoding == BINARY)) + if (is_buffer && + (encoding == BUFFER || encoding == BINARY || encoding == LATIN1)) return Buffer::Length(val); const char* data; @@ -435,8 +439,9 @@ size_t StringBytes::Size(Isolate* isolate, Local str = val->ToString(isolate); switch (encoding) { - case BINARY: case ASCII: + case LATIN1: + case BINARY: data_size = str->Length(); break; @@ -639,6 +644,7 @@ Local StringBytes::Encode(Isolate* isolate, buflen); break; + case LATIN1: case BINARY: if (buflen < EXTERN_APEX) val = OneByteString(isolate, buf, buflen); -- cgit v1.2.3