Copy a text field under a cap, cutting on a UTF-8 boundary and saying so. */
| 830 | |
| 831 | /* Copy a text field under a cap, cutting on a UTF-8 boundary and saying so. */ |
| 832 | static void ui_log_copy_field(char *out, size_t outsz, const char *in, size_t cap) { |
| 833 | size_t n = strlen(in); |
| 834 | bool cut = false; |
| 835 | if (n > cap) { |
| 836 | n = cap; |
| 837 | cut = true; |
| 838 | while (n > 0 && ((unsigned char)in[n] & 0xC0) == 0x80) |
| 839 | n--; |
| 840 | } |
| 841 | if (n >= outsz) |
| 842 | n = outsz - 1; |
| 843 | memcpy(out, in, n); |
| 844 | out[n] = '\0'; |
| 845 | if (cut) |
| 846 | snprintf(out + n, outsz - n, " [cut at %d]", (int)cap); |
| 847 | } |
| 848 | |
| 849 | static const char *ui_log_level_name(yyjson_val *v) { |
| 850 | static const char *const known[] = {"debug", "log", "info", "warn", "error"}; |
no outgoing calls
no test coverage detected