MCPcopy
hub / github.com/rclone/rclone / Encode

Method Encode

lib/encoder/encoder.go:220–683  ·  view source on GitHub ↗

Encode takes a raw name and substitutes any reserved characters and patterns in it

(in string)

Source from the content-addressed store, hash-verified

218// Encode takes a raw name and substitutes any reserved characters and
219// patterns in it
220func (mask MultiEncoder) Encode(in string) string {
221 if mask == EncodeRaw {
222 return in
223 }
224
225 if in == "" {
226 return ""
227 }
228
229 if mask.Has(EncodeDot) {
230 switch in {
231 case ".":
232 return "."
233 case "..":
234 return ".."
235 case ".":
236 return string(QuoteRune) + "."
237 case "..":
238 return string(QuoteRune) + "." + string(QuoteRune) + "."
239 }
240 }
241
242 // handle prefix only replacements
243 prefix := ""
244 if mask.Has(EncodeLeftSpace) { // Leading SPACE
245 if in[0] == ' ' {
246 prefix, in = "␠", in[1:] // SYMBOL FOR SPACE
247 } else if r, l := utf8.DecodeRuneInString(in); r == '␠' { // SYMBOL FOR SPACE
248 prefix, in = string(QuoteRune)+"␠", in[l:] // SYMBOL FOR SPACE
249 }
250 }
251 if mask.Has(EncodeLeftPeriod) && prefix == "" { // Leading PERIOD
252 if in[0] == '.' {
253 prefix, in = ".", in[1:] // FULLWIDTH FULL STOP
254 } else if r, l := utf8.DecodeRuneInString(in); r == '.' { // FULLWIDTH FULL STOP
255 prefix, in = string(QuoteRune)+".", in[l:] // FULLWIDTH FULL STOP
256 }
257 }
258 if mask.Has(EncodeLeftTilde) && prefix == "" { // Leading ~
259 if in[0] == '~' {
260 prefix, in = string('~'+fullOffset), in[1:] // FULLWIDTH TILDE
261 } else if r, l := utf8.DecodeRuneInString(in); r == '~'+fullOffset {
262 prefix, in = string(QuoteRune)+string('~'+fullOffset), in[l:] // FULLWIDTH TILDE
263 }
264 }
265 if mask.Has(EncodeLeftCrLfHtVt) && prefix == "" { // Leading CR LF HT VT
266 switch c := in[0]; c {
267 case '\t', '\n', '\v', '\r':
268 prefix, in = string('␀'+rune(c)), in[1:] // SYMBOL FOR NULL
269 default:
270 switch r, l := utf8.DecodeRuneInString(in); r {
271 case '␀' + '\t', '␀' + '\n', '␀' + '\v', '␀' + '\r':
272 prefix, in = string(QuoteRune)+string(r), in[l:]
273 }
274 }
275 }
276 // handle suffix only replacements
277 suffix := ""

Callers 1

transformPathSegmentFunction · 0.95

Calls 4

HasMethod · 0.95
appendQuotedBytesFunction · 0.85
WriteStringMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected