[gnome-characters] Fix the code point of characters outside the BMP
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters] Fix the code point of characters outside the BMP
- Date: Wed, 4 Mar 2015 02:54:47 +0000 (UTC)
commit edd7c95375a0abd365dbeaeb939bc9de83e19f6c
Author: Giovanni Campagna <scampa giovanni gmail com>
Date: Tue Mar 3 01:36:20 2015 -0800
Fix the code point of characters outside the BMP
Strings in JS are in UTF-16, so we need to resolve surrogate
pairs into full UTF-32 code points. We can't use glib functions
to do so because gunichar is translated back into a String by
gjs.
https://bugzilla.gnome.org/show_bug.cgi?id=745508
src/character.js | 2 +-
src/searchProvider.js | 2 +-
src/util.js | 11 +++++++++++
3 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/character.js b/src/character.js
index 71c1064..d39e663 100644
--- a/src/character.js
+++ b/src/character.js
@@ -109,7 +109,7 @@ const CharacterDialog = new Lang.Class({
this._character = this._character;
this._character_label.label = this._character;
- let codePoint = this._character.charCodeAt(0);
+ let codePoint = Util.toCodePoint(this._character);
let codePointHex = codePoint.toString(16).toUpperCase();
this._detail_label.label = _("Unicode U+%04s").format(codePointHex);
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 7f3df75..4e11421 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -84,7 +84,7 @@ const SearchProvider = new Lang.Class({
for (let i = 0; i < identifiers.length; i++) {
let character = identifiers[i];
- let codePoint = character.charCodeAt(0);
+ let codePoint = Util.toCodePoint(character);
let codePointHex = codePoint.toString(16).toUpperCase();
let name = Gc.character_name(character);
if (name == null)
diff --git a/src/util.js b/src/util.js
index 72dbcad..90ecc77 100644
--- a/src/util.js
+++ b/src/util.js
@@ -131,3 +131,14 @@ function capitalize(s) {
return w;
}).join(' ');
}
+
+function toCodePoint(s) {
+ let codePoint = s.charCodeAt(0);
+ if (codePoint > 0xD800) {
+ let high = codePoint;
+ let low = s.charCodeAt(1);
+ codePoint = 0x10000 + (high - 0xD800) * 0x400 + (low - 0xDC00);
+ }
+
+ return codePoint;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]