| 172 | } |
| 173 | |
| 174 | Torque::Path Path::MakeRelativePath( const Path &makeRelative, const Path &relativeTo, U32 mode ) |
| 175 | { |
| 176 | // We need to find the part of makeRelative that starts to diverge from |
| 177 | // relativeTo. We only need to check up to the end of makeRelative or realtiveTo |
| 178 | // (whichever comes first). |
| 179 | U32 minDirCount = getMin(makeRelative.getDirectoryCount(), relativeTo.getDirectoryCount()); |
| 180 | |
| 181 | // Store the index of the directory where we diverge. If we never diverge this |
| 182 | // will end up being the same as the number of directories in makeRelative |
| 183 | U32 divergeDirIdx = 0; |
| 184 | |
| 185 | for (divergeDirIdx = 0; divergeDirIdx < minDirCount; divergeDirIdx++) |
| 186 | { |
| 187 | // If our directories don't match then this is the diverge directory |
| 188 | if (!makeRelative.getDirectory(divergeDirIdx).equal(relativeTo.getDirectory(divergeDirIdx), mode)) |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | // Get the part of makeRelative's path after it diverged from relativeTo's path |
| 193 | String uniquePath; |
| 194 | |
| 195 | // If we never diverged then divergeDirIdx will be equal to the number of |
| 196 | // directories in makeRelative and this loop will immediately exit |
| 197 | for (U32 i = divergeDirIdx; i < makeRelative.getDirectoryCount(); i++) |
| 198 | uniquePath += makeRelative.getDirectory(i) + "/"; |
| 199 | |
| 200 | // Go ahead and add the full file name |
| 201 | uniquePath += makeRelative.getFullFileName(); |
| 202 | |
| 203 | // Now calculate the relative offset |
| 204 | String offsetPath; |
| 205 | |
| 206 | U32 numOffset = relativeTo.getDirectoryCount() - divergeDirIdx; |
| 207 | |
| 208 | // Push back an "up" for each directory we are offset |
| 209 | for (U32 i = 0; i < numOffset; i++) |
| 210 | offsetPath += "../"; |
| 211 | |
| 212 | return offsetPath + uniquePath; |
| 213 | } |
| 214 | |
| 215 | String Path::Join(const String& a,String::ValueType s,const String& b) |
| 216 | { |
nothing calls this directly
no test coverage detected