xref: /aosp_15_r20/external/llvm/lib/Support/Locale.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Locale.h"
2*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringRef.h"
3*9880d681SAndroid Build Coastguard Worker #include "llvm/Config/llvm-config.h"
4*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Unicode.h"
5*9880d681SAndroid Build Coastguard Worker 
6*9880d681SAndroid Build Coastguard Worker namespace llvm {
7*9880d681SAndroid Build Coastguard Worker namespace sys {
8*9880d681SAndroid Build Coastguard Worker namespace locale {
9*9880d681SAndroid Build Coastguard Worker 
columnWidth(StringRef Text)10*9880d681SAndroid Build Coastguard Worker int columnWidth(StringRef Text) {
11*9880d681SAndroid Build Coastguard Worker #if LLVM_ON_WIN32
12*9880d681SAndroid Build Coastguard Worker   return Text.size();
13*9880d681SAndroid Build Coastguard Worker #else
14*9880d681SAndroid Build Coastguard Worker   return llvm::sys::unicode::columnWidthUTF8(Text);
15*9880d681SAndroid Build Coastguard Worker #endif
16*9880d681SAndroid Build Coastguard Worker }
17*9880d681SAndroid Build Coastguard Worker 
isPrint(int UCS)18*9880d681SAndroid Build Coastguard Worker bool isPrint(int UCS) {
19*9880d681SAndroid Build Coastguard Worker #if LLVM_ON_WIN32
20*9880d681SAndroid Build Coastguard Worker   // Restrict characters that we'll try to print to the lower part of ASCII
21*9880d681SAndroid Build Coastguard Worker   // except for the control characters (0x20 - 0x7E). In general one can not
22*9880d681SAndroid Build Coastguard Worker   // reliably output code points U+0080 and higher using narrow character C/C++
23*9880d681SAndroid Build Coastguard Worker   // output functions in Windows, because the meaning of the upper 128 codes is
24*9880d681SAndroid Build Coastguard Worker   // determined by the active code page in the console.
25*9880d681SAndroid Build Coastguard Worker   return ' ' <= UCS && UCS <= '~';
26*9880d681SAndroid Build Coastguard Worker #else
27*9880d681SAndroid Build Coastguard Worker   return llvm::sys::unicode::isPrintable(UCS);
28*9880d681SAndroid Build Coastguard Worker #endif
29*9880d681SAndroid Build Coastguard Worker }
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker } // namespace locale
32*9880d681SAndroid Build Coastguard Worker } // namespace sys
33*9880d681SAndroid Build Coastguard Worker } // namespace llvm
34