String Handling
When to Use
Use this skill when the user asks about printing, comparing, or converting ovx strings.
Inputs
Resolve inputs in this order: existing repository files and referenced snippets, explicit user request, then broader agent context.
- Target API surface: C, C++, or Python interop with C strings.
- Source of the
ovx_string_t: error text, returned path, dictionary lookup, status message, or user-provided string wrapper.
- Required operation: print, compare, convert to
std::string_view, copy to owning storage, or preserve lifetime.
- Repository source snippets referenced below. Treat these snippets as the API source of truth.
Prerequisites
- Use an ovrtx checkout that contains the referenced examples and docs tests.
- Read the relevant
> **Source:** snippet before writing or explaining API usage.
- Know whether the string is API-owned borrowed storage or caller-owned storage before recommending a borrowed view or copy.
Instructions
- Identify whether the task is printing, comparing, converting, or preserving an
ovx_string_t.
- Use both
ptr and length; do not assume the string can be handled safely by APIs that only look for a null terminator.
- In C, print with a precision-limited string format and compare by checking
length before using strncmp.
- In C++, prefer
std::string_view when the caller only needs borrowed access, and copy immediately if the value must outlive the API-owned storage.
- When changing code, run the C example or helper test that owns the referenced string-handling pattern whenever practical.
Output Format
- For explanations, cite the relevant API names, source snippets, and caveats.
- For code changes, summarize the files changed, snippets affected, and validation run.
Scripts
This skill has no scripts.
Limitations
- The referenced snippets remain the source of truth; update or add tested snippets before documenting new API usage.
Overview
All strings returned by the ovrtx API use ovx_string_t — a (ptr, length) pair. The strings are null-terminated, but prefer using the length field over relying on the null terminator.
C
Print with the %.*s precision pattern so the explicit length controls how many
characters are read from ptr.
Compare by checking length first, then using strncmp for the exact byte count.
C++
Wrap ptr and length in std::string_view for zero-copy access to the
standard string API.
The error-handling helper in the minimal C example demonstrates this pattern:
Source: examples/c/minimal/main.cpp snippet check-error-helper
Key Types / Functions
| Type |
Header |
ovx_string_t |
include/ovx/types.h |
literal_to_ovx_string(str) |
include/ovx/types.h — creates ovx_string_t from a string literal |
is_ovx_string_empty(str) |
include/ovx/types.h — null/empty check |
Troubleshooting
- Do not pass
ovx_string_t::ptr directly to functions that expect a specific length (e.g. strcmp) without also checking length. Use strncmp or std::string_view instead.
- Error strings from
ovrtx_get_last_error() are in thread-local storage and are invalidated by the next API call on the same thread. Copy or consume them immediately.
References
- Use the
> **Source:** directives in this skill to locate tested snippets before reusing API patterns.
- Keep related skills, docs, and snippets synchronized when changing the workflow.
1---2name: string-handling3description: Working with ovx_string_t in C and C++. Use when user asks about printing, comparing, or converting ovx strings.4license: LicenseRef-NvidiaProprietary5---67# String Handling89## When to Use1011Use this skill when the user asks about printing, comparing, or converting ovx strings.1213## Inputs1415Resolve inputs in this order: existing repository files and referenced snippets, explicit user request, then broader agent context.1617- Target API surface: C, C++, or Python interop with C strings.18- Source of the `ovx_string_t`: error text, returned path, dictionary lookup, status message, or user-provided string wrapper.19- Required operation: print, compare, convert to `std::string_view`, copy to owning storage, or preserve lifetime.20- Repository source snippets referenced below. Treat these snippets as the API source of truth.2122## Prerequisites2324- Use an ovrtx checkout that contains the referenced examples and docs tests.25- Read the relevant `> **Source:**` snippet before writing or explaining API usage.26- Know whether the string is API-owned borrowed storage or caller-owned storage before recommending a borrowed view or copy.2728## Instructions29301. Identify whether the task is printing, comparing, converting, or preserving an `ovx_string_t`.312. Use both `ptr` and `length`; do not assume the string can be handled safely by APIs that only look for a null terminator.323. In C, print with a precision-limited string format and compare by checking `length` before using `strncmp`.334. In C++, prefer `std::string_view` when the caller only needs borrowed access, and copy immediately if the value must outlive the API-owned storage.345. When changing code, run the C example or helper test that owns the referenced string-handling pattern whenever practical.3536## Output Format3738- For explanations, cite the relevant API names, source snippets, and caveats.39- For code changes, summarize the files changed, snippets affected, and validation run.4041## Scripts4243This skill has no scripts.4445## Limitations4647- The referenced snippets remain the source of truth; update or add tested snippets before documenting new API usage.4849## Overview5051All strings returned by the ovrtx API use `ovx_string_t` — a `(ptr, length)` pair. The strings are null-terminated, but prefer using the `length` field over relying on the null terminator.5253## C5455Print with the `%.*s` precision pattern so the explicit length controls how many56characters are read from `ptr`.5758Compare by checking `length` first, then using `strncmp` for the exact byte count.5960## C++6162Wrap `ptr` and `length` in `std::string_view` for zero-copy access to the63standard string API.6465The error-handling helper in the minimal C example demonstrates this pattern:6667> **Source:** `examples/c/minimal/main.cpp` snippet `check-error-helper`6869## Key Types / Functions7071| Type | Header |72|------|--------|73| `ovx_string_t` | `include/ovx/types.h` |74| `literal_to_ovx_string(str)` | `include/ovx/types.h` — creates `ovx_string_t` from a string literal |75| `is_ovx_string_empty(str)` | `include/ovx/types.h` — null/empty check |7677## Troubleshooting7879- Do not pass `ovx_string_t::ptr` directly to functions that expect a specific length (e.g. `strcmp`) without also checking `length`. Use `strncmp` or `std::string_view` instead.80- Error strings from `ovrtx_get_last_error()` are in thread-local storage and are invalidated by the next API call on the same thread. Copy or consume them immediately.8182## References8384- Use the `> **Source:**` directives in this skill to locate tested snippets before reusing API patterns.85- Keep related skills, docs, and snippets synchronized when changing the workflow.