from stb.h
| 8 | |
| 9 | // from stb.h |
| 10 | void stringfile(char *buffer, std::vector<char*> &lines) { |
| 11 | char *s; |
| 12 | size_t count, i; |
| 13 | |
| 14 | // two passes through: first time count lines, second time set them |
| 15 | for (i = 0; i < 2; ++i) { |
| 16 | s = buffer; |
| 17 | if (i == 1) lines[0] = s; |
| 18 | count = 1; // was '1', but C arrays are 0-indexed |
| 19 | while (*s) { |
| 20 | if (*s == '\n' || *s == '\r') { |
| 21 | |
| 22 | // If this is the 2nd pass, then terminate the line at the first line break char |
| 23 | if (i == 1) *s = 0; |
| 24 | |
| 25 | s++; // next char |
| 26 | |
| 27 | // if the termination is a CRLF combo, then jump to the next char |
| 28 | if ((*s == '\r') || (*s == '\n')) s++; |
| 29 | |
| 30 | // if the char is valid (first after line break), set up the next item in the line array |
| 31 | if (*s) { // it's not over yet |
| 32 | if (i == 1) { |
| 33 | lines[count] = s; |
| 34 | // list[count+1] = NULL; |
| 35 | // fprintf(stdout,"%s\n",list[count]); |
| 36 | } |
| 37 | ++count; |
| 38 | } |
| 39 | } |
| 40 | s++; |
| 41 | } // while s |
| 42 | |
| 43 | // Generate the required array to hold all the line starting points |
| 44 | if (i == 0) { |
| 45 | lines.resize(count); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | char *fix_to_utf8(char *s, char **arena, char *arena_end) { |
| 51 | if (!utf8valid(s)) { |