29 #ifndef ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_ 30 #define ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_ 33 #include <initializer_list> 36 #include <type_traits> 47 #endif // _GLIBCXX_DEBUG 50 namespace strings_internal {
90 if (other.IsSelfReferential()) {
93 other.value_ = other.copy_;
111 template <
typename Splitter>
120 enum State { kInitState, kLastState, kEndState };
125 delimiter_(splitter->delimiter()),
126 predicate_(splitter->predicate()) {
136 if (splitter_->text().data() ==
nullptr) {
138 pos_ = splitter_->text().size();
142 if (
state_ == kEndState) {
143 pos_ = splitter_->text().size();
156 if (
state_ == kLastState) {
165 }
while (!predicate_(curr_));
193 template <
typename T,
typename =
void>
195 template <
typename T>
200 template <
typename T,
typename =
void>
202 template <
typename T>
207 template <
typename T,
typename =
void>
209 template <
typename T>
216 template <
typename T>
218 template <
typename T>
220 : decltype(IsInitializerListDispatch(static_cast<T*>(nullptr))) {};
232 template <
typename C,
bool has_value_type,
bool has_mapped_type>
235 template <
typename C>
237 : std::is_constructible<typename C::value_type, absl::string_view> {};
239 template <
typename C>
242 std::is_constructible<typename C::key_type, absl::string_view>,
243 std::is_constructible<typename C::mapped_type, absl::string_view>> {};
245 template <
typename C>
249 #ifdef _GLIBCXX_DEBUG
250 !IsStrictlyBaseOfAndConvertibleToSTLContainer<C>::value &&
253 typename std::remove_reference<C>::type>::value &&
254 HasValueType<C>::value && HasConstIterator<C>::value,
255 HasMappedType<C>::value> {
275 template <
typename Delimiter,
typename Predicate>
284 : text_(
std::
move(input_text)),
289 const Delimiter&
delimiter()
const {
return delimiter_; }
290 const Predicate&
predicate()
const {
return predicate_; }
300 template <
typename Container,
301 typename =
typename std::enable_if<
303 operator Container()
const {
312 template <
typename First,
typename Second>
313 operator std::pair<First, Second>()
const {
322 return {First(first), Second(second)};
333 template <
typename Container,
typename ValueType,
bool is_map = false>
337 auto it = std::inserter(c, c.end());
338 for (
const auto sp : splitter) {
339 *it++ = ValueType(sp);
350 template <
typename A>
362 std::vector<absl::string_view, A>
v;
363 std::array<raw_view, 16> ar;
367 ar[index].data = it->data();
368 ar[index].size = it->size();
370 }
while (++index != ar.size() && !it.at_end());
371 v.insert(v.end(), ar.begin(), ar.begin() + index);
383 template <
typename A>
386 const std::vector<absl::string_view>
v = splitter;
387 return std::vector<std::string, A>(v.begin(), v.end());
397 template <
typename Container,
typename First,
typename Second>
401 typename Container::iterator it;
403 for (
const auto sp : splitter) {
405 it = Inserter<Container>::Insert(&m, First(sp), Second());
407 it->second = Second(sp);
417 template <
typename Map>
420 template <
typename... Args>
421 static typename M::iterator
Insert(
M* m, Args&&... args) {
422 return m->insert(std::make_pair(std::forward<Args>(args)...)).first;
426 template <
typename... Ts>
427 struct Inserter<
std::map<Ts...>> {
428 using M = std::map<Ts...>;
429 template <
typename... Args>
430 static typename M::iterator
Insert(
M* m, Args&&... args) {
431 return m->emplace(std::make_pair(std::forward<Args>(args)...)).first;
435 template <
typename... Ts>
436 struct Inserter<
std::multimap<Ts...>> {
437 using M = std::multimap<Ts...>;
438 template <
typename... Args>
439 static typename M::iterator
Insert(
M* m, Args&&... args) {
440 return m->emplace(std::make_pair(std::forward<Args>(args)...));
453 #endif // ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_
SplitIterator(State state, const Splitter *splitter)
string_view substr(size_type pos, size_type n=npos) const
void StealMembers(ConvertibleToStringView &&other)
Splitter(ConvertibleToStringView input_text, Delimiter d, Predicate p)
ConvertibleToStringView(const ConvertibleToStringView &other)
friend bool operator!=(const SplitIterator &a, const SplitIterator &b)
const Delimiter & delimiter() const
absl::string_view text() const
ConvertibleToStringView(const char *s)
Container operator()(const Splitter &splitter) const
Splitter::DelimiterType delimiter_
static M::iterator Insert(M *m, Args &&...args)
ptrdiff_t difference_type
Splitter::PredicateType predicate_
absl::string_view value() const
bool IsSelfReferential() const
constexpr size_type size() const noexcept
pointer operator->() const
ConvertibleToStringView text_
static M::iterator Insert(M *m, Args &&...args)
reference operator*() const
ConvertibleToStringView(absl::string_view s)
ConvertibleToStringView(char *s)
const Predicate & predicate() const
static char data[kDataSize]
std::pair< std::string, std::string > pair
const_iterator begin() const
friend bool operator==(const SplitIterator &a, const SplitIterator &b)
ConvertibleToStringView(const std::string &s)
ConvertibleToStringView(std::string &&s)
static M::iterator Insert(M *m, Args &&...args)
typename type_traits_internal::VoidTImpl< Ts... >::type void_t
std::vector< absl::string_view, A > operator()(const Splitter &splitter) const
std::vector< std::string, A > operator()(const Splitter &splitter) const
constexpr const_pointer data() const noexcept
const Splitter * splitter_
std::input_iterator_tag iterator_category
typename std::iterator_traits< const_iterator >::value_type value_type
const_iterator end() const
std::false_type IsInitializerListDispatch(...)
std::shared_ptr< AllocState > state_
ConvertibleToStringView & operator=(ConvertibleToStringView other)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Container operator()(const Splitter &splitter) const
SplitIterator operator++(int)
ConvertibleToStringView(ConvertibleToStringView &&other)
SplitIterator & operator++()