mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
@@ -20,23 +20,23 @@ pub struct Decoder {
|
||||
}
|
||||
|
||||
// decode decodes certain `ast.Value`'s and all it's children.
|
||||
pub fn (d Decoder) decode(mut n ast.Value) ? {
|
||||
walker.walk_and_modify(d, mut n)?
|
||||
pub fn (d Decoder) decode(mut n ast.Value) ! {
|
||||
walker.walk_and_modify(d, mut n)!
|
||||
}
|
||||
|
||||
fn (d Decoder) modify(mut value ast.Value) ? {
|
||||
fn (d Decoder) modify(mut value ast.Value) ! {
|
||||
match value {
|
||||
ast.Quoted {
|
||||
mut v := &(value as ast.Quoted)
|
||||
d.decode_quoted(mut v)?
|
||||
d.decode_quoted(mut v)!
|
||||
}
|
||||
ast.Number {
|
||||
mut v := &(value as ast.Number)
|
||||
d.decode_number(mut v)?
|
||||
d.decode_number(mut v)!
|
||||
}
|
||||
ast.DateTime {
|
||||
mut v := &(value as ast.DateTime)
|
||||
d.decode_date_time(mut v)?
|
||||
d.decode_date_time(mut v)!
|
||||
}
|
||||
else {}
|
||||
}
|
||||
@@ -48,12 +48,12 @@ fn (d Decoder) excerpt(tp token.Pos) string {
|
||||
}
|
||||
|
||||
// decode_quoted returns an error if `q` is not a valid quoted TOML string.
|
||||
fn (d Decoder) decode_quoted(mut q ast.Quoted) ? {
|
||||
decode_quoted_escapes(mut q)?
|
||||
fn (d Decoder) decode_quoted(mut q ast.Quoted) ! {
|
||||
decode_quoted_escapes(mut q)!
|
||||
}
|
||||
|
||||
// decode_number decodes the `n ast.Number` into valid TOML.
|
||||
fn (d Decoder) decode_number(mut n ast.Number) ? {
|
||||
fn (d Decoder) decode_number(mut n ast.Number) ! {
|
||||
if n.text == '-nan' || n.text == '+nan' {
|
||||
n.text = 'nan'
|
||||
}
|
||||
@@ -73,7 +73,7 @@ fn (d Decoder) decode_number(mut n ast.Number) ? {
|
||||
// \\ - backslash (U+005C)
|
||||
// \uXXXX - Unicode (U+XXXX)
|
||||
// \UXXXXXXXX - Unicode (U+XXXXXXXX)
|
||||
pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
pub fn decode_quoted_escapes(mut q ast.Quoted) ! {
|
||||
// Setup a scanner in stack memory for easier navigation.
|
||||
mut eat_whitespace := false
|
||||
// TODO use string builder
|
||||
@@ -84,7 +84,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
return
|
||||
}
|
||||
|
||||
mut s := scanner.new_simple_text(q.text)?
|
||||
mut s := scanner.new_simple_text(q.text)!
|
||||
q.text = q.text.replace('\\"', '"')
|
||||
|
||||
for {
|
||||
@@ -214,7 +214,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
// The sequence is expected to be prefixed with either `u` or `U`.
|
||||
// decode_unicode_escape returns the decoded rune as
|
||||
// a string, it's integer value and it's length.
|
||||
fn decode_unicode_escape(esc_unicode string) ?(string, int, int) {
|
||||
fn decode_unicode_escape(esc_unicode string) !(string, int, int) {
|
||||
is_long_esc_type := esc_unicode.starts_with('U')
|
||||
mut sequence := esc_unicode[1..]
|
||||
hex_digits_len := if is_long_esc_type { 8 } else { 4 }
|
||||
@@ -226,13 +226,13 @@ fn decode_unicode_escape(esc_unicode string) ?(string, int, int) {
|
||||
if unicode_point.len < 8 {
|
||||
unicode_point = '0'.repeat(8 - unicode_point.len) + unicode_point
|
||||
}
|
||||
i64_val := strconv.parse_int(unicode_point, 16, 0)?
|
||||
i64_val := strconv.parse_int(unicode_point, 16, 0)!
|
||||
rn := rune(i64_val)
|
||||
return '$rn', int(i64_val), sequence_len
|
||||
}
|
||||
|
||||
// decode_date_time decodes the `dt ast.DateTime`.
|
||||
fn (d Decoder) decode_date_time(mut dt ast.DateTime) ? {
|
||||
fn (d Decoder) decode_date_time(mut dt ast.DateTime) ! {
|
||||
// Expand milliseconds that are only 1 char
|
||||
if dt.text.contains('.') {
|
||||
yymmddhhmmss := dt.text.all_before('.')
|
||||
|
||||
Reference in New Issue
Block a user