Skip to content

Commit

Permalink
JS: Well, this is the right place for surrogates.
Browse files Browse the repository at this point in the history
  • Loading branch information
tetek committed Nov 15, 2016
1 parent 292c2c9 commit bd850a2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions js/binary/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit bd850a2

Please sign in to comment.