| Seth Cantrell | 75dbcb8 | 2012-04-17 20:03:03 +0000 | [diff] [blame] | 1 | #include "llvm/Support/Locale.h" | 
| Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 2 | #include "llvm/ADT/StringRef.h" | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 3 | #include "llvm/Support/Unicode.h" | 
| Seth Cantrell | 75dbcb8 | 2012-04-17 20:03:03 +0000 | [diff] [blame] | 4 |  | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 5 | namespace llvm { | 
|  | 6 | namespace sys { | 
|  | 7 | namespace locale { | 
|  | 8 |  | 
|  | 9 | int columnWidth(StringRef Text) { | 
| Nico Weber | 712e8d2 | 2018-04-29 00:45:03 +0000 | [diff] [blame] | 10 | #if _WIN32 | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 11 | return Text.size(); | 
| Seth Cantrell | 75dbcb8 | 2012-04-17 20:03:03 +0000 | [diff] [blame] | 12 | #else | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 13 | return llvm::sys::unicode::columnWidthUTF8(Text); | 
| Seth Cantrell | 75dbcb8 | 2012-04-17 20:03:03 +0000 | [diff] [blame] | 14 | #endif | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 15 | } | 
|  | 16 |  | 
|  | 17 | bool isPrint(int UCS) { | 
| Nico Weber | 712e8d2 | 2018-04-29 00:45:03 +0000 | [diff] [blame] | 18 | #if _WIN32 | 
| Eric Christopher | 572e03a | 2015-06-19 01:53:21 +0000 | [diff] [blame] | 19 | // Restrict characters that we'll try to print to the lower part of ASCII | 
| Alexander Kornienko | 9aa60fd | 2013-09-04 16:00:12 +0000 | [diff] [blame] | 20 | // 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 |