mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: vfmt every .v file, except vlib/builtin/int_test.v (#9448)
This commit is contained in:
@ -16,7 +16,7 @@ pub fn tos(s byteptr, len int) string {
|
||||
if s == 0 {
|
||||
panic('tos(): nil string')
|
||||
}
|
||||
return string {
|
||||
return string{
|
||||
str: s
|
||||
len: len
|
||||
}
|
||||
@ -24,17 +24,17 @@ pub fn tos(s byteptr, len int) string {
|
||||
|
||||
fn (s string) add(a string) string {
|
||||
new_len := a.len + s.len
|
||||
mut res := string {
|
||||
mut res := string{
|
||||
len: new_len
|
||||
str: malloc(new_len + 1)
|
||||
}
|
||||
for j in 0..s.len {
|
||||
for j in 0 .. s.len {
|
||||
res[j] = s[j]
|
||||
}
|
||||
for j in 0..a.len {
|
||||
for j in 0 .. a.len {
|
||||
res[s.len + j] = a[j]
|
||||
}
|
||||
res[new_len] = `\0`// V strings are not null terminated, but just in case
|
||||
res[new_len] = `\0` // V strings are not null terminated, but just in case
|
||||
return res
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ pub fn tos2(s byteptr) string {
|
||||
if s == 0 {
|
||||
panic('tos2: nil string')
|
||||
}
|
||||
return string {
|
||||
return string{
|
||||
str: s
|
||||
len: strlen(s)
|
||||
}
|
||||
@ -63,51 +63,67 @@ pub fn tos3(s charptr) string {
|
||||
if s == 0 {
|
||||
panic('tos3: nil string')
|
||||
}
|
||||
return string {
|
||||
return string{
|
||||
str: byteptr(s)
|
||||
len: strlen(byteptr(s))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string_eq (s1, s2 string) bool {
|
||||
if s1.len != s2.len { return false }
|
||||
for i in 0..s1.len {
|
||||
if s1[i] != s2[i] { return false }
|
||||
pub fn string_eq(s1 string, s2 string) bool {
|
||||
if s1.len != s2.len {
|
||||
return false
|
||||
}
|
||||
for i in 0 .. s1.len {
|
||||
if s1[i] != s2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
pub fn string_ne (s1, s2 string) bool {
|
||||
return !string_eq(s1,s2)
|
||||
|
||||
pub fn string_ne(s1 string, s2 string) bool {
|
||||
return !string_eq(s1, s2)
|
||||
}
|
||||
|
||||
|
||||
pub fn i64_tos(buf byteptr, len int, n0 i64, base int) string {
|
||||
if base < 2 { panic("base must be >= 2")}
|
||||
if base > 36 { panic("base must be <= 36")}
|
||||
if base < 2 {
|
||||
panic('base must be >= 2')
|
||||
}
|
||||
if base > 36 {
|
||||
panic('base must be <= 36')
|
||||
}
|
||||
|
||||
mut b := tos(buf, len)
|
||||
mut i := len-1
|
||||
mut i := len - 1
|
||||
|
||||
mut n := n0
|
||||
neg := n < 0
|
||||
if neg { n = -n }
|
||||
if neg {
|
||||
n = -n
|
||||
}
|
||||
|
||||
b[i--] = 0
|
||||
|
||||
for {
|
||||
c := (n%base) + 48
|
||||
b[i--] = if c > 57 {c+7} else {c}
|
||||
if i < 0 { panic ("buffer to small") }
|
||||
c := (n % base) + 48
|
||||
b[i--] = if c > 57 { c + 7 } else { c }
|
||||
if i < 0 {
|
||||
panic('buffer to small')
|
||||
}
|
||||
n /= base
|
||||
if n < 1 {break}
|
||||
if n < 1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if neg {
|
||||
if i < 0 { panic ("buffer to small") }
|
||||
if i < 0 {
|
||||
panic('buffer to small')
|
||||
}
|
||||
b[i--] = 45
|
||||
}
|
||||
offset := i+1
|
||||
offset := i + 1
|
||||
b.str = b.str + offset
|
||||
b.len -= (offset+1)
|
||||
b.len -= (offset + 1)
|
||||
return b
|
||||
}
|
||||
|
||||
@ -117,14 +133,14 @@ pub fn i64_str(n0 i64, base int) string {
|
||||
}
|
||||
|
||||
pub fn ptr_str(ptr voidptr) string {
|
||||
buf := [16]byte
|
||||
hex := i64_tos(buf, 15, i64(ptr), 16)
|
||||
res := '0x' + hex
|
||||
return res
|
||||
buf := [16]byte{}
|
||||
hex := i64_tos(buf, 15, i64(ptr), 16)
|
||||
res := '0x' + hex
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (a string) clone() string {
|
||||
mut b := string {
|
||||
mut b := string{
|
||||
len: a.len
|
||||
str: malloc(a.len + 1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user