| 141 | } |
| 142 | |
| 143 | static bool output_text_requires_encoding(const char *data, size_t len) { |
| 144 | static const char bytes_prefix[] = "@bytes:"; |
| 145 | static const char utf8_prefix[] = "@utf8:"; |
| 146 | if (!data) { |
| 147 | return len != 0; |
| 148 | } |
| 149 | if ((len >= sizeof(bytes_prefix) - 1 && |
| 150 | memcmp(data, bytes_prefix, sizeof(bytes_prefix) - 1) == 0) || |
| 151 | (len >= sizeof(utf8_prefix) - 1 && |
| 152 | memcmp(data, utf8_prefix, sizeof(utf8_prefix) - 1) == 0)) { |
| 153 | return true; |
| 154 | } |
| 155 | size_t offset = 0; |
| 156 | while (offset < len) { |
| 157 | size_t sequence = utf8_sequence_length((const unsigned char *)data + offset, len - offset); |
| 158 | if (!sequence) { |
| 159 | return true; |
| 160 | } |
| 161 | offset += sequence; |
| 162 | } |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | bool cbm_output_encode_text(const char *data, size_t len, char **encoded, size_t *encoded_len) { |
| 167 | static const char bytes_prefix[] = "@bytes:"; |
no test coverage detected