LLVM API Documentation

Unicode.h
Go to the documentation of this file.
00001 //===- llvm/Support/Unicode.h - Unicode character properties  -*- C++ -*-=====//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines functions that allow querying certain properties of Unicode
00011 // characters.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_UNICODE_H
00016 #define LLVM_SUPPORT_UNICODE_H
00017 
00018 #include "llvm/ADT/StringRef.h"
00019 
00020 namespace llvm {
00021 namespace sys {
00022 namespace unicode {
00023 
00024 enum ColumnWidthErrors {
00025   ErrorInvalidUTF8 = -2,
00026   ErrorNonPrintableCharacter = -1
00027 };
00028 
00029 /// Determines if a character is likely to be displayed correctly on the
00030 /// terminal. Exact implementation would have to depend on the specific
00031 /// terminal, so we define the semantic that should be suitable for generic case
00032 /// of a terminal capable to output Unicode characters.
00033 ///
00034 /// All characters from the Unicode code point range are considered printable
00035 /// except for:
00036 ///   * C0 and C1 control character ranges;
00037 ///   * default ignorable code points as per 5.21 of
00038 ///     http://www.unicode.org/versions/Unicode6.2.0/UnicodeStandard-6.2.pdf
00039 ///     except for U+00AD SOFT HYPHEN, as it's actually displayed on most
00040 ///     terminals;
00041 ///   * format characters (category = Cf);
00042 ///   * surrogates (category = Cs);
00043 ///   * unassigned characters (category = Cn).
00044 /// \return true if the character is considered printable.
00045 bool isPrintable(int UCS);
00046 
00047 /// Gets the number of positions the UTF8-encoded \p Text is likely to occupy
00048 /// when output on a terminal ("character width"). This depends on the
00049 /// implementation of the terminal, and there's no standard definition of
00050 /// character width.
00051 ///
00052 /// The implementation defines it in a way that is expected to be compatible
00053 /// with a generic Unicode-capable terminal.
00054 ///
00055 /// \return Character width:
00056 ///   * ErrorNonPrintableCharacter (-1) if \p Text contains non-printable
00057 ///     characters (as identified by isPrintable);
00058 ///   * 0 for each non-spacing and enclosing combining mark;
00059 ///   * 2 for each CJK character excluding halfwidth forms;
00060 ///   * 1 for each of the remaining characters.
00061 int columnWidthUTF8(StringRef Text);
00062 
00063 } // namespace unicode
00064 } // namespace sys
00065 } // namespace llvm
00066 
00067 #endif