From 06029ec3340cdf6bf9a6a537dafb3f39eda0560e Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 8 Aug 2025 11:40:10 +0200 Subject: [PATCH] src: allow setting a default language in the CLI tool. The syntax of --weight stays the same with the addition that the language '*' means setting the default weight. For instance, if you are sure that your input is either French or English, you could run: > uchardet -l -w 'fr:1,en:1,*:0' (setting same weight to French and English, and everything else to 0) --- src/tools/uchardet.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index d5ff167..3aa65da 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -190,7 +190,10 @@ int main(int argc, char ** argv) return 1; } *comma = '\0'; - uchardet_weigh_language(handle, lang_weight, strtof (comma + 1, NULL)); + if (strcmp (lang_weight, "*") == 0) + uchardet_set_default_weight(handle, strtof (comma + 1, NULL)); + else + uchardet_weigh_language(handle, lang_weight, strtof (comma + 1, NULL)); } while ((lang_weight = strtok_r (NULL, ",", &saveptr))); }