diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-11-23 12:58:46 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-11-23 12:58:46 -0500 |
commit | 8fd930180e5d7a610117299bb9c48e28409d3106 (patch) | |
tree | 60ff00906cb23953335e719526bd3da8073fc6d5 /src/tparse/tokenize.go | |
parent | 60dcc7c3c013a2492d8db1b04d28cb437921cced (diff) |
[EVAL] Stubcode v2
Diffstat (limited to 'src/tparse/tokenize.go')
-rw-r--r-- | src/tparse/tokenize.go | 38 |
1 files changed, 3 insertions, 35 deletions
diff --git a/src/tparse/tokenize.go b/src/tparse/tokenize.go index 56e866f..8a79b04 100644 --- a/src/tparse/tokenize.go +++ b/src/tparse/tokenize.go @@ -22,7 +22,6 @@ import ( "os" "strings" "unicode" - "unicode/utf8" ) // Read in a number (may be a float) @@ -112,7 +111,7 @@ func charLiteral(r *bufio.Reader, line int, char *int) Token { func splitResRunes(str string, max, line, start int) []Token { out := []Token{} - rs := StringAsRunes(str) + rs := []rune(str) s, e := 0, max if max > len(rs) { @@ -120,8 +119,8 @@ func splitResRunes(str string, max, line, start int) []Token { } for e <= len(rs) && s < len(rs) { - if checkRuneGroup(RunesAsString(rs[s:e])) != -1 || e == s+1 { - tmp := RunesAsString(rs[s:e]) + if checkRuneGroup(string(rs[s:e])) != -1 || e == s+1 { + tmp := string(rs[s:e]) out = append(out, Token{Type: checkRuneGroup(tmp), Data: tmp, Line: line, Char: start + s}) s = e if s+max < len(rs) { @@ -340,34 +339,3 @@ func TokenizeFile(path string) []Token { return stripBlockComments(out) } - -// StringAsRunes returns a string as a rune slice -func StringAsRunes(s string) []rune { - out := []rune{} - var r rune - for i, j := 0, 0; i < len(s); i += j { - r, j = utf8.DecodeRuneInString(s[i:]) - out = append(out, r) - } - return out -} - -// BytesAsRunes returns a byte slice as a rune slice -func BytesAsRunes(b []byte) []rune { - out := []rune{} - for i, j := 0, 0; i < len(b); i += j { - r, w := utf8.DecodeRune(b[i:]) - out = append(out, r) - j = w - } - return out -} - -// RunesAsString returns a string from a slice of runes -func RunesAsString(rs []rune) string { - b := strings.Builder{} - for _, r := range rs { - b.WriteRune(r) - } - return b.String() -} |