MCPcopy Create free account
hub / github.com/apache/arrow-rs / parse_impl

Function parse_impl

arrow-buffer/src/bigint/mod.rs:134–162  ·  view source on GitHub ↗

Parse `s` with any sign and leading 0s removed

(s: &str, negative: bool)

Source from the content-addressed store, hash-verified

132
133/// Parse `s` with any sign and leading 0s removed
134fn parse_impl(s: &str, negative: bool) -> Result<i256, ParseI256Error> {
135 if s.len() <= 38 {
136 let low = i128::from_str(s)?;
137 return Ok(match negative {
138 true => i256::from_parts(low.neg() as _, -1),
139 false => i256::from_parts(low as _, 0),
140 });
141 }
142
143 let split = s.len() - 38;
144 if !s.as_bytes()[split].is_ascii_digit() {
145 // Ensures not splitting codepoint and no sign
146 return Err(ParseI256Error {});
147 }
148 let (hs, ls) = s.split_at(split);
149
150 let mut low = i128::from_str(ls)?;
151 let high = parse_impl(hs, negative)?;
152
153 if negative {
154 low = -low;
155 }
156
157 let low = i256::from_i128(low);
158
159 high.checked_mul(i256::from_i128(10_i128.pow(38)))
160 .and_then(|high| high.checked_add(low))
161 .ok_or(ParseI256Error {})
162}
163
164impl PartialOrd for i256 {
165 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {

Callers 1

from_strMethod · 0.85

Calls 6

and_thenMethod · 0.80
lenMethod · 0.45
negMethod · 0.45
as_bytesMethod · 0.45
checked_mulMethod · 0.45
checked_addMethod · 0.45

Tested by

no test coverage detected