aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/StringUtil.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/StringUtil.hxx76
1 files changed, 69 insertions, 7 deletions
diff --git a/src/util/StringUtil.hxx b/src/util/StringUtil.hxx
index 1c67910a9..9beda5441 100644
--- a/src/util/StringUtil.hxx
+++ b/src/util/StringUtil.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -22,24 +22,86 @@
#include "Compiler.h"
+#include <stddef.h>
+
/**
* 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.
*/
gcc_pure
const char *
-strchug_fast(const char *p);
+StripLeft(const char *p);
gcc_pure
static inline char *
-strchug_fast(char *p)
+StripLeft(char *p)
{
- return const_cast<char *>(strchug_fast((const char *)p));
+ return const_cast<char *>(StripLeft((const char *)p));
}
+gcc_pure
+const char *
+StripLeft(const char *p, const char *end);
+
+/**
+ * Determine the string's end as if it was stripped on the right side.
+ */
+gcc_pure
+const char *
+StripRight(const char *p, const char *end);
+
+/**
+ * Determine the string's end as if it was stripped on the right side.
+ */
+gcc_pure
+static inline char *
+StripRight(char *p, char *end)
+{
+ return const_cast<char *>(StripRight((const char *)p,
+ (const char *)end));
+}
+
+/**
+ * Determine the string's length as if it was stripped on the right
+ * side.
+ */
+gcc_pure
+size_t
+StripRight(const char *p, size_t length);
+
+/**
+ * Strip trailing whitespace by null-terminating the string.
+ */
+void
+StripRight(char *p);
+
+/**
+ * Skip whitespace at the beginning and terminate the string after the
+ * last non-whitespace character.
+ */
+char *
+Strip(char *p);
+
+gcc_pure
+bool
+StringStartsWith(const char *haystack, const char *needle);
+
+gcc_pure
+bool
+StringEndsWith(const char *haystack, const char *needle);
+
+/**
+ * Copy a string. If the buffer is too small, then the string is
+ * truncated. This is a safer version of strncpy().
+ *
+ * @param size the size of the destination buffer (including the null
+ * terminator)
+ * @return a pointer to the null terminator
+ */
+gcc_nonnull_all
+char *
+CopyString(char *dest, const char *src, size_t size);
+
/**
* Checks whether a string array contains the specified string.
*