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 |
| RightPeriod | `.` on the right of a string |
| RightSpace | SPACE on the right of a string |
| Semicolon | `;` |
| SingleQuote | `'` |
| Slash | `/` |
| SquareBracket | `[`, `]` |

View File

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

File diff suppressed because it is too large Load Diff

View File

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