# `HL7v2.Escape`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/escape.ex#L1)

Encodes and decodes HL7v2 escape sequences.

Delimiter characters appearing in field data must be escaped so they are not
confused with structural separators. The standard escape sequences are:

| Sequence   | Meaning                           |
|------------|-----------------------------------|
| `\F\`    | Field separator (default `|`)     |
| `\S\`    | Component separator (default `^`) |
| `\T\`    | Sub-component separator (`&`)     |
| `\R\`    | Repetition separator (`~`)        |
| `\E\`    | Escape character (`\`)           |
| `\Xdd\`  | Hexadecimal data                  |
| `\.br\`  | Line break                        |

Unrecognized escape sequences are passed through unchanged.

# `decode`

```elixir
@spec decode(binary(), HL7v2.Separator.t()) :: binary()
```

Decodes HL7v2 escape sequences in `text`, replacing them with literal characters.

## Examples

    iex> sep = HL7v2.Separator.default()
    iex> HL7v2.Escape.decode("foo\\F\\bar", sep)
    "foo|bar"

    iex> sep = HL7v2.Separator.default()
    iex> HL7v2.Escape.decode("line1\\.br\\line2", sep)
    "line1\r\nline2"

# `encode`

```elixir
@spec encode(binary(), HL7v2.Separator.t()) :: binary()
```

Encodes delimiter characters in `text` as HL7v2 escape sequences.

This is the inverse of `decode/2`. Characters matching any of the separator's
delimiters are replaced with their escape sequence equivalents.

## Examples

    iex> sep = HL7v2.Separator.default()
    iex> HL7v2.Escape.encode("pipe|here", sep)
    "pipe\\F\\here"

    iex> sep = HL7v2.Separator.default()
    iex> HL7v2.Escape.encode("no specials", sep)
    "no specials"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
