Coder Social home page Coder Social logo

unicode_data's Introduction

Unicode Data

This library puts Unicode data in a format that can be programmatically manipulated. The current implementation includes Unicode blocks and scrips data.

Background

Unicode code points are divided into code blocks that generally contains characters within the same or related writing systems. For example Basic Latin or Arabic. However, the complete character set needed for a writing system is often spread across a number of code blocks. This character set is referred to as a script. If you want to know what writing system a particular character belongs to, it is generally more accurate to use the Unicode script data rather than the block data. You can read more about the difference here.

This library contains classes for Unicode scripts and blocks. It was generated from the Unicode 12.0 Scripts.txt and Blocks.txt data files. This library is exhaustive in that it includes every script and block in those data files.

Usage

A simple usage example:

import 'package:unicode_data/unicode_data.dart';

main() {
  unicodeBlockExamples();
  unicodeScriptExamples();
}

// Unicode Blocks
void unicodeBlockExamples() {
  // get a list of all blocks
  List<Block> blocks = UnicodeBlock.blocks;

  // find the block name for a code point
  final codePoint = 'a'.runes.single;
  final found = blocks
      .where((block) => codePoint >= block.start && codePoint <= block.end);
  final blockName = found.single.name; // Basic Latin

  // get the range for a specific block name
  final block = blocks.where((block) => block.name == 'Mongolian').single;
  final rangeStart = block.start; // 6144
  final rangeEnd = block.end; // 6319
}

// Unicode Scripts
void unicodeScriptExamples() {
  // get a list of all scripts
  List<Script> scripts = UnicodeScript.scripts;

  // find the script name and category for a code point
  final codePoint = 'a'.runes.single;
  final found = scripts.where(
      (script) => codePoint >= script.start && codePoint <= script.end);
  final script = found.single;
  final name = script.name; // Latin
  final category = script.category; // L&

  // find all script ranges for Latin
  final latinScripts = scripts.where((script) => script.name == 'Latin');

  // final all script ranges that are punctuation
  final punctRanges = scripts.where((script) => script.category.startsWith('P'));
}

The category is the type of character that it is, whether a letter, punctuation or some other type.

Contributing

Your help and pull requests are welcome.

  • When there is a new Unicode version, the code should be regenerated from the data files. See the generators folder in the source code.
  • Because there is so much data in the list, it can be potentially expensive to query the list. I would appreciate advice or examples on how to do this more efficiently. Or I am open to using a different data structure.
  • There are other types of Unicode data that could be included in this library in the future. You can open an issue if you have a request.

unicode_data's People

Contributors

suragch avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.