• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "icing/absl_ports/str_join.h"
16 
17 namespace icing {
18 namespace lib {
19 namespace absl_ports {
20 
StrSplit(std::string_view text,std::string_view sep)21 std::vector<std::string_view> StrSplit(std::string_view text,
22                                        std::string_view sep) {
23   std::vector<std::string_view> substrings;
24   size_t separator_position = text.find(sep);
25   size_t current_start = 0;
26   size_t current_end = separator_position;
27   while (separator_position != std::string_view::npos) {
28     substrings.push_back(
29         text.substr(current_start, current_end - current_start));
30     current_start = current_end + sep.length();
31     separator_position = text.find(sep, current_start);
32     current_end = separator_position;
33   }
34   current_end = text.length();
35   substrings.push_back(text.substr(current_start, current_end - current_start));
36   return substrings;
37 }
38 
39 }  // namespace absl_ports
40 }  // namespace lib
41 }  // namespace icing
42