lib/encoder: add Semicolon encoding

This commit is contained in:
Nick Craig-Wood 2022-04-21 12:02:27 +01:00
parent bab91e4402
commit 07481396e0
4 changed files with 30498 additions and 28215 deletions

View File

@ -327,6 +327,7 @@ will show you the defaults for the backends.
| RightCrLfHtVt | CR 0x0D, LF 0x0A, HT 0x09, VT 0x0B on the right of a string | | RightCrLfHtVt | CR 0x0D, LF 0x0A, HT 0x09, VT 0x0B on the right of a string |
| RightPeriod | `.` on the right of a string | | RightPeriod | `.` on the right of a string |
| RightSpace | SPACE on the right of a string | | RightSpace | SPACE on the right of a string |
| Semicolon | `;` |
| SingleQuote | `'` | | SingleQuote | `'` |
| Slash | `/` | | Slash | `/` |
| SquareBracket | `[`, `]` | | SquareBracket | `[`, `]` |

View File

@ -64,6 +64,7 @@ const (
EncodeInvalidUtf8 // Invalid UTF-8 bytes EncodeInvalidUtf8 // Invalid UTF-8 bytes
EncodeDot // . and .. names EncodeDot // . and .. names
EncodeSquareBracket // [] EncodeSquareBracket // []
EncodeSemicolon // ;
// Synthetic // Synthetic
EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>| EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>|
@ -122,6 +123,7 @@ func init() {
alias("Slash", EncodeSlash) alias("Slash", EncodeSlash)
alias("LtGt", EncodeLtGt) alias("LtGt", EncodeLtGt)
alias("SquareBracket", EncodeSquareBracket) alias("SquareBracket", EncodeSquareBracket)
alias("Semicolon", EncodeSemicolon)
alias("DoubleQuote", EncodeDoubleQuote) alias("DoubleQuote", EncodeDoubleQuote)
alias("SingleQuote", EncodeSingleQuote) alias("SingleQuote", EncodeSingleQuote)
alias("BackQuote", EncodeBackQuote) alias("BackQuote", EncodeBackQuote)
@ -324,6 +326,12 @@ func (mask MultiEncoder) Encode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeSemicolon) { // ;
switch r {
case ';', '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '?', case '?',
@ -493,6 +501,17 @@ func (mask MultiEncoder) Encode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeSemicolon) { // ;
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 '?':
@ -739,6 +758,12 @@ func (mask MultiEncoder) Decode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeSemicolon) { // ;
switch r {
case '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
@ -895,6 +920,17 @@ func (mask MultiEncoder) Decode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeSemicolon) { // ;
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

@ -43,6 +43,7 @@ var maskBits = []struct {
{encoder.EncodeBackQuote, "EncodeBackQuote"}, {encoder.EncodeBackQuote, "EncodeBackQuote"},
{encoder.EncodeLtGt, "EncodeLtGt"}, {encoder.EncodeLtGt, "EncodeLtGt"},
{encoder.EncodeSquareBracket, "EncodeSquareBracket"}, {encoder.EncodeSquareBracket, "EncodeSquareBracket"},
{encoder.EncodeSemicolon, "EncodeSemicolon"},
{encoder.EncodeDollar, "EncodeDollar"}, {encoder.EncodeDollar, "EncodeDollar"},
{encoder.EncodeDoubleQuote, "EncodeDoubleQuote"}, {encoder.EncodeDoubleQuote, "EncodeDoubleQuote"},
{encoder.EncodeColon, "EncodeColon"}, {encoder.EncodeColon, "EncodeColon"},
@ -111,6 +112,11 @@ var allMappings = []mapping{{
}, []rune{ }, []rune{
'', '', '', '',
}}, { }}, {
encoder.EncodeSemicolon, []rune{
';',
}, []rune{
'',
}}, {
encoder.EncodeDoubleQuote, []rune{ encoder.EncodeDoubleQuote, []rune{
'"', '"',
}, []rune{ }, []rune{