MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / StringToNumber

Function StringToNumber

native/thirdpart/flatbuffers/util.h:337–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335// - If the converted value falls out of range of corresponding return type, a
336// range error occurs. In this case value MAX(T)/MIN(T) is returned.
337template<typename T> inline bool StringToNumber(const char *s, T *val) {
338 // Assert on `unsigned long` and `signed long` on LP64.
339 // If it is necessary, it could be solved with flatbuffers::enable_if<B,T>.
340 static_assert(sizeof(T) < sizeof(int64_t), "unexpected type T");
341 FLATBUFFERS_ASSERT(s && val);
342 int64_t i64;
343 // The errno check isn't needed, will return MAX/MIN on overflow.
344 if (StringToIntegerImpl(&i64, s, 0, false)) {
345 const int64_t max = (flatbuffers::numeric_limits<T>::max)();
346 const int64_t min = flatbuffers::numeric_limits<T>::lowest();
347 if (i64 > max) {
348 *val = static_cast<T>(max);
349 return false;
350 }
351 if (i64 < min) {
352 // For unsigned types return max to distinguish from
353 // "no conversion can be performed" when 0 is returned.
354 *val = static_cast<T>(flatbuffers::is_unsigned<T>::value ? max : min);
355 return false;
356 }
357 *val = static_cast<T>(i64);
358 return true;
359 }
360 *val = 0;
361 return false;
362}
363
364template<> inline bool StringToNumber<int64_t>(const char *str, int64_t *val) {
365 return StringToIntegerImpl(val, str);

Callers 12

atot_scalarFunction · 0.85
ParseTypeMethod · 0.85
ParseAlignAttributeMethod · 0.85
FindByValueMethod · 0.85
AssignEnumeratorValueMethod · 0.85
ParseFlexBufferValueMethod · 0.85
SerializeMethod · 0.85
AsDoubleMethod · 0.85
GenFloatConstantImplMethod · 0.85
GetAnyValueFFunction · 0.85
SetAnyValueSFunction · 0.85

Calls 2

StringToIntegerImplFunction · 0.85
StringToFloatImplFunction · 0.85

Tested by

no test coverage detected