| 91 | /////////////////////////////////////////// |
| 92 | |
| 93 | void log_replace_colors(const char *src, char *dest, const char **color_tags, const char **color_codes, int32_t count, int32_t code_size) { |
| 94 | // New string with new color values |
| 95 | int32_t curr = 0; |
| 96 | while (*src != '\0') { |
| 97 | // Logic while in a tag |
| 98 | if ( *src == '<') curr = 1; |
| 99 | else if (curr == 1 && *src != '~') curr = 0; |
| 100 | else if (curr == 5) { |
| 101 | curr = 0; |
| 102 | if (*src == '>') { |
| 103 | int key_id = count - 1; |
| 104 | for (int i = 0; i < count; i++) { |
| 105 | if (string_startswith(src-3, color_tags[i])) { |
| 106 | key_id = i; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | if (code_size != 0) memcpy(dest, color_codes[key_id], code_size); |
| 111 | dest += code_size; |
| 112 | src += 1; |
| 113 | continue; |
| 114 | } |
| 115 | } |
| 116 | else if (curr > 0) curr += 1; |
| 117 | |
| 118 | // Copy the character |
| 119 | if (curr == 0) { |
| 120 | *dest = *src; |
| 121 | dest += 1; |
| 122 | } |
| 123 | src += 1; |
| 124 | } |
| 125 | *dest = *src; |
| 126 | } |
| 127 | |
| 128 | /////////////////////////////////////////// |
| 129 |
no test coverage detected