struct Char

Overview

A Char represents a Unicode code point. It occupies 32 bits.

It is created by enclosing an UTF-8 character in single quotes.

'a'
'z'
'0'
'_'
'あ'

You can use a backslash to denote some characters:

'\'' # single quote
'\\' # backslash
'\e' # escape
'\f' # form feed
'\n' # newline
'\r' # carriage return
'\t' # tab
'\v' # vertical tab

You can use a backslash followed by an u and four hexadecimal characters to denote a unicode codepoint written:

'\u0041' # == 'A'

Or you can use curly braces and specify up to four hexadecimal numbers:

'\u{41}' # == 'A'

See Char literals in the language reference.

Included Modules

Defined in:

char_width.cr

Constant Summary

UNICODE_COMBINING_CHARS = {768..879, 1155..1158, 1160..1161, 1425..1469, 1471..1471, 1473..1474, 1476..1477, 1479..1479, 1536..1539, 1552..1557, 1611..1630, 1648..1648, 1750..1764, 1767..1768, 1770..1773, 1807..1807, 1809..1809, 1840..1866, 1958..1968, 2027..2035, 2305..2306, 2364..2364, 2369..2376, 2381..2381, 2385..2388, 2402..2403, 2433..2433, 2492..2492, 2497..2500, 2509..2509, 2530..2531, 2561..2562, 2620..2620, 2625..2626, 2631..2632, 2635..2637, 2672..2673, 2689..2690, 2748..2748, 2753..2757, 2759..2760, 2765..2765, 2786..2787, 2817..2817, 2876..2876, 2879..2879, 2881..2883, 2893..2893, 2902..2902, 2946..2946, 3008..3008, 3021..3021, 3134..3136, 3142..3144, 3146..3149, 3157..3158, 3260..3260, 3263..3263, 3270..3270, 3276..3277, 3298..3299, 3393..3395, 3405..3405, 3530..3530, 3538..3540, 3542..3542, 3633..3633, 3636..3642, 3655..3662, 3761..3761, 3764..3769, 3771..3772, 3784..3789, 3864..3865, 3893..3893, 3895..3895, 3897..3897, 3953..3966, 3968..3972, 3974..3975, 3984..3991, 3993..4028, 4038..4038, 4141..4144, 4146..4146, 4150..4151, 4153..4153, 4184..4185, 4448..4607, 4959..4959, 5906..5908, 5938..5940, 5970..5971, 6002..6003, 6068..6069, 6071..6077, 6086..6086, 6089..6099, 6109..6109, 6155..6157, 6313..6313, 6432..6434, 6439..6440, 6450..6450, 6457..6459, 6679..6680, 6912..6915, 6964..6964, 6966..6970, 6972..6972, 6978..6978, 7019..7027, 7616..7626, 7678..7679, 8203..8207, 8234..8238, 8288..8291, 8298..8303, 8400..8431, 12330..12335, 12441..12442, 43014..43014, 43019..43019, 43045..43046, 64286..64286, 65024..65039, 65056..65059, 65279..65279, 65529..65531, 68097..68099, 68101..68102, 68108..68111, 68152..68154, 68159..68159, 119143..119145, 119155..119170, 119173..119179, 119210..119213, 119362..119364, 917505..917505, 917536..917631, 917760..917999}

Based on https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c

This is an implementation of wcwidth() and wcswidth() (defined in IEEE Std 1002.1-2001) for Unicode.

UNICODE_INTERVAL_CHARS = {161..161, 164..164, 167..168, 170..170, 174..174, 176..180, 182..186, 188..191, 198..198, 208..208, 215..216, 222..225, 230..230, 232..234, 236..237, 240..240, 242..243, 247..250, 252..252, 254..254, 257..257, 273..273, 275..275, 283..283, 294..295, 299..299, 305..307, 312..312, 319..322, 324..324, 328..331, 333..333, 338..339, 358..359, 363..363, 462..462, 464..464, 466..466, 468..468, 470..470, 472..472, 474..474, 476..476, 593..593, 609..609, 708..708, 711..711, 713..715, 717..717, 720..720, 728..731, 733..733, 735..735, 913..929, 931..937, 945..961, 963..969, 1025..1025, 1040..1103, 1105..1105, 8208..8208, 8211..8214, 8216..8217, 8220..8221, 8224..8226, 8228..8231, 8240..8240, 8242..8243, 8245..8245, 8251..8251, 8254..8254, 8308..8308, 8319..8319, 8321..8324, 8364..8364, 8451..8451, 8453..8453, 8457..8457, 8467..8467, 8470..8470, 8481..8482, 8486..8486, 8491..8491, 8531..8532, 8539..8542, 8544..8555, 8560..8569, 8592..8601, 8632..8633, 8658..8658, 8660..8660, 8679..8679, 8704..8704, 8706..8707, 8711..8712, 8715..8715, 8719..8719, 8721..8721, 8725..8725, 8730..8730, 8733..8736, 8739..8739, 8741..8741, 8743..8748, 8750..8750, 8756..8759, 8764..8765, 8776..8776, 8780..8780, 8786..8786, 8800..8801, 8804..8807, 8810..8811, 8814..8815, 8834..8835, 8838..8839, 8853..8853, 8857..8857, 8869..8869, 8895..8895, 8978..8978, 9312..9449, 9451..9547, 9552..9587, 9600..9615, 9618..9621, 9632..9633, 9635..9641, 9650..9651, 9654..9655, 9660..9661, 9664..9665, 9670..9672, 9675..9675, 9678..9681, 9698..9701, 9711..9711, 9733..9734, 9737..9737, 9742..9743, 9748..9749, 9756..9756, 9758..9758, 9792..9792, 9794..9794, 9824..9825, 9827..9829, 9831..9834, 9836..9837, 9839..9839, 10045..10045, 10102..10111, 57344..63743, 65533..65533, 983040..1048573, 1048576..1114109}

Instance Method Summary

Instance Method Detail

def width : Int32 #

[View source]
def width_cjk : Int32 #

[View source]