File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 17
17
#include < cassert>
18
18
#include < cstddef>
19
19
#include < cstring>
20
+ #include < iterator>
20
21
#include < limits>
21
22
#include < string>
22
23
#include < string_view>
@@ -54,6 +55,9 @@ namespace llvm {
54
55
using iterator = const char *;
55
56
using const_iterator = const char *;
56
57
using size_type = size_t ;
58
+ using value_type = char ;
59
+ using reverse_iterator = std::reverse_iterator<iterator>;
60
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
57
61
58
62
private:
59
63
// / The start of the string, in an external buffer.
@@ -112,6 +116,14 @@ namespace llvm {
112
116
113
117
iterator end () const { return Data + Length; }
114
118
119
+ reverse_iterator rbegin () const {
120
+ return std::make_reverse_iterator (end ());
121
+ }
122
+
123
+ reverse_iterator rend () const {
124
+ return std::make_reverse_iterator (begin ());
125
+ }
126
+
115
127
const unsigned char *bytes_begin () const {
116
128
return reinterpret_cast <const unsigned char *>(begin ());
117
129
}
Original file line number Diff line number Diff line change @@ -57,9 +57,17 @@ TEST(StringRefTest, EmptyInitializerList) {
57
57
58
58
TEST (StringRefTest, Iteration) {
59
59
StringRef S (" hello" );
60
- const char *p = " hello" ;
61
- for (const char *it = S.begin (), *ie = S.end (); it != ie; ++it, ++p)
62
- EXPECT_EQ (*it, *p);
60
+ constexpr StringLiteral CS (" hello" );
61
+
62
+ // Note: Cannot use literal strings in equal() as iteration over a literal
63
+ // string includes the null terminator.
64
+ const std::string_view RefFwd (" hello" );
65
+ const std::string_view RefRev (" olleh" );
66
+
67
+ EXPECT_TRUE (equal (S, RefFwd));
68
+ EXPECT_TRUE (equal (CS, RefFwd));
69
+ EXPECT_TRUE (equal (make_range (S.rbegin (), S.rend ()), RefRev));
70
+ EXPECT_TRUE (equal (make_range (CS.rbegin (), CS.rend ()), RefRev));
63
71
}
64
72
65
73
TEST (StringRefTest, StringOps) {
You can’t perform that action at this time.
0 commit comments