encodings
nimony/lib/std/encodings.nim
Routines for converting between different character encodings. On UNIX, this uses the iconv:idx: library, on Windows the Windows API.
The following example shows how to change character encodings.
type EncodingConverter = ptr ConverterObj not nilCan convert between two character sets.
proc getCurrentEncoding(uiApp: bool): stringRetrieves the current encoding. On Unix, "UTF-8" is always returned. The
uiAppparameter is Windows specific. If true, the UI's code-page is returned, if false, the Console's code-page is returned.proc open(destEncoding: string; srcEncoding: string): ptr ConverterObj not nilOpens a converter that can convert from
srcEncodingtodestEncoding. RaisesEncodingErrorif it cannot fulfill the request.proc close(c: ptr ConverterObj not nil)Frees the resources the converter
cholds.proc convert(c: ptr ConverterObj not nil; s: string): stringConverts
stodestEncodingthat was given to the converterc. It assumes thatsis insrcEncoding... warning:: UTF-16BE and UTF-32 conversions are not supported on Windows.
proc convert(s: string; destEncoding: string; srcEncoding: string): stringConverts
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... warning:: UTF-16BE and UTF-32 conversions are not supported on Windows.