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

Method StripTrailingSeparatorsInternal

src/butil/files/file_path.cc:1248–1268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1246
1247
1248void FilePath::StripTrailingSeparatorsInternal() {
1249 // If there is no drive letter, start will be 1, which will prevent stripping
1250 // the leading separator if there is only one separator. If there is a drive
1251 // letter, start will be set appropriately to prevent stripping the first
1252 // separator following the drive letter, if a separator immediately follows
1253 // the drive letter.
1254 StringType::size_type start = FindDriveLetter(path_) + 2;
1255
1256 StringType::size_type last_stripped = StringType::npos;
1257 for (StringType::size_type pos = path_.length();
1258 pos > start && IsSeparator(path_[pos - 1]);
1259 --pos) {
1260 // If the string only has two separators and they're at the beginning,
1261 // don't strip them, unless the string began with more than two separators.
1262 if (pos != start + 1 || last_stripped == start + 2 ||
1263 !IsSeparator(path_[start - 1])) {
1264 path_.resize(pos - 1);
1265 last_stripped = pos;
1266 }
1267 }
1268}
1269
1270FilePath FilePath::NormalizePathSeparators() const {
1271 return NormalizePathSeparatorsTo(kSeparators[0]);

Callers 4

DirNameMethod · 0.80
BaseNameMethod · 0.80
AppendMethod · 0.80

Calls 3

FindDriveLetterFunction · 0.85
lengthMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected