MCPcopy Create free account
hub / github.com/apache/brpc / AppendFileName

Function AppendFileName

src/brpc/builtin/common.cpp:147–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145const butil::EndPoint *Path::LOCAL = (butil::EndPoint *)0x01;
146
147void AppendFileName(std::string* dir, const std::string& filename) {
148 if (dir->empty()) {
149 dir->append(filename);
150 return;
151 }
152 const size_t len = filename.size();
153 if (len >= 3) {
154 if (butil::back_char(*dir) != '/') {
155 dir->push_back('/');
156 }
157 dir->append(filename);
158 } else if (len == 1) {
159 if (filename[0] != '.') {
160 if (butil::back_char(*dir) != '/') {
161 dir->push_back('/');
162 }
163 dir->append(filename);
164 }
165 } else if (len == 2) {
166 if (filename[0] != '.' || filename[1] != '.') {
167 if (butil::back_char(*dir) != '/') {
168 dir->push_back('/');
169 }
170 dir->append(filename);
171 } else {
172 const bool is_abs = (dir->c_str()[0] == '/');
173 int npop = 1;
174 while (npop > 0) {
175 const char* p = dir->c_str() + dir->size() - 1;
176 for (; p != dir->c_str() && *p == '/'; --p);
177 if (p == dir->c_str()) {
178 dir->clear();
179 break;
180 }
181 dir->resize(p - dir->c_str() + 1);
182
183 size_t slash_pos = dir->find_last_of('/');
184 if (slash_pos == std::string::npos) {
185 --npop;
186 dir->clear();
187 break;
188 }
189 if (strcmp(dir->data() + slash_pos + 1, ".") != 0) {
190 if (strcmp(dir->data() + slash_pos + 1, "..") == 0) {
191 ++npop;
192 } else {
193 --npop;
194 }
195 }
196 ssize_t new_pos = (ssize_t)slash_pos - 1;
197 for (; new_pos >= 0 && (*dir)[new_pos] == '/'; --new_pos);
198 dir->resize(new_pos + 1);
199 if (dir->empty()) {
200 break;
201 }
202 }
203 if (dir->empty()) {
204 if (is_abs) {

Callers 2

TEST_FFunction · 0.85
default_methodMethod · 0.85

Calls 10

back_charFunction · 0.85
find_last_ofMethod · 0.80
emptyMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
c_strMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by 1

TEST_FFunction · 0.68