aboutsummaryrefslogtreecommitdiff
path: root/src/string_util.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-12-23 16:16:01 +0100
committerMax Kellermann <max@duempel.org>2010-12-23 16:23:20 +0100
commit5462f34ed037111d2d57638352b2f1a65a322579 (patch)
treed1acf3493d2d8edbbda9ae77a327d26ae249f3f9 /src/string_util.h
parent0958ed584431ac09e676dd51925e56142416e7c2 (diff)
string_util: add function strchug_fast()
Replace g_strchug() calls with a cheaper implementation.
Diffstat (limited to 'src/string_util.h')
-rw-r--r--src/string_util.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/string_util.h b/src/string_util.h
index df8ceeef..37235472 100644
--- a/src/string_util.h
+++ b/src/string_util.h
@@ -20,9 +20,50 @@
#ifndef MPD_STRING_UTIL_H
#define MPD_STRING_UTIL_H
+#include <glib.h>
+
#include <stdbool.h>
/**
+ * Remove the "const" attribute from a string pointer. This is a
+ * dirty hack, don't use it unless you know what you're doing!
+ */
+G_GNUC_CONST
+static inline char *
+deconst_string(const char *p)
+{
+ union {
+ const char *in;
+ char *out;
+ } u = {
+ .in = p,
+ };
+
+ return u.out;
+}
+
+/**
+ * Returns a pointer to the first non-whitespace character in the
+ * string, or to the end of the string.
+ *
+ * This is a faster version of g_strchug(), because it does not move
+ * data.
+ */
+G_GNUC_PURE
+const char *
+strchug_fast_c(const char *p);
+
+/**
+ * Same as strchug_fast_c(), but works with a writable pointer.
+ */
+G_GNUC_PURE
+static inline char *
+strchug_fast(char *p)
+{
+ return deconst_string(strchug_fast_c(p));
+}
+
+/**
* Checks whether a string array contains the specified string.
*
* @param haystack a NULL terminated list of strings