MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / safe_strto32

Function safe_strto32

tensorflow/core/lib/strings/numbers.cc:285–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285bool safe_strto32(StringPiece str, int32* value) {
286 SkipSpaces(&str);
287
288 int64 vmax = kint32max;
289 int sign = 1;
290 if (absl::ConsumePrefix(&str, "-")) {
291 sign = -1;
292 // Different max for positive and negative integers.
293 ++vmax;
294 }
295
296 if (!isdigit(SafeFirstChar(str))) return false;
297
298 int64 result = 0;
299 do {
300 result = result * 10 + SafeFirstChar(str) - '0';
301 if (result > vmax) {
302 return false;
303 }
304 str.remove_prefix(1);
305 } while (isdigit(SafeFirstChar(str)));
306
307 SkipSpaces(&str);
308
309 if (!str.empty()) return false;
310
311 *value = static_cast<int32>(result * sign);
312 return true;
313}
314
315bool safe_strtou32(StringPiece str, uint32* value) {
316 SkipSpaces(&str);

Callers 15

TESTFunction · 0.70
ProtoParseNumericFunction · 0.70
MainFunction · 0.50
InsertLoggingFunction · 0.50
GetOneInt32ParameterMethod · 0.50
GetLocalStarPortMethod · 0.50
InitMethod · 0.50
ParseChannelSpecMethod · 0.50
ParseFromStringMethod · 0.50
ParseFromStringMethod · 0.50
ComputeMethod · 0.50

Calls 4

SkipSpacesFunction · 0.85
SafeFirstCharFunction · 0.85
ConsumePrefixFunction · 0.50
emptyMethod · 0.45

Tested by 4

TESTFunction · 0.56
ParseFromStringMethod · 0.40
ParseFromStringMethod · 0.40
TEST_FFunction · 0.40