summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/StringExtrasTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ADT] Replace std::isprint by llvm::isPrint.Michael Kruse2018-07-261-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The standard library functions ::isprint/std::isprint have platform- and locale-dependent behavior which makes LLVM's output less predictable. In particular, regression tests my fail depending on the implementation of these functions. Implement llvm::isPrint in StringExtras.h with a standard behavior and replace all uses of ::isprint/std::isprint by a call it llvm::isPrint. The function is inlined and does not look up language settings so it should perform better than the standard library's version. Such a replacement has already been done for isdigit, isalpha, isxdigit in r314883. gtest does the same in gtest-printers.cc using the following justification: // Returns true if c is a printable ASCII character. We test the // value of c directly instead of calling isprint(), which is buggy on // Windows Mobile. inline bool IsPrintableAscii(wchar_t c) { return 0x20 <= c && c <= 0x7E; } Similar issues have also been encountered by Julia: https://github.com/JuliaLang/julia/issues/7416 I noticed the problem myself when on Windows isprint('\t') started to evaluate to true (see https://stackoverflow.com/questions/51435249) and thus caused several unit tests to fail. The result of isprint doesn't seem to be well-defined even for ASCII characters. Therefore I suggest to replace isprint by a platform-independent version. Differential Revision: https://reviews.llvm.org/D49680 llvm-svn: 338034
* [ADT] Make escaping fn conform to coding guidelinesJonas Devlieghere2018-05-311-2/+2
| | | | | | | | As noted by Adrian on llvm-commits, PrintHTMLEscaped and PrintEscaped in StringExtras did not conform to the LLVM coding guidelines. This commit rectifies that. llvm-svn: 333669
* [ADT] Add unit test for PrintHTMLEscapedJonas Devlieghere2018-05-301-0/+7
| | | | | | Add unit tests for PrintHTMLEscaped which was added in r333565. llvm-svn: 333590
* [Support] Add unit test for printLowerCaseFrancis Visoiu Mistrih2017-11-281-0/+8
| | | | | | Add test case for the function added in r319171. llvm-svn: 319177
* Fix double->float truncation warning on MSVCSimon Pilgrim2017-06-231-2/+2
| | | | llvm-svn: 306101
* [ADT] Add llvm::to_floatPavel Labath2017-06-231-1/+19
| | | | | | | | | | | | | | | | | | Summary: The function matches the interface of llvm::to_integer, but as we are calling out to a C library function, I let it take a Twine argument, so we can avoid a string copy at least in some cases. I add a test and replace a couple of existing uses of strtod with this function. Reviewers: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34518 llvm-svn: 306096
* [StringExtras] Add a fromHex to complement toHex.Zachary Turner2017-04-251-0/+16
| | | | | | | | | | We already have a function toHex that will convert a string like "\xFF\xFF" to the string "FFFF", but we do not have one that goes the other way - i.e. to convert a textual string representing a sequence of hexadecimal characters into the corresponding actual bytes. This patch adds such a function. llvm-svn: 301356
* Add llvm::join_items to StringExtras.Zachary Turner2016-09-271-0/+52
llvm::join_items is similar to llvm::join, which produces a string by concatenating a sequence of values together separated by a given separator. But it differs in that the arguments to llvm::join() are same-type members of a container, whereas the arguments to llvm::join_items are arbitrary types passed into a variadic template. The only requirement on parameters to llvm::join_items (including for the separator themselves) is that they be implicitly convertible to std::string or have an overload of std::string::operator+ Differential Revision: https://reviews.llvm.org/D24880 llvm-svn: 282502
OpenPOWER on IntegriCloud