| 148 | } |
| 149 | |
| 150 | void vtkSortFileNames::GroupFileNames(vtkStringArray* input, vtkStringArrayVector* output) |
| 151 | { |
| 152 | std::string baseName; |
| 153 | std::string extension; |
| 154 | std::string fileNamePath; |
| 155 | std::string reducedName; |
| 156 | |
| 157 | std::list<unsigned int> ungroupedFiles; |
| 158 | std::vector<std::string> reducedFileNames; |
| 159 | |
| 160 | vtkIdType numberOfStrings = input->GetNumberOfValues(); |
| 161 | for (vtkIdType i = 0; i < numberOfStrings; i++) |
| 162 | { |
| 163 | std::string& fileName = input->GetValue(i); |
| 164 | extension = vtksys::SystemTools::GetFilenameLastExtension(fileName); |
| 165 | fileNamePath = vtksys::SystemTools::GetFilenamePath(fileName); |
| 166 | baseName = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileName); |
| 167 | |
| 168 | // If extension is all digits, it is not a true extension, so |
| 169 | // add it back onto the filename. Note that the extension |
| 170 | // includes the leading dot. |
| 171 | int numericExtension = 1; |
| 172 | for (unsigned int j = 1; j < extension.length(); j++) |
| 173 | { |
| 174 | if (!(extension[j] >= '0' && extension[j] <= '9')) |
| 175 | { |
| 176 | numericExtension = 0; |
| 177 | } |
| 178 | } |
| 179 | if (numericExtension && !extension.empty()) |
| 180 | { |
| 181 | baseName.append(extension); |
| 182 | extension = ""; |
| 183 | } |
| 184 | |
| 185 | // Create a reduced filename that replaces all digit sequences |
| 186 | // in the filename with a single digit "0". We begin by setting |
| 187 | // the reduced filename to the path. |
| 188 | reducedName = fileNamePath + "/"; |
| 189 | int inDigitBlock = 0; |
| 190 | unsigned int charBlockStart = 0; |
| 191 | unsigned int stringLength = static_cast<unsigned int>(baseName.length()); |
| 192 | for (unsigned int k = 0; k < stringLength; k++) |
| 193 | { |
| 194 | if (baseName[k] >= '0' && baseName[k] <= '9') |
| 195 | { |
| 196 | if (!inDigitBlock && k != 0) |
| 197 | { |
| 198 | reducedName.append(baseName.substr(charBlockStart, k - charBlockStart)); |
| 199 | reducedName.append("0"); |
| 200 | } |
| 201 | inDigitBlock = 1; |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | if (inDigitBlock) |
| 206 | { |
| 207 | charBlockStart = k; |
no test coverage detected