Locale: add JSON format support

This commit is contained in:
李通洲
2023-09-05 16:25:08 +08:00
parent f9cd032a5f
commit e0ce520e0a
2 changed files with 16 additions and 1 deletions
+15 -1
View File
@@ -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);
}
+1
View File
@@ -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);