lib/encoder: add encoding of square brackets

This commit is contained in:
Ivan Andreev 2021-06-23 17:05:39 +03:00
parent 69f4b48719
commit 48e7246163
4 changed files with 28871 additions and 26586 deletions

View File

@ -280,6 +280,7 @@ will show you the defaults for the backends.
| RightSpace | SPACE on the right of a string | | RightSpace | SPACE on the right of a string |
| SingleQuote | `'` | | SingleQuote | `'` |
| Slash | `/` | | Slash | `/` |
| SquareBracket | `[`, `]` |
To take a specific example, the FTP backend's default encoding is To take a specific example, the FTP backend's default encoding is

View File

@ -63,6 +63,7 @@ const (
EncodeRightCrLfHtVt // Trailing CR LF HT VT EncodeRightCrLfHtVt // Trailing CR LF HT VT
EncodeInvalidUtf8 // Invalid UTF-8 bytes EncodeInvalidUtf8 // Invalid UTF-8 bytes
EncodeDot // . and .. names EncodeDot // . and .. names
EncodeSquareBracket // []
// Synthetic // Synthetic
EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>| EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>|
@ -120,6 +121,7 @@ func init() {
alias("None", EncodeZero) alias("None", EncodeZero)
alias("Slash", EncodeSlash) alias("Slash", EncodeSlash)
alias("LtGt", EncodeLtGt) alias("LtGt", EncodeLtGt)
alias("SquareBracket", EncodeSquareBracket)
alias("DoubleQuote", EncodeDoubleQuote) alias("DoubleQuote", EncodeDoubleQuote)
alias("SingleQuote", EncodeSingleQuote) alias("SingleQuote", EncodeSingleQuote)
alias("BackQuote", EncodeBackQuote) alias("BackQuote", EncodeBackQuote)
@ -315,6 +317,13 @@ func (mask MultiEncoder) Encode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '[', ']',
'', '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '?', case '?',
@ -473,6 +482,17 @@ func (mask MultiEncoder) Encode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeSquareBracket) { // []
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 '?':
@ -713,6 +733,13 @@ func (mask MultiEncoder) Decode(in string) string {
return true return true
} }
} }
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '', '':
return true
}
}
if mask.Has(EncodeQuestion) { // ? if mask.Has(EncodeQuestion) { // ?
switch r { switch r {
case '': case '':
@ -857,6 +884,17 @@ func (mask MultiEncoder) Decode(in string) string {
continue continue
} }
} }
if mask.Has(EncodeSquareBracket) { // []
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

@ -42,6 +42,7 @@ var maskBits = []struct {
{encoder.EncodeSingleQuote, "EncodeSingleQuote"}, {encoder.EncodeSingleQuote, "EncodeSingleQuote"},
{encoder.EncodeBackQuote, "EncodeBackQuote"}, {encoder.EncodeBackQuote, "EncodeBackQuote"},
{encoder.EncodeLtGt, "EncodeLtGt"}, {encoder.EncodeLtGt, "EncodeLtGt"},
{encoder.EncodeSquareBracket, "EncodeSquareBracket"},
{encoder.EncodeDollar, "EncodeDollar"}, {encoder.EncodeDollar, "EncodeDollar"},
{encoder.EncodeDoubleQuote, "EncodeDoubleQuote"}, {encoder.EncodeDoubleQuote, "EncodeDoubleQuote"},
{encoder.EncodeColon, "EncodeColon"}, {encoder.EncodeColon, "EncodeColon"},
@ -105,6 +106,11 @@ var allMappings = []mapping{{
}, []rune{ }, []rune{
'', '', '', '',
}}, { }}, {
encoder.EncodeSquareBracket, []rune{
'[', ']',
}, []rune{
'', '',
}}, {
encoder.EncodeDoubleQuote, []rune{ encoder.EncodeDoubleQuote, []rune{
'"', '"',
}, []rune{ }, []rune{