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

Function safe_strto64

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

Source from the content-addressed store, hash-verified

221} // namespace
222
223bool safe_strto64(StringPiece str, int64* value) {
224 SkipSpaces(&str);
225
226 int64 vlimit = kint64max;
227 int sign = 1;
228 if (absl::ConsumePrefix(&str, "-")) {
229 sign = -1;
230 // Different limit for positive and negative integers.
231 vlimit = kint64min;
232 }
233
234 if (!isdigit(SafeFirstChar(str))) return false;
235
236 int64 result = 0;
237 if (sign == 1) {
238 do {
239 int digit = SafeFirstChar(str) - '0';
240 if ((vlimit - digit) / 10 < result) {
241 return false;
242 }
243 result = result * 10 + digit;
244 str.remove_prefix(1);
245 } while (isdigit(SafeFirstChar(str)));
246 } else {
247 do {
248 int digit = SafeFirstChar(str) - '0';
249 if ((vlimit + digit) / 10 > result) {
250 return false;
251 }
252 result = result * 10 - digit;
253 str.remove_prefix(1);
254 } while (isdigit(SafeFirstChar(str)));
255 }
256
257 SkipSpaces(&str);
258 if (!str.empty()) return false;
259
260 *value = result;
261 return true;
262}
263
264bool safe_strtou64(StringPiece str, uint64* value) {
265 SkipSpaces(&str);

Callers 15

ParseMetaFileNameFunction · 0.85
TensorShapeFromStringFunction · 0.85
GetOneInt64ParameterMethod · 0.85
ReadSchemaMethod · 0.85
AppendValueToExampleMethod · 0.85
ComputeMethod · 0.85
GetKeyAndStepIdMethod · 0.85
GetWorkspaceLimitFunction · 0.85
ParseMethod · 0.85
ConsumeAttrNumberFunction · 0.85

Calls 4

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

Tested by 3

InferShapesMethod · 0.68
MakeShapeFromStringMethod · 0.68
TESTFunction · 0.68