Z / libzlang 0.29.0
C99 runtime library and the Zlang 0.29 source-to-source compiler
Loading...
Searching...
No Matches
strings.h
Go to the documentation of this file.
1#ifndef ZLANG_STANDARD_STRINGS_STRINGS_H
2#define ZLANG_STANDARD_STRINGS_STRINGS_H
3
5
6#if defined(ZLANG_STD_STRINGS_COMPARE)
7ZLANG_STATIC_INLINE int32_t zlang_std_strings_compare(zlang_string_t left, zlang_string_t right) {
8 return zlang_string_equal_compare(left, right);
9}
10#endif
11
12#if defined(ZLANG_STD_STRINGS_CONTAINS)
13ZLANG_STATIC_INLINE bool zlang_std_strings_contains(zlang_string_t value, zlang_string_t part) {
14 if ((value.data_ == NULL && value.length_ != 0U) ||
15 (part.data_ == NULL && part.length_ != 0U)) {
17 }
18 if (part.length_ == 0U) {
19 return true;
20 }
21 if (part.length_ > value.length_) {
22 return false;
23 }
24 for (uint32_t _index = 0U; _index + part.length_ <= value.length_; ++_index) {
25 bool _found_k = true;
26 for (uint32_t _offset = 0U; _offset < part.length_; ++_offset) {
27 if (value.data_[_index + _offset] != part.data_[_offset]) {
28 _found_k = false;
29 break;
30 }
31 }
32 if (_found_k) {
33 return true;
34 }
35 }
36 return false;
37}
38#endif
39
40#if defined(ZLANG_STD_STRINGS_STARTS_WITH)
41ZLANG_STATIC_INLINE bool zlang_std_strings_starts_with(zlang_string_t value,
42 zlang_string_t prefix) {
43 if ((value.data_ == NULL && value.length_ != 0U) ||
44 (prefix.data_ == NULL && prefix.length_ != 0U)) {
46 }
47 if (prefix.length_ > value.length_) {
48 return false;
49 }
50 for (uint32_t _index = 0U; _index < prefix.length_; ++_index) {
51 if (value.data_[_index] != prefix.data_[_index]) {
52 return false;
53 }
54 }
55 return true;
56}
57#endif
58
59#endif /* ZLANG_STANDARD_STRINGS_STRINGS_H */
#define ZLANG_STATIC_INLINE
Definition inline.h:9
ZLANG_STATIC_INLINE void zlang_trap(uint8_t code)
Terminate execution with a fixed trap code.
Definition runtime.h:73
#define ZLANG_TRAP_INVALID_ARGUMENT
Definition runtime.h:25
ZLANG_STATIC_INLINE int32_t zlang_string_equal_compare(zlang_string_t left, zlang_string_t right)
Compare two string views by content.
Definition runtime.h:596
Definition runtime.h:35
const char * data_
Definition runtime.h:36
uint32_t length_
Definition runtime.h:37