Codebase list mozc / f3e35c3
Replace atoi32, strtoll, and strtoull. BUG= TEST=unittest REF_BUG=19010851 REF_CL=84611844 Noriyuki Takahashi authored 8 years ago Yohei Yukawa committed 8 years ago
6 changed file(s) with 40 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
4141
4242 #include "base/crash_report_handler.h"
4343 #include "base/init.h"
44 #include "base/number_util.h"
4445 #include "base/singleton.h"
4546 #include "base/system_util.h"
4647 #include "base/util.h"
4849 DEFINE_string(program_invocation_name, "", "Program name copied from argv[0].");
4950
5051 namespace mozc_flags {
51
5252 namespace {
5353
5454 typedef map<string, mozc_flags::Flag *> FlagMap;
124124
125125 switch (flag->type) {
126126 case I:
127 *(reinterpret_cast<int32 *>(flag->storage)) = atoi32(v.c_str());
127 mozc::NumberUtil::SafeStrToInt32(
128 v, reinterpret_cast<int32 *>(flag->storage));
128129 break;
129130 case B:
130131 *(reinterpret_cast<bool *>(flag->storage)) = IsTrue(v.c_str());
131132 break;
132133 case I64:
133 *(reinterpret_cast<int64 *>(flag->storage)) =
134 strtoll(v.c_str(), NULL, 10);
134 mozc::NumberUtil::SafeStrToInt64(
135 v, reinterpret_cast<int64 *>(flag->storage));
135136 break;
136137 case U64:
137 *(reinterpret_cast<uint64 *>(flag->storage)) =
138 strtoull(v.c_str(), NULL, 10);
138 mozc::NumberUtil::SafeStrToUInt64(
139 v, reinterpret_cast<uint64 *>(flag->storage));
139140 break;
140141 case D:
141142 *(reinterpret_cast<double *>(flag->storage)) = strtod(v.c_str(), NULL);
267267 return converter.StartConversionForRequest(conversion_request, segments);
268268 } else if (func == "convertwithnodeinfo" || func == "cn") {
269269 CHECK_FIELDS_LENGTH(5);
270 Lattice::SetDebugDisplayNode(atoi32(fields[2].c_str()), // begin pos
271 atoi32(fields[3].c_str()), // end pos
272 fields[4]);
270 Lattice::SetDebugDisplayNode(
271 NumberUtil::SimpleAtoi(fields[2]), // begin pos
272 NumberUtil::SimpleAtoi(fields[3]), // end pos
273 fields[4]);
273274 const bool result = converter.StartConversion(segments, fields[1]);
274275 Lattice::ResetDebugDisplayNode();
275276 return result;
310311 } else if (func == "commitsegmentvalue" || func == "commit" || func == "c") {
311312 CHECK_FIELDS_LENGTH(3);
312313 return converter.CommitSegmentValue(segments,
313 atoi32(fields[1].c_str()),
314 atoi32(fields[2].c_str()));
314 NumberUtil::SimpleAtoi(fields[1]),
315 NumberUtil::SimpleAtoi(fields[2]));
315316 } else if (func == "commitallandfinish") {
316317 for (int i = 0; i < segments->conversion_segments_size(); ++i) {
317318 if (segments->conversion_segment(i).segment_type() !=
326327 } else if (func == "focussegmentvalue" || func == "focus") {
327328 CHECK_FIELDS_LENGTH(3);
328329 return converter.FocusSegmentValue(segments,
329 atoi32(fields[1].c_str()),
330 atoi32(fields[2].c_str()));
330 NumberUtil::SimpleAtoi(fields[1]),
331 NumberUtil::SimpleAtoi(fields[2]));
331332 } else if (func == "commitfirstsegment") {
332333 CHECK_FIELDS_LENGTH(2);
333334 vector<size_t> singleton_vector;
334 singleton_vector.push_back(static_cast<size_t>(atoi32(fields[1].c_str())));
335 singleton_vector.push_back(NumberUtil::SimpleAtoi(fields[1]));
335336 return converter.CommitSegments(segments, singleton_vector);
336337 } else if (func == "freesegmentvalue" || func == "free") {
337338 CHECK_FIELDS_LENGTH(2);
338339 return converter.FreeSegmentValue(segments,
339 atoi32(fields[1].c_str()));
340 NumberUtil::SimpleAtoi(fields[1]));
340341 } else if (func == "resizesegment" || func == "resize") {
341342 const ConversionRequest request;
342343 if (fields.size() == 3) {
343344 return converter.ResizeSegment(segments,
344345 request,
345 atoi32(fields[1].c_str()),
346 atoi32(fields[2].c_str()));
346 NumberUtil::SimpleAtoi(fields[1]),
347 NumberUtil::SimpleAtoi(fields[2]));
347348 } else if (fields.size() > 3) {
348349 vector<uint8> new_arrays;
349350 for (size_t i = 3; i < fields.size(); ++i) {
350 new_arrays.push_back(static_cast<uint8>(atoi32(fields[i].c_str())));
351 new_arrays.push_back(
352 static_cast<uint8>(NumberUtil::SimpleAtoi(fields[i])));
351353 }
352354 return converter.ResizeSegment(segments,
353355 request,
354 atoi32(fields[1].c_str()), // start
355 atoi32(fields[2].c_str()),
356 NumberUtil::SimpleAtoi(fields[1]),
357 NumberUtil::SimpleAtoi(fields[2]),
356358 &new_arrays[0],
357359 new_arrays.size());
358360 }
00 MAJOR=2
11 MINOR=17
2 BUILD=2131
2 BUILD=2132
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
3434 #include <vector>
3535
3636 #include "base/logging.h"
37 #include "base/number_util.h"
3738 #include "base/port.h"
3839 #include "base/util.h"
3940
9697 ++begin;
9798 }
9899
99 *output = atoi32(str.c_str());
100 *output = NumberUtil::SimpleAtoi(str);
100101
101102 return true;
102103 }
17411741 if (!NumberUtil::IsArabicNumber(era_year_str)) {
17421742 return false;
17431743 }
1744 *year = atoi32(era_year_str.c_str());
1744 *year = NumberUtil::SimpleAtoi(era_year_str);
17451745 if (*year <= 0) {
17461746 return false;
17471747 }
22492249 string year_str;
22502250 Util::FullWidthAsciiToHalfWidthAscii(current_key, &year_str);
22512251
2252 const uint32 year = atoi32(year_str.c_str());
2252 uint32 year = 0;
2253 if (!NumberUtil::SafeStrToUInt32(year_str, &year)) {
2254 return false;
2255 }
22532256
22542257 vector<string> results;
22552258 if (!AdToEra(year, &results)) {
23762379 string number_str;
23772380 Util::FullWidthAsciiToHalfWidthAscii(key, &number_str);
23782381
2379 const uint32 number = atoi32(number_str.c_str());
2382 uint32 number = 0;
2383 if (!NumberUtil::SafeStrToUInt32(number_str, &number)) {
2384 return false;
2385 }
23802386 const uint32 upper_number = number / 100;
23812387 const uint32 lower_number = number % 100;
23822388
3434
3535 #include "base/file_stream.h"
3636 #include "base/logging.h"
37 #include "base/number_util.h"
3738 #include "base/util.h"
3839 #include "rewriter/embedded_dictionary.h"
3940
4041 namespace mozc {
41
4242 namespace {
4343
4444 struct CompilerToken {
6363 return (t1.cost < t2.cost);
6464 }
6565 };
66
6667 } // namespace
6768
6869 EmbeddedDictionary::EmbeddedDictionary(const EmbeddedDictionary::Token *token,
114115 CompilerToken token;
115116 const string &key = fields[0];
116117 token.value = fields[4];
117 token.lid = atoi32(fields[1].c_str());
118 token.rid = atoi32(fields[2].c_str());
119 token.cost = atoi32(fields[3].c_str());
118 CHECK(NumberUtil::SafeStrToUInt16(fields[1], &token.lid));
119 CHECK(NumberUtil::SafeStrToUInt16(fields[2], &token.rid));
120 CHECK(NumberUtil::SafeStrToInt16(fields[3], &token.cost));
120121 token.description = (fields.size() > 5) ? fields[5] : "";
121122 token.additional_description = (fields.size() > 6) ? fields[6] : "";
122123 dic[key].push_back(token);