Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::Path Class Reference
Collaboration diagram for duckdb::Path:

Public Member Functions

string ToString () const
string GetBase () const
string GetPath () const
string GetTrailingSeparator () const
const string & GetScheme () const
const string & GetAuthority () const
const string & GetAnchor () const
char GetSeparator () const
bool HasScheme () const
bool HasAuthority () const
bool HasAnchor () const
bool HasDrive () const
char GetDriveChar () const
bool HasPathSegments () const
bool HasTrailingSeparator () const
bool IsAbsolute () const
bool IsLocal () const
bool IsRemote () const
const vector< string > & GetPathSegments () const
Path Join (const Path &rhs) const
Path Join (const string &rhs) const
template<typename... Args>
Path Join (const string &first, const Args &...rest) const
Path Join (const vector< string > &paths) const
Path Parent (int n=1) const

Static Public Member Functions

static Path FromString (const string &raw)
static string Normalize (const string &input)
static string AddSuffixToPath (const string &path, const string &suffix)

Private Member Functions

void NormalizeSegments (const string &raw, size_t path_offset)

Static Private Member Functions

static size_t ParseURIScheme (const string &input, Path &parsed)
static size_t ParseFilePathTail (const string &input, size_t start, Path &parsed)
static size_t ParseFileSchemes (const string &input, Path &parsed)

Private Attributes

string scheme
string authority
string anchor
vector< string > segments
char separator = '/'
bool has_trailing_separator = false
bool is_absolute = false

Member Function Documentation

◆ FromString()

Path duckdb::Path::FromString ( const string & raw)
static
92074 {
92075 Path parsed;
92076#if defined(_WIN32)
92077 const auto first_slash_pos = raw.find_first_of(R"(/\)");
92078#else
92079 const auto first_slash_pos = raw.find('/');
92080#endif
92081 const auto scheme_pos = raw.find("://");
92082 const auto drive_leads = (false
92083#if defined(_WIN32)
92084 || (first_slash_pos == 1 && StringUtil::CharacterIsAlpha(raw[0]))
92085#endif
92086 );
92087 parsed.separator = first_slash_pos == string::npos ? '/' : raw[first_slash_pos];
92088
92089 size_t path_offset;
92090 if (StringUtil::StartsWith(raw, "file:/")) {
92091 path_offset = ParseFileSchemes(raw, parsed);
92092 }
92093#if defined(_WIN32)
92094 else if (raw.size() >= 5 && StringUtil::StartsWith(raw, R"(\\)") && raw.find_first_of('\\', 3) != string::npos) {
92095 path_offset = ParseUNCScheme(raw, parsed);
92096 }
92097#endif
92098 else if (scheme_pos != string::npos && scheme_pos > 1 && scheme_pos < first_slash_pos && !drive_leads) {
92099 path_offset = ParseURIScheme(raw, parsed);
92100 } else {
92101 path_offset = ParseFilePathTail(raw, 0, parsed);
92102 }
92103 parsed.NormalizeSegments(raw, path_offset);
92104 if (!raw.empty() && IsPathSeparator(raw.back())) {
92105 parsed.has_trailing_separator = true;
92106 }
92107 D_ASSERT(parsed.HasScheme() || !parsed.HasAuthority());
92108 D_ASSERT(parsed.anchor.size() <= 4);
92109 return parsed;
92110}
static DUCKDB_API bool StartsWith(string str, string prefix)
Returns true if the target string starts with the given prefix.
Definition duckdb.cpp:109377

◆ ToString()

string duckdb::Path::ToString ( ) const
92112 {
92113 string result = scheme + authority + anchor;
92114 for (size_t i = 0; i < segments.size(); i++) {
92115 if (i) {
92116 result += separator;
92117 }
92118 result += segments[i];
92119 }
92120 if (has_trailing_separator && !segments.empty()) {
92121 result += separator;
92122 }
92123 if (result.empty()) {
92124 result = '.';
92125 }
92126 return result;
92127}

◆ GetBase()

string duckdb::Path::GetBase ( ) const
92129 {
92130 return scheme + authority + anchor;
92131}

◆ GetPath()

string duckdb::Path::GetPath ( ) const
92133 {
92134 if (segments.empty()) {
92135 return (scheme.empty() && anchor.empty()) ? "." : "";
92136 }
92137 string result;
92138 for (size_t i = 0; i < segments.size(); i++) {
92139 if (i) {
92140 result += separator;
92141 }
92142 result += segments[i];
92143 }
92144 return result;
92145}

◆ GetTrailingSeparator()

string duckdb::Path::GetTrailingSeparator ( ) const
inline
7987 { // returns "" or string(1, separator)
7988 return !segments.empty() && has_trailing_separator ? string(1, separator) : "";
7989 }

◆ GetScheme()

const string & duckdb::Path::GetScheme ( ) const
inline
7990 {
7991 return scheme;
7992 }

◆ GetAuthority()

const string & duckdb::Path::GetAuthority ( ) const
inline
7993 {
7994 return authority;
7995 }

◆ GetAnchor()

const string & duckdb::Path::GetAnchor ( ) const
inline
7996 {
7997 return anchor;
7998 }

◆ GetSeparator()

char duckdb::Path::GetSeparator ( ) const
inline
7999 {
8000 return separator;
8001 }

◆ HasScheme()

bool duckdb::Path::HasScheme ( ) const
inline
8003 {
8004 return !scheme.empty();
8005 }

◆ HasAuthority()

bool duckdb::Path::HasAuthority ( ) const
inline
8006 {
8007 return !authority.empty();
8008 }

◆ HasAnchor()

bool duckdb::Path::HasAnchor ( ) const
inline
8009 {
8010 return !anchor.empty();
8011 }

◆ HasDrive()

bool duckdb::Path::HasDrive ( ) const
92147 {
92148 return GetDriveChar() != 0;
92149}

◆ GetDriveChar()

char duckdb::Path::GetDriveChar ( ) const
92151 {
92152 const auto size = anchor.size();
92153 D_ASSERT(size <= 4);
92154 // must be one of {"C:", "C:\" or "\C:", "\C:\"}; switch on size & ':'
92155 if (size <= 1) {
92156 D_ASSERT(size == 0 || IsPathSeparator(anchor[0]));
92157 return 0;
92158 } else if (size == 2) {
92159 return anchor[0];
92160 } else if (size == 3) {
92161 return anchor[anchor[1] == ':' ? 0 : 1];
92162 } else /* (size == 4) */ {
92163 return anchor[1];
92164 }
92165}
GOpaque< Size > size(const GMat &src)

◆ HasPathSegments()

bool duckdb::Path::HasPathSegments ( ) const
inline
8016 {
8017 return !segments.empty();
8018 }

◆ HasTrailingSeparator()

bool duckdb::Path::HasTrailingSeparator ( ) const
inline
8020 {
8021 return has_trailing_separator;
8022 }

◆ IsAbsolute()

bool duckdb::Path::IsAbsolute ( ) const
inline
8024 {
8025 return is_absolute;
8026 }

◆ IsLocal()

bool duckdb::Path::IsLocal ( ) const
inline
8029 {
8030 // note: HasDrive() covers UNC locals too!
8031 return (!IsAbsolute() || !HasScheme() || HasDrive() || StringUtil::StartsWith(scheme, "file:"));
8032 }

◆ IsRemote()

bool duckdb::Path::IsRemote ( ) const
inline
8034 {
8035 return !IsLocal();
8036 }

◆ GetPathSegments()

const vector< string > & duckdb::Path::GetPathSegments ( ) const
inline
8038 {
8039 return segments;
8040 }

◆ Join() [1/4]

