MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / Peek

Method Peek

internal/utf8.cc:137–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135 bool HasRemaining() const { return size_ != 0; }
136
137 absl::string_view Peek(size_t n) {
138 ABSL_ASSERT(n <= Remaining());
139 if (n == 0) {
140 return absl::string_view();
141 }
142 if (n <= buffer_.size() - index_) {
143 // Enough data remaining in temporary buffer.
144 return absl::string_view(buffer_.data() + index_, n);
145 }
146 // We do not have enough data. See if we can fit it without allocating by
147 // shifting data back to the beginning of the buffer.
148 if (buffer_.capacity() >= n) {
149 // It will fit in the current capacity, see if we need to shift the
150 // existing data to make it fit.
151 if (buffer_.capacity() - buffer_.size() < n && index_ != 0) {
152 // We need to shift.
153 buffer_.erase(buffer_.begin(), buffer_.begin() + index_);
154 index_ = 0;
155 }
156 }
157 // Ensure we never reserve less than kUtf8Max.
158 buffer_.reserve(std::max(buffer_.size() + n, kUtf8Max));
159 size_t to_copy = n - (buffer_.size() - index_);
160 absl::CopyCordToString(input_.Subcord(0, to_copy), &buffer_);
161 input_.RemovePrefix(to_copy);
162 return absl::string_view(buffer_.data() + index_, n);
163 }
164
165 char Read() {
166 char value = Peek(1).front();

Callers 3

Utf8IsValidImplFunction · 0.45
Utf8CodePointCountImplFunction · 0.45
Utf8ValidateImplFunction · 0.45

Calls 3

RemovePrefixMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected