Codebase list mozc / 123f723
StringPiece substr constructor migration In favor of upcoming C++ 17 std::string_view. REF_BUG=26758622 REF_CL=120992516,122261849,122481249 REF_TIME=2016-04-27T23:43:48-07:00 REF_TIME_RAW=1461825828 -0700 Yohei Yukawa 8 years ago
7 changed file(s) with 24 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
424424 if (point_pos == StringPiece::npos) {
425425 point_pos = input_num.size();
426426 }
427 const StringPiece integer(input_num, 0, point_pos);
427 const StringPiece integer = input_num.substr(0, point_pos);
428428 // |fraction| has the decimal point with digits in fractional part.
429 const StringPiece fraction(input_num, point_pos,
430 input_num.size() - point_pos);
429 const StringPiece fraction =
430 input_num.substr(point_pos, input_num.size() - point_pos);
431431
432432 // We don't add separator to number whose integral part starts with '0'
433433 if (integer[0] == kAsciiZero) {
634634 StringPiece::size_type i;
635635 for (i = 0; i < str.size() && isspace(str[i]); ++i) {}
636636 DCHECK(i == str.size() || !isspace(str[i]));
637 return StringPiece(str, i);
637 return str.substr(i);
638638 }
639639
640640 // There is an informative discussion about the overflow detection in
825825 }
826826 uint64 tmp;
827827 if (stripped_str[0] == '-') {
828 StringPiece opposite_str = StringPiece(stripped_str,
829 1,
830 stripped_str.size() - 1);
828 StringPiece opposite_str = stripped_str.substr(1, stripped_str.size() - 1);
831829 if (!SafeStrToUInt64WithBase(opposite_str, 10, &tmp)) {
832830 return false;
833831 }
566566 ASSERT_EQ("12345", StringPiece("12345", 5));
567567
568568 // Tests for StringPiece(const StringPiece, size_type)
569 ASSERT_EQ("45", StringPiece(StringPiece("12345"), 3));
570 ASSERT_EQ("12345", StringPiece(StringPiece("12345"), 0));
571 ASSERT_EQ("", StringPiece(StringPiece("12345"), 5));
569 ASSERT_EQ("45", StringPiece("12345").substr(3));
570 ASSERT_EQ("12345", StringPiece("12345").substr(0));
571 ASSERT_EQ("", StringPiece("12345").substr(5));
572572
573573 // Tests for StringPiece(const StringPiece, size_type, size_type)
574 ASSERT_EQ("234", StringPiece("12345", 1, 3));
575 ASSERT_EQ("2345", StringPiece("12345", 1, 300));
576 ASSERT_EQ("", StringPiece("12345", 1, 0));
574 ASSERT_EQ("234", StringPiece("12345").substr(1, 3));
575 ASSERT_EQ("2345", StringPiece("12345").substr(1, 300));
576 ASSERT_EQ("", StringPiece("12345").substr(1, 0));
577577 }
578578
579579 } // namespace mozc
00 MAJOR=2
11 MINOR=18
2 BUILD=2562
2 BUILD=2563
33 REVISION=102
44 # CAUTION: NACL_DICTIONARY_VERSION is going to be migrated to ENGINE_VERSION.
55 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
102102
103103 // Open metadata.
104104 DataSetMetadata metadata;
105 const StringPiece metadata_chunk(memblock, metadata_offset, metadata_size);
105 const StringPiece metadata_chunk =
106 memblock.substr(metadata_offset, metadata_size);
106107 if (!metadata.ParseFromArray(metadata_chunk.data(), metadata_chunk.size())) {
107108 LOG(ERROR) << "Broken: Failed to parse metadata";
108109 return false;
731731 // encoded_actual_key_prediction_suffix = encode("ぐる")
732732 const StringPiece encoded_actual_key =
733733 key_trie_.RestoreKeyString(state.node, encoded_actual_key_buffer);
734 const StringPiece encoded_actual_key_prediction_suffix(
735 encoded_actual_key,
736 encoded_key.size(),
737 encoded_actual_key.size() - encoded_key.size());
734 const StringPiece encoded_actual_key_prediction_suffix =
735 encoded_actual_key.substr(
736 encoded_key.size(), encoded_actual_key.size() - encoded_key.size());
738737
739738 // decoded_key = "くーぐる" (= key + prediction suffix)
740739 decoded_key.clear();
827826 if (!key_trie.IsTerminalNode(node)) {
828827 continue;
829828 }
830 const StringPiece encoded_prefix(encoded_key, 0, i);
829 const StringPiece encoded_prefix = encoded_key.substr(0, i);
831830 const StringPiece prefix(key, codec->GetDecodedKeyLength(encoded_prefix));
832831
833832 switch (callback->OnKey(prefix)) {
934933 break;
935934 }
936935
937 const StringPiece encoded_prefix(encoded_key, 0, key_pos);
936 const StringPiece encoded_prefix = encoded_key.substr(0, key_pos);
938937 const StringPiece prefix(key, codec_->GetDecodedKeyLength(encoded_prefix));
939938 Callback::ResultType result = callback->OnKey(prefix);
940939 if (result == Callback::TRAVERSE_DONE ||
10961095 string lookup_key;
10971096 lookup_key.reserve(str.size());
10981097 while (pos < str.size()) {
1099 const StringPiece suffix(str, pos);
1098 const StringPiece suffix = str.substr(pos);
11001099 lookup_key.clear();
11011100 codec_->EncodeValue(suffix, &lookup_key);
11021101 AddKeyIdsOfAllPrefixes(value_trie_, lookup_key, &id_set);
6969
7070 struct OrderByKeyPrefix {
7171 bool operator()(const UserPOS::Token *token, StringPiece prefix) const {
72 return StringPiece(token->key, 0, prefix.size()) < prefix;
72 return StringPiece(token->key).substr(0, prefix.size()) < prefix;
7373 }
7474
7575 bool operator()(StringPiece prefix, const UserPOS::Token *token) const {
76 return prefix < StringPiece(token->key, 0, prefix.size());
76 return prefix < StringPiece(token->key).substr(0, prefix.size());
7777 }
7878 };
7979
400400 }
401401
402402 // Find the starting point for iteration over dictionary contents.
403 const StringPiece first_char(key, 0, Util::OneCharLen(key.data()));
403 const StringPiece first_char = key.substr(0, Util::OneCharLen(key.data()));
404404 Token token;
405405 for (auto it = std::lower_bound(tokens_->begin(), tokens_->end(), first_char,
406406 OrderByKey());
181181 // to get more performance but it's overkill here.
182182 // TODO(noriyukit): vector<string> would be better than set<string>. To
183183 // this end, we need to fix Comopser as well.
184 const StringPiece rest(key, original_key_len_);
184 const StringPiece rest = key.substr(original_key_len_);
185185 for (const string &chr : *subsequent_chars_) {
186186 if (Util::StartsWith(rest, chr)) {
187187 return TRAVERSE_CONTINUE;