Path duckdb::Path::Join ( const Path & rhs) const
92167 {
92168 Path lhs = *this;
92169#if defined(_WIN32)
92170 const bool win_local = (lhs.separator == '\\') || lhs.HasDrive();
92171 const auto auth_is_eq =
92172 win_local ? StringUtil::CIEquals(lhs.authority, rhs.authority) : (lhs.authority == rhs.authority);
92173 const auto seg_prefix =
92174 win_local ? (rhs.segments.size() >= lhs.segments.size() &&
92175 std::equal(lhs.segments.begin(), lhs.segments.end(), rhs.segments.begin(),
92176 [](const string &a, const string &b) { return StringUtil::CIEquals(a, b); }))
92177 : (rhs.segments.size() >= lhs.segments.size() &&
92178 std::equal(lhs.segments.begin(), lhs.segments.end(), rhs.segments.begin()));
92179#else
92180 const auto auth_is_eq = (lhs.authority == rhs.authority);
92181 const auto seg_prefix = (rhs.segments.size() >= lhs.segments.size() &&
92182 std::equal(lhs.segments.begin(), lhs.segments.end(), rhs.segments.begin()));
92183#endif
92184 if (!rhs.IsAbsolute() && !rhs.HasDrive()) {
92185 lhs.segments.insert(lhs.segments.end(), rhs.segments.begin(), rhs.segments.end());
92186 vector<string> result;
92187 result.reserve(lhs.segments.size());
92188 for (auto &seg : lhs.segments) {
92189 if (seg == ".." && !result.empty() && result.back() != "..") {
92190 result.pop_back();
92191 } else {
92192 result.push_back(std::move(seg));
92193 }
92194 }
92195 while (lhs.IsAbsolute() && !result.empty() && result.front() == "..") {
92196 result.erase(result.begin());
92197 }
92198 lhs.segments = std::move(result);
92199 } else if (auth_is_eq && seg_prefix && lhs.scheme == rhs.scheme && lhs.anchor == rhs.anchor) {
92200 if (lhs.segments.size() < rhs.segments.size()) {
92201 lhs.segments = rhs.segments;
92202 }
92203 } else {
92204 throw InvalidInputException("Path: cannot join incompatible paths: \"%s\" onto \"%s\"", rhs.ToString(),
92205 lhs.ToString());
92206 }
92207 lhs.has_trailing_separator = rhs.has_trailing_separator;
92208 return lhs;
92209}
static DUCKDB_API bool CIEquals(const string &l1, const string &l2)
Case insensitive equals.
Definition duckdb.cpp:109696

◆ Join() [2/4]

Path duckdb::Path::Join ( const string & rhs) const
92211 {
92212 return Join(Path::FromString(rhs));
92213}

◆ Join() [3/4]

template<typename... Args>
Path duckdb::Path::Join ( const string & first,
const Args &... rest ) const
inline
8047 {
8048 return Join(first).Join(rest...);
8049 }

◆ Join() [4/4]

Path duckdb::Path::Join ( const vector< string > & paths) const
inline
8051 {
8052 Path result = *this;
8053 for (const auto &rhs : paths) {
8054 result = result.Join(rhs);
8055 }
8056 return result;
8057 }

◆ Parent()

Path duckdb::Path::Parent ( int n = 1) const
92217 {
92218 if (n <= 0) {
92219 return *this;
92220 }
92221 string dots = "..";
92222 for (int i = 1; i < n; i++) {
92223 dots += "/..";
92224 }
92225 return Join(dots);
92226}

◆ Normalize()

string duckdb::Path::Normalize ( const string & input)
inlinestatic
8062 {
8063 return FromString(input).ToString();
8064 }

◆ AddSuffixToPath()

string duckdb::Path::AddSuffixToPath ( const string & path,
const string & suffix )
static
92389 {
92390 // we append the ".wal" **before** a question mark in case of GET parameters
92391 // but only if we are not in a windows long path (which starts with \\?\‍)
92392 std::size_t question_mark_pos = std::string::npos;
92393 if (!StringUtil::StartsWith(path, "\\\\?\\")) {
92394 question_mark_pos = path.find('?');
92395 }
92396 auto result = path;
92397 if (question_mark_pos != std::string::npos) {
92398 result.insert(question_mark_pos, suffix);
92399 } else {
92400 result += suffix;
92401 }
92402 return result;
92403}

◆ NormalizeSegments()

