Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.01 KB

File metadata and controls

46 lines (33 loc) · 1.01 KB

schars

Small Haxe library for working with Unicode characters as code points.

s.Char is an Int abstract with helpers for letters, digits, and case checks. s.CharArray converts a string to an array of Char without splitting UTF-16 surrogate pairs.

Unicode data is generated from UnicodeData.txt 17.0.0.

Usage

import s.Char;
import s.CharArray;

class Main {
	static function main() {
		var c:Char = "я";

		trace(c.isAlpha()); // true
		trace(c.isLower()); // true
		trace(c.toUpper()); // "Я"

		var chars:CharArray = "A𐐨۵中";
		trace(chars.length); // 4
		trace(chars.toString()); // A𐐨۵中
	}
}

API

  • Create Char from Int or String.
  • toString() converts a code point back to a string.
  • isAlpha(), isLetter(), isDigit(), isUpper(), isLower().
  • toUpper(), toLower().
  • next(), previous().
  • CharArray converts String to Array<Char> and back.

Char represents one Unicode code point, not a grapheme cluster.

Tests

haxe tests.hxml