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

check-md: verify code example formatting (#7143)

This commit is contained in:
Lukas Neubert
2020-12-05 22:54:41 +01:00
committed by GitHub
parent 0d28f12c54
commit 8adb1acf31
14 changed files with 836 additions and 752 deletions

View File

@@ -13,9 +13,10 @@ is replaced by the textual version of the following parameters.
```v
import strconv
fn main() {
a := "World"
s := strconv.v_sprintf("Hello %s!", a)
a := 'World'
s := strconv.v_sprintf('Hello %s!', a)
println(s)
}
```
@@ -49,16 +50,16 @@ The Flags field may be zero or more (in any order) of:
#### Width field
The Width field specifies a *maximum* number of characters to output,
and is typically used to pad fixed-width fields in tabulated output,
The Width field specifies a *maximum* number of characters to output,
and is typically used to pad fixed-width fields in tabulated output,
it causes truncation of oversized fields.
The width field may be omitted, or it may be a numeric integer value,
or may also be specified by a parameter when indicated by an asterisk `*`.
For example, `v_printf("%*.s", 5, my_string)` will result in ` mystring` being printed,
The width field may be omitted, or it may be a numeric integer value,
or may also be specified by a parameter when indicated by an asterisk `*`.
For example, `v_printf("%*.s", 5, my_string)` will result in ` mystring` being printed,
with a total width of 5 characters.
#### Length field
#### Length field
The Length field can be omitted or be any of:
@@ -71,7 +72,7 @@ The Length field can be omitted or be any of:
| | |
| | |
#### Type field
#### Type field
The Type field can be any of:
@@ -93,15 +94,15 @@ The Type field can be any of:
various types
```v oksyntax
a0 := u32(10)
b0 := 200
c0 := byte(12)
s0 := "ciAo"
a0 := u32(10)
b0 := 200
c0 := byte(12)
s0 := 'ciAo'
ch0 := `B`
f0 := 0.312345
f1 := 200000.0
sc0 := "ciao: [%-08u] %d %hhd [%8s] [%08X] [%-20.4f] [%-20.4f] [%c]"
temp_s = strconv.v_sprintf(sc0 ,a0 ,b0 ,c0 ,s0, b0 ,f0, f1, ch0)
f0 := 0.312345
f1 := 200000.0
sc0 := 'ciao: [%-08u] %d %hhd [%8s] [%08X] [%-20.4f] [%-20.4f] [%c]'
temp_s = strconv.v_sprintf(sc0, a0, b0, c0, s0, b0, f0, f1, ch0)
println(temp_s)
```
@@ -116,8 +117,8 @@ a := byte(12)
b := i16(13)
c := 14
d := i64(15)
sc1 := "==>%hhd %hd %d %ld"
temp_s = strconv.v_sprintf(sc1, a ,b ,c, d)
sc1 := '==>%hhd %hd %d %ld'
temp_s = strconv.v_sprintf(sc1, a, b, c, d)
println(temp_s)
```
@@ -130,10 +131,10 @@ unsigned integer
```v oksyntax
a1 := byte(0xff)
b1 := u16(0xffff)
c1 := u32(0xffff_ffff)
c1 := u32(0xffffffff)
d1 := u64(-1)
sc2 := "%hhu %hu %u %lu"
temp_s = strconv.v_sprintf(sc2, a1 ,b1 ,c1, d1)
sc2 := '%hhu %hu %u %lu'
temp_s = strconv.v_sprintf(sc2, a1, b1, c1, d1)
println(temp_s)
```
@@ -146,10 +147,10 @@ hexadecimal
```v oksyntax
a1 := byte(0xff)
b1 := i16(0xffff)
c1 := u32(0xffff_ffff)
c1 := u32(0xffffffff)
d1 := u64(-1)
sc3 := "%hhx %hx %x %lx"
temp_s = strconv.v_sprintf(sc3, a1 ,b1 ,c1, d1)
sc3 := '%hhx %hx %x %lx'
temp_s = strconv.v_sprintf(sc3, a1, b1, c1, d1)
println(temp_s)
```
@@ -161,7 +162,7 @@ hexadecimal
```v oksyntax
a2 := 125
sc7 := "[%9x] [%9X] [%-9x] [%-9X] [%09x] [%09X]"
sc7 := '[%9x] [%9X] [%-9x] [%-9X] [%09x] [%09X]'
temp_s = strconv.v_sprintf(sc7, a2, a2, a2, a2, a2, a2)
println(temp_s)
```
@@ -173,11 +174,11 @@ println(temp_s)
floating points
```v oksyntax
f0 := 0.312345
f1 := 200000.0
f2 := -1234.300e6
f3 := 1234.300e-6
sc4 := "[%-20.3e] [%20.3e] [%-020.3e] [%-020.3E] [%-020.3e] [%-020.3e]"
f0 := 0.312345
f1 := 200000.0
f2 := -1234.300e6
f3 := 1234.300e-6
sc4 := '[%-20.3e] [%20.3e] [%-020.3e] [%-020.3E] [%-020.3e] [%-020.3e]'
temp_s = strconv.v_sprintf(sc4, f0, f1, f1, f1, f2, f3)
println(temp_s)
```
@@ -190,11 +191,11 @@ float automatic notations
```v oksyntax
mut ft := -1e-7
mut x := 0
sc8 := "[%20g][%20G]|"
mut x := 0
sc8 := '[%20g][%20G]|'
for x < 12 {
temp_s = strconv.v_sprintf(sc8, ft, ft)
println("$temp_s\n")
println('$temp_s\n')
ft = ft * 10.0
x++
}
@@ -220,13 +221,13 @@ for x < 12 {
The format module also has some utility functions:
```v oksyntax
```v oksyntax nofmt
// calling struct
struct BF_param {
pad_ch byte = ` ` // padding char
len0 int = -1 // default len for whole the number or string
len1 int = 6 // number of decimal digits, if needed
positive bool = true // mandatory: the sign of the number passed
positive bool = true // mandatory: the sign of the number passed
sign_flag bool = false // flag for print sign as prefix in padding
allign Align_text = .right // alignment of the string
rm_tail_zero bool = false // remove the tail zeros from floats
@@ -243,7 +244,7 @@ fn remove_tail_zeros(s string) string
`format_fl` format a float number in normal notation using the parameters in the `BF_param` struct.
`format_es format a float number in scientific notation using the parameters in the BF_param`
`format_es format a float number in scientific notation using the parameters in the BF_param`
struct.
`remove_tail_zeros` removes the tailing zeros from a floating point number as string.
`remove_tail_zeros` removes the tailing zeros from a floating point number as string.