aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/binary
diff options
context:
space:
mode:
authorGravatar Wojciech Mandrysz <tetek1@gmail.com>2016-11-15 14:08:49 +0100
committerGravatar Wojciech Mandrysz <tetek1@gmail.com>2016-11-15 14:10:09 +0100
commitbd850a25f51dfb662a761473c151c016c815bcb5 (patch)
tree7ba6250aaf3189b0857d013a86356aea7c7b4c36 /js/binary
parent292c2c91cfc16eda5dc8f835ef6073febef118e5 (diff)
JS: Well, this is the right place for surrogates.
Diffstat (limited to 'js/binary')
-rw-r--r--js/binary/encoder.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/js/binary/encoder.js b/js/binary/encoder.js
index a9d09d72..d952d714 100644
--- a/js/binary/encoder.js
+++ b/js/binary/encoder.js
@@ -426,17 +426,19 @@ jspb.BinaryEncoder.prototype.writeString = function(value) {
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
c = (c - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
+
+ this.buffer_.push((c >> 18) | 240);
+ this.buffer_.push(((c >> 12) & 63 ) | 128);
+ this.buffer_.push(((c >> 6) & 63) | 128);
+ this.buffer_.push((c & 63) | 128);
+ i++;
}
}
- this.buffer_.push((c >> 12) | 224);
- this.buffer_.push(((c >> 6) & 63) | 128);
- this.buffer_.push((c & 63) | 128);
- } else {
- this.buffer_.push((c >> 18) | 240);
- this.buffer_.push(((c >> 12) & 63 ) | 128);
- this.buffer_.push(((c >> 6) & 63) | 128);
- this.buffer_.push((c & 63) | 128);
- i++;
+ else {
+ this.buffer_.push((c >> 12) | 224);
+ this.buffer_.push(((c >> 6) & 63) | 128);
+ this.buffer_.push((c & 63) | 128);
+ }
}
}