STRING::ESCAPE_FILENAME 1g 2024-04-29 laplante@plcb.ca GOWEB/STRINGtitle: “STRING::ESCAPE_FILENAME” version: “1.0.0” date: 2024-04-29 author: “laplante@plcb.ca” section: “1g” category: “GOWEBstring”
astring::escape_filename Escape Special Characters in Filenames
string::escape_filename(string [, double: false, char: "-", keep_dir: false, keep_ext: true])
escape_filename(string [, double: false, char: "-", keep_dir: false, keep_ext: true])
string::escapeFilename(string [, double: false, char: "-", keep_dir: false, keep_ext: true])
escapeFilename(string [, double: false, char: "-", keep_dir: false, keep_ext: true])
The escape_filename function replaces special characters in a string to produce a safe filename.
By default, it retains the characters:
a-zA-Z0-9-_Other characters are replaced according to the following mapping:
à, á, â, ä, ã, å → aÀ, Á, Â, Ä, Ã, Å → Aæ → aeÆ → AEç → cÇ → Cé, ê, è, ë → eÉ, Ê, È, Ë → Eì, í, î, ï → iÌ, Í, Î, Ï → IÐ → Dð → dÑ → Nñ → nÒ, Ó, Ô, Õ, Ö, Ø → Oò, ó, ô, õ, ö, ø → o× → xÙ, Ú, Û, Ü → Uù, ú, û, ü → uÝ, Ÿ → Yý, ÿ → yÞ → Bþ → bdouble (boolean, optional)
If false, when a character is replaced, only a single replacement character is inserted, even if multiple special characters occur consecutively.
char (string, optional)
The character used to replace special characters. Default is "-".
keep_ext (boolean, optional)
If true, the period (.) character is preserved for file extensions (e.g., resolv.conf).
keep_dir (boolean, optional)
If true, the slash (/) character is preserved for directory paths.
res={{
escape_filename("ééaa..$$##!!.xyz");
escape_filename("
'à', 'á', 'â', 'ä', 'ã', 'å':
'À', 'Á', 'Â', 'Ä', 'Ã', 'Å':
'æ':
'Æ':
'ç':
'Ç':
'é', 'ê', 'è', 'ë':
'É', 'Ê', 'È', 'Ë':
'ì', 'í', 'î', 'ï':
'Ì', 'Í', 'Î', 'Ï':
'Ð':
'ð':
'Ñ':
'ñ':
'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø':
'ò', 'ó', 'ô', 'õ', 'ö', 'ø':
'×':
'Ù', 'Ú', 'Û', 'Ü':
'ù', 'ú', 'û', 'ü':
'Ý', 'Ÿ':
'ý', 'ÿ':
'Þ':
'þ':");
}};
Returns:
res = eeaa-xyz-a-a-a-a-a-a-A-A-A-A-A-A-ae-AE-c-C-e-e-e-e-E-E-E-E-i-i-i-i-I-I-I-I-D-d-N-n-O-O-O-O-O-O-o-o-o-o-o-o-x-U-U-U-U-u-u-u-u-Y-Y-y-y-B-b-.