File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-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 @@ -72,9 +72,18 @@ TEST(StringRefTest, EmptyInitializerList) {
72
72
73
73
TEST (StringRefTest, Iteration) {
74
74
StringRef S (" hello" );
75
- const char *p = " hello" ;
76
- for (const char *it = S.begin (), *ie = S.end (); it != ie; ++it, ++p)
77
- EXPECT_EQ (*it, *p);
75
+ constexpr StringLiteral CS (" hello" );
76
+
77
+ // Note: Cannot use literal strings in equal() as iteration over a literal
78
+ // string includes the null terminator.
79
+ constexpr std::string_view RefFwd (" hello" );
80
+ constexpr std::string_view RefRev (" olleh" );
81
+
82
+ EXPECT_TRUE (equal (S, RefFwd));
83
+ EXPECT_TRUE (equal (CS, RefFwd));
84
+ // reverse() builds an iterator range using StringRef::rbegin()/rend().
85
+ EXPECT_TRUE (equal (reverse (S), RefRev));
86
+ EXPECT_TRUE (equal (reverse (CS), RefRev));
78
87
}
79
88
80
89
TEST (StringRefTest, StringOps) {
You can’t perform that action at this time.
0 commit comments