LLVM  15.0.0git
Unicode.h
Go to the documentation of this file.
1 //===- llvm/Support/Unicode.h - Unicode character properties -*- C++ -*-=====//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines functions that allow querying certain properties of Unicode
10 // characters.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_UNICODE_H
15 #define LLVM_SUPPORT_UNICODE_H
16 
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/SmallString.h"
19 #include <string>
20 
21 namespace llvm {
22 class StringRef;
23 
24 namespace sys {
25 namespace unicode {
26 
30 };
31 
32 /// Determines if a character is likely to be displayed correctly on the
33 /// terminal. Exact implementation would have to depend on the specific
34 /// terminal, so we define the semantic that should be suitable for generic case
35 /// of a terminal capable to output Unicode characters.
36 ///
37 /// Printable codepoints are those in the categories L, M, N, P, S and Zs
38 /// \return true if the character is considered printable.
39 bool isPrintable(int UCS);
40 
41 // Formatting codepoints are codepoints in the Cf category.
42 bool isFormatting(int UCS);
43 
44 /// Gets the number of positions the UTF8-encoded \p Text is likely to occupy
45 /// when output on a terminal ("character width"). This depends on the
46 /// implementation of the terminal, and there's no standard definition of
47 /// character width.
48 ///
49 /// The implementation defines it in a way that is expected to be compatible
50 /// with a generic Unicode-capable terminal.
51 ///
52 /// \return Character width:
53 /// * ErrorNonPrintableCharacter (-1) if \p Text contains non-printable
54 /// characters (as identified by isPrintable);
55 /// * 0 for each non-spacing and enclosing combining mark;
56 /// * 2 for each CJK character excluding halfwidth forms;
57 /// * 1 for each of the remaining characters.
58 int columnWidthUTF8(StringRef Text);
59 
60 /// Fold input unicode character according the Simple unicode case folding
61 /// rules.
62 int foldCharSimple(int C);
63 
64 /// Maps the name or the alias of a Unicode character to its associated
65 /// codepoints.
66 /// The names and aliases are derived from UnicodeData.txt and NameAliases.txt
67 /// For compatibility with the semantics of named character escape sequences in
68 /// C++, this mapping does an exact match sensitive to casing and spacing.
69 /// \return The codepoint of the corresponding character, if any.
71 
73  char32_t CodePoint;
75 };
76 
78 
80  std::string Name;
82  char32_t Value = 0;
83 };
84 
86 nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount);
87 
88 } // namespace unicode
89 } // namespace sys
90 } // namespace llvm
91 
92 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Optional.h
llvm::sys::unicode::LooseMatchingResult
Definition: Unicode.h:72
llvm::sys::unicode::ErrorInvalidUTF8
@ ErrorInvalidUTF8
Definition: Unicode.h:28
llvm::sys::unicode::LooseMatchingResult::CodePoint
char32_t CodePoint
Definition: Unicode.h:73
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::sys::unicode::nameToCodepointStrict
Optional< char32_t > nameToCodepointStrict(StringRef Name)
Maps the name or the alias of a Unicode character to its associated codepoints.
Definition: UnicodeNameToCodepoint.cpp:404
llvm::sys::unicode::foldCharSimple
int foldCharSimple(int C)
Fold input unicode character according the Simple unicode case folding rules.
Definition: UnicodeCaseFold.cpp:16
llvm::sys::unicode::MatchForCodepointName::Distance
uint32_t Distance
Definition: Unicode.h:81
llvm::Optional
Definition: APInt.h:33
llvm::sys::unicode::LooseMatchingResult::Name
SmallString< 64 > Name
Definition: Unicode.h:74
SmallString.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sys::unicode::MatchForCodepointName::Name
std::string Name
Definition: Unicode.h:80
llvm::sys::unicode::ColumnWidthErrors
ColumnWidthErrors
Definition: Unicode.h:27
llvm::SmallString< 64 >
llvm::sys::unicode::isFormatting
bool isFormatting(int UCS)
Unicode code points of the Cf category are considered formatting characters.
Definition: Unicode.cpp:273
llvm::sys::unicode::nearestMatchesForCodepointName
SmallVector< MatchForCodepointName > nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount)
Definition: UnicodeNameToCodepoint.cpp:423
llvm::sys::unicode::columnWidthUTF8
int columnWidthUTF8(StringRef Text)
Gets the number of positions the UTF8-encoded Text is likely to occupy when output on a terminal ("ch...
Definition: Unicode.cpp:418
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::sys::unicode::MatchForCodepointName
Definition: Unicode.h:79
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::sys::unicode::ErrorNonPrintableCharacter
@ ErrorNonPrintableCharacter
Definition: Unicode.h:29
llvm::sys::unicode::isPrintable
bool isPrintable(int UCS)
Determines if a character is likely to be displayed correctly on the terminal.
Definition: Unicode.cpp:27
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::sys::unicode::nameToCodepointLooseMatching
Optional< LooseMatchingResult > nameToCodepointLooseMatching(StringRef Name)
Definition: UnicodeNameToCodepoint.cpp:412