llvm.org GIT mirror llvm / fdc97cd
platform support for counting column widths and checking isprint git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154944 91177308-0d34-0410-b5e6-96231b3b80d8 Seth Cantrell 8 years ago
6 changed file(s) with 121 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #ifndef LLVM_SUPPORT_LOCALE
1 #define LLVM_SUPPORT_LOCALE
2
3 #include "llvm/ADT/StringRef.h"
4
5 namespace llvm {
6 namespace sys {
7 namespace locale {
8
9 int columnWidth(StringRef s);
10 bool isPrint(int c);
11
12 }
13 }
14 }
15
16 #endif // LLVM_SUPPORT_LOCALE
3131 IntrusiveRefCntPtr.cpp
3232 IsInf.cpp
3333 IsNAN.cpp
34 Locale.cpp
3435 LockFileManager.cpp
3536 ManagedStatic.cpp
3637 MemoryBuffer.cpp
0 #include "llvm/Support/Locale.h"
1 #include "llvm/Config/config.h"
2
3 #ifdef __APPLE__
4 #include "LocaleXlocale.inc"
5 #elif LLVM_ON_WIN32
6 #include "LocaleWindows.inc"
7 #else
8 #include "LocaleGeneric.inc"
9 #endif
0 #include
1
2 namespace llvm {
3 namespace sys {
4 namespace locale {
5
6 int columnWidth(StringRef s) {
7 return s.size();
8 }
9
10 bool isPrint(int c) {
11 return iswprint(c);
12 }
13
14 }
15 }
16 }
0 namespace llvm {
1 namespace sys {
2 namespace locale {
3
4 int columnWidth(StringRef s) {
5 return s.size();
6 }
7
8 bool isPrint(int c) {
9 return ' ' <= c && c <= '~';
10 }
11
12 }
13 }
14 }
0 #include "llvm/ADT/SmallVector.h"
1 #include "llvm/ADT/SmallString.h"
2 #include "llvm/Support/ManagedStatic.h"
3 #include
4 #include
5
6
7 namespace {
8 struct locale_holder {
9 locale_holder()
10 : l(newlocale(LC_CTYPE_MASK,"en_US.UTF-8",LC_GLOBAL_LOCALE))
11 {
12 assert(NULL!=l);
13 }
14 ~locale_holder() {
15 freelocale(l);
16 }
17
18 int mbswidth(llvm::SmallString<16> s) const {
19 // this implementation assumes no '\0' in s
20 assert(s.size()==strlen(s.c_str()));
21
22 size_t size = mbstowcs_l(NULL,s.c_str(),0,l);
23 assert(size>=0);
24 if (size==0)
25 return 0;
26 llvm::SmallVector ws(size);
27 size = mbstowcs_l(&ws[0],s.c_str(),ws.size(),l);
28 assert(ws.size()==size);
29 return wcswidth_l(&ws[0],ws.size(),l);
30 }
31
32 int isprint(int c) const {
33 return iswprint_l(c,l);
34 }
35
36 private:
37
38 locale_t l;
39 };
40
41 llvm::ManagedStatic l;
42 }
43
44 namespace llvm {
45 namespace sys {
46 namespace locale {
47
48 int columnWidth(StringRef s) {
49 int width = l->mbswidth(s);
50 assert(width>=0);
51 return width;
52 }
53
54 bool isPrint(int c) {
55 return l->isprint(c);
56 }
57
58 }
59 }
60 }