LLVM 24.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
19#include <optional>
20#include <string>
21
22namespace llvm {
23class StringRef;
24
25namespace sys {
26namespace unicode {
27
32
33/// Unicode code points that are considered characters. This function
34/// returns true for any code point defined by Unicode as a character, false for
35/// any code point defined as a non-character, as reserved, as a surrogate code
36/// point, or not defined at all.
37LLVM_ABI bool isCharacter(int UCS);
38
39/// Determines if a character is likely to be displayed correctly on the
40/// terminal. Exact implementation would have to depend on the specific
41/// terminal, so we define the semantic that should be suitable for generic case
42/// of a terminal capable to output Unicode characters.
43///
44/// Printable codepoints are those in the categories L, M, N, P, S and Zs
45/// \return true if the character is considered printable.
46LLVM_ABI bool isPrintable(int UCS);
47
48// Control codepoints are codepoints in the Cc category.
49LLVM_ABI bool isControl(int UCS);
50
51// Formatting codepoints are codepoints in the Cf category.
52LLVM_ABI bool isFormatting(int UCS);
53
54/// Gets the number of positions the UTF8-encoded \p Text is likely to occupy
55/// when output on a terminal ("character width"). This depends on the
56/// implementation of the terminal, and there's no standard definition of
57/// character width.
58///
59/// The implementation defines it in a way that is expected to be compatible
60/// with a generic Unicode-capable terminal.
61///
62/// \return Character width:
63/// * ErrorNonPrintableCharacter (-1) if \p Text contains non-printable
64/// characters (as identified by isPrintable);
65/// * 0 for each non-spacing and enclosing combining mark;
66/// * 2 for each CJK character excluding halfwidth forms;
67/// * 1 for each of the remaining characters.
69
70/// Fold input unicode character according the Simple unicode case folding
71/// rules.
73
74/// Maps the name or the alias of a Unicode character to its associated
75/// codepoints.
76/// The names and aliases are derived from UnicodeData.txt and NameAliases.txt
77/// For compatibility with the semantics of named character escape sequences in
78/// C++, this mapping does an exact match sensitive to casing and spacing.
79/// \return The codepoint of the corresponding character, if any.
80LLVM_ABI std::optional<char32_t> nameToCodepointStrict(StringRef Name);
81
86
87LLVM_ABI std::optional<LooseMatchingResult>
89
91 std::string Name;
93 char32_t Value = 0;
94};
95
97nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount);
98
99} // namespace unicode
100} // namespace sys
101} // namespace llvm
102
103#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
@ ErrorNonPrintableCharacter
Definition Unicode.h:30
LLVM_ABI int foldCharSimple(int C)
Fold input unicode character according the Simple unicode case folding rules.
LLVM_ABI std::optional< char32_t > nameToCodepointStrict(StringRef Name)
Maps the name or the alias of a Unicode character to its associated codepoints.
LLVM_ABI SmallVector< MatchForCodepointName > nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount)
LLVM_ABI 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:95
LLVM_ABI bool isCharacter(int UCS)
Unicode code points that are considered characters.
Definition Unicode.cpp:33
LLVM_ABI std::optional< LooseMatchingResult > nameToCodepointLooseMatching(StringRef Name)
LLVM_ABI bool isControl(int UCS)
Unicode code points of the Cc category are considered control characters.
Definition Unicode.cpp:52
LLVM_ABI bool isFormatting(int UCS)
Unicode code points of the Cf category are considered formatting characters.
Definition Unicode.cpp:59
LLVM_ABI bool isPrintable(int UCS)
Determines if a character is likely to be displayed correctly on the terminal.
Definition Unicode.cpp:43
This is an optimization pass for GlobalISel generic memory operations.