11cb0ef41Sopenharmony_ci### Javascript porting of Markus Kuhn's wcwidth() implementation 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciThe following explanation comes from the original C implementation: 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciThis is an implementation of wcwidth() and wcswidth() (defined in 61cb0ef41Sopenharmony_ciIEEE Std 1002.1-2001) for Unicode. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cihttp://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html 91cb0ef41Sopenharmony_cihttp://www.opengroup.org/onlinepubs/007904975/functions/wcswidth.html 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciIn fixed-width output devices, Latin characters all occupy a single 121cb0ef41Sopenharmony_ci"cell" position of equal width, whereas ideographic CJK characters 131cb0ef41Sopenharmony_cioccupy two such cells. Interoperability between terminal-line 141cb0ef41Sopenharmony_ciapplications and (teletype-style) character terminals using the 151cb0ef41Sopenharmony_ciUTF-8 encoding requires agreement on which character should advance 161cb0ef41Sopenharmony_cithe cursor by how many cell positions. No established formal 171cb0ef41Sopenharmony_cistandards exist at present on which Unicode character shall occupy 181cb0ef41Sopenharmony_cihow many cell positions on character terminals. These routines are 191cb0ef41Sopenharmony_cia first attempt of defining such behavior based on simple rules 201cb0ef41Sopenharmony_ciapplied to data provided by the Unicode Consortium. 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciFor some graphical characters, the Unicode standard explicitly 231cb0ef41Sopenharmony_cidefines a character-cell width via the definition of the East Asian 241cb0ef41Sopenharmony_ciFullWidth (F), Wide (W), Half-width (H), and Narrow (Na) classes. 251cb0ef41Sopenharmony_ciIn all these cases, there is no ambiguity about which width a 261cb0ef41Sopenharmony_citerminal shall use. For characters in the East Asian Ambiguous (A) 271cb0ef41Sopenharmony_ciclass, the width choice depends purely on a preference of backward 281cb0ef41Sopenharmony_cicompatibility with either historic CJK or Western practice. 291cb0ef41Sopenharmony_ciChoosing single-width for these characters is easy to justify as 301cb0ef41Sopenharmony_cithe appropriate long-term solution, as the CJK practice of 311cb0ef41Sopenharmony_cidisplaying these characters as double-width comes from historic 321cb0ef41Sopenharmony_ciimplementation simplicity (8-bit encoded characters were displayed 331cb0ef41Sopenharmony_cisingle-width and 16-bit ones double-width, even for Greek, 341cb0ef41Sopenharmony_ciCyrillic, etc.) and not any typographic considerations. 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciMuch less clear is the choice of width for the Not East Asian 371cb0ef41Sopenharmony_ci(Neutral) class. Existing practice does not dictate a width for any 381cb0ef41Sopenharmony_ciof these characters. It would nevertheless make sense 391cb0ef41Sopenharmony_citypographically to allocate two character cells to characters such 401cb0ef41Sopenharmony_cias for instance EM SPACE or VOLUME INTEGRAL, which cannot be 411cb0ef41Sopenharmony_cirepresented adequately with a single-width glyph. The following 421cb0ef41Sopenharmony_ciroutines at present merely assign a single-cell width to all 431cb0ef41Sopenharmony_cineutral characters, in the interest of simplicity. This is not 441cb0ef41Sopenharmony_cientirely satisfactory and should be reconsidered before 451cb0ef41Sopenharmony_ciestablishing a formal standard in this area. At the moment, the 461cb0ef41Sopenharmony_cidecision which Not East Asian (Neutral) characters should be 471cb0ef41Sopenharmony_cirepresented by double-width glyphs cannot yet be answered by 481cb0ef41Sopenharmony_ciapplying a simple rule from the Unicode database content. Setting 491cb0ef41Sopenharmony_ciup a proper standard for the behavior of UTF-8 character terminals 501cb0ef41Sopenharmony_ciwill require a careful analysis not only of each Unicode character, 511cb0ef41Sopenharmony_cibut also of each presentation form, something the author of these 521cb0ef41Sopenharmony_ciroutines has avoided to do so far. 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_cihttp://www.unicode.org/unicode/reports/tr11/ 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ciMarkus Kuhn -- 2007-05-26 (Unicode 5.0) 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ciPermission to use, copy, modify, and distribute this software 591cb0ef41Sopenharmony_cifor any purpose and without fee is hereby granted. The author 601cb0ef41Sopenharmony_cidisclaims all warranties with regard to this software. 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciLatest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci 66