MCPcopy Create free account
hub / github.com/alibaba/graph-learn / SafeStringTo64

Function SafeStringTo64

graphlearn/src/common/string/numeric.cc:130–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130bool SafeStringTo64(LiteString str, int64_t* value) {
131 SkipSpaces(&str);
132
133 int64_t vlimit = kInt64Max;
134 int sign = 1;
135 if (str.Consume("-")) {
136 sign = -1;
137 vlimit = kInt64Min;
138 }
139
140 if (!isdigit(SafeFirstChar(str))) {
141 return false;
142 }
143
144 int64_t result = 0;
145 if (sign == 1) {
146 do {
147 int digit = SafeFirstChar(str) - '0';
148 if ((vlimit - digit) / 10 < result) {
149 return false;
150 }
151 result = result * 10 + digit;
152 str.remove_prefix(1);
153 } while (isdigit(SafeFirstChar(str)));
154 } else {
155 do {
156 int digit = SafeFirstChar(str) - '0';
157 if ((vlimit + digit) / 10 > result) {
158 return false;
159 }
160 result = result * 10 - digit;
161 str.remove_prefix(1);
162 } while (isdigit(SafeFirstChar(str)));
163 }
164
165 SkipSpaces(&str);
166 if (!str.empty()) {
167 return false;
168 }
169
170 *value = result;
171 return true;
172}
173
174bool FastStringTo32(const char* str, int32_t* value) {
175 char* end = nullptr;

Callers

nothing calls this directly

Calls 5

SkipSpacesFunction · 0.85
SafeFirstCharFunction · 0.85
ConsumeMethod · 0.80
remove_prefixMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected