lib/encoder: add Exclamation mark encoding

This commit is contained in:
Nick Craig-Wood 2024-07-25 08:55:46 +01:00
parent 27b281ef69
commit bac9abebfb
4 changed files with 32127 additions and 29845 deletions

View File

@ -369,6 +369,7 @@ will show you the defaults for the backends.
| Dollar | `$` | `` | | Dollar | `$` | `` |
| Dot | `.` or `..` as entire string | ``, `` | | Dot | `.` or `..` as entire string | ``, `` |
| DoubleQuote | `"` | `` | | DoubleQuote | `"` | `` |
| Exclamation | `!` | `` |
| Hash | `#` | `` | | Hash | `#` | `` |
| InvalidUtf8 | An invalid UTF-8 character (e.g. latin1) | `<60>` | | InvalidUtf8 | An invalid UTF-8 character (e.g. latin1) | `<60>` |
| LeftCrLfHtVt | CR 0x0D, LF 0x0A, HT 0x09, VT 0x0B on the left of a string | `␍`, `␊`, `␉`, `␋` | | LeftCrLfHtVt | CR 0x0D, LF 0x0A, HT 0x09, VT 0x0B on the left of a string | `␍`, `␊`, `␉`, `␋` |

View File

@ -64,6 +64,7 @@ const (
EncodeDot // . and .. names EncodeDot // . and .. names
EncodeSquareBracket // [] EncodeSquareBracket // []
EncodeSemicolon // ; EncodeSemicolon // ;
EncodeExclamation // !
// Synthetic // Synthetic
EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>| EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>|
@ -124,6 +125,7 @@ func init() {
alias("LtGt", EncodeLtGt) alias("LtGt", EncodeLtGt)
alias("SquareBracket", EncodeSquareBracket) alias("SquareBracket", EncodeSquareBracket)
alias("Semicolon", EncodeSemicolon) alias("Semicolon", EncodeSemicolon)
alias("Exclamation", EncodeExclamation)
alias("DoubleQuote", EncodeDoubleQuote) alias("DoubleQuote", EncodeDoubleQuote)
alias("SingleQuote", EncodeSingleQuote) alias("SingleQuote", EncodeSingleQuote)
alias("BackQuote", EncodeBackQuote) alias("BackQuote", EncodeBackQuote)
@ -336,6 +338,12 @@ func (mask MultiEncoder) Encode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeExclamation) { // !
switch r {
case '!', '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '?', case '?',
@ -516,6 +524,17 @@ func (mask MultiEncoder) Encode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeExclamation) { // !
switch r {
case '!':
out.WriteRune(r + fullOffset)
continue
case '':
out.WriteRune(QuoteRune)
out.WriteRune(r)
continue
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '?': case '?':
@ -772,7 +791,12 @@ func (mask MultiEncoder) Decode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeExclamation) { // !
switch r {
case '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '': case '':
@ -939,6 +963,17 @@ func (mask MultiEncoder) Decode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeExclamation) { // !
switch r {
case '':
if unquote {
out.WriteRune(r)
} else {
out.WriteRune(r - fullOffset)
}
continue
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '': case '':

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,7 @@ var maskBits = []struct {
{encoder.EncodeLtGt, "EncodeLtGt"}, {encoder.EncodeLtGt, "EncodeLtGt"},
{encoder.EncodeSquareBracket, "EncodeSquareBracket"}, {encoder.EncodeSquareBracket, "EncodeSquareBracket"},
{encoder.EncodeSemicolon, "EncodeSemicolon"}, {encoder.EncodeSemicolon, "EncodeSemicolon"},
{encoder.EncodeExclamation, "EncodeExclamation"},
{encoder.EncodeDollar, "EncodeDollar"}, {encoder.EncodeDollar, "EncodeDollar"},
{encoder.EncodeDoubleQuote, "EncodeDoubleQuote"}, {encoder.EncodeDoubleQuote, "EncodeDoubleQuote"},
{encoder.EncodeColon, "EncodeColon"}, {encoder.EncodeColon, "EncodeColon"},
@ -118,6 +119,11 @@ var allMappings = []mapping{{
}, []rune{ }, []rune{
'', '',
}}, { }}, {
encoder.EncodeExclamation, []rune{
'!',
}, []rune{
'',
}}, {
encoder.EncodeDoubleQuote, []rune{ encoder.EncodeDoubleQuote, []rune{
'"', '"',
}, []rune{ }, []rune{