-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
rune.go
44 lines (39 loc) · 816 Bytes
/
rune.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package commonfmt
import (
"fmt"
"github.com/inoxlang/inox/internal/utils"
)
var (
QUOTED_BELL_RUNE = []byte("'\\b'")
QUOTED_FFEED_RUNE = []byte("'\\f'")
QUOTED_NL_RUNE = []byte("'\\n'")
QUOTED_CR_RUNE = []byte("'\\r'")
QUOTED_TAB_RUNE = []byte("'\\t'")
QUOTED_VTAB_RUNE = []byte("'\\v'")
QUOTED_SQUOTE_RUNE = []byte("'\\''")
QUOTED_ASLASH_RUNE = []byte("'\\\\'")
)
func FmtRune(r rune) string {
var b []byte
switch r {
case '\b':
b = QUOTED_BELL_RUNE
case '\f':
b = QUOTED_FFEED_RUNE
case '\n':
b = QUOTED_NL_RUNE
case '\r':
b = QUOTED_CR_RUNE
case '\t':
b = QUOTED_TAB_RUNE
case '\v':
b = QUOTED_VTAB_RUNE
case '\'':
b = QUOTED_SQUOTE_RUNE
case '\\':
b = QUOTED_ASLASH_RUNE
default:
b = utils.StringAsBytes(fmt.Sprintf("'%c'", r))
}
return string(b)
}