summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/StringRefTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [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
* Implements StringRef::compare with bounds. It is behaves similarly to ↵Lenny Maiorani2011-04-151-0/+13
| | | | | | strncmp(). Unit tests also included. llvm-svn: 129582
* Don't infinitely recurse! Patch by Marius Wachtler!Chris Lattner2011-01-271-1/+1
| | | | llvm-svn: 124366
* StringRef::compare_numeric also differed from StringRef::compare for ↵Benjamin Kramer2010-08-261-0/+1
| | | | | | characters > 127. llvm-svn: 112189
* Do unsigned char comparisons in StringRef::compare_lower to be more ↵Benjamin Kramer2010-08-261-0/+8
| | | | | | consistent with compare in corner cases. llvm-svn: 112185
* Add StringRef::compare_numeric and use it to sort TableGen register records.Jakob Stoklund Olesen2010-05-261-0/+11
| | | | | | | This means that our Registers are now ordered R7, R8, R9, R10, R12, ... Not R1, R10, R11, R12, R2, R3, ... llvm-svn: 104745
* Silence compiler warning.Benjamin Kramer2009-12-311-1/+1
| | | | | warning: comparison between signed and unsigned integer expressions llvm-svn: 92359
* Document the edit-distance algorithm used in StringRef, switch it overDouglas Gregor2009-12-311-0/+5
| | | | | | to SmallVector, and add a unit test. llvm-svn: 92340
* Move the two definitions of operator<< into namespace llvm, so theyDouglas Gregor2009-12-241-1/+4
| | | | | | | will be found by argument-dependent lookup. As with the previous commit, GCC is allowing ill-formed code. llvm-svn: 92146
* Change StringRef::startswith and StringRef::endswith to versions which are aEli Friedman2009-12-211-0/+8
| | | | | | bit more verbose, but optimize to much shorter code. llvm-svn: 91817
* Reenable Split2 StringRef test with Apple gcc.Benjamin Kramer2009-11-191-6/+0
| | | | llvm-svn: 89357
OpenPOWER on IntegriCloud