Extract the format out of a format string with leading or trailing decorations fmt = "blah blah" -> return fmt fmt = "%.3f" -> return fmt fmt = "hello %.3f" -> return fmt + 6 fmt = "%.3f hello" -> return buf written with "%.3f"
| 3204 | // fmt = "hello %.3f" -> return fmt + 6 |
| 3205 | // fmt = "%.3f hello" -> return buf written with "%.3f" |
| 3206 | const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_size) |
| 3207 | { |
| 3208 | const char* fmt_start = ImParseFormatFindStart(fmt); |
| 3209 | if (fmt_start[0] != '%') |
| 3210 | return fmt; |
| 3211 | const char* fmt_end = ImParseFormatFindEnd(fmt_start); |
| 3212 | if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data. |
| 3213 | return fmt_start; |
| 3214 | ImStrncpy(buf, fmt_start, ImMin((size_t)(fmt_end - fmt_start) + 1, buf_size)); |
| 3215 | return buf; |
| 3216 | } |
| 3217 | |
| 3218 | // Sanitize format |
| 3219 | // - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi |
no test coverage detected