Advances |text| to first non white space character and writes the new position to |position|. If a null terminator is found during the text advance, SPV_END_OF_STREAM is returned, SPV_SUCCESS otherwise. No error checking is performed on the parameters, its the users responsibility to ensure these are non null.
| 62 | // returned, SPV_SUCCESS otherwise. No error checking is performed on the |
| 63 | // parameters, its the users responsibility to ensure these are non null. |
| 64 | spv_result_t advance(spv_text text, spv_position position) { |
| 65 | // NOTE: Consume white space, otherwise don't advance. |
| 66 | while (true) { |
| 67 | if (position->index >= text->length) return SPV_END_OF_STREAM; |
| 68 | switch (text->str[position->index]) { |
| 69 | case '\0': |
| 70 | return SPV_END_OF_STREAM; |
| 71 | case ';': |
| 72 | if (spv_result_t error = advanceLine(text, position)) return error; |
| 73 | continue; |
| 74 | case ' ': |
| 75 | case '\t': |
| 76 | case '\r': |
| 77 | position->column++; |
| 78 | position->index++; |
| 79 | continue; |
| 80 | case '\n': |
| 81 | position->column = 0; |
| 82 | position->line++; |
| 83 | position->index++; |
| 84 | continue; |
| 85 | default: |
| 86 | return SPV_SUCCESS; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Fetches the next word from the given text stream starting from the given |
| 92 | // *position. On success, writes the decoded word into *word and updates |
no test coverage detected