MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_number

Function parse_number

nodedb-sql/src/parser/object_literal.rs:168–197  ·  view source on GitHub ↗
(chars: &[char], pos: &mut usize)

Source from the content-addressed store, hash-verified

166}
167
168fn parse_number(chars: &[char], pos: &mut usize) -> Result<Value, SqlError> {
169 let start = *pos;
170 if *pos < chars.len() && chars[*pos] == '-' {
171 *pos += 1;
172 }
173 while *pos < chars.len() && chars[*pos].is_ascii_digit() {
174 *pos += 1;
175 }
176 let is_float = *pos < chars.len() && chars[*pos] == '.';
177 if is_float {
178 *pos += 1; // consume '.'
179 while *pos < chars.len() && chars[*pos].is_ascii_digit() {
180 *pos += 1;
181 }
182 }
183 let raw: String = chars[start..*pos].iter().collect();
184 if is_float {
185 raw.parse::<f64>()
186 .map(Value::Float)
187 .map_err(|_| SqlError::Parse {
188 detail: format!("invalid float: {raw}"),
189 })
190 } else {
191 raw.parse::<i64>()
192 .map(Value::Integer)
193 .map_err(|_| SqlError::Parse {
194 detail: format!("invalid integer: {raw}"),
195 })
196 }
197}
198
199fn parse_array(chars: &[char], pos: &mut usize) -> Result<Vec<Value>, SqlError> {
200 // Expect '['

Callers 1

parse_valueFunction · 0.85

Calls 3

collectMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected