1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: string interpolation field width support for large integers and utf8 strings

This commit is contained in:
Uwe Krüger
2020-05-02 00:43:59 +02:00
committed by GitHub
parent 2f64594ce0
commit 170ee4312f
7 changed files with 290 additions and 138 deletions

View File

@ -215,6 +215,14 @@ Both single and double quotes can be used to denote strings. For consistency,
Interpolation syntax is pretty simple. It also works with fields:
`'age = $user.age'`. If you need more complex expressions, use `${}`: `'can register = ${user.age > 13}'`.
Format specifiers similar to those in C's `printf()` are supported, too. `f`, `g`, `x`, etc. are optional
and specify the output format. The compiler takes care of the storage size, so there is no `hd` or `llu`.
```v
println('x = ${x:12.3f}'`
println('${item:-20} ${n:20d})
```
All operators in V must have values of the same type on both sides. This code will not compile if `age` is an `int`:
```v