MCPcopy Create free account
hub / github.com/boostorg/filesystem / decrement_v4

Method decrement_v4

src/path.cpp:1339–1397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1337}
1338
1339BOOST_FILESYSTEM_DECL void path_algorithms::decrement_v4(path_detail::path_iterator& it)
1340{
1341 const size_type size = it.m_path_ptr->m_pathname.size();
1342 BOOST_ASSERT_MSG(it.m_pos > 0, "path::iterator decrement past begin()");
1343 BOOST_ASSERT_MSG(it.m_pos <= size, "path::iterator decrement after the referenced path was modified");
1344
1345 size_type root_name_size = 0;
1346 size_type root_dir_pos = find_root_directory_start(it.m_path_ptr->m_pathname.c_str(), size, root_name_size);
1347
1348 if (root_dir_pos < size && it.m_pos == root_dir_pos)
1349 {
1350 // Was pointing at root directory, decrement to root name
1351 set_to_root_name:
1352 it.m_pos = 0u;
1353 const path::value_type* p = it.m_path_ptr->m_pathname.c_str();
1354 it.m_element.m_pathname.assign(p, p + root_name_size);
1355 return;
1356 }
1357
1358 // if at end and there was a trailing '/', return ""
1359 if (it.m_pos == size &&
1360 size > 1 &&
1361 detail::is_directory_separator(it.m_path_ptr->m_pathname[it.m_pos - 1]) &&
1362 !is_root_separator(it.m_path_ptr->m_pathname, root_dir_pos, it.m_pos - 1))
1363 {
1364 --it.m_pos;
1365 it.m_element.m_pathname.clear();
1366 return;
1367 }
1368
1369 // skip separators unless root directory
1370 size_type end_pos = it.m_pos;
1371 while (end_pos > root_name_size)
1372 {
1373 --end_pos;
1374
1375 if (end_pos == root_dir_pos)
1376 {
1377 // Decremented to the root directory
1378 it.m_pos = end_pos;
1379 it.m_element.m_pathname = path::separator; // generic format; see docs
1380 return;
1381 }
1382
1383 if (!detail::is_directory_separator(it.m_path_ptr->m_pathname[end_pos]))
1384 {
1385 ++end_pos;
1386 break;
1387 }
1388 }
1389
1390 if (end_pos <= root_name_size)
1391 goto set_to_root_name;
1392
1393 size_type filename_size = find_filename_size(it.m_path_ptr->m_pathname, root_name_size, end_pos);
1394 it.m_pos = end_pos - filename_size;
1395 const path::value_type* p = it.m_path_ptr->m_pathname.c_str();
1396 it.m_element.m_pathname.assign(p + it.m_pos, p + end_pos);

Callers

nothing calls this directly

Calls 8

is_directory_separatorFunction · 0.85
is_root_separatorFunction · 0.85
find_filename_sizeFunction · 0.85
clearMethod · 0.80
sizeMethod · 0.45
c_strMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected