MCPcopy Create free account
hub / github.com/beefytech/Beef / GetAbsPath

Method GetAbsPath

BeefySysLib/Common.cpp:1139–1224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1137}
1138
1139String Beefy::GetAbsPath(const StringImpl& relPathIn, const StringImpl& dir)
1140{
1141 String relPath = relPathIn;
1142
1143 String driveString = "";
1144 String newPath;
1145 newPath = dir;
1146 for (int i = 0; i < (int)newPath.length(); i++)
1147 if (newPath[i] == DIR_SEP_CHAR_ALT)
1148 newPath[i] = DIR_SEP_CHAR;
1149
1150 for (int i = 0; i < (int)relPath.length(); i++)
1151 if (relPath[i] == DIR_SEP_CHAR_ALT)
1152 relPath[i] = DIR_SEP_CHAR;
1153
1154 if ((relPath.length() >= 2) && (relPath[1] == ':'))
1155 return relPath;
1156
1157 char slashChar = DIR_SEP_CHAR;
1158
1159 if ((newPath.length() >= 2) && (newPath[1] == ':'))
1160 {
1161 driveString = newPath.Substring(0, 2);
1162 newPath = newPath.Substring(2);
1163 }
1164
1165 // Append a trailing slash if necessary
1166 if ((newPath.length() > 0) && (newPath[newPath.length() - 1] != '\\') && (newPath[newPath.length() - 1] != '/'))
1167 newPath += slashChar;
1168
1169 int relIdx = 0;
1170
1171 for (;;)
1172 {
1173 if (newPath.length() == 0)
1174 break;
1175
1176 int firstSlash = -1;
1177 for (int32 i = relIdx; i < (int)relPath.length(); i++)
1178 if ((relPath[i] == '\\') || (relPath[i] == '/'))
1179 {
1180 firstSlash = i;
1181 break;
1182 }
1183 if (firstSlash == -1)
1184 break;
1185
1186 String chDir = relPath.Substring(relIdx, firstSlash - relIdx);
1187
1188 relIdx = firstSlash + 1;
1189
1190 if (chDir == "..")
1191 {
1192 int lastDirStart = (int)newPath.length() - 1;
1193 while ((lastDirStart > 0) && (newPath[lastDirStart - 1] != '\\') && (newPath[lastDirStart - 1] != '/'))
1194 lastDirStart--;
1195
1196 String lastDir = newPath.Substring(lastDirStart, newPath.length() - lastDirStart - 1);

Callers

nothing calls this directly

Calls 3

SubstringMethod · 0.80
lengthMethod · 0.45
RemoveToEndMethod · 0.45

Tested by

no test coverage detected