-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String recoding improvements. (#3238)
* Cleanup tutils and tests logic. * * Add settings.log.recode and settings.log.recode.encoding. * Add settings.metadata.recode * Add doc. Fixes: #3231
- Loading branch information
Showing
8 changed files
with
161 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Strings encoding | ||
|
||
Liquidsoap operates internally using the UTF-8 string encoding. Most strings inside the application are converted | ||
to UTF-8 whenever possible. Conversion is done using [camomile](https://github.com/ocaml-community/camomile) automatic | ||
string encoding detection. If the conversion fails, the string is kept as-is. The list of encodings used for automatic | ||
detection is set via [settings.charset.encodings](settings.html#list-of-encodings-to-try-for-automatic-encoding-detection.) | ||
|
||
There are some exceptions, however. For instance, filenames and paths are not converted: if your system expects paths | ||
to be in a different encoding than UTF-8 then we do need to keep strings representing files and paths in this encoding | ||
to prevent errors. | ||
|
||
In general, you are advised to set the string encoding to UTF-8 on all systems running liquidsoap scripts for consistency | ||
and clarity. | ||
|
||
However, if for some reasons you need to tweak string encoding, these settings can be of use: | ||
|
||
- `settings.log.recode` and `settings.log.recode.encoding`: set the first one to `true` and the second one to the string encoding you would like log entries to be converted into. | ||
- `settings.metadata.recode`: set to `false` to prevent metadata from being converted to UTF-8. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
avi_format | ||
biquad_filter | ||
blank | ||
charset_base | ||
charset | ||
child_support | ||
chord | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(***************************************************************************** | ||
Liquidsoap, a programmable audio stream generator. | ||
Copyright 2003-2023 Savonet team | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details, fully stated in the COPYING | ||
file at the root of the liquidsoap distribution. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*****************************************************************************) | ||
|
||
let conf_charset = | ||
Dtools.Conf.void | ||
~p:(Configure.conf#plug "charset") | ||
"Settings related to charset conversion." | ||
|
||
let conf_path = | ||
Dtools.Conf.string ~p:(conf_charset#plug "path") | ||
~d:(Liquidsoap_paths.camomile_dir ()) | ||
"Directory where charset files are to be found." | ||
|
||
let conf_encoding = | ||
Dtools.Conf.list | ||
~p:(conf_charset#plug "encodings") | ||
~d:["UTF-8"; "ISO-8859-1"; "UTF-16"] | ||
"List of encodings to try for automatic encoding detection." | ||
|
||
module C = CamomileLib.CharEncoding.Configure (struct | ||
let basedir = conf_path#get | ||
let datadir = Filename.concat basedir "database" | ||
let localedir = Filename.concat basedir "locales" | ||
let charmapdir = Filename.concat basedir "charmaps" | ||
let unimapdir = Filename.concat basedir "mappings" | ||
end) | ||
|
||
include C | ||
|
||
exception Unknown_encoding of string | ||
exception Unsupported_encoding of t | ||
|
||
let of_string s = try C.of_name s with Not_found -> raise (Unknown_encoding s) | ||
let to_string = C.name_of | ||
let custom_encoding = ref None | ||
|
||
let automatic_encoding () = | ||
match !custom_encoding with | ||
| Some e -> e | ||
| None -> | ||
let encs = conf_encoding#get in | ||
let e = C.automatic "auto" (List.map of_string encs) C.utf8 in | ||
custom_encoding := Some e; | ||
e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters