Extract the format out of a format string with leading or trailing decorations fmt = "blah blah" -> return "" fmt = "%.3f" -> return fmt fmt = "hello %.3f" -> return fmt + 6 fmt = "%.3f hello" -> return buf written with "%.3f"
| 3276 | // fmt = "hello %.3f" -> return fmt + 6 |
| 3277 | // fmt = "%.3f hello" -> return buf written with "%.3f" |
| 3278 | const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_size) |
| 3279 | { |
| 3280 | const char* fmt_start = ImParseFormatFindStart(fmt); |
| 3281 | if (fmt_start[0] != '%') |
| 3282 | return ""; |
| 3283 | const char* fmt_end = ImParseFormatFindEnd(fmt_start); |
| 3284 | if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data. |
| 3285 | return fmt_start; |
| 3286 | ImStrncpy(buf, fmt_start, ImMin((size_t)(fmt_end - fmt_start) + 1, buf_size)); |
| 3287 | return buf; |
| 3288 | } |
| 3289 | |
| 3290 | // Sanitize format |
| 3291 | // - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi |
no test coverage detected