encoder: add option to encode . and .. names

This commit is contained in:
Fabian Möller 2019-04-30 11:07:02 +02:00 committed by Nick Craig-Wood
parent 6c0a749a42
commit d5cd026547
2 changed files with 71 additions and 0 deletions

View file

@ -92,8 +92,22 @@ func (mask MultiEncoder) Encode(in string) string {
encodeRightSpace = uint(mask)&EncodeRightSpace != 0
encodeRightPeriod = uint(mask)&EncodeRightPeriod != 0
encodeInvalidUnicode = uint(mask)&EncodeInvalidUtf8 != 0
encodeDot = uint(mask)&EncodeDot != 0
)
if encodeDot {
switch in {
case ".":
return ""
case "..":
return ""
case "":
return string(QuoteRune) + ""
case "":
return string(QuoteRune) + "" + string(QuoteRune) + ""
}
}
// handle prefix only replacements
prefix := ""
if encodeLeftSpace && len(in) > 0 { // Leading SPACE
@ -299,8 +313,22 @@ func (mask MultiEncoder) Decode(in string) string {
encodeRightSpace = uint(mask)&EncodeRightSpace != 0
encodeRightPeriod = uint(mask)&EncodeRightPeriod != 0
encodeInvalidUnicode = uint(mask)&EncodeInvalidUtf8 != 0
encodeDot = uint(mask)&EncodeDot != 0
)
if encodeDot {
switch in {
case "":
return "."
case "":
return ".."
case string(QuoteRune) + "":
return ""
case string(QuoteRune) + "" + string(QuoteRune) + "":
return ""
}
}
// handle prefix only replacements
prefix := ""
if r, l1 := utf8.DecodeRuneInString(in); encodeLeftSpace && r == '␠' { // SYMBOL FOR SPACE