1259698Sdim//===- llvm/Support/Unicode.h - Unicode character properties -*- C++ -*-=====// 2259698Sdim// 3259698Sdim// The LLVM Compiler Infrastructure 4259698Sdim// 5259698Sdim// This file is distributed under the University of Illinois Open Source 6259698Sdim// License. See LICENSE.TXT for details. 7259698Sdim// 8259698Sdim//===----------------------------------------------------------------------===// 9259698Sdim// 10259698Sdim// This file defines functions that allow querying certain properties of Unicode 11259698Sdim// characters. 12259698Sdim// 13259698Sdim//===----------------------------------------------------------------------===// 14259698Sdim 15259698Sdim#include "llvm/ADT/StringRef.h" 16259698Sdim 17259698Sdimnamespace llvm { 18259698Sdimnamespace sys { 19259698Sdimnamespace unicode { 20259698Sdim 21259698Sdimenum ColumnWidthErrors { 22259698Sdim ErrorInvalidUTF8 = -2, 23259698Sdim ErrorNonPrintableCharacter = -1 24259698Sdim}; 25259698Sdim 26259698Sdim/// Determines if a character is likely to be displayed correctly on the 27259698Sdim/// terminal. Exact implementation would have to depend on the specific 28259698Sdim/// terminal, so we define the semantic that should be suitable for generic case 29259698Sdim/// of a terminal capable to output Unicode characters. 30259698Sdim/// 31259698Sdim/// All characters from the Unicode code point range are considered printable 32259698Sdim/// except for: 33259698Sdim/// * C0 and C1 control character ranges; 34259698Sdim/// * default ignorable code points as per 5.21 of 35259698Sdim/// http://www.unicode.org/versions/Unicode6.2.0/UnicodeStandard-6.2.pdf 36259698Sdim/// except for U+00AD SOFT HYPHEN, as it's actually displayed on most 37259698Sdim/// terminals; 38259698Sdim/// * format characters (category = Cf); 39259698Sdim/// * surrogates (category = Cs); 40259698Sdim/// * unassigned characters (category = Cn). 41259698Sdim/// \return true if the character is considered printable. 42259698Sdimbool isPrintable(int UCS); 43259698Sdim 44259698Sdim/// Gets the number of positions the UTF8-encoded \p Text is likely to occupy 45259698Sdim/// when output on a terminal ("character width"). This depends on the 46259698Sdim/// implementation of the terminal, and there's no standard definition of 47259698Sdim/// character width. 48259698Sdim/// 49259698Sdim/// The implementation defines it in a way that is expected to be compatible 50259698Sdim/// with a generic Unicode-capable terminal. 51259698Sdim/// 52259698Sdim/// \return Character width: 53259698Sdim/// * ErrorNonPrintableCharacter (-1) if \p Text contains non-printable 54259698Sdim/// characters (as identified by isPrintable); 55259698Sdim/// * 0 for each non-spacing and enclosing combining mark; 56259698Sdim/// * 2 for each CJK character excluding halfwidth forms; 57259698Sdim/// * 1 for each of the remaining characters. 58259698Sdimint columnWidthUTF8(StringRef Text); 59259698Sdim 60259698Sdim} // namespace unicode 61259698Sdim} // namespace sys 62259698Sdim} // namespace llvm 63