MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

WStringAPI.hxx
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2010-2015 Max Kellermann <max.kellermann@gmail.com>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef WSTRING_API_HXX
31 #define WSTRING_API_HXX
32
33 #include "Compiler.h"
34
35 #include <wchar.h>
36
37 gcc_pure gcc_nonnull_all
38 static inline size_t
39 StringLength(const wchar_t *p)
40 {
41 return wcslen(p);
42 }
43
44 gcc_pure gcc_nonnull_all
45 static inline const wchar_t *
46 StringFind(const wchar_t *haystack, const wchar_t *needle)
47 {
48 return wcsstr(haystack, needle);
49 }
50
51 gcc_pure gcc_nonnull_all
52 static inline const wchar_t *
53 StringFind(const wchar_t *haystack, wchar_t needle, size_t size)
54 {
55 return wmemchr(haystack, needle, size);
56 }
57
58 gcc_pure gcc_nonnull_all
59 static inline wchar_t *
60 StringFind(wchar_t *haystack, wchar_t needle, size_t size)
61 {
62 return wmemchr(haystack, needle, size);
63 }
64
65 gcc_pure gcc_nonnull_all
66 static inline const wchar_t *
67 StringFind(const wchar_t *haystack, wchar_t needle)
68 {
69 return wcschr(haystack, needle);
70 }
71
72 gcc_pure gcc_nonnull_all
73 static inline wchar_t *
74 StringFind(wchar_t *haystack, wchar_t needle)
75 {
76 return wcschr(haystack, needle);
77 }
78
79 gcc_pure gcc_nonnull_all
80 static inline const wchar_t *
81 StringFindLast(const wchar_t *haystack, wchar_t needle)
82 {
83 return wcsrchr(haystack, needle);
84 }
85
86 gcc_pure gcc_nonnull_all
87 static inline wchar_t *
88 StringFindLast(wchar_t *haystack, wchar_t needle)
89 {
90 return wcsrchr(haystack, needle);
91 }
92
93 gcc_nonnull_all
94 static inline void
95 UnsafeCopyString(wchar_t *dest, const wchar_t *src)
96 {
97 wcscpy(dest, src);
98 }
99
100 gcc_nonnull_all
101 static inline wchar_t *
102 UnsafeCopyStringP(wchar_t *dest, const wchar_t *src)
103 {
104 #if defined(WIN32) || defined(__BIONIC__) || defined(__OpenBSD__) || \
105 defined(__NetBSD__)
106 /* emulate wcpcpy() */
107 UnsafeCopyString(dest, src);
108 return dest + StringLength(dest);
109 #else
110 return wcpcpy(dest, src);
111 #endif
112 }
113
120 gcc_pure gcc_nonnull_all
121 static inline bool
122 StringIsEqual(const wchar_t *str1, const wchar_t *str2)
123 {
124 return wcscmp(str1, str2) == 0;
125 }
126
130 gcc_pure gcc_nonnull_all
131 static inline bool
132 StringIsEqual(const wchar_t *a, const wchar_t *b, size_t length)
133 {
134 return wcsncmp(a, b, length) == 0;
135 }
136
137 #ifndef __BIONIC__
138
139 gcc_malloc gcc_nonnull_all
140 static inline wchar_t *
141 DuplicateString(const wchar_t *p)
142 {
143 return wcsdup(p);
144 }
145
146 #endif
147
148 #endif
StringLength
gcc_pure static gcc_nonnull_all size_t StringLength(const wchar_t *p)
Definition: WStringAPI.hxx:39
UnsafeCopyStringP
static gcc_nonnull_all wchar_t * UnsafeCopyStringP(wchar_t *dest, const wchar_t *src)
Definition: WStringAPI.hxx:102
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
gcc_malloc
#define gcc_malloc
Definition: Compiler.h:112
StringFind
gcc_pure static gcc_nonnull_all const wchar_t * StringFind(const wchar_t *haystack, const wchar_t *needle)
Definition: WStringAPI.hxx:46
Compiler.h
StringFindLast
gcc_pure static gcc_nonnull_all const wchar_t * StringFindLast(const wchar_t *haystack, wchar_t needle)
Definition: WStringAPI.hxx:81
UnsafeCopyString
static gcc_nonnull_all void UnsafeCopyString(wchar_t *dest, const wchar_t *src)
Definition: WStringAPI.hxx:95
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
StringIsEqual
gcc_pure static gcc_nonnull_all bool StringIsEqual(const wchar_t *str1, const wchar_t *str2)
Checks whether str1 and str2 are equal.
Definition: WStringAPI.hxx:122
DuplicateString
gcc_malloc static gcc_nonnull_all wchar_t * DuplicateString(const wchar_t *p)
Definition: WStringAPI.hxx:141