| 149 | } |
| 150 | |
| 151 | int FileContents::getField(int lineNum, int field, char *dest, int len) |
| 152 | { |
| 153 | int curfield = field; |
| 154 | int curline = lineNum; |
| 155 | |
| 156 | dest[0] = '\0'; |
| 157 | if (lineNum >= numLinesInFile) { |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | if (printfFile) { |
| 162 | curline %= realLinesInFile; |
| 163 | } |
| 164 | const std::string & line = fileLines[curline]; |
| 165 | |
| 166 | size_t pos(0), oldpos(0); |
| 167 | |
| 168 | do { |
| 169 | oldpos = pos; |
| 170 | size_t localpos = line.find(';', oldpos); |
| 171 | |
| 172 | if (localpos != std::string::npos) { |
| 173 | pos = localpos + 1; |
| 174 | } else { |
| 175 | pos = localpos; |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | if (curfield == 0) { |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | curfield --; |
| 184 | } while (oldpos != std::string::npos); |
| 185 | |
| 186 | |
| 187 | if (curfield) { |
| 188 | WARNING("Field %d not found in the file %s", field, fileName); |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | if (std::string::npos == oldpos) { |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | if (std::string::npos != pos) { |
| 198 | // should not be decremented for fieldN |
| 199 | pos -= (oldpos + 1); |
| 200 | } |
| 201 | |
| 202 | std::string x = line.substr(oldpos, pos); |
| 203 | if (x.length()) { |
| 204 | if (printfFile) { |
| 205 | const char *s = x.c_str(); |
| 206 | int l = strlen(s); |
| 207 | int copied = 0; |
| 208 | for (int i = 0; i < l; i++) { |
no test coverage detected