aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-06 20:11:55 +0000
commit5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch)
tree1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp
parent3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff)
parent312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp b/contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp
index accebf1098ab..40592660acaa 100644
--- a/contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/UnicodeNameToCodepoint.cpp
@@ -119,11 +119,11 @@ static Node readNode(uint32_t Offset, const Node *Parent = nullptr) {
static bool startsWith(StringRef Name, StringRef Needle, bool Strict,
std::size_t &Consummed, char &PreviousCharInName,
- char &PreviousCharInNeedle, bool IsPrefix = false) {
+ bool IsPrefix = false) {
Consummed = 0;
if (Strict) {
- if (!Name.startswith(Needle))
+ if (!Name.starts_with(Needle))
return false;
Consummed = Needle.size();
return true;
@@ -135,18 +135,18 @@ static bool startsWith(StringRef Name, StringRef Needle, bool Strict,
auto NeedlePos = Needle.begin();
char PreviousCharInNameOrigin = PreviousCharInName;
- char PreviousCharInNeedleOrigin = PreviousCharInNeedle;
-
+ char PreviousCharInNeedle = *Needle.begin();
auto IgnoreSpaces = [](auto It, auto End, char &PreviousChar,
- bool IgnoreEnd = false) {
+ bool IsPrefix = false) {
while (It != End) {
const auto Next = std::next(It);
// Ignore spaces, underscore, medial hyphens
- // https://unicode.org/reports/tr44/#UAX44-LM2.
+ // The generator ensures a needle never ends (or starts) by a medial
+ // hyphen https://unicode.org/reports/tr44/#UAX44-LM2.
bool Ignore =
*It == ' ' || *It == '_' ||
(*It == '-' && isAlnum(PreviousChar) &&
- ((Next != End && isAlnum(*Next)) || (Next == End && IgnoreEnd)));
+ ((Next != End && isAlnum(*Next)) || (Next == End && IsPrefix)));
PreviousChar = *It;
if (!Ignore)
break;
@@ -171,20 +171,18 @@ static bool startsWith(StringRef Name, StringRef Needle, bool Strict,
Consummed = std::distance(Name.begin(), NamePos);
if (NeedlePos != Needle.end()) {
PreviousCharInName = PreviousCharInNameOrigin;
- PreviousCharInNeedle = PreviousCharInNeedleOrigin;
}
return NeedlePos == Needle.end();
}
static std::tuple<Node, bool, uint32_t>
compareNode(uint32_t Offset, StringRef Name, bool Strict,
- char PreviousCharInName, char PreviousCharInNeedle,
- BufferType &Buffer, const Node *Parent = nullptr) {
+ char PreviousCharInName, BufferType &Buffer,
+ const Node *Parent = nullptr) {
Node N = readNode(Offset, Parent);
std::size_t Consummed = 0;
- bool DoesStartWith =
- N.IsRoot || startsWith(Name, N.Name, Strict, Consummed,
- PreviousCharInName, PreviousCharInNeedle);
+ bool DoesStartWith = N.IsRoot || startsWith(Name, N.Name, Strict, Consummed,
+ PreviousCharInName);
if (!DoesStartWith)
return std::make_tuple(N, false, 0);
@@ -199,7 +197,7 @@ compareNode(uint32_t Offset, StringRef Name, bool Strict,
uint32_t Value;
std::tie(C, Matches, Value) =
compareNode(ChildOffset, Name.substr(Consummed), Strict,
- PreviousCharInName, PreviousCharInNeedle, Buffer, &N);
+ PreviousCharInName, Buffer, &N);
if (Matches) {
std::reverse_copy(C.Name.begin(), C.Name.end(),
std::back_inserter(Buffer));
@@ -215,7 +213,7 @@ compareNode(uint32_t Offset, StringRef Name, bool Strict,
static std::tuple<Node, bool, uint32_t>
compareNode(uint32_t Offset, StringRef Name, bool Strict, BufferType &Buffer) {
- return compareNode(Offset, Name, Strict, 0, 0, Buffer);
+ return compareNode(Offset, Name, Strict, 0, Buffer);
}
// clang-format off
@@ -262,7 +260,6 @@ static std::size_t findSyllable(StringRef Name, bool Strict,
char &PreviousInName, int &Pos, int Column) {
assert(Column == 0 || Column == 1 || Column == 2);
static std::size_t CountPerColumn[] = {LCount, VCount, TCount};
- char NeedleStart = 0;
int Len = -1;
int Prev = PreviousInName;
for (std::size_t I = 0; I < CountPerColumn[Column]; I++) {
@@ -271,8 +268,8 @@ static std::size_t findSyllable(StringRef Name, bool Strict,
continue;
std::size_t Consummed = 0;
char PreviousInNameCopy = PreviousInName;
- bool DoesStartWith = startsWith(Name, Syllable, Strict, Consummed,
- PreviousInNameCopy, NeedleStart);
+ bool DoesStartWith =
+ startsWith(Name, Syllable, Strict, Consummed, PreviousInNameCopy);
if (!DoesStartWith)
continue;
Len = Consummed;
@@ -290,9 +287,9 @@ nameToHangulCodePoint(StringRef Name, bool Strict, BufferType &Buffer) {
Buffer.clear();
// Hangul Syllable Decomposition
std::size_t Consummed = 0;
- char NameStart = 0, NeedleStart = 0;
- bool DoesStartWith = startsWith(Name, "HANGUL SYLLABLE ", Strict, Consummed,
- NameStart, NeedleStart);
+ char NameStart = 0;
+ bool DoesStartWith =
+ startsWith(Name, "HANGUL SYLLABLE ", Strict, Consummed, NameStart);
if (!DoesStartWith)
return std::nullopt;
Name = Name.substr(Consummed);
@@ -348,9 +345,9 @@ nameToGeneratedCodePoint(StringRef Name, bool Strict, BufferType &Buffer) {
for (auto &&Item : GeneratedNamesDataTable) {
Buffer.clear();
std::size_t Consummed = 0;
- char NameStart = 0, NeedleStart = 0;
+ char NameStart = 0;
bool DoesStartWith = startsWith(Name, Item.Prefix, Strict, Consummed,
- NameStart, NeedleStart, /*isPrefix*/ true);
+ NameStart, /*IsPrefix=*/true);
if (!DoesStartWith)
continue;
auto Number = Name.substr(Consummed);
@@ -390,8 +387,7 @@ static std::optional<char32_t> nameToCodepoint(StringRef Name, bool Strict,
std::reverse(Buffer.begin(), Buffer.end());
// UAX44-LM2. Ignore case, whitespace, underscore ('_'), and all medial
// hyphens except the hyphen in U+1180 HANGUL JUNGSEONG O-E.
- if (!Strict && Value == 0x116c &&
- Name.find_insensitive("O-E") != StringRef::npos) {
+ if (!Strict && Value == 0x116c && Name.contains_insensitive("O-E")) {
Buffer = "HANGUL JUNGSEONG O-E";
Value = 0x1180;
}