如何在 dart 中检索字符的 unicode 类别?

发布于 2025-01-10 06:45:42 字数 400 浏览 0 评论 0原文

在Python中有一个unicode库来获取有关字符类别的信息。

https://docs.python.org/3/library/unicodedata .html?#unicodedata.category

示例:https://stackoverflow.com/a/48060112/579689

是否有类似的方法来检索 unicode 字符的类别信息镖?

In python there is a unicode library to get information about the category of a character.

https://docs.python.org/3/library/unicodedata.html?#unicodedata.category

Example: https://stackoverflow.com/a/48060112/579689

Is there a similar method to retrieve the category information of a unicode character in dart?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2025-01-17 06:45:42

可以获得有限数量的信息。

import 'package:unicode/blocks.dart';
import 'package:unicode/decomposer.dart';
import 'package:unicode/decomposers/canonical.dart';
import 'package:unicode/decomposers/compat.dart';
import 'package:unicode/unicode.dart' as unicode;

void main(List<String> args) {
  const s = 'DŽ';
  final c = unicode.toRune(s);
  final block = getUnicodeBlock(c);
  final category = unicode.getUnicodeCategory(c);
  final lowerCaseChar = unicode.charToLowerCase(c);
  final titleCaseChar = unicode.charToTitleCase(c);
  final lowerCase = unicode.toLowerCase(s);
  final titleCase = unicode.toTitleCase(s);
  final decomposed = decompose(s, const [
    CanonicalDecomposer(),
    CompatDecomposer(),
  ]).runes.map(String.fromCharCode).join(', ');
  print('Char: ${c.toRadixString(16)}');
  print('String: $s');
  print('Category: $category');
  print('Block: $block');
  print('Lower case: $lowerCase');
  print('Lower case char: $lowerCaseChar');
  print('Title case: $titleCase');
  print('Title case char: $titleCaseChar');
  print('Decomposed: $decomposed');
}

输出:

Char: 1c4
String: DŽ
Category: UnicodeCategory.upperCaseLetter
Block: UnicodeBlock.latinExtendedB
Lower case: dž
Lower case char: 454
Title case: Dž
Title case char: 453
Decomposed: D, Ž

It is possible to obtain a limited amount of information.

import 'package:unicode/blocks.dart';
import 'package:unicode/decomposer.dart';
import 'package:unicode/decomposers/canonical.dart';
import 'package:unicode/decomposers/compat.dart';
import 'package:unicode/unicode.dart' as unicode;

void main(List<String> args) {
  const s = 'DŽ';
  final c = unicode.toRune(s);
  final block = getUnicodeBlock(c);
  final category = unicode.getUnicodeCategory(c);
  final lowerCaseChar = unicode.charToLowerCase(c);
  final titleCaseChar = unicode.charToTitleCase(c);
  final lowerCase = unicode.toLowerCase(s);
  final titleCase = unicode.toTitleCase(s);
  final decomposed = decompose(s, const [
    CanonicalDecomposer(),
    CompatDecomposer(),
  ]).runes.map(String.fromCharCode).join(', ');
  print('Char: ${c.toRadixString(16)}');
  print('String: $s');
  print('Category: $category');
  print('Block: $block');
  print('Lower case: $lowerCase');
  print('Lower case char: $lowerCaseChar');
  print('Title case: $titleCase');
  print('Title case char: $titleCaseChar');
  print('Decomposed: $decomposed');
}

Output:

Char: 1c4
String: DŽ
Category: UnicodeCategory.upperCaseLetter
Block: UnicodeBlock.latinExtendedB
Lower case: dž
Lower case char: 454
Title case: Dž
Title case char: 453
Decomposed: D, Ž
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文