clang: lib/Format/Encoding.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_CLANG_LIB_FORMAT_ENCODING_H
16#define LLVM_CLANG_LIB_FORMAT_ENCODING_H
17
19#include "llvm/Support/ConvertUTF.h"
20#include "llvm/Support/Unicode.h"
21
23namespace format {
24namespace encoding {
25
30
31
32
34 const llvm::UTF8 *Ptr = reinterpret_cast<const llvm::UTF8 *>(Text.begin());
35 const llvm::UTF8 *BufEnd = reinterpret_cast<const llvm::UTF8 *>(Text.end());
36 if (llvm::isLegalUTF8String(&Ptr, BufEnd))
39}
40
41
42
43
46 int ContentWidth = llvm::sys::unicode::columnWidthUTF8(Text);
47
48
49
50
51 if (ContentWidth >= 0)
52 return ContentWidth;
53 }
54 return Text.size();
55}
56
57
58
59
62 unsigned TotalWidth = 0;
63 StringRef Tail = Text;
64 for (;;) {
65 StringRef::size_type TabPos = Tail.find('\t');
66 if (TabPos == StringRef::npos)
69 if (TabWidth)
70 TotalWidth += TabWidth - (TotalWidth + StartColumn) % TabWidth;
71 Tail = Tail.substr(TabPos + 1);
72 }
73}
74
75
76
80 return llvm::getNumBytesForUTF8(FirstChar);
81 default:
82 return 1;
83 }
84}
85
86inline bool isOctDigit(char c) { return '0' <= c && c <= '7'; }
87
89 return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') ||
91}
92
93
94
95
97 assert(Text[0] == '\\');
98 if (Text.size() < 2)
99 return 1;
100
101 switch (Text[1]) {
102 case 'u':
103 return 6;
104 case 'U':
105 return 10;
106 case 'x': {
107 unsigned I = 2;
109 ++I;
110 return I;
111 }
112 default:
114 unsigned I = 1;
116 ++I;
117 return I;
118 }
119 return 1 + llvm::getNumBytesForUTF8(Text[1]);
120 }
121}
122
123}
124}
125}
126
127#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
__device__ __2f16 float c
unsigned columnWidthWithTabs(StringRef Text, unsigned StartColumn, unsigned TabWidth, Encoding Encoding)
Returns the number of columns required to display the Text, starting from the StartColumn on a termin...
Encoding detectEncoding(StringRef Text)
Detects encoding of the Text.
unsigned getEscapeSequenceLength(StringRef Text)
Gets the length of an escape sequence inside a C++ string literal.
unsigned getCodePointNumBytes(char FirstChar, Encoding Encoding)
Gets the number of bytes in a sequence representing a single codepoint and starting with FirstChar in...
unsigned columnWidth(StringRef Text, Encoding Encoding)
Returns the number of columns required to display the Text on a generic Unicode-capable terminal.
The JSON file list parser is used to communicate input to InstallAPI.