mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00

Some checks failed
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
json decoder benchmark CI / json-encode-benchmark (push) Has been cancelled
json encoder benchmark CI / json-encode-benchmark (push) Has been cancelled
35 lines
732 B
V
35 lines
732 B
V
module big
|
|
|
|
// from_json_number implements a custom decoder for json2
|
|
pub fn (mut result Integer) from_json_number(raw_number string) ! {
|
|
mut index := 0
|
|
mut is_negative := false
|
|
|
|
if raw_number[0] == `-` {
|
|
is_negative = true
|
|
index++
|
|
}
|
|
|
|
ten := integer_from_int(10)
|
|
|
|
for index < raw_number.len {
|
|
digit := raw_number[index] - `0`
|
|
|
|
if digit > 9 { // comma, e and E are all smaller 0 in ASCII so they underflow
|
|
return error('expected integer but got real number')
|
|
}
|
|
|
|
result = (result * ten) + integer_from_int(int(digit))
|
|
|
|
index++
|
|
}
|
|
|
|
if is_negative {
|
|
result = result * integer_from_int(-1)
|
|
}
|
|
}
|
|
|
|
// to_json implements a custom encoder for json2
|
|
pub fn (result Integer) to_json() string {
|
|
return result.str()
|
|
}
|