File tree Expand file tree Collapse file tree 2 files changed +39
-11
lines changed Expand file tree Collapse file tree 2 files changed +39
-11
lines changed Original file line number Diff line number Diff line change @@ -471,19 +471,45 @@ pub fn (b byte) ascii_str() string {
471
471
472
472
// str_escaped returns the contents of `byte` as an escaped `string`.
473
473
// Example: assert byte(0).str_escaped() == r'`\0`'
474
+ [manualfree ]
474
475
pub fn (b byte) str_escaped () string {
475
476
str := match b {
476
- 0 { r '`\0`' }
477
- 7 { r '`\a`' }
478
- 8 { r '`\b`' }
479
- 9 { r '`\t`' }
480
- 10 { r '`\n`' }
481
- 11 { r '`\v`' }
482
- 12 { r '`\f`' }
483
- 13 { r '`\r`' }
484
- 27 { r '`\e`' }
485
- 32 ...126 { b.ascii_str () }
486
- else { '0x' + b.hex () }
477
+ 0 {
478
+ r '`\0`'
479
+ }
480
+ 7 {
481
+ r '`\a`'
482
+ }
483
+ 8 {
484
+ r '`\b`'
485
+ }
486
+ 9 {
487
+ r '`\t`'
488
+ }
489
+ 10 {
490
+ r '`\n`'
491
+ }
492
+ 11 {
493
+ r '`\v`'
494
+ }
495
+ 12 {
496
+ r '`\f`'
497
+ }
498
+ 13 {
499
+ r '`\r`'
500
+ }
501
+ 27 {
502
+ r '`\e`'
503
+ }
504
+ 32 ...126 {
505
+ b.ascii_str ()
506
+ }
507
+ else {
508
+ xx := b.hex ()
509
+ yy := '0x' + xx
510
+ unsafe { xx.free () }
511
+ yy
512
+ }
487
513
}
488
514
return str
489
515
}
Original file line number Diff line number Diff line change 1
1
fn main () {
2
2
a := `Y` .str ()
3
3
println (a)
4
+ b := `★` .bytes ()
5
+ println (b)
4
6
}
You can’t perform that action at this time.
0 commit comments