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

builtin: add charptr str() and change string format (#12973)

This commit is contained in:
yuyi
2021-12-31 04:34:24 +08:00
committed by GitHub
parent b10ff1e41b
commit a0a1807e2b
5 changed files with 26 additions and 20 deletions

View File

@@ -391,14 +391,18 @@ pub fn (nn int_literal) hex() string {
// hex returns the value of the `voidptr` as a hexadecimal `string`.
// Note that the output is ***not*** zero padded.
pub fn (nn voidptr) str() string {
return u64(nn).hex()
return '0x' + u64(nn).hex()
}
// hex returns the value of the `byteptr` as a hexadecimal `string`.
// Note that the output is ***not*** zero padded.
// pub fn (nn byteptr) str() string {
pub fn (nn byteptr) str() string {
return u64(nn).hex()
return '0x' + u64(nn).hex()
}
pub fn (nn charptr) str() string {
return '0x' + u64(nn).hex()
}
pub fn (nn byte) hex_full() string {

View File

@@ -29,12 +29,14 @@ fn test_str_methods() {
assert u32(-1).str() == '4294967295'
assert u64(1).str() == '1'
assert u64(-1).str() == '18446744073709551615'
assert voidptr(-1).str() == 'ffffffffffffffff'
assert voidptr(1).str() == '1'
assert voidptr(-1).str() == '0xffffffffffffffff'
assert voidptr(1).str() == '0x1'
assert (&byte(-1)).str() == 'ffffffffffffffff'
assert (&byte(1)).str() == '1'
assert byteptr(-1).str() == 'ffffffffffffffff'
assert byteptr(1).str() == '1'
assert byteptr(-1).str() == '0xffffffffffffffff'
assert byteptr(1).str() == '0x1'
assert charptr(-1).str() == '0xffffffffffffffff'
assert charptr(1).str() == '0x1'
}
fn test_and_precendence() {