패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.1.9

unicode

http://www.unicode.org 에서 자동 생성된 유니코드 문자 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
142만
좋아요
9
Pub 점수
155

패키지 설치

flutter pub add unicode

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

유니코드 패키지는 공식 유니코드 컨소시엄 데이터베이스에서 자동으로 생성된 포괄적인 유니코드 문자 라이브러리를 제공합니다. 개발자들이 이모지, 기호, 국제 문자 체계 등 다양한 문자를 플러터 애플리케이션 내에서 쉽게 접근하고 사용할 수 있도록 합니다. 풍부한 텍스트 렌더링, 다국어 지원 또는 이모지 통합이 필요한 앱에 특히 유용합니다. 이 패키지는 플랫폼 독립적이며 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 주요 모든 플랫폼을 지원합니다.

사용 사례

  • UI에서 이모티콘 표시하기
  • 다국어 텍스트 지원
  • 특수 기호 렌더링
  • 풍부한 텍스트 편집기 구축
  • 국제화 (i18n)

주요 기능

  • 유니코드 협회에서 자동 생성
  • 포괄적인 문자 커버리지
  • 크로스 플랫폼 호환성
  • 문자 검색을 위한 간단한 API
  • 이모티콘 및 스크립트 다양성 지원

적합한 대상

  • 이모지 지원이 필요한 앱
  • 다국어 애플리케이션
  • 텍스트 처리 도구
  • 다양한 문자 체계를 갖춘 교육 앱
  • 특수 문자를 포함한 UI 컴포넌트

고려 사항

  • 광범위한 데이터로 인해 패키지 크기가 큽니다
  • 모든 문자를 로드할 때 성능에 미치는 잠재적 영향
  • 실시간 캐릭터 생성에 최적화되지 않음
  • 검색 외의 맞춤 설정 제한
  • 메모리 제약이 있는 환경에서는 신중한 조작이 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

unicode

Unicode characters library auto generated from http://www.unicode.org.

Version 1.1.9

Unicode Version 17.0.0

Examples:

example/example.dart

import 'package:unicode/blocks.dart';
import 'package:unicode/unicode.dart' as unicode;

void main(List<String> args) {
  var ch = unicode.toRune('я');
  if (unicode.isLowerCaseLetter(ch)) {
    print('${ch.s} is lowercase letter');
  }

  ch = unicode.toRune('{');
  if (unicode.isOpenPunctuation(ch)) {
    print('${ch.s} is open punctuation');
  }

  ch = unicode.toRune('©');
  if (unicode.isOtherSymbol(ch)) {
    print('${ch.s} is other symbol');
  }

  ch = unicode.toRune('ǁ');
  if (unicode.isOtherLetter(ch)) {
    print('${ch.s} is other letter');
  }

  ch = 'ソ'.c;
  final block = getUnicodeBlock(ch);
  if (block == UnicodeBlock.katakana) {
    print('${ch.s} is katakana');
  }

  ch = unicode.charToTitleCase(unicode.toRune('dž'));
  print('${ch.s} is title case of dž');

  ch = unicode.charToUpperCase(unicode.toRune('dž'));
  print('${ch.s} is upper case of dž');
}

extension on String {
  int get c => unicode.toRune(this);
}

extension on int {
  String get s => String.fromCharCode(this);
}

Output:

