return ss.length > 0 ? (unsigned char) ss.string[ss.length - 1] : EOF;
}
+/* Returns true if SS starts with PREFIX, false otherwise. */
+bool
+ss_starts_with (struct substring ss, struct substring prefix)
+{
+ return (ss.length >= prefix.length
+ && !memcmp (ss.string, prefix.string, prefix.length));
+}
+
/* Returns true if SS ends with SUFFIX, false otherwise. */
bool
ss_ends_with (struct substring ss, struct substring suffix)
return p != NULL ? p - ss.string : SIZE_MAX;
}
+/* Returns the offset in HAYSTACK of the first instance of NEEDLE,
+ or SIZE_MAX if NEEDLE does not occur in HAYSTACK. */
+size_t
+ss_find_substring (struct substring haystack, struct substring needle)
+{
+ const char *p = memmem (haystack.string, haystack.length,
+ needle.string, needle.length);
+ return p != NULL ? p - haystack.string : SIZE_MAX;
+}
+
/* Compares A and B and returns a strcmp()-type comparison
result. */
int
int ss_at (struct substring, size_t idx);
int ss_first (struct substring);
int ss_last (struct substring);
+bool ss_starts_with (struct substring, struct substring prefix);
bool ss_ends_with (struct substring, struct substring suffix);
size_t ss_span (struct substring, struct substring skip_set);
size_t ss_cspan (struct substring, struct substring stop_set);
size_t ss_find_byte (struct substring, char);
+size_t ss_find_substring (struct substring, struct substring);
int ss_compare (struct substring, struct substring);
int ss_compare_case (struct substring, struct substring);
int ss_equals (struct substring, struct substring);