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