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

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