blob: 53bc0e36d830e1b59939b2fd279b9195937acf8d [file] [log] [blame]
Yaron Keren102e3ce2015-09-11 13:22:47 +00001#include "llvm/Config/llvm-config.h"
Seth Cantrell75dbcb82012-04-17 20:03:03 +00002#include "llvm/Support/Locale.h"
Alexander Kornienko9aa60fd2013-09-04 16:00:12 +00003#include "llvm/Support/Unicode.h"
Seth Cantrell75dbcb82012-04-17 20:03:03 +00004
Alexander Kornienko9aa60fd2013-09-04 16:00:12 +00005namespace llvm {
6namespace sys {
7namespace locale {
8
9int columnWidth(StringRef Text) {
10#if LLVM_ON_WIN32
11 return Text.size();
Seth Cantrell75dbcb82012-04-17 20:03:03 +000012#else
Alexander Kornienko9aa60fd2013-09-04 16:00:12 +000013 return llvm::sys::unicode::columnWidthUTF8(Text);
Seth Cantrell75dbcb82012-04-17 20:03:03 +000014#endif
Alexander Kornienko9aa60fd2013-09-04 16:00:12 +000015}
16
17bool isPrint(int UCS) {
18#if LLVM_ON_WIN32
Eric Christopher572e03a2015-06-19 01:53:21 +000019 // Restrict characters that we'll try to print to the lower part of ASCII
Alexander Kornienko9aa60fd2013-09-04 16:00:12 +000020 // except for the control characters (0x20 - 0x7E). In general one can not
21 // reliably output code points U+0080 and higher using narrow character C/C++
22 // output functions in Windows, because the meaning of the upper 128 codes is
23 // determined by the active code page in the console.
24 return ' ' <= UCS && UCS <= '~';
25#else
26 return llvm::sys::unicode::isPrintable(UCS);
27#endif
28}
29
30} // namespace locale
31} // namespace sys
32} // namespace llvm