17 #ifndef FOLLY_GEN_STRING_H_ 18 #error This file may only be included from folly/gen/String.h 39 size_t found = in.
find(delimiter);
55 auto found = in.
find(delimiter);
57 found += delimiter.
size();
60 return delimiter.
size();
70 const auto kCRLF =
"\r\n";
71 const size_t kLenCRLF = 2;
74 if (p != std::string::npos) {
75 const auto in_start = in.
data();
91 inline const char*
ch(
const unsigned char* p) {
92 return reinterpret_cast<const char*
>(p);
96 template <
class Callback>
99 auto num_to_add = s.
size();
101 num_to_add = std::min<uint64_t>(num_to_add, maxLength);
112 template <
class Callback>
127 template <
class Callback>
129 CHECK(maxLength_ == 0 ||
buffer_.length() < maxLength_);
138 template <
class Callback>
149 CHECK(
buffer_.length() < maxLength_);
167 }
else if (maxLength_ &&
buffer_.length() + in.
size() >= maxLength_) {
191 while (in.
size() >= maxLength_) {
205 CHECK(maxLength_ == 0 ||
buffer_.length() < maxLength_);
217 : delimiter_(delimiter), keepDelimiter_(keepDelimiter) {}
219 template <
class Source>
226 Generator(Source source,
char delimiter,
bool keepDelimiter)
228 delimiter_(delimiter),
229 keepDelimiter_(keepDelimiter) {}
231 template <
class Body>
240 if (s.
back() != this->delimiter_) {
243 if (!keepDelimiter_) {
248 if (!source_.apply(splitter)) {
251 return splitter.flush();
254 static constexpr
bool infinite = Source::infinite;
257 template <
class Source,
class Value,
class Gen = Generator<Source>>
259 return Gen(
std::move(source.self()), delimiter_, keepDelimiter_);
262 template <
class Source,
class Value,
class Gen = Generator<Source>>
264 return Gen(source.
self(), delimiter_, keepDelimiter_);
268 template <
class DelimiterType =
char>
270 :
public GenImpl<StringPiece, SplitStringSource<DelimiterType>> {
276 : source_(source), delimiter_(
std::
move(delimiter)) {}
278 template <
class Body>
282 while (
size_t delim_len =
splitPrefix(rest, prefix, this->delimiter_)) {
303 template <
class Delimiter,
class Output>
310 template <
class Source,
class Value>
325 template <
class Delimiter,
class OutputBuffer>
332 : delimiter_(delimiter), outputBuffer_(outputBuffer) {
336 template <
class Source,
class Value>
340 bool skipDelim = outputBuffer_->empty();
344 toAppend(std::forward<Value>(
v), outputBuffer_);
346 toAppend(delimiter_, std::forward<Value>(
v), outputBuffer_);
355 template <
class Target,
class =
void>
363 #pragma GCC diagnostic ignored "-Wreturn-stack-address" 376 template <
class TargetContainer,
class Delimiter,
class... Targets>
381 explicit SplitTo(Delimiter delimiter) : delimiter_(delimiter) {}
388 auto eatField = [&]() ->
StringPiece& {
return fields[i++]; };
392 detail::passthrough<StringPiece&, Targets>(eatField())...)) {
393 throw std::runtime_error(
"field count mismatch");
396 return TargetContainer(
To<Targets>()(eatField())...);
SplitTo(Delimiter delimiter)
Output compose(const GenImpl< Value, Source > &source) const
#define FOLLY_POP_WARNING
const char * ch(const unsigned char *p)
SplitStringSource(const StringPiece source, DelimiterType delimiter)
bool consumeBufferPlus(Callback &cb, IOBuf &buf, StringPiece &s, uint64_t n)
#define FOLLY_PUSH_WARNING
StringResplitter(char delimiter, bool keepDelimiter=false)
size_type find_first_of(const_range_type needles) const
constexpr detail::Map< Move > move
size_type find(const_range_type str) const
void advance(size_type n)
constexpr size_type size() const
const uint8_t * data() const
void reserve(std::size_t minHeadroom, std::size_t minTailroom)
bool operator()(StringPiece in)
—— Concurrent Priority Queue Implementation ——
Generator(Source source, char delimiter, bool keepDelimiter)
bool prefix(Cursor &c, uint32_t expected)
size_t splitPrefix(StringPiece &in, StringPiece &prefix, char delimiter)
Gen compose(GenImpl< Value, Source > &&source) const
constexpr bool empty() const
bool Value(const T &value, M matcher)
constexpr Iter data() const
std::size_t length() const
void assign(Iter start, Iter end)
S split(const StringPiece source, char delimiter)
bool apply(Body &&body) const
Target passthrough(Target target)
bool removePrefix(const const_range_type &prefix)
void toAppend(char value, Tgt *result)
constexpr Iter begin() const
static const size_type npos
Gen compose(const GenImpl< Value, Source > &source) const
StreamSplitter< Callback > streamSplitter(char delimiter, Callback &&pieceCb, uint64_t capacity=0)
const Self & self() const
void subtract(size_type n)
bool apply(Body &&body) const
Unsplit(const Delimiter &delimiter)
Range< const char * > StringPiece
bool consumeFixedSizeChunks(Callback &cb, StringPiece &s, uint64_t maxLength)
UnsplitBuffer(const Delimiter &delimiter, OutputBuffer *outputBuffer)
std::unique_ptr< unsigned char[]> buffer_
OutputBuffer * outputBuffer_
TargetContainer operator()(StringPiece line) const
void append(std::size_t amount)
void compose(const GenImpl< Value, Source > &source) const