я is lowercase letter
{ is open punctuation
© is other symbol
ǁ is other letter
ソ is katakana
Dž is title case of dž
DŽ is upper case of dž

example\emoji\decompose_characters.dart

import 'package:unicode/decomposer.dart';
import 'package:unicode/decomposers/circle.dart';
import 'package:unicode/decomposers/font.dart';
import 'package:unicode/decomposers/wide.dart';
import 'package:unicode/unicode.dart' as unicode;

void main(List<String> args) {
  const s1 =
      '𝑻𝒉𝒆 ℚ𝕦𝕚𝕔𝕜 Brown 🅵🅾🆇 𝔍𝔲𝔪𝔭𝔢𝔡 ⓞⓥⓔⓡ ʇɥǝ 𝗟𝗮𝘇𝘆 𝙳𝚘𝚐';
  final s2 = decompose(s1, _decomposers);
  print(s1);
  print(s2);
}

final _decomposer1 = LetterMappingDecomposer([
  ('ʇ'.c, 't'.c),
  ('ɥ'.c, 'h'.c),
  ('ǝ'.c, 'e'.c),
]);

final _decomposer2 = LetterCasingDecomposer([
  ('🅰'.c, '🆉'.c, 'A'.c - '🅰'.c),
]);

final _decomposers = [
  const FontDecomposer(),
  const WideDecomposer(),
  const CircleDecomposer(),
  _decomposer2,
  _decomposer1,
];

extension on String {
  int get c => unicode.toRune(this);
}

Output:

𝑻𝒉𝒆 ℚ𝕦𝕚𝕔𝕜 Brown 🅵🅾🆇 𝔍𝔲𝔪𝔭𝔢𝔡 ⓞⓥⓔⓡ ʇɥǝ 𝗟𝗮𝘇𝘆 𝙳𝚘𝚐
The Quick Brown FOX Jumped over the Lazy Dog

example/get_emoji_by_name.dart

import 'dart:math';

import 'package:unicode/emoji/emoji.dart';

void main(List<String> args) {
  // The full names can be found here
  // https://unicode.org/Public/emoji/latest/emoji-test.txt
  print(heartWithArrow);
  print(raisedBackOfHand);
  print(smilingFaceWithHearts);
  print(redHeart);
  print(redHeartUnqualified);

  print('I $redHeart you!');

  final names = getUnicodeEmojiList().map((e) => e.name).toList();
  final names2 = <String>[];
  final r = Random();
  for (var i = 0; i < 10000; i++) {
    final value = r.nextInt(names.length - 1);
    names2.add(names[value]);
  }

  final sw = Stopwatch();
  sw.start();
  for (var i = 0; i < names2.length; i++) {
    final name = names2[i];
    // ignore: unused_local_variable
    final element = Emoji.findByName(name);
  }

  sw.stop();
  print('''
Performance test:
Info: Emoji.getByName()
Number of calls: ${names2.length}
Elapsed time (sec): ${sw.elapsedMilliseconds / 1000}''');
}

final heartWithArrow = _findEmoji('heart with arrow');

final raisedBackOfHand = _findEmoji('raised back of hand: light skin tone');

final redHeart = _findEmoji('red heart');

final redHeartUnqualified =
    _findEmoji('red heart', status: EmojiStatus.unqualified);

final smilingFaceWithHearts = _findEmoji('smiling face with hearts');

String _findEmoji(String fullname, {EmojiStatus? status}) {
  final emoji = Emoji.findByName(fullname, status: status);
  return emoji == null ? '�' : String.fromCharCodes(emoji.codePoints);
}

Output

💘
🤚🏻
🥰
❤️
❤
I ❤️ you!
Performance test:
Info: Emoji.getByName()
Number of calls: 10000
Elapsed time (sec): 0.015

example/info_about_all_emoji.dart

import 'package:unicode/emoji/emoji.dart';

void main(List<String> args) {
  final emojis = getUnicodeEmojiList();
  final groups = <String, Set<String>>{};
  final names = <String>[];
  for (final element in emojis) {
    (groups[element.group] ??= {}).add(element.subgroup);
    names.add(element.name);
  }

  print('Total number of emojis: ${emojis.length}');
  print('Total number of unique emojis: ${names.toSet().length}');

  for (final group in groups.entries) {
    print(
        '${group.key}:\n${group.value.map((e) => '- $e (${e.length})').join('\n')}');
  }
}

Output:

Total number of emojis: 5225
Total number of unique emojis: 3953
Activities:
- award-medal (11)
- event (5)
- sport (5)
- arts & crafts (13)
- game (4)
Symbols:
- alphanum (8)
- transport-sign (14)
- zodiac (6)
- arrow (5)
- other-symbol (12)
- av-symbol (9)
- religion (8)
- warning (7)
- geometric (9)
- currency (8)
- math (4)
- punctuation (11)
- gender (6)
- keycap (6)
Travel & Places:
- place-building (14)
- transport-air (13)
- time (4)
- transport-ground (16)
- transport-water (15)
- place-other (11)
- place-geographic (16)
- hotel (5)
- place-religious (15)
- sky & weather (13)
- place-map (9)
People & Body:
- person-fantasy (14)
- hand-fingers-partial (20)
- body-parts (10)
- person-role (11)
- person (6)
- hand-single-finger (18)
- person-activity (15)
- person-symbol (13)
- hands (5)
- family (6)
- person-gesture (14)
- hand-fingers-open (17)
- person-sport (12)
- hand-fingers-closed (19)
- person-resting (14)
- hand-prop (9)
Animals & Nature:
- animal-reptile (14)
- animal-bug (10)
- animal-bird (11)
- animal-mammal (13)
- plant-flower (12)
- animal-marine (13)
- plant-other (11)
- animal-amphibian (16)
Smileys & Emotion:
- emotion (7)
- face-costume (12)
- face-negative (13)
- face-concerned (14)
- face-smiling (12)
- heart (5)
- cat-face (8)
- face-unwell (11)
- face-hat (8)
- face-neutral-skeptical (22)
- face-sleepy (11)
- face-affection (14)
- face-tongue (11)
- face-hand (9)
- face-glasses (12)
- monkey-face (11)
Objects:
- computer (8)
- musical-instrument (18)
- medical (7)
- science (7)
- tool (4)
- clothing (8)
- mail (4)
- office (6)
- household (9)
- sound (5)
- writing (7)
- book-paper (10)
- light & video (13)
- money (5)
- other-object (12)
- music (5)
- phone (5)
- lock (4)
Food & Drink:
- dishware (8)
- food-vegetable (14)
- drink (5)
- food-prepared (13)
- food-fruit (10)
- food-asian (10)
- food-sweet (10)
Component:
- hair-style (10)
- skin-tone (9)
Flags:
- flag (4)
- country-flag (12)
- subdivision-flag (16)

example\emoji\remove_emoji.dart

import 'package:sequence_processor/sequence_processor.dart';
import 'package:unicode/emoji/emoji.dart';

void main(List<String> args) {
  const str = 'I 💗 you! 😘❤️‍🔥 ';
  print(str);
  print(_removeEmoji(str));
}

// Should be stored in a static member for performance reasons.
final _emojiProcessor = () {
  final emojis = getUnicodeEmojiList();
  final processor = SequenceProcessor<int, Emoji>();
  for (final emoji in emojis) {
    processor.addSequence(emoji.codePoints, emoji);
  }

  return processor;
}();

/// Removes emoji.
String _removeEmoji(String text) {
  if (text.isEmpty) {
    return '';
  }

  final elements = _emojiProcessor.process(text.runes.toList());
  final clean = elements.where((e) => e.data is! Emoji).map((e) => e.element!);
  return String.fromCharCodes(clean);
}

Output:

I 💗 you! 😘❤️‍🔥
I  you!

example\emoji\separate_emoji_and_regular_text.dart

import 'package:sequence_processor/sequence_processor.dart';
import 'package:unicode/emoji/emoji.dart';

void main(List<String> args) {
  const str = 'I 💗 you! 😘❤️‍🔥 ';
  print(str);
  final parts = _separateEmoji(str);
  print(parts);
  for (final element in parts) {
    final kind = element.$1 ? 'Emoji  :' : 'Regular:';
    print(
      '$kind "${element.$2}"',
    );
  }
}

// Should be stored in a static member for performance reasons.
final _emojiProcessor = () {
  final emojis = getUnicodeEmojiList();
  final processor = SequenceProcessor<int, Emoji>();
  for (final emoji in emojis) {
    processor.addSequence(emoji.codePoints, emoji);
  }

  return processor;
}();

/// Separates emoji and text.
List<(bool, String)> _separateEmoji(String text) {
  if (text.isEmpty) {
    return [];
  }

  final elements = _emojiProcessor.process(text.runes.toList());
  final result = <(bool, List<int>)>[];
  (bool, List<int>)? regular;
  (bool, List<int>)? emojis;
  for (final element in elements) {
    if (element.data is Emoji) {
      regular = null;
      if (emojis == null) {
        emojis = (true, []);
        result.add(emojis);
      }

      emojis.$2.addAll(element.sequence!);
    } else {
      emojis = null;
      if (regular == null) {
        regular = (false, []);
        result.add(regular);
      }

      regular.$2.add(element.element!);
    }
  }

  return result.map((e) => (e.$1, String.fromCharCodes(e.$2))).toList();
}

Output:

I 💗 you! 😘❤️‍🔥
[(false, I ), (true, 💗), (false,  you! ), (true, 😘❤️‍🔥), (false,  )]
Regular: "I "
Emoji  : "💗"
Regular: " you! "
Emoji  : "😘❤️‍🔥"
Regular: " "

example\emoji\trim_last_characters.dart

import 'package:sequence_processor/sequence_processor.dart';
import 'package:unicode/decomposers/canonical.dart';
import 'package:unicode/emoji/emoji.dart';

void main(List<String> args) {
  var str = 'I 💗 you! 😘❤️‍🔥 ';
  print('"$str"');
  while (str.isNotEmpty) {
    str = _removeLastChars(str, 1);
    print('"$str"');
  }

  str = 'Amélie';
  print('"$str"');
  while (str.isNotEmpty) {
    str = _removeLastChars(str, 1);
    print('"$str"');
  }

  str = "Hello 😀 World";
  print('"$str"');
  while (str.isNotEmpty) {
    str = _removeLastChars(str, 1);
    print('"$str"');
  }
}

// Should be stored in a static member for performance reasons.
final _processor = () {
  final emojis = getUnicodeEmojiList();
  final processor = SequenceProcessor<int, Object>();
  for (final emoji in emojis) {
    processor.addSequence(emoji.codePoints, emoji);
  }

  // We will also use the mapping information of the canonical decomposition to
  // avoid changing canonically equivalent sequences.
  const decomposer = CanonicalDecomposer();
  final mappingList = decomposer.getMappingList();
  for (var i = 0; i < mappingList.length; i++) {
    final mapping = mappingList[i];
    final sequence = mapping.$2;
    if (sequence.length > 1) {
      if (!processor.hasSequence(sequence)) {
        processor.addSequence(sequence, mapping.$1);
      }
    }
  }

  return processor;
}();

String _removeLastChars(String text, int n) {
  if (text.isEmpty) {
    return '';
  }

  final result = _processor.process(text.runes.toList());
  if (result.length < n) {
    return '';
  }

  return result
      .take(result.length - n)
      .map((e) => e.data == null
          ? String.fromCharCode(e.element!)
          : String.fromCharCodes(e.sequence!))
      .join();
}

Output:

"I 💗 you! 😘❤️‍🔥 "
"I 💗 you! 😘❤️‍🔥"
"I 💗 you! 😘"
"I 💗 you! "
"I 💗 you!"
"I 💗 you"
"I 💗 yo"
"I 💗 y"
"I 💗 "
"I 💗"
"I "
"I"
""
"Amélie"
"Améli"
"Amél"
"Amé"
"Am"
"A"
""
"Hello 😀 World"
"Hello 😀 Worl"
"Hello 😀 Wor"
"Hello 😀 Wo"
"Hello 😀 W"
"Hello 😀 "
"Hello 😀"
"Hello "
"Hello"
"Hell"
"Hel"
"He"
"H"
""

카테고리

의존성

의존성 목록 2 개

  • archive^4.0.2
  • simple_sparse_list^0.1.4

소스 저장소

이 패키지를 사용하는 프로젝트