| 2050 | // Member Functions |
| 2051 | |
| 2052 | std::string ExpandPath(const std::string& pathIn, const std::string& defaultPath) |
| 2053 | { |
| 2054 | std::string expandedPath; |
| 2055 | bool isExpanded = false, wasPathSeparator = true; |
| 2056 | size_t charI = 0; |
| 2057 | const size_t nChars = pathIn.length(); |
| 2058 | |
| 2059 | std::string::size_type delim = 0; |
| 2060 | |
| 2061 | if ('<' == pathIn[0] && (delim = pathIn.find(">/")) != std::string::npos) |
| 2062 | { |
| 2063 | // Expand a leading <tag>/ |
| 2064 | // Convenient for frequently used directories - see OpenFOAM stringOps.C |
| 2065 | // |
| 2066 | // Handle |
| 2067 | // <case>/ => FOAM_CASE directory |
| 2068 | // <constant>/ => FOAM_CASE/constant directory |
| 2069 | // <system>/ => FOAM_CASE/system directory |
| 2070 | // <etc>/ => not handled |
| 2071 | |
| 2072 | const std::string tag(pathIn, 1, delim - 2); |
| 2073 | |
| 2074 | if (tag == "case") |
| 2075 | { |
| 2076 | expandedPath = this->CasePath + '/'; |
| 2077 | isExpanded = true; |
| 2078 | wasPathSeparator = false; |
| 2079 | } |
| 2080 | else if (tag == "constant" || tag == "system") |
| 2081 | { |
| 2082 | expandedPath = this->CasePath + '/' + tag + '/'; |
| 2083 | isExpanded = true; |
| 2084 | wasPathSeparator = false; |
| 2085 | } |
| 2086 | // <etc> in not handled |
| 2087 | |
| 2088 | if (isExpanded) |
| 2089 | { |
| 2090 | charI = delim + 2; |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | while (charI < nChars) |
| 2095 | { |
| 2096 | const char c = pathIn[charI]; |
| 2097 | switch (c) |
| 2098 | { |
| 2099 | case '$': // $-variable expansion |
| 2100 | { |
| 2101 | std::string variable; |
| 2102 | ++charI; // skip the '$' |
| 2103 | while (charI < nChars && (isalnum(pathIn[charI]) || pathIn[charI] == '_')) |
| 2104 | { |
| 2105 | variable += pathIn[charI++]; |
| 2106 | } |
| 2107 | if (variable == "FOAM_CASE") // discard path until the variable |
| 2108 | { |
| 2109 | expandedPath = this->CasePath; |
no test coverage detected