# Trimming and Translating

> StringZilla for C++

Trimming is exposed in C++ on the view: `strip(byteset)`, `lstrip(byteset)`, and `rstrip(byteset)` return a narrowed view with the matching leading/trailing bytes removed — no copy is made.

```cpp
#include <stringzilla/stringzilla.hpp>
namespace sz = ashvardanian::stringzilla;

int main() {
    sz::string_view_t padded = "  \t spaced out \n";
    sz::string_view_t tight = padded.strip(sz::whitespaces_set());
    assert(tight == "spaced out");
    return 0;
}
```

Translation — mapping every byte through a 256-entry lookup table — is offered both at the C ABI level through `sz_strings_lookup_best`, documented under [String Collections and Containers](https://www.unum.cloud/docs/stringzilla/cpp/sorting-and-sets.md#string-collections-and-containers), and in C++ through `sz::lookup`:

```cpp
#include <stringzilla/stringzilla.hpp>
namespace sz = ashvardanian::stringzilla;

int main() {
    sz::look_up_table_t to_upper = sz::look_up_table_t::identity();
    for (int i = 'a'; i <= 'z'; ++i) to_upper[(char)i] = (char)(i - 32);

    sz::string_t text;
    if (sz::failed(text.assign("hello"))) return 1;
    text.lookup(to_upper); // in place
    assert(text == "HELLO");
    return 0;
}
```

The C side ships ready-made table initializers — `sz_strings_lookup_init_lower`, `sz_strings_lookup_init_upper`, and `sz_strings_lookup_init_ascii`.
To select an ASCII-only fast path, scan for the complement of `sz_byteset_init_ascii` with `sz_find_byteset_best`, which reaches the SIMD byteset kernels instead of a scalar loop.

`#include <stringzilla/stringzilla.hpp>`

## look_up_table_t

A look-up table for byte-to-byte replacement, exactly 256 bytes.

```cpp
class look_up_table_t
```

## lookup

Maps all characters in the `source` string into the `target` buffer using the provided lookup `table`.

```cpp
status_t lookup(
    string_view_t source,
    look_up_table_t const & table,
    char *target,
    sz_capability_t capabilities = default_capabilities(),
    sz_stream_t stream = nullptr) noexcept;
```

```cpp
status_t lookup(
    string_span_t string,
    look_up_table_t const & table,
    sz_capability_t capabilities = default_capabilities(),
    sz_stream_t stream = nullptr) noexcept;
```

Replaces ____(in-place) all characters in the string using the provided lookup table.

- `source` (in): The characters to map.
- `table` (in): The byte-to-byte mapping.
- `target` (out): Where the mapped characters go, `source's` own bytes for an in-place map.
- `capabilities` (in): Capabilities to pick from.
- `stream` (in): Null on the CPU, or the stream of the device `capabilities` describes.
- `string` (inout): The characters to map, overwritten.

See also: [sz_strings_lookup_best](https://www.unum.cloud/docs/stringzilla/c/trimming-and-translating.md#sz_strings_lookup_best)

