StringUtil.hxx 2.2 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20 21
#ifndef MPD_STRING_UTIL_HXX
#define MPD_STRING_UTIL_HXX
22

23
#include "Compiler.h"
24

25 26
#include <stddef.h>

27 28 29 30 31 32 33
/**
 * 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.
 */
34
gcc_pure
35
const char *
36
strchug_fast(const char *p);
37

38
gcc_pure
39 40 41
static inline char *
strchug_fast(char *p)
{
42
	return const_cast<char *>(strchug_fast((const char *)p));
43 44
}

45 46 47 48 49 50 51
/**
 * Skip whitespace at the beginning and terminate the string after the
 * last non-whitespace character.
 */
char *
Strip(char *p);

52 53 54 55
gcc_pure
bool
StringStartsWith(const char *haystack, const char *needle);

56 57 58 59
gcc_pure
bool
StringEndsWith(const char *haystack, const char *needle);

60 61 62 63 64 65 66 67 68 69 70 71
/**
 * 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);

72 73 74 75 76 77 78 79
/**
 * Checks whether a string array contains the specified string.
 *
 * @param haystack a NULL terminated list of strings
 * @param needle the string to search for; the comparison is
 * case-insensitive for ASCII characters
 * @return true if found
 */
80
gcc_pure
81 82 83 84
bool
string_array_contains(const char *const* haystack, const char *needle);

#endif