encoder: add option to encode . and .. names

This commit is contained in:
Fabian Möller authored and Nick Craig-Wood committed 2019-09-30 14:05:49 +01:00
1 parent 6c0a749a42
commit d5cd026547
2 files changed
+71

No files matched your search

+28
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