Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / bytestr.h / byte_str.3.md

% limb manual
% byte_str(3)
% limb 0.2.0
% 2024-01-09

# NAME

byte_str byte_istr - locate a byte array within another byte array

# SYNOPSIS

    #include <limb/bytestr.h>

```pre hl
size_t byte_str(const char *<em>haystack</em>, size_t <em>hlen</em>, const char *<em>needle</em>, size_t <em>nlen</em>)
size_t byte_istr(const char *<em>haystack</em>, size_t <em>hlen</em>, const char *<em>needle</em>, size_t <em>nlen</em>)
```

# DESCRIPTION

The `byte_str`() function looks for the first occurrence of the byte array
`needle` of length `nlen` in the byte array `haystack` of length `hlen`.

Neither `haystack` nor `needle` need be NUL-terminated, and in fact can contain
themselves bytes of any value.

The `byte_istr`() function is similar but performing case-insensitive
comparisons for the current locale. (Specifically, it relies on [tolower](3).)

! WARNING:
! Unless both arrays are small, the `byte_istr`() function will perform poorly.

# RETURN VALUE

The `byte_str`() and `byte_istr`() functions return the offset of the first
occurrence of `needle` within `haystack` if found. Otherwise, they returns
`hlen`.