Closest schema property to `key` for a "did you mean" suggestion, or NULL * when nothing is plausibly near (distance > half the key length, min 2). */
| 11796 | /* Closest schema property to `key` for a "did you mean" suggestion, or NULL |
| 11797 | * when nothing is plausibly near (distance > half the key length, min 2). */ |
| 11798 | static const char *cli_closest_prop(yyjson_val *props, const char *key) { |
| 11799 | const char *best = NULL; |
| 11800 | int best_d = 0; |
| 11801 | size_t idx; |
| 11802 | size_t max; |
| 11803 | yyjson_val *k; |
| 11804 | yyjson_val *v; |
| 11805 | yyjson_obj_foreach(props, idx, max, k, v) { |
| 11806 | const char *name = yyjson_get_str(k); |
| 11807 | if (!name) { |
| 11808 | continue; |
| 11809 | } |
| 11810 | int d = cli_edit_distance(key, name); |
| 11811 | if (!best || d < best_d) { |
| 11812 | best = name; |
| 11813 | best_d = d; |
| 11814 | } |
| 11815 | } |
| 11816 | int limit = (int)(strlen(key) / 2); |
| 11817 | if (limit < 2) { |
| 11818 | limit = 2; |
| 11819 | } |
| 11820 | return (best && best_d <= limit) ? best : NULL; |
| 11821 | } |
| 11822 | |
| 11823 | /* True if the schema's required[] array contains `key`. */ |
| 11824 | static bool cli_schema_required_has(yyjson_val *required, const char *key) { |
no test coverage detected