Skip to content

Commit be36153

Browse files
committed
content [nfc]: Move tryParseEmojiCodeToUnicode out to toplevel, to export
1 parent 69574ae commit be36153

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/model/content.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,27 @@ class ImageEmojiNode extends EmojiNode {
495495

496496
////////////////////////////////////////////////////////////////
497497
498+
// Ported from https://github.com/zulip/zulip-mobile/blob/c979530d6804db33310ed7d14a4ac62017432944/src/emoji/data.js#L108-L112
499+
//
500+
// Which was in turn ported from https://github.com/zulip/zulip/blob/63c9296d5339517450f79f176dc02d77b08020c8/zerver/models.py#L3235-L3242
501+
// and that describes the encoding as follows:
502+
//
503+
// > * For Unicode emoji, [emoji_code is] a dash-separated hex encoding of
504+
// > the sequence of Unicode codepoints that define this emoji in the
505+
// > Unicode specification. For examples, see "non_qualified" or
506+
// > "unified" in the following data, with "non_qualified" taking
507+
// > precedence when both present:
508+
// > https://github.com/raw/iamcal/emoji-data/master/emoji_pretty.json
509+
String? tryParseEmojiCodeToUnicode(String code) {
510+
try {
511+
return String.fromCharCodes(code.split('-').map((hex) => int.parse(hex, radix: 16)));
512+
} on FormatException { // thrown by `int.parse`
513+
return null;
514+
} on ArgumentError { // thrown by `String.fromCharCodes`
515+
return null;
516+
}
517+
}
518+
498519
/// What sort of nodes a [_ZulipContentParser] is currently expecting to find.
499520
enum _ParserContext {
500521
/// The parser is currently looking for block nodes.
@@ -525,27 +546,6 @@ class _ZulipContentParser {
525546

526547
static final _emojiClassRegexp = RegExp(r"^emoji(-[0-9a-f]+)*$");
527548

528-
// Ported from https://github.com/zulip/zulip-mobile/blob/c979530d6804db33310ed7d14a4ac62017432944/src/emoji/data.js#L108-L112
529-
//
530-
// Which was in turn ported from https://github.com/zulip/zulip/blob/63c9296d5339517450f79f176dc02d77b08020c8/zerver/models.py#L3235-L3242
531-
// and that describes the encoding as follows:
532-
//
533-
// > * For Unicode emoji, [emoji_code is] a dash-separated hex encoding of
534-
// > the sequence of Unicode codepoints that define this emoji in the
535-
// > Unicode specification. For examples, see "non_qualified" or
536-
// > "unified" in the following data, with "non_qualified" taking
537-
// > precedence when both present:
538-
// > https://github.com/raw/iamcal/emoji-data/master/emoji_pretty.json
539-
String? tryParseEmojiCodeToUnicode(String code) {
540-
try {
541-
return String.fromCharCodes(code.split('-').map((hex) => int.parse(hex, radix: 16)));
542-
} on FormatException { // thrown by `int.parse`
543-
return null;
544-
} on ArgumentError { // thrown by `String.fromCharCodes`
545-
return null;
546-
}
547-
}
548-
549549
InlineContentNode parseInlineContent(dom.Node node) {
550550
assert(_debugParserContext == _ParserContext.inline);
551551
final debugHtmlNode = kDebugMode ? node : null;

0 commit comments

Comments
 (0)