MCPcopy Create free account
hub / github.com/WinMerge/winmerge / IsPathAbsolute

Function IsPathAbsolute

Src/paths.cpp:598–619  ·  view source on GitHub ↗

* @brief Checks if path is an absolute path. * @param [in] path Path to check. * @return true if given path is absolute path. */

Source from the content-addressed store, hash-verified

596 * @return true if given path is absolute path.
597 */
598bool IsPathAbsolute(const String &path)
599{
600 if (path.length() < 3)
601 return false;
602
603 size_t pos = path.find_last_of('\\');
604
605 // Absolute path must have "\" and cannot start with it.
606 // Also "\\blahblah" is invalid.
607 if (pos < 2 || pos == String::npos)
608 return false;
609
610 // Maybe "X:\blahblah"?
611 if (path[1] == ':' && path[2] == '\\')
612 return true;
613
614 // So "\\blahblah\"?
615 if (path[0] == '\\' && path[1] == '\\' && pos > 2)
616 return true;
617 else
618 return false;
619}
620
621/**
622 * @brief Checks if folder exists and creates it if needed.

Callers 3

OnOKMethod · 0.85
TEST_FFunction · 0.85

Calls 1

lengthMethod · 0.45

Tested by 1

TEST_FFunction · 0.68