encodings

Converts between different character encodings. On UNIX, this uses the iconv library, on Windows the Windows API.

EncodingConverter = object
  dest, src: CodePage
  ソース 編集
EncodingError = object of ValueError
exception that is raised for encoding errors   Source Edit

プロシージャ

proc nameToCodePage(name: string): CodePage {...}{.raises: [ValueError], tags: [].}
  ソース 編集
proc codePageToName(c: CodePage): string {...}{.raises: [], tags: [].}
  ソース 編集
proc getCurrentEncoding(uiApp = false): string {...}{.raises: [], tags: [].}
retrieves the current encoding. On Unix, always "UTF-8" is returned. The uiApp parameter is Windows specific. If true, the UI's code-page is returned, if false, the Console's code-page is returned.   ソース 編集
proc open(destEncoding = "UTF-8"; srcEncoding = "CP1252"): EncodingConverter {...}{.
    raises: [ValueError, EncodingError], tags: [].}
opens a converter that can convert from srcEncoding to destEncoding. Raises IOError if it cannot fulfill the request.   ソース 編集
proc close(c: EncodingConverter) {...}{.raises: [], tags: [].}
frees the resources the converter c holds.   ソース 編集
proc convert(c: EncodingConverter; s: string): string {...}{.
    raises: [EncodingError, OSError], tags: [].}
converts s to destEncoding that was given to the converter c. It assumed that s is in srcEncoding. utf-16BE, utf-32 conversions not supported on windows   Source Edit
proc convert(s: string; destEncoding = "UTF-8"; srcEncoding = "CP1252"): string {...}{.
    raises: [ValueError, EncodingError, EncodingError, OSError], tags: [].}
converts s to destEncoding. It assumed that s is in srcEncoding. 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