summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/StringRefTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [polly][Support] Un-break polly testsAlexandre Ganea2020-01-011-0/+1
| | | | | | Previously, the polly unit tests were stuck in a infinite loop. There was an edge case in StringRef::count() introduced by 9f6b13e5cce96066d7262d224c971d93c2724795, where an empty 'Str' would cause the function to never exit. Also fixed usage in polly.
* [Support] Fix behavior of StringRef::count with overlapping occurrences, add ↵Johannes Doerfert2019-12-241-0/+7
| | | | | | | | | | | | | | | | | | tests Summary: Fix the behavior of StringRef::count(StringRef) to not count overlapping occurrences, as is stated in the documentation. Fixes bug https://bugs.llvm.org/show_bug.cgi?id=44072 I added Krzysztof Parzyszek to review this change because a use of this function in HexagonInstrInfo::getInlineAsmLength might depend on the overlapping-behavior. I don't have enough domain knowledge to tell if this change could break anything there. All other uses of this method in LLVM (besides the unit tests) only use single-character search strings. In those cases, search occurrences can not overlap anyway. Patch by Benno (@Bensge) Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D70585
* [StringRef] Test all default characters in unit testJonas Devlieghere2019-12-111-0/+4
| | | | | The default characters for trim, ltrim and rtrim are " \t\n\v\f\r" but only spaces were tested. Test that the others are trimmed as well.
* [ADT] Make StringRef(const char*) constexprBenjamin Kramer2019-08-261-0/+4
| | | | | | | | | | This should let us get rid of StringLiteral in the long term and avoid chasing accidental StringRef globals once and for all. This requires C++14, I godbolted it on every compiler I know we support so I hope there won't be much fallout. llvm-svn: 369961
* reland [gtest] Fix printing of StringRef and SmallString in assert messages.Sam McCall2019-08-211-0/+6
| | | | | | | | | Renames GTEST_NO_LLVM_RAW_OSTREAM -> GTEST_NO_LLVM_SUPPORT and guards the new features behind it. This reverts commit a063bcf3ef5a879adbe9639a3c187d876eee0e66. llvm-svn: 369527
* Revert "[gtest] Fix printing of StringRef and SmallString in assert messages."Sam McCall2019-08-211-6/+0
| | | | | | This reverts commit 4becb2ab4e9f52ce98272d1f5930d6942af5172b. llvm-svn: 369525
* [gtest] Fix printing of StringRef and SmallString in assert messages.Sam McCall2019-08-211-0/+6
| | | | | | | | | | | | | | | | | | Summary: These are detected by gtest as containers, and so previously printed as e.g. { '.' (46, 0x2E), 's' (115, 0x73), 'e' (101, 0x65), 'c' (99, 0x63), '0' (48, 0x30) }, gtest itself overloads PrintTo for std::string and friends, we use the same mechanism. Reviewers: labath Subscribers: dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66520 llvm-svn: 369518
* [ADT] Enable ArrayRef/StringRef is_assignable tests on MSVCSimon Pilgrim2019-07-091-6/+0
| | | | | | Now that we've dropped VS2015 support (D64326) we can enable these static_asserts on MSVC builds as VS2017+ correctly handles them llvm-svn: 365471
* Replace llvm::isPodLike<...> by llvm::is_trivially_copyable<...>Serge Guelton2019-01-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in https://bugs.llvm.org/show_bug.cgi?id=36651, the specialization for isPodLike<std::pair<...>> did not match the expectation of std::is_trivially_copyable which makes the memcpy optimization invalid. This patch renames the llvm::isPodLike trait into llvm::is_trivially_copyable. Unfortunately std::is_trivially_copyable is not portable across compiler / STL versions. So a portable version is provided too. Note that the following specialization were invalid: std::pair<T0, T1> llvm::Optional<T> Tests have been added to assert that former specialization are respected by the standard usage of llvm::is_trivially_copyable, and that when a decent version of std::is_trivially_copyable is available, llvm::is_trivially_copyable is compared to std::is_trivially_copyable. As of this patch, llvm::Optional is no longer considered trivially copyable, even if T is. This is to be fixed in a later patch, as it has impact on a long-running bug (see r347004) Note that GCC warns about this UB, but this got silented by https://reviews.llvm.org/D50296. Differential Revision: https://reviews.llvm.org/D54472 llvm-svn: 351701
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [ADT] Add `StringRef::rsplit(StringRef Separator)`.Henry Wong2018-06-081-0/+11
| | | | | | | | | | | | | | Summary: Add `StringRef::rsplit(StringRef Separator)` to achieve the function of getting the tail substring according to the separator. A typical usage is to get `data` in `std::basic_string::data`. Reviewers: mehdi_amini, zturner, beanz, xbolva00, vsk Reviewed By: zturner, xbolva00, vsk Subscribers: vsk, xbolva00, llvm-commits, MTC Differential Revision: https://reviews.llvm.org/D47406 llvm-svn: 334283
* Fix incorrect usage of std::is_assignable.Richard Smith2018-02-021-6/+6
| | | | | | We want to check that we can assign to an lvalue here, not a prvalue. llvm-svn: 324152
* Fix APFloat from string conversion for InfSerguei Katkov2017-12-191-1/+6
| | | | | | | | | | | | | | | | | | The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Re-landing after fix. Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon, anna Reviewed By: anna Subscribers: mkazantsev, FlameTop, llvm-commits, reames, apilipenko Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 321054
* Added braces to work around gcc warning in googletest: suggest explicit ↵Galina Kistanova2017-06-151-1/+2
| | | | | | braces to avoid ambiguous 'else'. NFC. llvm-svn: 305506
* Add more test cases for StringRef::edit_distanceAlex Denisov2017-04-141-2/+16
| | | | | | Example strings taken from here: http://www.let.rug.nl/~kleiweg/lev/ llvm-svn: 300312
* [ADT] Add a version of llvm::join() that takes a range.Zachary Turner2017-03-211-0/+2
| | | | llvm-svn: 298427
* [Support] Add StringRef::getAsDouble.Zachary Turner2017-02-141-0/+21
| | | | | | Differential Revision: https://reviews.llvm.org/D29918 llvm-svn: 295089
* [ADT] Add llvm::StringLiteral.Zachary Turner2016-12-131-0/+6
| | | | | | | | | | | StringLiteral is a wrapper around a string literal useful for replacing global tables of char arrays with global tables of StringRefs that can initialized in a constexpr context, avoiding the invocation of a global constructor. Differential Revision: https://reviews.llvm.org/D27686 llvm-svn: 289551
* [Support] Add StringRef::find_lower and contains_lower.Zachary Turner2016-11-121-15/+61
| | | | | | Differential Revision: https://reviews.llvm.org/D25299 llvm-svn: 286724
* Add tests for r286139.Jordan Rose2016-11-071-0/+36
| | | | llvm-svn: 286141
* Fix signed / unsigned comparison.Zachary Turner2016-09-251-2/+2
| | | | llvm-svn: 282348
* Add some predicated searching functions to StringRef.Zachary Turner2016-09-251-0/+56
| | | | | | | | | | | | | | | | | | | | | | This adds 4 new functions to StringRef, which can be used to take or drop characters while a certain condition is met, or until a certain condition is met. They are: take_while - Return characters until a condition is not met. take_until - Return characters until a condition is met. drop_while - Remove characters until a condition is not met. drop_until - Remove characters until a condition is met. Internally, all of these functions delegate to two additional helper functions which can be used to search for the position of a character meeting or not meeting a condition, which are: find_if - Find the first character matching a predicate. find_if_not - Find the first character not matching a predicate. Differential Revision: https://reviews.llvm.org/D24842 llvm-svn: 282346
* Fix build breakage due to typo in cast.Zachary Turner2016-09-221-0/+2
| | | | llvm-svn: 282183
* Speculative fix for build failures due to consumeInteger.Zachary Turner2016-09-221-1/+2
| | | | | | | | | | | | | | | | A recent patch added support for consumeInteger() and made getAsInteger delegate to this function. A few buildbots are failing as a result with an assertion failure. On a hunch, I tested what happens if I call getAsInteger() on an empty string, and sure enough it crashes the same way that the buildbots are crashing. I confirmed that getAsInteger() on an empty string did not crash before my patch, so I suspect this to be the cause. I also added a unit test for the empty string. llvm-svn: 282170
* [Support] Add StringRef::consumeInteger.Zachary Turner2016-09-221-0/+177
| | | | | | | | | | | | | | | | | | | | | StringRef::getInteger() exists and treats the entire string as an integer of the specified radix, failing if any invalid characters are encountered or the number overflows. Sometimes you might have something like "123456foo" and you want to get the number 123456 and leave the string "foo" remaining. This is similar to what would be possible by using the standard runtime library functions strtoul et al and specifying an end pointer. This patch adds consumeInteger(), which does exactly that. It consumes as much as possible until an invalid character is found, and modifies the StringRef in place so that upon return only the portion of the StringRef after the number remains. Differential Revision: https://reviews.llvm.org/D24778 llvm-svn: 282164
* Add StringRef::take_front and StringRef::take_backZachary Turner2016-08-301-0/+43
| | | | | | | Reviewed By: majnemer, rnk Differential Revision: https://reviews.llvm.org/D23965 llvm-svn: 280114
* [ADT] Add 'consume_front' and 'consume_back' methods to StringRef whichChandler Carruth2016-07-311-0/+32
| | | | | | | | | | | are very handy when parsing text. They are essentially a combination of startswith and a self-modifying drop_front, or endswith and drop_back respectively. Differential Revision: https://reviews.llvm.org/D22723 llvm-svn: 277288
* StringRef::copy shouldn't allocate anything for length 0 strings.Pete Cooper2016-03-231-0/+9
| | | | | | | | | | | The BumpPtrAllocator currently doesn't handle zero length allocations well. The discussion for how to fix that is ongoing. However, there's no need for StringRef::copy to actually allocate anything here anyway, so just return StringRef() when we get a zero length copy. Reviewed by David Blaikie llvm-svn: 264201
* [ADT] Add StringRef::{l,r}trim(char) overloads (NFC)Vedant Kumar2016-02-161-1/+1
| | | | | | | | | Add support for trimming a single kind of character from a StringRef. This makes the common case of trimming null bytes much neater. It's also probably a bit speedier too, since it avoids creating a std::bitset in find_{first,last}_not_of. llvm-svn: 260925
* [ADT] Fix a confusing interface spec and some annoying peculiaritiesChandler Carruth2015-09-101-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | with the StringRef::split method when used with a MaxSplit argument other than '-1' (which nobody really does today, but which should actually work). The spec claimed both to split up to MaxSplit times, but also to append <= MaxSplit strings to the vector. One of these doesn't make sense. Given the name "MaxSplit", let's go with it being a max over how many *splits* occur, which means the max on how many strings get appended is MaxSplit+1. I'm not actually sure the implementation correctly provided this logic either, as it used a really opaque loop structure. The implementation was also playing weird games with nullptr in the data field to try to rely on a totally opaque hidden property of the split method that returns a pair. Nasty IMO. Replace all of this with what is (IMO) simpler code that doesn't use the pair returning split method, and instead just finds each separator and appends directly. I think this is a lot easier to read, and it most definitely matches the spec. Added some tests that exercise the corner cases around StringRef() and StringRef("") that all now pass. I'll start using this in code in the next commit. llvm-svn: 247249
* [ADT] Add a single-character version of the small vector split routineChandler Carruth2015-09-101-0/+5
| | | | | | | | | | | on StringRef. Finding and splitting on a single character is substantially faster than doing it on even a single character StringRef -- we immediately get to a *very* tuned memchr call this way. Even nicer, we get to this even in a debug build, shaving 18% off the runtime of TripleTest.Normalization, helping PR23676 some more. llvm-svn: 247244
* Retire llvm::array_endof in favor of non-member std::end.Benjamin Kramer2014-04-121-0/+1
| | | | | | While there make array_lengthof constexpr if we have support for it. llvm-svn: 206112
* Fix layering StringRef copy using BumpPtrAllocator.Nick Kledzik2014-02-051-0/+15
| | | | | | | | | Now to copy a string into a BumpPtrAllocator and get a StringRef to the copy: StringRef myCopy = myStr.copy(myAllocator); llvm-svn: 200885
* Roll back the ConstStringRef change for nowAlp Toker2014-01-271-18/+0
| | | | | | | | | | | There are a couple of interesting things here that we want to check over (particularly the expecting asserts in StringRef) and get right for general use in ADT so hold back on this one. For clang we have a workable templated solution to use in the meanwhile. This reverts commit r200187. llvm-svn: 200194
* StringRef: Extend constexpr capabilities and introduce ConstStringRefAlp Toker2014-01-271-0/+18
| | | | | | | | | | | | | | | | | | | (1) Add llvm_expect(), an asserting macro that can be evaluated as a constexpr expression as well as a runtime assert or compiler hint in release builds. This technique can be used to construct functions that are both unevaluated and compiled depending on usage. (2) Update StringRef using llvm_expect() to preserve runtime assertions while extending the same checks to static asserts in C++11 builds that support the feature. (3) Introduce ConstStringRef, a strong subclass of StringRef that references compile-time constant strings. It's convertible to, but not from, ordinary StringRef and thus can be used to add compile-time safety to various interfaces in LLVM and clang that only accept fixed inputs such as diagnostic format strings that tend to get misused. llvm-svn: 200187
* Re-sort all of the includes with ./utils/sort_includes.py so thatChandler Carruth2014-01-071-1/+1
| | | | | | | | | | subsequent changes are easier to review. About to fix some layering issues, and wanted to separate out the necessary churn. Also comment and sink the include of "Windows.h" in three .inc files to match the usage in Memory.inc. llvm-svn: 198685
* Add {start,end}with_lower methods to StringRef.Rui Ueyama2013-10-301-0/+23
| | | | | | | | | startswith_lower is ocassionally useful and I think worth adding. endwith_lower is added for completeness. Differential Revision: http://llvm-reviews.chandlerc.com/D2041 llvm-svn: 193706
* Add a few tests for StringRef::{start,end}with.Rui Ueyama2013-10-281-0/+2
| | | | llvm-svn: 193550
* Add a Python-like join function to merge a list of strings with aJoerg Sonnenberger2013-09-031-0/+27
| | | | | | separator between each two elements. llvm-svn: 189846
* Sort the #include lines for unittest/...Chandler Carruth2012-12-041-1/+1
| | | | llvm-svn: 169250
* Use unsigned long long instead of uin64_t for OS where that matters.Nick Kledzik2012-10-031-1/+1
| | | | llvm-svn: 165147
* Don't call getAsUnsignedInteger directly, it fails to compile if uint64_t is ↵Benjamin Kramer2012-10-031-1/+5
| | | | | | | | not "unsigned long long". while there add more test cases. llvm-svn: 165140
* Add getAsUnsignedInteger test case that checks that known bad values are ↵Nick Kledzik2012-10-031-0/+19
| | | | | | rejected llvm-svn: 165136
* [Support/StringRef] Add find_last_not_of and {r,l,}trim.Michael J. Spencer2012-05-111-0/+28
| | | | llvm-svn: 156652
* Fix warnings.Michael J. Spencer2012-03-111-4/+4
| | | | llvm-svn: 152522
* Make StringRef::getAsInteger work with all integer types. Before this changeMichael J. Spencer2012-03-101-0/+118
| | | | | | | | it would fail with {,u}int64_t on x86-64 Linux. This also removes code duplication. llvm-svn: 152517
* Add generic support for hashing StringRef objects using the new hashing library.Chandler Carruth2012-03-041-0/+19
| | | | llvm-svn: 152003
* Add a bad char heuristic to StringRef::find.Benjamin Kramer2011-10-151-0/+6
| | | | | | | | | Based on Horspool's simplified version of Boyer-Moore. We use a constant-sized table of uint8_ts to keep cache thrashing low, needles bigger than 255 bytes are uncommon anyways. The worst case is still O(n*m) but we do a lot better on the average case now. llvm-svn: 142061
* Fix a bug in compare_numeric().Jakob Stoklund Olesen2011-09-301-0/+6
| | | | | | Thanks to Alexandru Dura and Jonas Paulsson for finding it. llvm-svn: 140859
* Remove bounded StringRef::compare() since nothing but Clang SA was using it ↵Lenny Maiorani2011-04-281-13/+0
| | | | | | and it is just as easy to use StringRef::substr() preceding StringRef::compare() to achieve the same thing. llvm-svn: 130430
OpenPOWER on IntegriCloud