encodings
Converts between different character encodings. On UNIX, this uses the iconv library, on Windows the Windows API.
Imports
Types
EncodingConverter = ptr ConverterObj
- can convert between two character sets Source Edit
EncodingError = object of ValueError
- exception that is raised for encoding errors Source Edit
Procs
proc getCurrentEncoding(uiApp = false): string {...}{.raises: [], tags: [].}- retrieves the current encoding. On Unix, always "UTF-8" is returned. The
uiAppparameter is Windows specific. If true, the UI's code-page is returned, if false, the Console's code-page is returned. Source Edit proc open(destEncoding = "UTF-8"; srcEncoding = "CP1252"): EncodingConverter {...}{. raises: [EncodingError], tags: [].}- opens a converter that can convert from
srcEncodingtodestEncoding. RaisesIOErrorif it cannot fulfill the request. Source Edit proc close(c: EncodingConverter) {...}{.raises: [], tags: [].}- frees the resources the converter
cholds. Source Edit proc convert(c: EncodingConverter; s: string): string {...}{.raises: [OSError], tags: [].}- Source Edit
proc convert(s: string; destEncoding = "UTF-8"; srcEncoding = "CP1252"): string {...}{. raises: [EncodingError, OSError], tags: [].}- converts
stodestEncoding. It assumed thatsis insrcEncoding. This opens a converter, uses it and closes it again and is thus more convenient but also likely less efficient than re-using a converter. utf-16BE, utf-32 conversions not supported on windows Source Edit
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/encodings.html