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 <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Trevor Norris authored and Anna Henningsen committed 2016-08-08 21:37:37 +02:00
1 parent 75b37a6bac
commit 28071a130e
37 files changed
+246 -124

No files matched your search

+10 -4
View File
@@ -282,6 +282,7 @@ size_t StringBytes::Write(Isolate* isolate,
switch (encoding) {
case ASCII:
case LATIN1:
case BINARY:
if (is_extern && str->IsOneByte()) {
memcpy(buf, data, nbytes);
@@ -387,15 +388,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<String> str = val->ToString(isolate);
switch (encoding) {
case BINARY:
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;
@@ -436,7 +439,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;
@@ -446,8 +450,9 @@ size_t StringBytes::Size(Isolate* isolate,
Local<String> str = val->ToString(isolate);
switch (encoding) {
case BINARY:
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;
@@ -650,6 +655,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
buflen);
break;
case LATIN1:
case BINARY:
if (buflen < EXTERN_APEX)
val = OneByteString(isolate, buf, buflen);