aboutsummaryrefslogtreecommitdiffstats
path: root/src/wchar
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-10 17:15:49 +0200
committerMattias Andrée <maandree@operamail.com>2015-10-10 17:17:49 +0200
commitae2709a72b748e1656b7067951e0532dfe45ae2d (patch)
treefee49a5ff60f363fa220bf2c73cd76dbbf0e505d /src/wchar
parentm doc (diff)
downloadslibc-ae2709a72b748e1656b7067951e0532dfe45ae2d.tar.gz
slibc-ae2709a72b748e1656b7067951e0532dfe45ae2d.tar.bz2
slibc-ae2709a72b748e1656b7067951e0532dfe45ae2d.tar.xz
add strstarts strends strcasestarts strcaseends wcsstarts wcsends wcscasestarts wcscaseends
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/wchar/wcsstr.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c
index f54ff6e..bc2bbec 100644
--- a/src/wchar/wcsstr.c
+++ b/src/wchar/wcsstr.c
@@ -192,3 +192,87 @@ wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length,
#undef CASE
}
+
+/**
+ * Check whether a string starts with a specific string.
+ * This check is case sensitive.
+ *
+ * This is a slibc extension.
+ *
+ * @param string The string to inspect.
+ * @param desired The desired beginning of the string.
+ * @return `string` if `string` begins with
+ * `desired`, `NULL` otherwise.
+ */
+wchar_t* wcsstarts(const wchar_t* string, const wchar_t* desired)
+{
+ size_t n = wcslen(string);
+ size_t m = wcslen(desired);
+ if (n < m)
+ return NULL;
+ return wmemcmp(string, desired, m) ? NULL : string;
+}
+
+
+/**
+ * Check whether a string ends with a specific string.
+ * This check is case sensitive.
+ *
+ * This is a slibc extension.
+ *
+ * @param string The string to inspect.
+ * @param desired The desired ending of the string.
+ * @return The `string`, where `desired` beings if
+ * `string` ends with `desired`, `NULL` otherwise.
+ */
+wchar_t* wcsends(const wchar_t* string, const wchar_t* desired)
+{
+ size_t n = wcslen(string);
+ size_t m = wcslen(desired);
+ if (n < m)
+ return NULL;
+ return wmemcmp(string + (n - m), desired, m) ? NULL : (string + n);
+}
+
+
+/**
+ * Check whether a string starts with a specific string.
+ * This check is case insensitive.
+ *
+ * This is a slibc extension.
+ *
+ * @param string The string to inspect.
+ * @param desired The desired beginning of the string.
+ * @return `string` if `string` begins with
+ * `desired`, `NULL` otherwise.
+ */
+wchar_t* wcscasestarts(const wchar_t* string, const wchar_t* desired)
+{
+ size_t n = wcslen(string);
+ size_t m = wcslen(desired);
+ if (n < m)
+ return NULL;
+ return wmemcasecmp(string, desired, m) ? NULL : string;
+}
+
+
+/**
+ * Check whether a string ends with a specific string.
+ * This check is case insensitive.
+ *
+ * This is a slibc extension.
+ *
+ * @param string The string to inspect.
+ * @param desired The desired ending of the string.
+ * @return The `string`, where `desired` beings if
+ * `string` ends with `desired`, `NULL` otherwise.
+ */
+wchar_t* wcscaseends(const wchar_t* string, const wchar_t* desired)
+{
+ size_t n = wcslen(string);
+ size_t m = wcslen(desired);
+ if (n < m)
+ return NULL;
+ return wmemcasecmp(string + (n - m), desired, m) ? NULL : (string + n);
+}
+