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
424 | 424 | if (point_pos == StringPiece::npos) { |
425 | 425 | point_pos = input_num.size(); |
426 | 426 | } |
427 | const StringPiece integer(input_num, 0, point_pos); | |
427 | const StringPiece integer = input_num.substr(0, point_pos); | |
428 | 428 | // |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); | |
431 | 431 | |
432 | 432 | // We don't add separator to number whose integral part starts with '0' |
433 | 433 | if (integer[0] == kAsciiZero) { |
634 | 634 | StringPiece::size_type i; |
635 | 635 | for (i = 0; i < str.size() && isspace(str[i]); ++i) {} |
636 | 636 | DCHECK(i == str.size() || !isspace(str[i])); |
637 | return StringPiece(str, i); | |
637 | return str.substr(i); | |
638 | 638 | } |
639 | 639 | |
640 | 640 | // There is an informative discussion about the overflow detection in |
825 | 825 | } |
826 | 826 | uint64 tmp; |
827 | 827 | 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); | |
831 | 829 | if (!SafeStrToUInt64WithBase(opposite_str, 10, &tmp)) { |
832 | 830 | return false; |
833 | 831 | } |
566 | 566 | ASSERT_EQ("12345", StringPiece("12345", 5)); |
567 | 567 | |
568 | 568 | // 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)); | |
572 | 572 | |
573 | 573 | // 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)); | |
577 | 577 | } |
578 | 578 | |
579 | 579 | } // namespace mozc |
0 | 0 | MAJOR=2 |
1 | 1 | MINOR=18 |
2 | BUILD=2562 | |
2 | BUILD=2563 | |
3 | 3 | REVISION=102 |
4 | 4 | # CAUTION: NACL_DICTIONARY_VERSION is going to be migrated to ENGINE_VERSION. |
5 | 5 | # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be |
102 | 102 | |
103 | 103 | // Open metadata. |
104 | 104 | DataSetMetadata metadata; |
105 | const StringPiece metadata_chunk(memblock, metadata_offset, metadata_size); | |
105 | const StringPiece metadata_chunk = | |
106 | memblock.substr(metadata_offset, metadata_size); | |
106 | 107 | if (!metadata.ParseFromArray(metadata_chunk.data(), metadata_chunk.size())) { |
107 | 108 | LOG(ERROR) << "Broken: Failed to parse metadata"; |
108 | 109 | return false; |
731 | 731 | // encoded_actual_key_prediction_suffix = encode("ぐる") |
732 | 732 | const StringPiece encoded_actual_key = |
733 | 733 | 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()); | |
738 | 737 | |
739 | 738 | // decoded_key = "くーぐる" (= key + prediction suffix) |
740 | 739 | decoded_key.clear(); |
827 | 826 | if (!key_trie.IsTerminalNode(node)) { |
828 | 827 | continue; |
829 | 828 | } |
830 | const StringPiece encoded_prefix(encoded_key, 0, i); | |
829 | const StringPiece encoded_prefix = encoded_key.substr(0, i); | |
831 | 830 | const StringPiece prefix(key, codec->GetDecodedKeyLength(encoded_prefix)); |
832 | 831 | |
833 | 832 | switch (callback->OnKey(prefix)) { |
934 | 933 | break; |
935 | 934 | } |
936 | 935 | |
937 | const StringPiece encoded_prefix(encoded_key, 0, key_pos); | |
936 | const StringPiece encoded_prefix = encoded_key.substr(0, key_pos); | |
938 | 937 | const StringPiece prefix(key, codec_->GetDecodedKeyLength(encoded_prefix)); |
939 | 938 | Callback::ResultType result = callback->OnKey(prefix); |
940 | 939 | if (result == Callback::TRAVERSE_DONE || |
1096 | 1095 | string lookup_key; |
1097 | 1096 | lookup_key.reserve(str.size()); |
1098 | 1097 | while (pos < str.size()) { |
1099 | const StringPiece suffix(str, pos); | |
1098 | const StringPiece suffix = str.substr(pos); | |
1100 | 1099 | lookup_key.clear(); |
1101 | 1100 | codec_->EncodeValue(suffix, &lookup_key); |
1102 | 1101 | AddKeyIdsOfAllPrefixes(value_trie_, lookup_key, &id_set); |
69 | 69 | |
70 | 70 | struct OrderByKeyPrefix { |
71 | 71 | 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; | |
73 | 73 | } |
74 | 74 | |
75 | 75 | 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()); | |
77 | 77 | } |
78 | 78 | }; |
79 | 79 | |
400 | 400 | } |
401 | 401 | |
402 | 402 | // 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())); | |
404 | 404 | Token token; |
405 | 405 | for (auto it = std::lower_bound(tokens_->begin(), tokens_->end(), first_char, |
406 | 406 | OrderByKey()); |
181 | 181 | // to get more performance but it's overkill here. |
182 | 182 | // TODO(noriyukit): vector<string> would be better than set<string>. To |
183 | 183 | // 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_); | |
185 | 185 | for (const string &chr : *subsequent_chars_) { |
186 | 186 | if (Util::StartsWith(rest, chr)) { |
187 | 187 | return TRAVERSE_CONTINUE; |