-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support counting Asian characters double for line-breaking purposes #21
Labels
Milestone
Comments
From lanterna TerminalTextUtils: /**
* Given a character, is this character considered to be a CJK character?
* Shamelessly stolen from
* <a href="http://stackoverflow.com/questions/1499804/how-can-i-detect-japanese-text-in-a-java-string">StackOverflow</a>
* where it was contributed by user Rakesh N
* @param c Character to test
* @return {@code true} if the character is a CJK character
*
*/
public static boolean isCharCJK(final char c) {
Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(c);
return (unicodeBlock == Character.UnicodeBlock.HIRAGANA)
|| (unicodeBlock == Character.UnicodeBlock.KATAKANA)
|| (unicodeBlock == Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS)
|| (unicodeBlock == Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO)
|| (unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO)
|| (unicodeBlock == Character.UnicodeBlock.HANGUL_SYLLABLES)
|| (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS)
|| (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A)
|| (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B)
|| (unicodeBlock == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS)
|| (unicodeBlock == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS)
|| (unicodeBlock == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT)
|| (unicodeBlock == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION)
|| (unicodeBlock == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS)
|| (unicodeBlock == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS && c < 0xFF61); //The magic number here is the separating index between full-width and half-width
}
/**
* Checks if a character is expected to be taking up two columns if printed to a terminal. This will generally be
* {@code true} for CJK (Chinese, Japanese and Korean) characters.
* @param c Character to test if it's double-width when printed to a terminal
* @return {@code true} if this character is expected to be taking up two columns when printed to the terminal,
* otherwise {@code false}
*/
public static boolean isCharDoubleWidth(final char c) {
return isCharCJK(c);
} |
Should add a setting to switch this off.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See argparse4j
enable if { "ja", "zh", "ko" }.contains(Locale.getDefault().getLanguage())
Apply to Unicode characters having East Asian Width property Wide/Full/Ambiguous.
The text was updated successfully, but these errors were encountered: