/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOLLY_GEN_STRING_H_ #error This file may only be included from folly/gen/String.h #endif #include <folly/Conv.h> #include <folly/Portability.h> #include <folly/String.h> namespace folly { namespace gen { namespace detail { /** * Finds the first occurrence of delimiter in "in", advances "in" past the * delimiter. Populates "prefix" with the consumed bytes, including the * delimiter. * * Returns the number of trailing bytes of "prefix" that make up the * delimiter, or 0 if the delimiter was not found. */ inline size_t splitPrefix( StringPiece& in, StringPiece& prefix, char delimiter) { … } /** * As above, but supports multibyte delimiters. */ inline size_t splitPrefix( StringPiece& in, StringPiece& prefix, StringPiece delimiter) { … } /** * As above, but splits by any of the EOL terms: \r, \n, or \r\n. */ inline size_t splitPrefix(StringPiece& in, StringPiece& prefix, MixedNewlines) { … } inline const char* ch(const unsigned char* p) { … } // Chop s into pieces of at most maxLength, feed them to cb template <class Callback> bool consumeFixedSizeChunks(Callback& cb, StringPiece& s, uint64_t maxLength) { … } // Consumes all of buffer, plus n chars from s. template <class Callback> bool consumeBufferPlus(Callback& cb, IOBuf& buf, StringPiece& s, uint64_t n) { … } } // namespace detail template <class Callback> bool StreamSplitter<Callback>::flush() { … } template <class Callback> bool StreamSplitter<Callback>::operator()(StringPiece in) { … } namespace detail { class StringResplitter : public Operator<StringResplitter> { … }; template <class DelimiterType = char> class SplitStringSource : public GenImpl<StringPiece, SplitStringSource<DelimiterType>> { … }; /** * Unsplit - For joining tokens from a generator into a string. This is * the inverse of `split` above. * * This type is primarily used through the 'unsplit' function. */ template <class Delimiter, class Output> class Unsplit : public Operator<Unsplit<Delimiter, Output>> { … }; /** * UnsplitBuffer - For joining tokens from a generator into a string, * and inserting them into a custom buffer. * * This type is primarily used through the 'unsplit' function. */ template <class Delimiter, class OutputBuffer> class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> { … }; /** * Hack for static for-like constructs */ template <class Target, class = void> inline Target passthrough(Target target) { … } FOLLY_PUSH_WARNING #ifdef __clang__ // Clang isn't happy with eatField() hack below. #pragma GCC diagnostic ignored "-Wreturn-stack-address" #endif // __clang__ /** * ParseToTuple - For splitting a record and immediatlely converting it to a * target tuple type. Primary used through the 'eachToTuple' helper, like so: * * auto config * = split("1:a 2:b", ' ') * | eachToTuple<int, string>() * | as<vector<tuple<int, string>>>(); * */ template <class TargetContainer, class Delimiter, class... Targets> class SplitTo { … }; FOLLY_POP_WARNING } // namespace detail } // namespace gen } // namespace folly