JS: Well, this is the right place for surrogates.

pull/1907/head
Wojciech Mandrysz 8 years ago
parent 292c2c91cf
commit bd850a25f5
  1. 14
      js/binary/encoder.js

@ -426,12 +426,7 @@ jspb.BinaryEncoder.prototype.writeString = function(value) {
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
c = (c - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; c = (c - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
}
}
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 >> 18) | 240);
this.buffer_.push(((c >> 12) & 63 ) | 128); this.buffer_.push(((c >> 12) & 63 ) | 128);
this.buffer_.push(((c >> 6) & 63) | 128); this.buffer_.push(((c >> 6) & 63) | 128);
@ -439,6 +434,13 @@ jspb.BinaryEncoder.prototype.writeString = function(value) {
i++; i++;
} }
} }
else {
this.buffer_.push((c >> 12) | 224);
this.buffer_.push(((c >> 6) & 63) | 128);
this.buffer_.push((c & 63) | 128);
}
}
}
var length = this.buffer_.length - oldLength; var length = this.buffer_.length - oldLength;
return length; return length;

Loading…
Cancel
Save