fluffos/docs/efun/strings/strsrch.md
Yucong Sun 887f9ebbd1
docs: document UTF-8 native strings in the LPC language reference (#1226)
Add a 'UTF-8 Native Strings' section to lpc/types/strings.md covering
what the driver actually implements: lengths and positions are measured
in extended grapheme clusters (UAX #29), indexing yields code points and
errors on multi-code-point clusters, ranges/explode/strsrch operate on
character boundaries, display width (strwidth, UAX #11) vs length,
\uXXXX and surrogate-pair escapes, UTF-8 validity requirements, and the
encoding boundary (set_encoding for connections, string_encode /
string_decode / buffer_transcode elsewhere). Note in the old
sub-ranging section that positions are characters, not bytes.

Clarify sizeof() (string = grapheme clusters, buffer = bytes) and
strsrch() (character offsets, character-boundary matches).

Every documented example is pinned by a new testsuite file,
testsuite/single/tests/compiler/utf8_doc_examples.lpc, verified against
a freshly built driver (19 checks). Notably replace_string() is
byte-oriented, so it is deliberately NOT listed among the
grapheme-aware operations.


Claude-Session: https://claude.ai/code/session_01TSzcESzU9947zkGzQ6SMmE

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-10 07:42:20 -04:00

1,013 B
Raw Permalink Blame History

title
strings / strsrch

strsrch

NAME

strsrch() - search for substrings in a string

SYNOPSIS

int strsrch( string str, string substr | int char, int flag );

DESCRIPTION

strsrch()  searches  for  the first occurance of the string 'substr' in
the string 'str'.  The last occurance of 'substr' can be found by pass
ing  '-1' as the 3rd argument (which is optional).  If the second argu
ment is an integer, that character is found  (a  la  C's  strchr()/str
rchr().)  The empty string or null value cannot be searched for.

RETURN VALUE

The  integer  offset  of  the  first  (last)  match is returned.  -1 is
returned if there was no match, or an error occurred (bad args, etc).

The offset is measured in UTF-8 characters (grapheme clusters), the
same unit used by strlen(3) and string indexing/ranges, and matches
are only found at character boundaries.

SEE ALSO

explode(3), sscanf(3), replace_string(3), regexp(3)