diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:31:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-31 18:56:55 +0000 |
commit | af732203b8f7f006927528db5497f5cbc4c4742a (patch) | |
tree | 596f112de3b76118552871dbb6114bb7e3e17f40 /contrib/llvm-project/llvm/lib/Support/Unicode.cpp | |
parent | 83dea422ac8d4a8323e64203c2eadaa813768717 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Unicode.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/Unicode.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Unicode.cpp b/contrib/llvm-project/llvm/lib/Support/Unicode.cpp index 4d195069682b..bb6e75555b4c 100644 --- a/contrib/llvm-project/llvm/lib/Support/Unicode.cpp +++ b/contrib/llvm-project/llvm/lib/Support/Unicode.cpp @@ -339,11 +339,22 @@ static inline int charWidth(int UCS) return 1; } +static bool isprintableascii(char c) { return c > 31 && c < 127; } + int columnWidthUTF8(StringRef Text) { unsigned ColumnWidth = 0; unsigned Length; for (size_t i = 0, e = Text.size(); i < e; i += Length) { Length = getNumBytesForUTF8(Text[i]); + + // fast path for ASCII characters + if (Length == 1) { + if (!isprintableascii(Text[i])) + return ErrorNonPrintableCharacter; + ColumnWidth += 1; + continue; + } + if (Length <= 0 || i + Length > Text.size()) return ErrorInvalidUTF8; UTF32 buf[1]; |