diff options
| author | Ben Winston | 2024-06-06 22:37:34 -0400 |
|---|---|---|
| committer | Ben Winston | 2024-06-06 22:37:34 -0400 |
| commit | 5b163ece6dbdad4867902c1d30de644062a2b0ab (patch) | |
| tree | 7150a9d92b4d211fb003dcda22dc6af8bbf5ccf1 | |
| parent | cbcd1fbb716664be4d784d7e8b359e342cb073c9 (diff) | |
refactor: less locals
| -rw-r--r-- | booki.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -22,20 +22,18 @@ char* characters_from_end(char* str, int len_in_bytes, int number_of_chars) { return str; // start at the end of the string, locate all code points - char* newptr = str + len_in_bytes; // will update to last character in do..while unsigned char ch; do { - // update the pointer, get the character - newptr--; + // get the last/previous byte len_in_bytes--; - ch = (unsigned char) *newptr; + ch = (unsigned char) *(str + len_in_bytes); // if we're at the first byte of a unicode point, we've found a whole character if (ch < 0x80 || ch >= 0xC3) number_of_chars--; } while (number_of_chars > 0 && len_in_bytes > 0); - return newptr; + return str + len_in_bytes; } bool comparable(const char* pattern, const char* candidate, int len) { |
