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:
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user