@@ -31,15 +31,15 @@ const (
31
31
32
32
// This implementation is the quickest with gcc -O2
33
33
// str_l returns the string representation of the integer nn with max chars.
34
- [inline ] [ direct_array_access]
34
+ [direct_array_access; inline ]
35
35
fn (nn int) str_l (max int ) string {
36
36
unsafe {
37
37
mut n := i64 (nn)
38
38
mut d := 0
39
39
if n == 0 {
40
40
return '0'
41
41
}
42
-
42
+
43
43
mut is_neg := false
44
44
if n < 0 {
45
45
n = - n
@@ -84,7 +84,7 @@ fn (nn int) str_l(max int) string {
84
84
*/
85
85
return tos (buf, diff)
86
86
87
- // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
87
+ // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
88
88
}
89
89
}
90
90
@@ -114,7 +114,7 @@ pub fn (n int) str() string {
114
114
115
115
// str returns the value of the `u32` as a `string`.
116
116
// Example: assert u32(20000).str() == '20000'
117
- [inline ] [ direct_array_access]
117
+ [direct_array_access; inline ]
118
118
pub fn (nn u32) str () string {
119
119
unsafe {
120
120
mut n := nn
@@ -146,7 +146,7 @@ pub fn (nn u32) str() string {
146
146
C.memmove (buf, buf + index, diff + 1 )
147
147
return tos (buf, diff)
148
148
149
- // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
149
+ // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
150
150
}
151
151
}
152
152
@@ -158,7 +158,7 @@ pub fn (n int_literal) str() string {
158
158
159
159
// str returns the value of the `i64` as a `string`.
160
160
// Example: assert i64(-200000).str() == '-200000'
161
- [inline ] [ direct_array_access]
161
+ [direct_array_access; inline ]
162
162
pub fn (nn i64) str () string {
163
163
unsafe {
164
164
mut n := nn
@@ -199,13 +199,13 @@ pub fn (nn i64) str() string {
199
199
diff := max - index
200
200
C.memmove (buf, buf + index, diff + 1 )
201
201
return tos (buf, diff)
202
- // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
202
+ // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
203
203
}
204
204
}
205
205
206
206
// str returns the value of the `u64` as a `string`.
207
207
// Example: assert u64(2000000).str() == '2000000'
208
- [inline ] [ direct_array_access]
208
+ [direct_array_access; inline ]
209
209
pub fn (nn u64) str () string {
210
210
unsafe {
211
211
mut n := nn
@@ -236,7 +236,7 @@ pub fn (nn u64) str() string {
236
236
diff := max - index
237
237
C.memmove (buf, buf + index, diff + 1 )
238
238
return tos (buf, diff)
239
- // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
239
+ // return tos(memdup(&buf[0] + index, (max - index)), (max - index))
240
240
}
241
241
}
242
242
@@ -254,7 +254,7 @@ pub fn (b bool) str() string {
254
254
//
255
255
256
256
// u64_to_hex converts the number `nn` to a (zero padded if necessary) hexadecimal `string`.
257
- [inline ] [ direct_array_access]
257
+ [direct_array_access; inline ]
258
258
fn u64_to_hex (nn u64 , len byte ) string {
259
259
mut n := nn
260
260
mut buf := [256 ]byte {}
@@ -270,7 +270,7 @@ fn u64_to_hex(nn u64, len byte) string {
270
270
}
271
271
272
272
// u64_to_hex_no_leading_zeros converts the number `nn` to hexadecimal `string`.
273
- [inline ] [ direct_array_access]
273
+ [direct_array_access; inline ]
274
274
fn u64_to_hex_no_leading_zeros (nn u64 , len byte ) string {
275
275
mut n := nn
276
276
mut buf := [256 ]byte {}
@@ -391,32 +391,54 @@ pub fn (nn voidptr) str() string {
391
391
392
392
// hex returns the value of the `byteptr` as a hexadecimal `string`.
393
393
// Note that the output is ***not*** zero padded.
394
- // pub fn (nn byteptr) str() string {
394
+ // pub fn (nn byteptr) str() string {
395
395
pub fn (nn byteptr) str () string {
396
396
return u64 (nn).hex ()
397
397
}
398
398
399
- /*
400
- pub fn (nn byte) hex_full() string { return u64_to_hex(nn, 2) }
401
- pub fn (nn i8) hex_full() string { return u64_to_hex(byte(nn), 2) }
402
- pub fn (nn u16) hex_full() string { return u64_to_hex(nn, 4) }
403
- pub fn (nn i16) hex_full() string { return u64_to_hex(u16(nn), 4) }
404
- pub fn (nn u32) hex_full() string { return u64_to_hex(nn, 8) }
405
- pub fn (nn int) hex_full() string { return u64_to_hex(u32(nn), 8) }
406
- */
399
+ pub fn (nn byte) hex_full () string {
400
+ return u64_to_hex (u64 (nn), 2 )
401
+ }
402
+
403
+ pub fn (nn i8) hex_full () string {
404
+ return u64_to_hex (u64 (nn), 2 )
405
+ }
406
+
407
+ pub fn (nn u16) hex_full () string {
408
+ return u64_to_hex (u64 (nn), 4 )
409
+ }
410
+
411
+ pub fn (nn i16) hex_full () string {
412
+ return u64_to_hex (u64 (nn), 4 )
413
+ }
414
+
415
+ pub fn (nn u32) hex_full () string {
416
+ return u64_to_hex (u64 (nn), 8 )
417
+ }
418
+
419
+ pub fn (nn int) hex_full () string {
420
+ return u64_to_hex (u64 (nn), 8 )
421
+ }
422
+
423
+ pub fn (nn i64) hex_full () string {
424
+ return u64_to_hex (u64 (nn), 16 )
425
+ }
426
+
427
+ pub fn (nn voidptr) hex_full () string {
428
+ return u64_to_hex (u64 (nn), 16 )
429
+ }
430
+
431
+ pub fn (nn int_literal) hex_full () string {
432
+ return u64_to_hex (u64 (nn), 16 )
433
+ }
434
+
407
435
// hex_full returns the value of the `u64` as a *full* 16-digit hexadecimal `string`.
408
436
// Example: assert u64(2).hex_full() == '0000000000000002'
409
437
// Example: assert u64(255).hex_full() == '00000000000000ff'
410
438
pub fn (nn u64) hex_full () string {
411
439
return u64_to_hex (nn, 16 )
412
440
}
413
441
414
- /*
415
- pub fn (nn i64) hex_full() string { return u64_to_hex(u64(nn), 16) }
416
- pub fn (nn int_literal) hex_full() string { return u64_to_hex(nn, 16) }
417
- pub fn (nn voidptr) hex_full() string { return u64_to_hex(nn, 16) }
418
- pub fn (nn byteptr) hex_full() string { return u64_to_hex(nn, 16) }
419
- */
420
442
// str returns the contents of `byte` as a zero terminated `string`.
421
443
// Example: assert byte(111).str() == '111'
422
444
pub fn (b byte) str () string {
0 commit comments