MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / encodePath

Function encodePath

3rd-party/ftpd/source/ftpSession.cpp:115–167  ·  view source on GitHub ↗

\brief Encode path \param buffer_ Buffer to encode \param quotes_ Whether to encode quotes

Source from the content-addressed store, hash-verified

113/// \param buffer_ Buffer to encode
114/// \param quotes_ Whether to encode quotes
115std::string encodePath (std::string_view const buffer_, bool const quotes_ = false)
116{
117 // check if the buffer has \n
118 bool const lf = std::memchr (buffer_.data (), '\n', buffer_.size ());
119
120 auto end = std::end (buffer_);
121
122 std::size_t numQuotes = 0;
123 if (quotes_)
124 {
125 // check for \" that needs to be encoded
126 auto p = buffer_.data ();
127 do
128 {
129 p = static_cast<char const *> (std::memchr (p, '"', end - p));
130 if (p)
131 {
132 ++p;
133 ++numQuotes;
134 }
135 } while (p);
136 }
137
138 // if nothing needs escaping, return it as-is
139 if (!lf && !numQuotes)
140 return std::string (buffer_);
141
142 // reserve output buffer
143 std::string path (buffer_.size () + numQuotes, '\0');
144 auto in = buffer_.data ();
145 auto out = path.data ();
146
147 // encode into the output buffer
148 while (in < end)
149 {
150 if (*in == '\n')
151 {
152 // encoded \n is \0
153 *out++ = '\0';
154 }
155 else if (quotes_ && *in == '"')
156 {
157 // encoded \" is \"\"
158 *out++ = '"';
159 *out++ = '"';
160 }
161 else
162 *out++ = *in;
163 ++in;
164 }
165
166 return path;
167}
168
169/// \brief Get parent directory name of a path
170/// \param path_ Path to get parent of

Callers 5

fillDirentMethod · 0.85
xferDirMethod · 0.85
readCommandMethod · 0.85
listTransferMethod · 0.85
PWDMethod · 0.85

Calls 4

stringFunction · 0.85
endFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected