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

Function first_element

src/path.cpp:577–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575 // if src.empty(), sets pos,len, to 0,0.
576
577 void first_element(
578 const string_type & src,
579 size_type & element_pos,
580 size_type & element_size,
581 size_type size
582)
583 {
584 if (size == string_type::npos) size = src.size();
585 element_pos = 0;
586 element_size = 0;
587 if (src.empty()) return;
588
589 string_type::size_type cur(0);
590
591 // deal with // [network]
592 if (size >= 2 && is_separator(src[0])
593 && is_separator(src[1])
594 && (size == 2
595 || !is_separator(src[2])))
596 {
597 cur += 2;
598 element_size += 2;
599 }
600
601 // leading (not non-network) separator
602 else if (is_separator(src[0]))
603 {
604 ++element_size;
605 // bypass extra leading separators
606 while (cur+1 < size
607 && is_separator(src[cur+1]))
608 {
609 ++cur;
610 ++element_pos;
611 }
612 return;
613 }
614
615 // at this point, we have either a plain name, a network name,
616 // or (on Windows only) a device name
617
618 // find the end
619 while (cur < size
620# ifdef BOOST_WINDOWS_API
621 && src[cur] != colon
622# endif
623 && !is_separator(src[cur]))
624 {
625 ++cur;
626 ++element_size;
627 }
628
629# ifdef BOOST_WINDOWS_API
630 if (cur == size) return;
631 // include device delimiter
632 if (src[cur] == colon)
633 { ++element_size; }
634# endif

Callers 1

beginMethod · 0.85

Calls 1

is_separatorFunction · 0.85

Tested by

no test coverage detected