mirror of
https://github.com/zellyn/diskii.git
synced 2024-12-22 15:30:13 +00:00
e6508a39b4
It doesn't do proper spacing yet - the intbasic code listing is extremely tricky to undestand.
36 lines
761 B
Go
36 lines
761 B
Go
// Package basic contains routines useful for both Applesoft and
|
|
// Integer BASIC.
|
|
package basic
|
|
|
|
import "regexp"
|
|
|
|
var controlCharRegexp = regexp.MustCompile(`[\x00-\x1F]`)
|
|
|
|
// ChevronControlCodes converts ASCII control characters like chr(4)
|
|
// to chevron-surrounded codes like «ctrl-D».
|
|
func ChevronControlCodes(s string) string {
|
|
return controlCharRegexp.ReplaceAllStringFunc(s, func(s string) string {
|
|
if s == "\n" || s == "\t" {
|
|
return s
|
|
}
|
|
if s >= "\x01" && s <= "\x1a" {
|
|
return "«ctrl-" + string('A'-1+s[0]) + "»"
|
|
}
|
|
code := "?"
|
|
switch s[0] {
|
|
case '\x00':
|
|
code = "NUL"
|
|
case '\x1C':
|
|
code = "FS"
|
|
case '\x1D':
|
|
code = "GS"
|
|
case '\x1E':
|
|
code = "RS"
|
|
case '\x1F':
|
|
code = "US"
|
|
}
|
|
|
|
return "«" + code + "»"
|
|
})
|
|
}
|