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)
This commit is contained in:
Jehan 2025-08-08 11:40:10 +02:00
parent 9699dfce07
commit 06029ec334

View File

@ -190,6 +190,9 @@ int main(int argc, char ** argv)
return 1; return 1;
} }
*comma = '\0'; *comma = '\0';
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)); uchardet_weigh_language(handle, lang_weight, strtof (comma + 1, NULL));
} }
while ((lang_weight = strtok_r (NULL, ",", &saveptr))); while ((lang_weight = strtok_r (NULL, ",", &saveptr)));