mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
ce1ba2ad02
commit
cd96a43030
@ -94,9 +94,7 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Typ
|
||||
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
|
||||
node.fmt_poss[i])
|
||||
}
|
||||
// v fmt doesn't format this correctly
|
||||
if
|
||||
c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
&& fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`] {
|
||||
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
|
||||
node.fmt_poss[i])
|
||||
|
@ -152,7 +152,8 @@ pub struct RemoveNewLineConfig {
|
||||
imports_buffer bool // Work on f.out_imports instead of f.out
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) remove_new_line(cfg RemoveNewLineConfig) {
|
||||
// When the removal action actually occurs, the string of the last line after the removal is returned
|
||||
pub fn (mut f Fmt) remove_new_line(cfg RemoveNewLineConfig) string {
|
||||
mut buffer := if cfg.imports_buffer { unsafe { &f.out_imports } } else { unsafe { &f.out } }
|
||||
mut i := 0
|
||||
for i = buffer.len - 1; i >= 0; i-- {
|
||||
@ -160,8 +161,23 @@ pub fn (mut f Fmt) remove_new_line(cfg RemoveNewLineConfig) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if i == buffer.len - 1 {
|
||||
return ''
|
||||
}
|
||||
buffer.go_back(buffer.len - i - 1)
|
||||
f.empty_line = false
|
||||
mut line_len := 0
|
||||
mut last_line_str := []u8{}
|
||||
for i = buffer.len - 1; i >= 0; i-- {
|
||||
ch := buffer.byte_at(i)
|
||||
if ch == `\n` {
|
||||
break
|
||||
}
|
||||
line_len += if ch == `\t` { 4 } else { 1 }
|
||||
last_line_str << ch
|
||||
}
|
||||
f.line_len = line_len
|
||||
return last_line_str.reverse().bytestr()
|
||||
}
|
||||
|
||||
//=== Specialized write methods ===//
|
||||
@ -2181,10 +2197,17 @@ fn (mut f Fmt) write_splitted_infix(conditions []string, penalties []int, ignore
|
||||
f.write_splitted_infix(conds, pens, true, is_cond)
|
||||
continue
|
||||
}
|
||||
mut is_wrap_needed := true
|
||||
if i == 0 {
|
||||
f.remove_new_line()
|
||||
last_line_str := f.remove_new_line().trim_space()
|
||||
if last_line_str in ['if', 'for'] {
|
||||
f.write(' ')
|
||||
is_wrap_needed = false
|
||||
}
|
||||
}
|
||||
if is_wrap_needed {
|
||||
f.writeln('')
|
||||
}
|
||||
f.writeln('')
|
||||
f.indent++
|
||||
f.write(c)
|
||||
f.indent--
|
||||
|
@ -31,3 +31,9 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
&& fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`] {
|
||||
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
|
||||
node.fmt_poss[i])
|
||||
}
|
||||
|
@ -22,3 +22,9 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
&& fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`] {
|
||||
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
|
||||
node.fmt_poss[i])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user