MCPcopy Index your code
hub / github.com/rclone/rclone / Decode

Method Decode

lib/encoder/encoder.go:686–1142  ·  view source on GitHub ↗

Decode takes a name and undoes any substitutions made by Encode

(in string)

Source from the content-addressed store, hash-verified

684
685// Decode takes a name and undoes any substitutions made by Encode
686func (mask MultiEncoder) Decode(in string) string {
687 if mask == EncodeRaw {
688 return in
689 }
690
691 if mask.Has(EncodeDot) {
692 switch in {
693 case ".":
694 return "."
695 case "..":
696 return ".."
697 case string(QuoteRune) + ".":
698 return "."
699 case string(QuoteRune) + "." + string(QuoteRune) + ".":
700 return ".."
701 }
702 }
703
704 // handle prefix only replacements
705 prefix := ""
706 if r, l1 := utf8.DecodeRuneInString(in); mask.Has(EncodeLeftSpace) && r == '␠' { // SYMBOL FOR SPACE
707 prefix, in = " ", in[l1:]
708 } else if mask.Has(EncodeLeftPeriod) && r == '.' { // FULLWIDTH FULL STOP
709 prefix, in = ".", in[l1:]
710 } else if mask.Has(EncodeLeftTilde) && r == '~' { // FULLWIDTH TILDE
711 prefix, in = "~", in[l1:]
712 } else if mask.Has(EncodeLeftCrLfHtVt) && (r == '␀'+'\t' || r == '␀'+'\n' || r == '␀'+'\v' || r == '␀'+'\r') {
713 prefix, in = string(r-'␀'), in[l1:]
714 } else if r == QuoteRune {
715 if r, l2 := utf8.DecodeRuneInString(in[l1:]); mask.Has(EncodeLeftSpace) && r == '␠' { // SYMBOL FOR SPACE
716 prefix, in = "␠", in[l1+l2:]
717 } else if mask.Has(EncodeLeftPeriod) && r == '.' { // FULLWIDTH FULL STOP
718 prefix, in = ".", in[l1+l2:]
719 } else if mask.Has(EncodeLeftTilde) && r == '~' { // FULLWIDTH TILDE
720 prefix, in = "~", in[l1+l2:]
721 } else if mask.Has(EncodeLeftCrLfHtVt) && (r == '␀'+'\t' || r == '␀'+'\n' || r == '␀'+'\v' || r == '␀'+'\r') {
722 prefix, in = string(r), in[l1+l2:]
723 }
724 }
725
726 // handle suffix only replacements
727 suffix := ""
728 if r, l := utf8.DecodeLastRuneInString(in); mask.Has(EncodeRightSpace) && r == '␠' { // SYMBOL FOR SPACE
729 in = in[:len(in)-l]
730 if q, l2 := utf8.DecodeLastRuneInString(in); q == QuoteRune {
731 suffix, in = "␠", in[:len(in)-l2]
732 } else {
733 suffix = " "
734 }
735 } else if mask.Has(EncodeRightPeriod) && r == '.' { // FULLWIDTH FULL STOP
736 in = in[:len(in)-l]
737 if q, l2 := utf8.DecodeLastRuneInString(in); q == QuoteRune {
738 suffix, in = ".", in[:len(in)-l2]
739 } else {
740 suffix = "."
741 }
742 } else if mask.Has(EncodeRightCrLfHtVt) && (r == '␀'+'\t' || r == '␀'+'\n' || r == '␀'+'\v' || r == '␀'+'\r') {
743 in = in[:len(in)-l]

Callers 1

transformPathSegmentFunction · 0.95

Calls 4

HasMethod · 0.95
appendUnquotedByteFunction · 0.85
WriteStringMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected