### replace_nonexistent - Usage with from_string! Source: https://hexdocs.pm/codepagex/Codepagex.html Example of using `replace_nonexistent/1` with `from_string!/3` to replace invalid characters. ```iex iex> from_string!("Hello æøå!", :ascii, replace_nonexistent("_")) "Hello ___!" ``` -------------------------------- ### Define Custom Missing Function for from_string/4 Source: https://hexdocs.pm/codepagex/index.html Demonstrates defining a custom `missing_fun` for `from_string/4` to handle character encoding errors. This example replaces invalid characters and counts them. ```elixir iex> missing_fun = ...> fn encoding -> ...> case from_string("#", encoding) do ...> {:ok, replacement} -> ...> inner_fun = ...> fn <<_ :: utf8, rest :: binary>>, acc -> ...> {:ok, replacement, rest, acc + 1} ...> end ...> {:ok, inner_fun} ...> err -> ...> err ...> end ...> end iex> from_string("Hello æøå!", :ascii, missing_fun, 0) {:ok, "Hello ###!", 3} ``` -------------------------------- ### Define Custom Missing Function for from_string Source: https://hexdocs.pm/codepagex/Codepagex.html Define and use a custom `missing_fun` to handle invalid byte sequences during string conversion. This example shows a more complex scenario where the replacement logic is defined within the function. ```iex iex> missing_fun = ...> fn encoding -> ...> case from_string("#", encoding) do ...> {:ok, replacement} -> ...> inner_fun = ...> fn <<_ :: utf8, rest :: binary>>, acc -> ...> {:ok, replacement, rest, acc + 1} ...> end ...> {:ok, inner_fun} ...> err -> ...> err ...> end ...> end iex> from_string("Hello æøå!", :ascii, missing_fun, 0) {:ok, "Hello ###!", 3} ``` -------------------------------- ### from_string! - Basic Conversion Source: https://hexdocs.pm/codepagex/Codepagex.html Demonstrates the use of `from_string!/2` for direct conversion of a binary to an Elixir string, raising an exception on errors. ```iex iex> from_string!("Hɦ¦Ó", :iso_8859_1) <<72, 201, 166, 166, 211>> ``` -------------------------------- ### Convert Binary to String with Replacement and Accumulator (from_string) Source: https://hexdocs.pm/codepagex/index.html Uses `from_string/3` with `replace_nonexistent/1` to convert a binary to a string, replacing invalid bytes. The accumulator tracks the number of replacements. ```elixir iex> from_string("Hello æøå!", :ascii, replace_nonexistent("_"), 100) {:ok, "Hello ___!", 103} ``` -------------------------------- ### Handle Invalid Byte Sequences with UTF-8 Replacement Source: https://hexdocs.pm/codepagex/index.html Converts a string to ASCII, using UTF-8 replacement characters for invalid byte sequences. This example first converts to ISO-8859-1 and then to ASCII with UTF-8 replacement. ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string!(iso, :ascii, use_utf_replacement()) "Hello !" ``` -------------------------------- ### encoding_list/0 Source: https://hexdocs.pm/codepagex/index.html Returns a list of supported encodings. Call with :all to see all available options, even those unavailable. ```APIDOC ## encoding_list/0 ### Description Returns a list of the supported encodings. These are extracted from http://unicode.org/ and the names correspond to an encoding file on that page. `encoding_list/1` is normally called without any parameters to list the encodings that are currently configured during compilation. To see all available options, even those unavailable, use `encoding_list(:all)`. ### Parameters #### Query Parameters - **selection** (atom()) - Optional - Use `:all` to list all available options, even unavailable ones. Defaults to currently configured encodings. ### Response #### Success Response (200) - **[String.t()]** - A list of supported encoding names. ``` -------------------------------- ### Use use_utf_replacement/0 for safe string conversion Source: https://hexdocs.pm/codepagex/Codepagex.html Demonstrates `use_utf_replacement/0` with `to_string/3` to safely convert a string, returning the result and the count of replacements. ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string(iso, :ascii, use_utf_replacement()) {:ok, "Hello !", 3} ``` -------------------------------- ### from_string!(string, encoding, missing_fun, acc \\ nil) Source: https://hexdocs.pm/codepagex/Codepagex.html Converts a binary to a string using the specified encoding, with custom error handling for missing characters. Raises an exception on errors. ```APIDOC ## from_string!(string, encoding, missing_fun, acc \\ nil) ### Description Converts a binary to a string using the specified encoding, with custom error handling for missing characters. Raises an exception on errors. ### Signature ```elixir @spec from_string!(String.t(), encoding(), from_s_missing_outer(), term()) :: binary() | no_return() ``` ### Examples ```elixir missing_fun = replace_nonexistent("_") from_string!("Hello æøå!", :ascii, missing_fun) # Expected output: "Hello ___!" ``` ``` -------------------------------- ### Convert Binary to String with Error Handling (from_string!) Source: https://hexdocs.pm/codepagex/index.html Uses `from_string!/2` to convert a binary to a string, raising an exception on encoding errors. This is suitable when errors are unexpected and should halt execution. ```elixir iex> from_string!("Hɦ¦Ó", :iso_8859_1) <<72, 201, 166, 166, 211>> ``` ```elixir iex> from_string!("ʒ", :iso_8859_1) ** (Codepagex.Error) Invalid bytes for encoding ``` -------------------------------- ### from_string!(binary, encoding) Source: https://hexdocs.pm/codepagex/Codepagex.html Converts a binary to a string using the specified encoding. Raises an exception on errors. ```APIDOC ## from_string!(binary, encoding) ### Description Converts a binary to a string using the specified encoding. Raises an exception on errors. ### Signature ```elixir @spec from_string!(String.t(), encoding()) :: binary() | no_return() ``` ### Examples ```elixir from_string!("Hɦ¦Ó", :iso_8859_1) # Expected output: <<72, 201, 166, 166, 211>> from_string!("ʒ", :iso_8859_1) # Expected output: ** (Codepagex.Error) Invalid bytes for encoding ``` ``` -------------------------------- ### Convert Binary to String with Custom Replacement (from_string!) Source: https://hexdocs.pm/codepagex/index.html Uses `from_string!/3` with a custom `missing_fun` (obtained via `replace_nonexistent/1`) to convert a binary to a string, replacing invalid bytes. This version raises exceptions on errors. ```elixir iex> missing_fun = replace_nonexistent("_") iex> from_string!("Hello æøå!", :ascii, missing_fun) "Hello ___!" ``` -------------------------------- ### encoding_list/0 and encoding_list/1 Source: https://hexdocs.pm/codepagex/Codepagex.html Retrieves a list of supported encodings. `encoding_list/0` lists currently configured encodings, while `encoding_list(:all)` lists all available options. ```APIDOC ## encoding_list/0 and encoding_list/1 ### Description Returns a list of the supported encodings. These are extracted from http://unicode.org/ and the names correspond to an encoding file on that page. `encoding_list/1` is normally called without any parameters to list the encodings that are currently configured during compilation. To see all available options, even those unavailable, use `encoding_list(:all)`. ### Method `encoding_list/0` or `encoding_list/1` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir # To list currently configured encodings Codepagex.encoding_list() # To list all available encodings Codepagex.encoding_list(:all) ``` ### Response #### Success Response (List of Encodings) - Returns a list of strings, where each string is a supported encoding name. ### Response Example ```elixir ["ETSI/GSM0338", "ISO8859/8859-1", ...] ``` ### Available Encodings ETSI/GSM0338| ISO8859/8859-1| ISO8859/8859-10 ISO8859/8859-11| ISO8859/8859-13| ISO8859/8859-14 ISO8859/8859-15| ISO8859/8859-16| ISO8859/8859-2 ISO8859/8859-3| ISO8859/8859-4| ISO8859/8859-5 ISO8859/8859-6| ISO8859/8859-7| ISO8859/8859-8 ISO8859/8859-9| VENDORS/MICSFT/EBCDIC/CP037| VENDORS/MICSFT/EBCDIC/CP1026 VENDORS/MICSFT/EBCDIC/CP500| VENDORS/MICSFT/MAC/CYRILLIC| VENDORS/MICSFT/MAC/GREEK VENDORS/MICSFT/MAC/ICELAND| VENDORS/MICSFT/MAC/LATIN2| VENDORS/MICSFT/MAC/ROMAN VENDORS/MICSFT/MAC/TURKISH| VENDORS/MICSFT/PC/CP437| VENDORS/MICSFT/PC/CP737 VENDORS/MICSFT/PC/CP775| VENDORS/MICSFT/PC/CP850| VENDORS/MICSFT/PC/CP852 VENDORS/MICSFT/PC/CP855| VENDORS/MICSFT/PC/CP857| VENDORS/MICSFT/PC/CP860 VENDORS/MICSFT/PC/CP861| VENDORS/MICSFT/PC/CP862| VENDORS/MICSFT/PC/CP863 VENDORS/MICSFT/PC/CP864| VENDORS/MICSFT/PC/CP865| VENDORS/MICSFT/PC/CP866 VENDORS/MICSFT/PC/CP869| VENDORS/MICSFT/PC/CP874| VENDORS/MICSFT/WINDOWS/CP1250 VENDORS/MICSFT/WINDOWS/CP1251| VENDORS/MICSFT/WINDOWS/CP1252| VENDORS/MICSFT/WINDOWS/CP1253 VENDORS/MICSFT/WINDOWS/CP1254| VENDORS/MICSFT/WINDOWS/CP1255| VENDORS/MICSFT/WINDOWS/CP1256 VENDORS/MICSFT/WINDOWS/CP1257| VENDORS/MICSFT/WINDOWS/CP1258| VENDORS/MICSFT/WINDOWS/CP874 VENDORS/MICSFT/WINDOWS/CP932| VENDORS/MICSFT/WINDOWS/CP936| VENDORS/MICSFT/WINDOWS/CP949 VENDORS/MICSFT/WINDOWS/CP950| VENDORS/MISC/ATARIST| VENDORS/MISC/CP424 VENDORS/MISC/CP856| VENDORS/MISC/KOI8-R| VENDORS/MISC/KOI8-U VENDORS/MISC/KPS9566| VENDORS/MISC/KZ1048| VENDORS/MISC/US-ASCII-QUOTES ``` -------------------------------- ### to_string!(binary, encoding) Source: https://hexdocs.pm/codepagex/index.html Converts a binary to a string with a specified encoding. Raises exceptions on errors. ```APIDOC ## to_string!(binary, encoding) ```@spec to_string!(binary(), encoding()) :: String.t() | no_return()``` Like `to_string/2` but raises exceptions on errors. ## Examples ```iex iex> to_string!(<<72, 201, 166, 166, 211>>, :iso_8859_1) "Hɦ¦Ó" iex> to_string!(<<128>>, "ETSI/GSM0338") ** (Codepagex.Error) Invalid bytes for encoding ``` ``` -------------------------------- ### aliases/1 Source: https://hexdocs.pm/codepagex/index.html Returns a list of shorthand aliases that may be used instead of the full name of the encoding. The available aliases are: :ascii, :iso_8859_1, :iso_8859_2, etc. Some of these may not be available depending on mix configuration. If the `selection` parameter is `:all` then all possible aliases are listed, otherwise, only the available aliases are listed. For a full list of encodings, see `encoding_list/1`. ```APIDOC ## aliases(selection \ nil) ### Description Returns a list of shorthand aliases that may be used instead of the full name of the encoding. ### Parameters #### Path Parameters - **selection** (atom()) - Optional - Specifies the selection of aliases to retrieve. If `:all`, all possible aliases are listed. Otherwise, only available aliases are listed. ### Returns - `[atom()]` - A list of encoding aliases. ``` -------------------------------- ### Convert Binary to String with `to_string!/2` Source: https://hexdocs.pm/codepagex/index.html Use `to_string!/2` for direct conversion of a binary to a string with a specified encoding. This function raises an exception if the conversion fails due to invalid bytes. ```elixir iex> to_string!(<<72, 201, 166, 166, 211>>, :iso_8859_1) "Hɦ¦Ó" ``` ```elixir iex> to_string!(<<128>>, "ETSI/GSM0338") ** (Codepagex.Error) Invalid bytes for encoding ``` -------------------------------- ### List Supported Encodings - Elixir Source: https://hexdocs.pm/codepagex/index.html Returns a list of supported encodings. Call with :all to see all available options, even those unavailable during compilation. ```elixir @spec encoding_list(atom()) :: [String.t()] ``` -------------------------------- ### to_string!(binary, encoding, missing_fun, acc \ nil) Source: https://hexdocs.pm/codepagex/index.html Converts a binary to a string with a specified encoding, using a custom function for handling missing bytes. Raises exceptions on errors. ```APIDOC ## to_string!(binary, encoding, missing_fun, acc \ nil) ```@spec to_string!(binary(), encoding(), to_s_missing_outer(), term()) :: String.t() | no_return()``` Like `to_string/4` but raises exceptions on errors. ## Examples ```iex iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string!(iso, :ascii, use_utf_replacement()) "Hello !" ``` ``` -------------------------------- ### to_string!(binary, encoding, missing_fun, acc) Source: https://hexdocs.pm/codepagex/Codepagex.html Converts a binary to a string with custom error handling using a missing function and an accumulator. Raises exceptions on errors. ```APIDOC ## to_string!(binary, encoding, missing_fun, acc) ### Description Converts a binary to a string with custom error handling using a missing function and an accumulator. Raises exceptions on errors. ### Signature ```elixir @spec to_string!(binary(), encoding(), to_s_missing_outer(), term()) :: String.t() | no_return() ``` ### Examples ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string!(iso, :ascii, use_utf_replacement()) "Hello !" ``` ``` -------------------------------- ### to_string!/2 Source: https://hexdocs.pm/codepagex/index.html Like `to_string/2` but raises exceptions on errors. ```APIDOC ## to_string!(binary, encoding) ### Description Converts a binary in a specified encoding to an Elixir string in utf-8 encoding, raising exceptions on errors. ### Parameters #### Path Parameters - **binary** (binary()) - The input binary. - **encoding** (atom() | String.t()) - The encoding of the input binary. ### Returns - `String.t()` - The converted Elixir string in utf-8 encoding. ### Raises - Exception - If an error occurs during conversion. ``` -------------------------------- ### from_string!/2 Source: https://hexdocs.pm/codepagex/index.html Like `from_string/2` but raising exceptions on errors. ```APIDOC ## from_string!(binary, encoding) ### Description Converts an Elixir string in utf-8 encoding to a binary in another encoding, raising exceptions on errors. ### Parameters #### Path Parameters - **binary** (String.t()) - The input string in utf-8 encoding. - **encoding** (atom() | String.t()) - The target encoding. ### Returns - `binary()` - The converted binary in the specified encoding. ### Raises - Exception - If an error occurs during conversion. ``` -------------------------------- ### from_string!(binary, encoding) Source: https://hexdocs.pm/codepagex/index.html Converts a binary in a specified encoding to an Elixir string in utf-8 encoding, raising exceptions on errors. ```APIDOC ## from_string!(binary, encoding) ### Description Converts a binary in a specified encoding to an Elixir string in utf-8 encoding, raising exceptions on errors. ### Method `from_string!/2` ### Parameters - `binary` (binary()): The input binary to convert. - `encoding` (encoding()): The target encoding. ### Response - `binary()`: The converted string as a binary. ### Errors - `Codepagex.Error`: Raised on invalid bytes for the specified encoding. ``` -------------------------------- ### Use `use_utf_replacement/0` with `to_string/4` Source: https://hexdocs.pm/codepagex/index.html Shows how `use_utf_replacement/0` can be used with `to_string/4` to handle invalid bytes gracefully. The function will not fail, and the accumulator will be incremented by the number of replacements made. ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string!(iso, :ascii, use_utf_replacement()) "Hello !" ``` ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string(iso, :ascii, use_utf_replacement()) {:ok, "Hello !", 3} ``` -------------------------------- ### Convert String to ISO-8859-1 Binary (Bang) Source: https://hexdocs.pm/codepagex/index.html Converts a string to a binary using ISO-8859-1, raising an error on failure. Use `from_string/2` for {:ok, result} tuple. ```elixir iex> from_string!("æøåÆØÅ", :iso_8859_1) <<230, 248, 229, 198, 216, 197>> ``` -------------------------------- ### from_string! - Error Handling Source: https://hexdocs.pm/codepagex/Codepagex.html Illustrates how `from_string!/2` raises a `Codepagex.Error` when encountering invalid bytes for the specified encoding. ```iex iex> from_string!("ʒ", :iso_8859_1) ** (Codepagex.Error) Invalid bytes for encoding ``` -------------------------------- ### Handle Invalid Bytes with `use_utf_replacement/0` Source: https://hexdocs.pm/codepagex/index.html Demonstrates how to use `use_utf_replacement/0` with `to_string/4` to replace invalid bytes with a placeholder character instead of failing. The accumulator tracks the number of replacements. ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> to_string(iso, :ascii, use_utf_replacement()) {:ok, "Hello !", 3} ``` ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> missing_fun = ...> fn encoding -> ...> case to_string("#", encoding) do ...> {:ok, replacement} -> ...> inner_fun = ...> fn <<_, rest :: binary>>, acc -> ...> {:ok, replacement, rest, acc + 1} ...> end ...> {:ok, inner_fun} ...> err -> ...> err ...> end ...> end iex> to_string(iso, :ascii, missing_fun, 0) {:ok, "Hello ###!", 3} ``` ```elixir iex> iso = "Hello æøå!" |> from_string!(:iso_8859_1) iex> missing_fun = ...> fn _encoding -> ...> inner_fun = ...> fn <<_, rest :: binary>>, acc -> ...> {:ok, "#", rest, acc + 1} ...> end ...> {:ok, inner_fun} ...> end iex> to_string(iso, :ascii, missing_fun, 10) {:ok, "Hello ###!", 13} ``` -------------------------------- ### to_string(binary, encoding, missing_fun, acc \\ nil) Source: https://hexdocs.pm/codepagex/index.html Converts a binary in a specified encoding to an Elixir string in utf-8 encoding, with custom error handling for encoding issues. ```APIDOC ## to_string(binary, encoding, missing_fun, acc \\ nil) ### Description Converts a binary in a specified encoding to an Elixir string in utf-8 encoding, with custom error handling for encoding issues. ### Method `to_string/4` ### Parameters - `binary` (binary()): The input binary. - `encoding` (encoding()): The encoding of the input binary. - `missing_fun` (to_s_missing_outer()): A function to handle encoding errors. - `acc` (term(), optional): An accumulator value, passed between `missing_fun` calls. ### Response - `{:ok, String.t(), integer()}`: The converted string in utf-8 encoding, along with the final accumulator value. - `{:error, term(), integer()}`: An error tuple if conversion fails, along with the accumulator value at the point of failure. ``` -------------------------------- ### Convert ISO-8859-1 Binary to String (Bang) Source: https://hexdocs.pm/codepagex/index.html Converts a binary encoded in ISO-8859-1 to a string, raising an error on failure. Use `to_string/2` for {:ok, result} tuple. ```elixir iex> to_string!(<<230, 248, 229, 198, 216, 197>>, :iso_8859_1) "æøåÆØÅ" ``` -------------------------------- ### to_string!/4 Source: https://hexdocs.pm/codepagex/index.html Like `to_string/4` but raises exceptions on errors. ```APIDOC ## to_string!(binary, encoding, missing_fun, acc \ nil) ### Description Converts a binary in a specified encoding into an Elixir string in utf-8 encoding, with custom handling for unrepresentable bytes, and raises exceptions on errors. ### Parameters #### Path Parameters - **binary** (binary()) - The input binary. - **encoding** (atom() | String.t()) - The encoding of the input binary. - **missing_fun** (to_s_missing_inner()) - A function to handle bytes that do not have a proper encoding. - **acc** (term()) - Optional - An accumulator for the `missing_fun`. ### Returns - `{:ok, String.t(), binary(), term()} | {:error, term()}` - The result of the conversion, including the converted string, remaining binary, and accumulator, or an error tuple. ### Raises - Exception - If an error occurs during conversion. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-10%22.html Converts a binary string to its ISO8859-10 representation. ```APIDOC ## from_string/3 ### Description Converts a binary string to its ISO8859-10 representation. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary) - The input binary string to convert. - `missing_fun` (function) - A function to handle characters not found in the encoding. - `acc` (any) - An accumulator for the conversion process. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-13%22.html Converts a binary to a string using the ISO8859-13 encoding. Handles missing characters with a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary to a string using the ISO8859-13 encoding. Handles missing characters with a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary data to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the `missing_fun`. ``` -------------------------------- ### from_string!/4 Source: https://hexdocs.pm/codepagex/index.html Like `from_string/4` but raising exceptions on errors. ```APIDOC ## from_string!(string, encoding, missing_fun, acc \ nil) ### Description Converts an Elixir string in utf-8 to a binary in a specified encoding, with custom handling for unrepresentable codepoints, and raises exceptions on errors. ### Parameters #### Path Parameters - **string** (String.t()) - The input string in utf-8 encoding. - **encoding** (atom() | String.t()) - The target encoding. - **missing_fun** (from_s_missing_inner()) - A function to handle codepoints not representable in the target encoding. - **acc** (term()) - Optional - An accumulator for the `missing_fun`. ### Returns - `{:ok, binary(), String.t(), term()} | {:error, term()}` - The result of the conversion, including the converted binary, remaining string, and accumulator, or an error tuple. ### Raises - Exception - If an error occurs during conversion. ``` -------------------------------- ### use_utf_replacement/0 Source: https://hexdocs.pm/codepagex/index.html This function may be used as a parameter to `to_string/4` or `to_string!/4` such that any bytes in the input binary that don't have a proper encoding are replaced with a special unicode character and the function will not fail. ```APIDOC ## use_utf_replacement() ### Description Configures the `to_string/4` or `to_string!/4` functions to replace unencodable bytes with a special unicode character, preventing failure. ### Returns - `term()` - Indicates that UTF replacement is enabled. ``` -------------------------------- ### encoding_list/1 Source: https://hexdocs.pm/codepagex/index.html Returns a list of the supported encodings. These are extracted from http://unicode.org/ and the names correspond to an encoding file on that page. ```APIDOC ## encoding_list(selection \ nil) ### Description Returns a list of the supported encodings. ### Parameters #### Path Parameters - **selection** (atom()) - Optional - Not explicitly defined in source, but implied by `nil` default. ### Returns - `[atom()]` - A list of supported encoding atoms. ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/%3A%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-15%22.html Converts a list of integers representing characters in the ISO8859-15 codepage back to a binary string. ```APIDOC ## to_string/3 ### Description Converts a list of integers (representing ISO8859-15 characters) back to a binary string. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### Convert String to ISO-8859-1 Binary Source: https://hexdocs.pm/codepagex/index.html Converts a string to a binary using the ISO-8859-1 encoding. Use `from_string/3` for custom error handling. ```elixir iex> from_string("æøåÆØÅ", :iso_8859_1) {:ok, <<230, 248, 229, 198, 216, 197>>} ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-16%22.html Converts a binary string from the ISO8859_8859-16 codepage representation back to a standard binary string. ```APIDOC ## to_string/3 ### Description Converts a binary string from the ISO8859_8859-16 codepage representation back to a standard binary string. ### Parameters - `binary` (binary) - The input binary string in ISO8859_8859-16 format. - `missing_fun` (function) - A function to handle characters not present in the codepage. - `acc` (any) - An accumulator for the conversion process. ### Returns (any) - The resulting binary string. ``` -------------------------------- ### from_string!(string, encoding, missing_fun, acc \\ nil) Source: https://hexdocs.pm/codepagex/index.html Converts a string in a specified encoding to an Elixir string in utf-8 encoding, raising exceptions on errors and allowing custom handling for missing characters. ```APIDOC ## from_string!(string, encoding, missing_fun, acc \\ nil) ### Description Converts a string in a specified encoding to an Elixir string in utf-8 encoding, raising exceptions on errors and allowing custom handling for missing characters. ### Method `from_string!/4` ### Parameters - `string` (String.t()): The input string to convert. - `encoding` (encoding()): The target encoding. - `missing_fun` (from_s_missing_outer()): A function to handle missing characters. - `acc` (term(), optional): An accumulator value, defaults to `nil`. ### Response - `binary()`: The converted string as a binary. ### Errors - `Codepagex.Error`: Raised on invalid bytes for the specified encoding. ``` -------------------------------- ### to_string!/2 Source: https://hexdocs.pm/codepagex/Codepagex.html Converts a binary in a specified encoding to an Elixir string (UTF-8), raising exceptions on errors. ```APIDOC ## to_string!/2 ### Description Like `to_string/2` but raises exceptions on errors. ### Parameters #### Path Parameters - **binary** (binary()) - The input binary. - **encoding** (encoding()) - The source encoding. ### Returns - `String.t()` - The converted Elixir string (UTF-8). ### Raises - Exception if conversion fails. ``` -------------------------------- ### from_string!/2 Source: https://hexdocs.pm/codepagex/Codepagex.html Converts an Elixir string (UTF-8) to a binary in a specified encoding, raising exceptions on errors. ```APIDOC ## from_string!/2 ### Description Like `from_string/2` but raising exceptions on errors. ### Parameters #### Path Parameters - **string** (String.t()) - The input Elixir string (UTF-8). - **encoding** (encoding()) - The target encoding. ### Returns - `binary()` - The converted binary in the target encoding. ### Raises - Exception if conversion fails. ``` -------------------------------- ### Configure Codepagex Encodings (ASCII Only) Source: https://hexdocs.pm/codepagex/index.html Specifies that only the ASCII encoding should be included by Codepagex. This configuration requires recompilation of the dependency. ```elixir use Mix.Config config :codepagex, :encodings, [:ascii] ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-13%22.html Converts a string to a binary using the ISO8859-13 encoding. Handles missing characters with a provided function. ```APIDOC ## to_string/3 ### Description Converts a string to a binary using the ISO8859-13 encoding. Handles missing characters with a provided function. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary data to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the `missing_fun`. ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/%3A%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-6%22.html Converts a list of integers representing characters in the ISO8859-6 codepage back to a binary string. ```APIDOC ## to_string/3 ### Description Converts a list of integers representing characters in the ISO8859-6 codepage back to a binary string. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters * `binary` (binary) - The input binary string. * `missing_fun` (function) - A function to handle characters not found in the codepage. * `acc` (any) - An accumulator for the conversion process. ``` -------------------------------- ### translate!/3 Source: https://hexdocs.pm/codepagex/index.html Like `translate/3` but raises exceptions on errors. ```APIDOC ## translate!(binary, encoding_from, encoding_to) ### Description Converts a binary from one encoding to another, using utf-8 as an intermediate encoding, and raises exceptions on errors. ### Parameters #### Path Parameters - **binary** (binary()) - The input binary. - **encoding_from** (atom() | String.t()) - The source encoding. - **encoding_to** (atom() | String.t()) - The target encoding. ### Returns - `binary()` - The converted binary in the target encoding. ### Raises - Exception - If an error occurs during conversion. ``` -------------------------------- ### Configure Codepagex Encodings (Multiple) Source: https://hexdocs.pm/codepagex/index.html Configures Codepagex to include multiple encodings using aliases, regex, and full names. This configuration requires recompilation of the dependency. ```elixir use Mix.Config config :codepagex, :encodings, [ :ascii, # by alias name ~r[iso8859]i, # by a regex matching the full name "ISO8859/8859-9", # by the full name as a string :"MISC/CP856" # by a full name as an atom ] ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/%3A%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-5%22.html Converts a string to a binary string using the ISO8859-5 encoding. Handles missing characters with a provided function. ```APIDOC ## to_string/3 ### Description Converts a string to a binary string using the ISO8859-5 encoding. Handles missing characters with a provided function. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary) - The input binary string to convert. - `missing_fun` (function) - A function to handle characters not found in the codepage. - `acc` (any) - An accumulator for the conversion process. ``` -------------------------------- ### Configure Codepagex Encodings (Multiple) Source: https://hexdocs.pm/codepagex/Codepagex.html Configures Codepagex to use multiple encodings specified by aliases, regex, and full names in `config/config.exs`. This allows for a flexible selection of encodings. ```elixir use Mix.Config config :codepagex, :encodings, [ :ascii, # by alias name ~r[iso8859]i, # by a regex matching the full name "ETSI/GSM0338", # by the full name as a string :"MISC/CP856" # by a full name as an atom ] ``` -------------------------------- ### aliases/1 Source: https://hexdocs.pm/codepagex/Codepagex.html Returns a list of shorthand aliases for encoding names. These aliases can be used instead of the full encoding names. ```APIDOC ## aliases/1 ### Description Returns a list of shorthand aliases that may be used instead of the full name of the encoding. ### Parameters #### Path Parameters - **selection** (atom()) - Optional - If `:all`, lists all possible aliases. Otherwise, lists available aliases. ### Returns - `[atom()]` - A list of encoding aliases. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/%3A%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-5%22.html Converts a binary string to a string using the ISO8859-5 encoding. Handles missing characters with a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary string to a string using the ISO8859-5 encoding. Handles missing characters with a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary) - The input binary string to convert. - `missing_fun` (function) - A function to handle characters not found in the codepage. - `acc` (any) - An accumulator for the conversion process. ``` -------------------------------- ### from_string/2 Source: https://hexdocs.pm/codepagex/index.html Converts an Elixir string in utf-8 encoding to a binary in another encoding. ```APIDOC ## from_string(string, encoding) ### Description Converts an Elixir string in utf-8 encoding to a binary in another encoding. ### Parameters #### Path Parameters - **string** (String.t()) - The input string in utf-8 encoding. - **encoding** (atom() | String.t()) - The target encoding. ### Returns - `binary()` - The converted binary in the specified encoding. ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-15%22.html Converts a string to a binary string using the ISO8859-15 encoding. Handles missing characters using a provided function. ```APIDOC ## to_string/3 ### Description Converts a string to a binary string using the ISO8859-15 encoding. Handles missing characters using a provided function. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-11%22.html Converts a string to a binary representation using the ISO8859-11 encoding. Handles missing characters with a provided function. ```APIDOC ## to_string/3 ### Description Converts a string to a binary representation using the ISO8859-11 encoding. Handles missing characters with a provided function. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### Force Recompilation After Configuration Change Source: https://hexdocs.pm/codepagex/Codepagex.html Forces the recompilation of the `codepagex` dependency after changing the encoding configuration. This step is necessary to ensure that the specified encodings are compiled into the project. ```bash mix deps.compile codepagex --force ``` -------------------------------- ### Simplified Custom Missing Function for from_string Source: https://hexdocs.pm/codepagex/Codepagex.html A simplified version of a custom `missing_fun` for `from_string/4`. This version directly returns the replacement string and assumes valid encoding. ```iex iex> missing_fun = fn _encoding -> ...> inner_fun = ...> fn <<_ :: utf8, rest :: binary>>, acc -> ...> {:ok, "#", rest, acc + 1} ...> end ...> {:ok, inner_fun} ...> end iex> from_string("Hello æøå!", :ascii, missing_fun, 10) {:ok, "Hello ###!", 13} ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-15%22.html Converts a binary string to a string using the ISO8859-15 encoding. Handles missing characters using a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary string to a string using the ISO8859-15 encoding. Handles missing characters using a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### from_string/4 Source: https://hexdocs.pm/codepagex/index.html Converts an Elixir string in UTF-8 to a binary in a specified encoding, with custom handling for unrepresentable codepoints. ```APIDOC ## from_string/4 ### Description Convert an Elixir String in UTF-8 to a binary in a specified encoding. A function parameter specifies how to deal with codepoints that are not representable in the target encoding. Compared to `from_string/2`, you may pass a `missing_fun` function parameter to handle encoding errors in `string`. The function `replace_nonexistent/1` may be used as a default error handling mechanism. The `encoding` parameter should be in `encoding_list/0` as an atom or String, or in `aliases/0`. ### Parameters #### Path Parameters - **string** (binary()) - The input string in UTF-8 encoding. - **encoding** (encoding()) - The target encoding. Can be an atom or String from `encoding_list/0` or `aliases/0`. - **missing_fun** (from_s_missing_outer()) - A function to handle unrepresentable codepoints. - **acc** (term()) - An accumulator, passed between invocations of the inner function returned by `missing_fun`. ### Response #### Success Response (200) - **{:ok, String.t(), integer()}** - The converted string, the number of characters processed, and the final accumulator value. #### Error Response - **{:error, term(), integer()}** - An error message, the number of characters processed, and the final accumulator value. ``` -------------------------------- ### from_string!/4 Source: https://hexdocs.pm/codepagex/Codepagex.html Converts an Elixir string (UTF-8) to a binary in a specified encoding, raising exceptions on errors and with custom handling for unrepresentable codepoints. ```APIDOC ## from_string!/4 ### Description Like `from_string/4` but raising exceptions on errors. ### Parameters #### Path Parameters - **string** (String.t()) - The input Elixir string (UTF-8). - **encoding** (encoding()) - The target encoding. - **missing_fun** (from_s_missing_inner()) - A function to handle unrepresentable codepoints. - **acc** (term()) - Optional - Accumulator for the missing function. ### Returns - `binary()` - The converted binary in the target encoding. ### Raises - Exception if conversion fails. ``` -------------------------------- ### Convert ISO-8859-1 Binary to String Source: https://hexdocs.pm/codepagex/index.html Converts a binary encoded in ISO-8859-1 back to a string. Use `to_string/3` for custom error handling. ```elixir iex> to_string(<<230, 248, 229, 198, 216, 197>>, :iso_8859_1) {:ok, "æøåÆØÅ"} ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-16%22.html Converts a binary string to a representation using the ISO8859_8859-16 codepage. ```APIDOC ## from_string/3 ### Description Converts a binary string to a representation using the ISO8859_8859-16 codepage. ### Parameters - `binary` (binary) - The input binary string. - `missing_fun` (function) - A function to handle characters not present in the codepage. - `acc` (any) - An accumulator for the conversion process. ### Returns (any) - The result of the conversion process. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-5%22.html Converts a binary string to a list of characters using the ISO8859-5 encoding. Handles missing characters with a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary string to a list of characters using the ISO8859-5 encoding. Handles missing characters with a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-11%22.html Converts a binary string to a string using the ISO8859-11 encoding. Handles missing characters with a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary string to a string using the ISO8859-11 encoding. Handles missing characters with a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the codepage. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### to_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-9%22.html Converts a string to a binary string using ISO8859-9 encoding. Handles missing characters with a provided function. ```APIDOC ## to_string/3 ### Description Converts a string to a binary string using ISO8859-9 encoding. Handles missing characters with a provided function. ### Function Signature `to_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the encoding. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### from_string/3 Source: https://hexdocs.pm/codepagex/:%22Elixir.Codepagex.Functions.Generated.ISO8859_8859-8%22.html Converts a binary string to a list of integers using the ISO8859-8 encoding. Handles missing characters with a provided function. ```APIDOC ## from_string/3 ### Description Converts a binary string to a list of integers using the ISO8859-8 encoding. Handles missing characters with a provided function. ### Function Signature `from_string(binary, missing_fun, acc)` ### Parameters - `binary` (binary): The input binary string to convert. - `missing_fun` (function): A function to handle characters not found in the encoding. - `acc` (any): An accumulator for the conversion process. ``` -------------------------------- ### from_string/2 Source: https://hexdocs.pm/codepagex/index.html Converts an Elixir string in UTF-8 encoding to a binary in another specified encoding. ```APIDOC ## from_string/2 ### Description Converts an Elixir string in UTF-8 encoding to a binary in another encoding. The `encoding` parameter should be in `encoding_list/0` as an atom or String, or in `aliases/0`. ### Parameters #### Path Parameters - **string** (String.t()) - The input string in UTF-8 encoding. - **encoding** (encoding()) - The target encoding. Can be an atom or String from `encoding_list/0` or `aliases/0`. ### Response #### Success Response (200) - **{:ok, binary()}** - The converted binary string. #### Error Response - **{:error, term()}** - An error message if the conversion fails. ``` -------------------------------- ### to_string/2 Source: https://hexdocs.pm/codepagex/index.html Converts a binary in a specified encoding to an Elixir string in utf-8 encoding. ```APIDOC ## to_string(binary, encoding) ### Description Converts a binary in a specified encoding to an Elixir string in utf-8 encoding. ### Parameters #### Path Parameters - **binary** (binary()) - The input binary. - **encoding** (atom() | String.t()) - The encoding of the input binary. ### Returns - `String.t()` - The converted Elixir string in utf-8 encoding. ```