From e0ce520e0aa644c9c64aa30ed17d61918443d3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 5 Sep 2023 16:25:08 +0800 Subject: [PATCH] Locale: add JSON format support --- src/modules/locale/locale.c | 16 +++++++++++++++- src/modules/locale/locale.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index 3d783f79f..10c53ba3d 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -32,7 +32,7 @@ void ffPrintLocale(FFLocaleOptions* options) void ffInitLocaleOptions(FFLocaleOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, NULL); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJson); ffOptionInitModuleArg(&options->moduleArgs); } @@ -67,3 +67,17 @@ void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module) ffPrintError(FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } + +void ffGenerateLocaleJson(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate(); + + ffDetectLocale(&locale); + if(locale.length == 0) + { + yyjson_mut_obj_add_str(doc, module, "error", "No locale found"); + return; + } + + yyjson_mut_obj_add_strbuf(doc, module, "result", &locale); +} diff --git a/src/modules/locale/locale.h b/src/modules/locale/locale.h index 405f697c9..8570a3c8d 100644 --- a/src/modules/locale/locale.h +++ b/src/modules/locale/locale.h @@ -9,3 +9,4 @@ void ffInitLocaleOptions(FFLocaleOptions* options); bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value); void ffDestroyLocaleOptions(FFLocaleOptions* options); void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module); +void ffGenerateLocaleJson(FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);