unicode
What Unicode knows about a character: category, script, writing direction, case, decomposition and composition.
import unicode
Unicode gives every character of every script in the world a number, called a code point: "ش" is 1588 and "A" is 65. For any code point, the unicode package says what kind of character it is: letter or digit, which script it belongs to, whether it is written right to left or left to right, and what its upper and lower case forms are.
Most of the time the str package is enough, and it uses this one underneath. This package is for when you are inspecting text character by character yourself, in a parser, an editor or a text cleaning tool. The data is generated from the official Unicode database, version 16.
To get the code points of a string, use str.CodePoints.
Constants and variables
ZWNJ
const ZWNJ: i32 = 8204import unicode
func main:
println unicode.ZWNJ, unicode.ZWJ, unicode.MaxCodePoint
println "unicode", unicode.Version
endZWJ
const ZWJ: i32 = 8205The example for this item is shown with the ones above: unicode-ZWNJ.salam
MaxCodePoint
const MaxCodePoint: i32 = 1114111The example for this item is shown with the ones above: unicode-ZWNJ.salam
Hangul syllable constants Hangul…
| Name | Value |
|---|---|
HangulSBase | 44032 |
HangulLBase | 4352 |
HangulVBase | 4449 |
HangulTBase | 4519 |
HangulLCount | 19 |
HangulVCount | 21 |
HangulTCount | 28 |
HangulNCount | 588 |
HangulSCount | 11172 |
import unicode
func main:
lead := 18
vowel := 0
tail := 4
syllable := unicode.HangulSBase + (lead * unicode.HangulVCount + vowel) * unicode.HangulTCount + tail
println syllable
println unicode.HangulNCount, unicode.HangulSCount
println unicode.HangulLBase, unicode.HangulVBase, unicode.HangulTBase
println unicode.HangulLCount
endVersion
const Version: str = "16.0.0"The example for this item is shown with the ones above: unicode-ZWNJ.salam
MaxFoldLen
const MaxFoldLen: i32 = 3import unicode
func main:
println unicode.ToUpper(945), unicode.ToLower(913), unicode.ToTitle(454), unicode.ToFold(913)
println unicode.ToUpper(1588)
c := 223
println unicode.HasFullFold(c), unicode.FullFoldLen(c)
repeat unicode.FullFoldLen(c) in i:
print unicode.FullFoldAt(c, i), ""
end
println ""
println unicode.MaxFoldLen
endGeneral categories Cat…
Category returns one of these numbers and CategoryName returns its two-letter short name, such as Lo. Categories whose first letter is the same are numbered consecutively.| Name | Value |
|---|---|
CatLu | 0 |
CatLl | 1 |
CatLt | 2 |
CatLm | 3 |
CatLo | 4 |
CatMn | 5 |
CatMc | 6 |
CatMe | 7 |
CatNd | 8 |
CatNl | 9 |
CatNo | 10 |
CatPc | 11 |
CatPd | 12 |
CatPs | 13 |
CatPe | 14 |
CatPi | 15 |
CatPf | 16 |
CatPo | 17 |
CatSm | 18 |
CatSc | 19 |
CatSk | 20 |
CatSo | 21 |
CatZs | 22 |
CatZl | 23 |
CatZp | 24 |
CatCc | 25 |
CatCf | 26 |
CatCs | 27 |
CatCo | 28 |
CatCn | 29 |
import unicode
func main:
each c in [65, 1588, 1776, 1614, 8204, 12288, 888]:
println c, unicode.CategoryName(c), unicode.Category(c), unicode.IsAssigned(c)
end
println unicode.Category(1588) == unicode.CatLo
endGrapheme break classes Gcb…
GraphemeBreak returns. The str package uses them to find where one "visible letter" ends and the next begins; a letter with its marks, or a composed emoji, is one cluster.| Name | Value |
|---|---|
GcbOther | 0 |
GcbCR | 1 |
GcbLF | 2 |
GcbControl | 3 |
GcbExtend | 4 |
GcbZWJ | 5 |
GcbRegionalIndicator | 6 |
GcbPrepend | 7 |
GcbSpacingMark | 8 |
GcbL | 9 |
GcbV | 10 |
GcbT | 11 |
GcbLV | 12 |
GcbLVT | 13 |
GcbExtendedPictographic | 14 |
import unicode
func main:
println unicode.GraphemeBreak(1614) == unicode.GcbExtend
println unicode.GraphemeBreak(8205) == unicode.GcbZWJ
println unicode.GraphemeBreak(128512) == unicode.GcbExtendedPictographic
println unicode.GraphemeBreak(10), unicode.GraphemeBreak(65)
println unicode.ConjunctBreak(2325) == unicode.IncbConsonant, unicode.ConjunctBreak(2381) == unicode.IncbLinker
endConjunct break classes Incb…
ConjunctBreak returns. This rule keeps consonants joined by a virama in Indic scripts inside a single cluster.| Name | Value |
|---|---|
IncbNone | 0 |
IncbConsonant | 1 |
IncbExtend | 2 |
IncbLinker | 3 |
The example for this item is shown with the ones above: unicode-GraphemeBreak.salam
Bidirectional classes Bc…
BidiClass returns, which the bidirectional algorithm uses to decide where each character of mixed text appears. Arabic script letters are "Arabic", Latin letters are "left to right", and digits have classes of their own.| Name | Value |
|---|---|
BcL | 0 |
BcR | 1 |
BcAL | 2 |
BcEN | 3 |
BcES | 4 |
BcET | 5 |
BcAN | 6 |
BcCS | 7 |
BcNSM | 8 |
BcBN | 9 |
BcB | 10 |
BcS | 11 |
BcWS | 12 |
BcON | 13 |
BcLRE | 14 |
BcRLE | 15 |
BcLRO | 16 |
BcRLO | 17 |
BcPDF | 18 |
BcLRI | 19 |
BcRLI | 20 |
BcFSI | 21 |
BcPDI | 22 |
import unicode
func main:
println unicode.BidiClass(65) == unicode.BcL
println unicode.BidiClass(1588) == unicode.BcAL
println unicode.BidiClass(1488) == unicode.BcR
println unicode.BidiClass(1776) == unicode.BcEN, unicode.BidiClass(1632) == unicode.BcAN
println unicode.PairedBracketType(40) == unicode.PbtOpen, unicode.PairedBracketType(41) == unicode.PbtClose
println unicode.PairedBracket(40), unicode.PairedBracket(65)
endPaired bracket types Pbt…
PairedBracketType: whether the character is an opening bracket, a closing one, or not a bracket at all.| Name | Value |
|---|---|
PbtNone | 0 |
PbtOpen | 1 |
PbtClose | 2 |
The example for this item is shown with the ones above: unicode-BidiClass.salam
Script identifiers Script…
Script returns one of them. Persian and Arabic letters are both "Arabic script". "Common" characters such as digits and punctuation are used by several scripts, and "inherited" means the character takes the script of the character before it, as marks do.| Name | Value |
|---|---|
ScriptUnknown | 0 |
ScriptCommon | 1 |
ScriptLatin | 2 |
ScriptGreek | 3 |
ScriptCyrillic | 4 |
ScriptArmenian | 5 |
ScriptHebrew | 6 |
ScriptArabic | 7 |
ScriptSyriac | 8 |
ScriptThaana | 9 |
ScriptDevanagari | 10 |
ScriptBengali | 11 |
ScriptGurmukhi | 12 |
ScriptGujarati | 13 |
ScriptOriya | 14 |
ScriptTamil | 15 |
ScriptTelugu | 16 |
ScriptKannada | 17 |
ScriptMalayalam | 18 |
ScriptSinhala | 19 |
ScriptThai | 20 |
ScriptLao | 21 |
ScriptTibetan | 22 |
ScriptMyanmar | 23 |
ScriptGeorgian | 24 |
ScriptHangul | 25 |
ScriptEthiopic | 26 |
ScriptCherokee | 27 |
ScriptCanadianAboriginal | 28 |
ScriptOgham | 29 |
ScriptRunic | 30 |
ScriptKhmer | 31 |
ScriptMongolian | 32 |
ScriptHiragana | 33 |
ScriptKatakana | 34 |
ScriptBopomofo | 35 |
ScriptHan | 36 |
ScriptYi | 37 |
ScriptOldItalic | 38 |
ScriptGothic | 39 |
ScriptDeseret | 40 |
ScriptInherited | 41 |
ScriptTagalog | 42 |
ScriptHanunoo | 43 |
ScriptBuhid | 44 |
ScriptTagbanwa | 45 |
ScriptLimbu | 46 |
ScriptTaiLe | 47 |
ScriptLinearB | 48 |
ScriptUgaritic | 49 |
ScriptShavian | 50 |
ScriptOsmanya | 51 |
ScriptCypriot | 52 |
ScriptBraille | 53 |
ScriptBuginese | 54 |
ScriptCoptic | 55 |
ScriptNewTaiLue | 56 |
ScriptGlagolitic | 57 |
ScriptTifinagh | 58 |
ScriptSylotiNagri | 59 |
ScriptOldPersian | 60 |
ScriptKharoshthi | 61 |
ScriptBalinese | 62 |
ScriptCuneiform | 63 |
ScriptPhoenician | 64 |
ScriptPhagsPa | 65 |
ScriptNko | 66 |
ScriptSundanese | 67 |
ScriptLepcha | 68 |
ScriptOlChiki | 69 |
ScriptVai | 70 |
ScriptSaurashtra | 71 |
ScriptKayahLi | 72 |
ScriptRejang | 73 |
ScriptLycian | 74 |
ScriptCarian | 75 |
ScriptLydian | 76 |
ScriptCham | 77 |
ScriptTaiTham | 78 |
ScriptTaiViet | 79 |
ScriptAvestan | 80 |
ScriptEgyptianHieroglyphs | 81 |
ScriptSamaritan | 82 |
ScriptLisu | 83 |
ScriptBamum | 84 |
ScriptJavanese | 85 |
ScriptMeeteiMayek | 86 |
ScriptImperialAramaic | 87 |
ScriptOldSouthArabian | 88 |
ScriptInscriptionalParthian | 89 |
ScriptInscriptionalPahlavi | 90 |
ScriptOldTurkic | 91 |
ScriptKaithi | 92 |
ScriptBatak | 93 |
ScriptBrahmi | 94 |
ScriptMandaic | 95 |
ScriptChakma | 96 |
ScriptMeroiticCursive | 97 |
ScriptMeroiticHieroglyphs | 98 |
ScriptMiao | 99 |
ScriptSharada | 100 |
ScriptSoraSompeng | 101 |
ScriptTakri | 102 |
ScriptCaucasianAlbanian | 103 |
ScriptBassaVah | 104 |
ScriptDuployan | 105 |
ScriptElbasan | 106 |
ScriptGrantha | 107 |
ScriptPahawhHmong | 108 |
ScriptKhojki | 109 |
ScriptLinearA | 110 |
ScriptMahajani | 111 |
ScriptManichaean | 112 |
ScriptMendeKikakui | 113 |
ScriptModi | 114 |
ScriptMro | 115 |
ScriptOldNorthArabian | 116 |
ScriptNabataean | 117 |
ScriptPalmyrene | 118 |
ScriptPauCinHau | 119 |
ScriptOldPermic | 120 |
ScriptPsalterPahlavi | 121 |
ScriptSiddham | 122 |
ScriptKhudawadi | 123 |
ScriptTirhuta | 124 |
ScriptWarangCiti | 125 |
ScriptAhom | 126 |
ScriptAnatolianHieroglyphs | 127 |
ScriptHatran | 128 |
ScriptMultani | 129 |
ScriptOldHungarian | 130 |
ScriptSignWriting | 131 |
ScriptAdlam | 132 |
ScriptBhaiksuki | 133 |
ScriptMarchen | 134 |
ScriptNewa | 135 |
ScriptOsage | 136 |
ScriptTangut | 137 |
ScriptMasaramGondi | 138 |
ScriptNushu | 139 |
ScriptSoyombo | 140 |
ScriptZanabazarSquare | 141 |
ScriptDogra | 142 |
ScriptGunjalaGondi | 143 |
ScriptMakasar | 144 |
ScriptMedefaidrin | 145 |
ScriptHanifiRohingya | 146 |
ScriptSogdian | 147 |
ScriptOldSogdian | 148 |
ScriptElymaic | 149 |
ScriptNandinagari | 150 |
ScriptNyiakengPuachueHmong | 151 |
ScriptWancho | 152 |
ScriptChorasmian | 153 |
ScriptDivesAkuru | 154 |
ScriptKhitanSmallScript | 155 |
ScriptYezidi | 156 |
ScriptCyproMinoan | 157 |
ScriptOldUyghur | 158 |
ScriptTangsa | 159 |
ScriptToto | 160 |
ScriptVithkuqi | 161 |
ScriptKawi | 162 |
ScriptNagMundari | 163 |
ScriptGaray | 164 |
ScriptGurungKhema | 165 |
ScriptKiratRai | 166 |
ScriptOlOnal | 167 |
ScriptSunuwar | 168 |
ScriptTodhri | 169 |
ScriptTuluTigalari | 170 |
import unicode
func main:
each c in [65, 1588, 945, 20013, 12354, 1776, 1614]:
println c, unicode.ScriptName(c)
end
println unicode.Script(1588) == unicode.ScriptArabic, unicode.Script(65) == unicode.ScriptLatin
println unicode.Script(66464) == unicode.ScriptOldPersian, unicode.ScriptName(66464)
endFunctions
Category
func Category(cp: int): intThe example for this item is shown with the ones above: unicode-Category.salam
CategoryName
func CategoryName(cp: int): strLo for a Persian letter and Nd for a digit.The example for this item is shown with the ones above: unicode-Category.salam
IsAssigned
func IsAssigned(cp: int): boolThe example for this item is shown with the ones above: unicode-Category.salam
IsLetter
func IsLetter(cp: int): boolimport unicode
func main:
println unicode.IsLetter(1588), unicode.IsAlphabetic(1614), unicode.IsLetter(1614)
println unicode.IsUpper(915), unicode.IsLower(947), unicode.IsTitle(453)
println unicode.IsMark(1614), unicode.IsDigit(1776), unicode.IsNumber(8544), unicode.IsDigit(8544)
println unicode.IsAlnum(1776), unicode.IsPunct(1548), unicode.IsSymbol(65020)
println unicode.IsSpace(12288), unicode.IsControl(10), unicode.IsFormat(8204), unicode.IsJoinControl(8204)
endIsAlphabetic
func IsAlphabetic(cp: int): boolIsLetter, but wider: it also counts the marks that are part of reading a letter. Most of the time this is what "is it a letter?" means.The example for this item is shown with the ones above: unicode-IsLetter.salam
IsUpper
func IsUpper(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsLower
func IsLower(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsTitle
func IsTitle(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsMark
func IsMark(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsDigit
func IsDigit(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsNumber
func IsNumber(cp: int): boolIsDigit.The example for this item is shown with the ones above: unicode-IsLetter.salam
IsAlnum
func IsAlnum(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsPunct
func IsPunct(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsSymbol
func IsSymbol(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsSpace
func IsSpace(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsControl
func IsControl(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsFormat
func IsFormat(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
IsJoinControl
func IsJoinControl(cp: int): boolThe example for this item is shown with the ones above: unicode-IsLetter.salam
ToUpper
func ToUpper(cp: int): intThe example for this item is shown with the ones above: unicode-ToUpper.salam
ToLower
func ToLower(cp: int): intThe example for this item is shown with the ones above: unicode-ToUpper.salam
ToTitle
func ToTitle(cp: int): intThe example for this item is shown with the ones above: unicode-ToUpper.salam
ToFold
func ToFold(cp: int): intThe example for this item is shown with the ones above: unicode-ToUpper.salam
HasFullFold
func HasFullFold(cp: int): boolThe example for this item is shown with the ones above: unicode-ToUpper.salam
FullFoldLen
func FullFoldLen(cp: int): intThe example for this item is shown with the ones above: unicode-ToUpper.salam
FullFoldAt
func FullFoldAt(cp: int, k: int): intk of the character's full case fold.The example for this item is shown with the ones above: unicode-ToUpper.salam
CombiningClass
func CombiningClass(cp: int): intimport unicode
func main:
alef_madda := 1570
println unicode.DecompLen(alef_madda), unicode.DecompAt(alef_madda, 0), unicode.DecompAt(alef_madda, 1)
println unicode.Compose(1575, 1619), unicode.Compose(1575, 65)
println unicode.CombiningClass(1614), unicode.CombiningClass(1616), unicode.CombiningClass(1575)
lam_alef := 65271
println unicode.DecompLen(lam_alef), unicode.CompatDecompLen(lam_alef)
println unicode.CompatDecompAt(lam_alef, 0), unicode.CompatDecompAt(lam_alef, 1)
endDecompLen
func DecompLen(cp: int): intThe example for this item is shown with the ones above: unicode-Decomp.salam
DecompAt
func DecompAt(cp: int, k: int): intk of the character's canonical decomposition.The example for this item is shown with the ones above: unicode-Decomp.salam
CompatDecompLen
func CompatDecompLen(cp: int): intThe example for this item is shown with the ones above: unicode-Decomp.salam
CompatDecompAt
func CompatDecompAt(cp: int, k: int): intk of the compatibility decomposition.The example for this item is shown with the ones above: unicode-Decomp.salam
Compose
func Compose(a: int, b: int): intThe example for this item is shown with the ones above: unicode-Decomp.salam
GraphemeBreak
func GraphemeBreak(cp: int): intThe example for this item is shown with the ones above: unicode-GraphemeBreak.salam
ConjunctBreak
func ConjunctBreak(cp: int): intThe example for this item is shown with the ones above: unicode-GraphemeBreak.salam
BidiClass
func BidiClass(cp: int): intThe example for this item is shown with the ones above: unicode-BidiClass.salam
PairedBracketType
func PairedBracketType(cp: int): intThe example for this item is shown with the ones above: unicode-BidiClass.salam
PairedBracket
func PairedBracket(cp: int): intThe example for this item is shown with the ones above: unicode-BidiClass.salam
Script
func Script(cp: int): intThe example for this item is shown with the ones above: unicode-Script.salam
ScriptName
func ScriptName(cp: int): strArabic.The example for this item is shown with the ones above: unicode-Script.salam