aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringRefTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-14[llvm] Use std::bool_constant (NFC) (#158520)Kazu Hirata1-3/+2
This patch replaces, std::integral_constant<bool, ...> with std::bool_constant for brevity. Note that std::bool_constant was introduced as part of C++17. There are cases where we could replace EXPECT_EQ(false, ...) with EXPECT_FALSE(...), but I'm not doing that in this patch to avoid doing multiple things in one patch.
2025-08-07[ADT] Make `getAutoSenseRadix` in `StringRef` global (#152503)Ilia Kuklin1-0/+13
Needed in #152308
2024-08-22[NFC][ADT] Add reverse iterators and `value_type` to StringRef (#105579)Rahul Joshi1-3/+11
- Add reverse iterators and `value_type` to StringRef. - Add unit test for all 4 iterator flavors. - This prepares StringRef to be used with `SequenceToOffsetTable`.
2024-08-21[NFC][ADT] Remove << operators from StringRefTest (#105500)Rahul Joshi1-15/+0
- Remove ostream << operators for StringRef and StringRef pair from StringTest. Both of these are natively supported by googletest framework.
2024-08-21[NFC][ADT] Format StringRefTest.cpp to fit in 80 columns. (#105502)Rahul Joshi1-11/+13
2024-05-08[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)Kazu Hirata1-3/+3
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 70 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-04-27[ADT] Add StringRef::{starts,ends}_with(char) (#90311)Kazu Hirata1-0/+4
This patch adds to StringRef the equivalent of std::string_view::{starts,ends}_with(char) in C++20.
2024-01-11[ADT] Make StringRef std::string_view conversion operator constexpr. NFC ↵Luke Lau1-0/+14
(#77506) This would allow us to compare StringRefs via std::string_view, avoiding having to make the existing StringRef compare machinery constexpr for now.
2023-05-23Add StringRef::consumeInteger(APInt)Thomas Preud'homme1-0/+7
This will be required to allow arbitrary precision support to FileCheck's numeric variables and expressions. Note: as per getAsInteger(), this does not support negative value. If there is interest for that it can be added in a separate patch. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D150878
2023-01-15[ADT] Make StringRef::compare like std::string_view::compareBenjamin Kramer1-5/+5
string_view has a slightly weaker contract, which only specifies whether the value is bigger or smaller than 0. Adapt users accordingly and just forward to the standard function (that also compiles down to memcmp)
2022-11-08Reland "[llvm][NFC] Use c++17 style variable type traits"Nathan James1-20/+13
This reverts commit 632a389f96355cbe7ed8fa7b8d2ed6267c92457c. This relands commit 1834a310d060d55748ca38d4ae0482864c2047d8. Differential Revision: https://reviews.llvm.org/D137493
2022-11-08Revert "[llvm][NFC] Use c++17 style variable type traits"Nathan James1-13/+20
This reverts commit 1834a310d060d55748ca38d4ae0482864c2047d8.
2022-11-08[llvm][NFC] Use c++17 style variable type traitsNathan James1-20/+13
This was done as a test for D137302 and it makes sense to push these changes Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D137493
2022-10-15[ADT] Introduce StringRef::{starts,ends}_width{,_insensitive}Kazu Hirata1-21/+21
This patch introduces: StringRef::starts_with StringRef::starts_with_insensitive StringRef::ends_with StringRef::ends_with_insensitive to be more compatible with std::string and std::string_view. I'm planning to deprecate the existing functions in favor of the new ones. Differential Revision: https://reviews.llvm.org/D136030
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser1-6/+6
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-08-11[Support] Remove some #if __cplusplus > 201402LFangrui Song1-4/+0
2022-06-05[ADT] Add edit_distance_insensitive to StringRefNathan James1-0/+9
In some instances its advantageous to calculate edit distances without worrying about casing. Currently to achieve this both strings need to be converted to the same case first, then edit distance can be calculated. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D126159
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-6/+6
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-6/+6
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-21[ADT] [NFC] Add StringRef::detectEOLChris Bieneman1-0/+30
This change moves EOL detection out of the clang::InclusionRewriter into llvm::StringRef so that it can be easily reused elsewhere. It also adds additional explicit test cases to verify the correct and expected return results. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D117626
2021-12-08ADT: Make StringRef::size() and StringRef::empty() constexprDuncan P. N. Exon Smith1-0/+4
This unblocks using `StringLiteral::size()` for a SmallVector size in another patch. Differential Revision: https://reviews.llvm.org/D115395
2021-06-25[ADT] Rename StringRef case insensitive methods for clarityMartin Storsjö1-49/+49
Rename functions with the `xx_lower()` names to `xx_insensitive()`. This was requested during the review of D104218. Test names and variables in llvm/unittests/ADT/StringRefTest.cpp that refer to "lower" are renamed to "insensitive" correspondingly. Unused function aliases with the former method names are left in place (without any deprecation attributes) for transition purposes. All references within the monorepo will be changed (with essentially mechanical changes), and then the old names will be removed in a later commit. Also remove the superfluous method names at the start of doxygen comments, for the methods that are touched here. (There are more occurrances of this left in other methods though.) Also remove duplicate doxygen comments from the implementation file. Differential Revision: https://reviews.llvm.org/D104819
2021-06-22[ADT] Add StringRef consume_front_lower and consume_back_lowerMartin Storsjö1-0/+36
These serve as a convenient combination of consume_front/back and startswith_lower/endswith_lower, consistent with other existing case insensitive methods named <operation>_lower. Differential Revision: https://reviews.llvm.org/D104218
2021-03-19[RGT] Recode more unreachable assertions and tautologiesPaul Robinson1-28/+10
Count iterations of zero-trip loops and assert the count is zero, rather than asserting inside the loop. Unreachable functions should use llvm_unreachable. Remove tautological 'if' statements, even when they're following a pattern of checks. Found by the Rotten Green Tests project.
2020-12-02Switch from llvm::is_trivially_copyable to std::is_trivially_copyableFangrui Song1-1/+2
GCC<5 did not support std::is_trivially_copyable. Now LLVM builds require 5.1 we can migrate to std::is_trivially_copyable. The Optional.h change made MSVC choke (https://buildkite.com/llvm-project/premerge-checks/builds/18587#cd1bb616-ffdc-4581-9795-b42c284196de) so I leave it out for now. Differential Revision: https://reviews.llvm.org/D92514
2020-12-02Revert "Use std::is_trivially_copyable", breaks MSVC buildReid Kleckner1-2/+1
Revert "Delete llvm::is_trivially_copyable and CMake variable HAVE_STD_IS_TRIVIALLY_COPYABLE" This reverts commit 4d4bd40b578d77b8c5bc349ded405fb58c333c78. This reverts commit 557b00e0afb2dc1776f50948094ca8cc62d97be4.
2020-12-02Use std::is_trivially_copyableFangrui Song1-1/+2
GCC<5 did not support std::is_trivially_copyable. Now LLVM builds require 5.1 we can migrate to std::is_trivially_copyable.
2020-01-28[ADT] Implicitly convert between StringRef and std::string_view when we have ↵Benjamin Kramer1-0/+10
C++17 This makes the types almost seamlessly interchangeable in C++17 codebases. Eventually we want to replace StringRef with the standard type, but that requires C++17 being the default and a huge refactoring job as StringRef has a lot more functionality.
2020-01-01[polly][Support] Un-break polly testsAlexandre Ganea1-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.
2019-12-24[Support] Fix behavior of StringRef::count with overlapping occurrences, add ↵Johannes Doerfert1-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
2019-12-11[StringRef] Test all default characters in unit testJonas Devlieghere1-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.
2019-08-26[ADT] Make StringRef(const char*) constexprBenjamin Kramer1-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
2019-08-21reland [gtest] Fix printing of StringRef and SmallString in assert messages.Sam McCall1-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
2019-08-21Revert "[gtest] Fix printing of StringRef and SmallString in assert messages."Sam McCall1-6/+0
This reverts commit 4becb2ab4e9f52ce98272d1f5930d6942af5172b. llvm-svn: 369525
2019-08-21[gtest] Fix printing of StringRef and SmallString in assert messages.Sam McCall1-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
2019-07-09[ADT] Enable ArrayRef/StringRef is_assignable tests on MSVCSimon Pilgrim1-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
2019-01-20Replace llvm::isPodLike<...> by llvm::is_trivially_copyable<...>Serge Guelton1-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
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-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
2018-06-08[ADT] Add `StringRef::rsplit(StringRef Separator)`.Henry Wong1-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
2018-02-02Fix incorrect usage of std::is_assignable.Richard Smith1-6/+6
We want to check that we can assign to an lvalue here, not a prvalue. llvm-svn: 324152
2017-12-19Fix APFloat from string conversion for InfSerguei Katkov1-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
2017-06-15Added braces to work around gcc warning in googletest: suggest explicit ↵Galina Kistanova1-1/+2
braces to avoid ambiguous 'else'. NFC. llvm-svn: 305506
2017-04-14Add more test cases for StringRef::edit_distanceAlex Denisov1-2/+16
Example strings taken from here: http://www.let.rug.nl/~kleiweg/lev/ llvm-svn: 300312
2017-03-21[ADT] Add a version of llvm::join() that takes a range.Zachary Turner1-0/+2
llvm-svn: 298427
2017-02-14[Support] Add StringRef::getAsDouble.Zachary Turner1-0/+21
Differential Revision: https://reviews.llvm.org/D29918 llvm-svn: 295089
2016-12-13[ADT] Add llvm::StringLiteral.Zachary Turner1-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
2016-11-12[Support] Add StringRef::find_lower and contains_lower.Zachary Turner1-15/+61
Differential Revision: https://reviews.llvm.org/D25299 llvm-svn: 286724
2016-11-07Add tests for r286139.Jordan Rose1-0/+36
llvm-svn: 286141
2016-09-25Fix signed / unsigned comparison.Zachary Turner1-2/+2
llvm-svn: 282348
2016-09-25Add some predicated searching functions to StringRef.Zachary Turner1-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