Classify line to empty / code / comment / single punctuation char. * Very rough and mostly suitable for our C++ style. */
| 334 | * Very rough and mostly suitable for our C++ style. |
| 335 | */ |
| 336 | void setLineInfo(std::string full_line) |
| 337 | { |
| 338 | UInt8 num_spaces = 0; |
| 339 | |
| 340 | const char * pos = full_line.data(); |
| 341 | const char * end = pos + full_line.size(); |
| 342 | |
| 343 | while (pos < end) |
| 344 | { |
| 345 | if (*pos == ' ') |
| 346 | ++num_spaces; |
| 347 | else if (*pos == '\t') |
| 348 | num_spaces += 4; |
| 349 | else |
| 350 | break; |
| 351 | ++pos; |
| 352 | } |
| 353 | |
| 354 | indent = std::min<UInt8>(255U, num_spaces); |
| 355 | line.assign(pos, end); |
| 356 | |
| 357 | if (pos == end) |
| 358 | { |
| 359 | line_type = LineType::Empty; |
| 360 | } |
| 361 | else if (pos + 1 < end |
| 362 | && ((pos[0] == '/' && (pos[1] == '/' || pos[1] == '*')) |
| 363 | || (pos[0] == '*' && pos[1] == ' ') /// This is not precise. |
| 364 | || (pos[0] == '#' && pos[1] == ' '))) |
| 365 | { |
| 366 | line_type = LineType::Comment; |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | while (pos < end) |
| 371 | { |
| 372 | if (isAlphaNumericASCII(*pos)) |
| 373 | { |
| 374 | line_type = LineType::Code; |
| 375 | break; |
| 376 | } |
| 377 | ++pos; |
| 378 | } |
| 379 | if (pos == end) |
| 380 | line_type = LineType::Punct; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | void writeTextWithoutNewline(WriteBuffer & out) const |
| 385 | { |
no test coverage detected