# Module encodings

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

# Imports

os, parseutils, strutils

# Types

    PConverter = ptr TConverter

  can convert between two character sets

    EInvalidEncoding = object of EInvalidValue

  exception that is raised for encoding errors

# Procs

    proc getCurrentEncoding(): string {.raises: [], tags: [].}

  retrieves the current encoding. On Unix, always "UTF-8" is returned.

    proc open(destEncoding = "UTF-8"; srcEncoding = "CP1252"): PConverter {.
        raises: [EInvalidEncoding], tags: [].}

  opens a converter that can convert from srcEncoding to destEncoding. Raises EIO if it cannot fullfill the request.

    proc close(c: PConverter) {.raises: [], tags: [].}

  frees the resources the converter c holds.

    proc convert(c: PConverter; s: string): string {.raises: [EOS], tags: [].}

    proc convert(s: string; destEncoding = "UTF-8"; srcEncoding = "CP1252"): string {.
        raises: [EInvalidEncoding, EOS], 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 convienent but also likely less efficient than re-using a converter.

Generated: 2013-05-21 09:55:21 UTC