void duckdb::Path::NormalizeSegments ( const string & raw,
size_t path_offset )
private
92232 {
92233 // normalize URI schemes to lowercase; UNC prefixes (\\, \\?, \\?\UNC\‍) are not URI schemes
92234 if (!scheme.empty() && !IsPathSeparator(scheme[0])) {
92235 scheme = StringUtil::Lower(scheme);
92236 }
92237
92238 if (HasAnchor()) {
92239 string normal;
92240 if (IsPathSeparator(anchor[0])) {
92241 normal.append(1, separator);
92242 }
92243 auto drive_char = std::find_if_not(anchor.begin(), anchor.end(), IsPathSeparator);
92244 if (drive_char != anchor.end()) {
92245 normal.append(1, StringUtil::CharacterToUpper(*drive_char));
92246 normal.append(1, ':');
92247 if (IsPathSeparator(anchor.back())) {
92248 normal.append(1, separator);
92249 }
92250 }
92251 anchor = normal;
92252 }
92253
92254 vector<string> raw_segs;
92255 SegmentAndNormalizePath(raw.begin() + static_cast<string::difference_type>(path_offset), raw.end(), raw_segs);
92256 segments.clear();
92257 for (auto &seg : raw_segs) {
92258 if (IsAbsolute() && segments.empty() && seg == "..") {
92259 continue; // drop leading ".." on absolute paths (can't go above root)
92260 }
92261 segments.push_back(std::move(seg));
92262 }
92263}
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630

◆ ParseURIScheme()

size_t duckdb::Path::ParseURIScheme ( const string & input,
Path & parsed )
staticprivate
92270 {
92271 parsed.is_absolute = true;
92272
92273 const size_t auth_begin = input.find("://") + 3;
92274 D_ASSERT(auth_begin >= 4); // non-empty protocol
92275 parsed.scheme = input.substr(0, auth_begin);
92276
92277 const size_t path_begin = input.find('/', auth_begin);
92278 D_ASSERT(path_begin == string::npos || path_begin > auth_begin);
92279 parsed.authority = input.substr(auth_begin, path_begin == string::npos ? string::npos : path_begin - auth_begin);
92280 parsed.anchor = '/';
92281 return path_begin == string::npos ? input.size() : path_begin + 1;
92282}

◆ ParseFilePathTail()

size_t duckdb::Path::ParseFilePathTail ( const string & input,
size_t start,
Path & parsed )
staticprivate
92284 {
92285 size_t pos = start;
92286
92287#if defined(_WIN32)
92288 if (input.size() >= pos + 2 && input[pos + 1] == ':' && StringUtil::CharacterIsAlpha(input[pos])) {
92289 parsed.anchor.append(1, input[pos]);
92290 parsed.anchor.append(1, ':');
92291 pos += 2;
92292 }
92293#endif
92294
92295 if (input.size() > pos && IsPathSeparator(input[pos])) {
92296 parsed.anchor.append(1, parsed.separator);
92297 parsed.is_absolute = true;
92298 pos += 1;
92299 }
92300 return pos;
92301}

◆ ParseFileSchemes()

size_t duckdb::Path::ParseFileSchemes ( const string & input,
Path & parsed )
staticprivate
92320 {
92321 parsed.is_absolute = true;
92322
92323 size_t input_len = input.size();
92324 size_t path_begin = string::npos;
92325 D_ASSERT(input_len >= 6 && StringUtil::StartsWith(input, "file:/"));
92326
92327 if (/* file:/// */ input_len >= 8 && input[6] == '/' && input[7] == '/') {
92328 parsed.scheme = "file://";
92329 parsed.anchor = "/";
92330 path_begin = 8;
92331 } else if (/* file:// */ input_len >= 7 && input[6] == '/') {
92332 ParseURIScheme(input, parsed);
92333 if (StringUtil::Lower(parsed.authority) != "localhost") {
92334 throw InvalidInputException("Path: file:// scheme only supports localhost authority, got: %s",
92335 parsed.authority);
92336 }
92337 path_begin = parsed.scheme.size() + parsed.authority.size() + parsed.anchor.size();
92338 } else /* file:/ */ {
92339 parsed.scheme = "file:";
92340 parsed.anchor = "/";
92341 path_begin = 6;
92342 }
92343
92344 D_ASSERT(parsed.scheme == "file:" || parsed.scheme == "file://");
92345 D_ASSERT(parsed.scheme == "file://" || !parsed.HasAuthority());
92346 return ParseFilePathTail(input, path_begin, parsed);
92347}

The documentation for this class was generated from the following files: