| 1072 | #endif |
| 1073 | |
| 1074 | string GetAbsolutePath(const string &file) |
| 1075 | { |
| 1076 | string str = file; |
| 1077 | |
| 1078 | // If this is a relative path, complement it with the current path |
| 1079 | if( !((str.length() > 0 && (str[0] == '/' || str[0] == '\\')) || |
| 1080 | str.find(":") != string::npos) ) |
| 1081 | { |
| 1082 | str = GetCurrentDir() + "/" + str; |
| 1083 | } |
| 1084 | |
| 1085 | // Replace backslashes for forward slashes |
| 1086 | size_t pos = 0; |
| 1087 | while( (pos = str.find("\\", pos)) != string::npos ) |
| 1088 | str[pos] = '/'; |
| 1089 | |
| 1090 | // Replace /./ with / |
| 1091 | pos = 0; |
| 1092 | while( (pos = str.find("/./", pos)) != string::npos ) |
| 1093 | str.erase(pos+1, 2); |
| 1094 | |
| 1095 | // For each /../ remove the parent dir and the /../ |
| 1096 | pos = 0; |
| 1097 | while( (pos = str.find("/../")) != string::npos ) |
| 1098 | { |
| 1099 | size_t pos2 = str.rfind("/", pos-1); |
| 1100 | if( pos2 != string::npos ) |
| 1101 | str.erase(pos2, pos+3-pos2); |
| 1102 | else |
| 1103 | { |
| 1104 | // The path is invalid |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | return str; |
| 1110 | } |
| 1111 | |
| 1112 | string GetCurrentDir() |
| 1113 | { |
no test coverage detected