Home | History | Annotate | Download | only in lite_strings
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef NLP_SAFT_COMPONENTS_COMMON_MOBILE_LITE_STRINGS_STR_SPLIT_H_
     18 #define NLP_SAFT_COMPONENTS_COMMON_MOBILE_LITE_STRINGS_STR_SPLIT_H_
     19 
     20 #include <vector>
     21 
     22 #include "lang_id/common/lite_strings/stringpiece.h"
     23 
     24 namespace libtextclassifier3 {
     25 namespace mobile {
     26 
     27 // Splits |text| on |delim|; similar to absl::StrSplit.
     28 //
     29 // Returns a list of tokens.  Each token is represented by a StringPiece that
     30 // indicates a range of chars from |text|.
     31 //
     32 // Example: StrSplit("apple,orange", ',') returns two tokens: a StringPiece that
     33 // points to "apple", and another one for "orange".
     34 //
     35 // If one concatenates all returned tokens with |delim| in between, one gets the
     36 // original |text|.  E.g., If we split "apple,orange," on ',', we get three
     37 // tokens: "apple", "orange" and "" (an empty token).  We do not filter out
     38 // empty tokens.  If necessary, the caller can do that.
     39 //
     40 // Note: if the input text is empty, we return an empty list of tokens.  In
     41 // general, the number of returned tokens is 1 + the number of occurences of
     42 // |delim| inside |text|.
     43 std::vector<StringPiece> LiteStrSplit(StringPiece text, char delim);
     44 
     45 }  // namespace mobile
     46 }  // namespace nlp_saft
     47 
     48 #endif  // NLP_SAFT_COMPONENTS_COMMON_MOBILE_LITE_STRINGS_STR_SPLIT_H_
     49