StrStartsWith
Description
Check whether a Str starts with a prefix.
Three call shapes via OVERLOAD + _Generic on prefix: StrStartsWith(s, prefix) – prefix is Str * or Zstr. StrStartsWith(s, prefix, prefix_len) – prefix is a fixed-length view (Zstr, size).
Parameters
| Name | Direction | Description |
|---|---|---|
s |
in | Str to check. |
prefix |
in | Candidate prefix (Str * / Zstr). |
prefix_len |
in | Length of prefix when using the 3-arg fixed-length form. |
Success
Returns true when s starts with prefix. The string is not modified.
Failure
Returns false. The string is not modified.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Str.Ops.c:126:
// Test string starts/ends with functions
bool test_str_starts_ends_with(void) {
WriteFmt("Testing StrStartsWith and StrEndsWith variants\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Ops.c:135:
// Test Str-form
bool result = StrStartsWith(&s, &prefix);
// Test Str-form
- In
Str.Ops.c:141:
// Test Zstr-form (string literal)
result = result && StrStartsWith(&s, "Hello");
result = result && !StrStartsWith(&s, "World");- In
Str.Ops.c:142:
// Test Zstr-form (string literal)
result = result && StrStartsWith(&s, "Hello");
result = result && !StrStartsWith(&s, "World");
// Test Zstr-form (string literal)
- In
Str.Ops.c:149:
// Test Cstr-form (fixed-length view)
result = result && StrStartsWith(&s, "Hell", 4);
result = result && !StrStartsWith(&s, "Worl", 4);- In
Str.Ops.c:150:
// Test Cstr-form (fixed-length view)
result = result && StrStartsWith(&s, "Hell", 4);
result = result && !StrStartsWith(&s, "Worl", 4);
// Test Cstr-form (fixed-length view)
Last updated on