Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / Core / NptUtils.h
blob89b2e29812cf399fbdf1c99e657d606f7a60b26f
1 /*****************************************************************
3 | Neptune Utils
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ****************************************************************/
32 #ifndef _NPT_UTILS_H_
33 #define _NPT_UTILS_H_
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptConfig.h"
39 #include "NptTypes.h"
40 #include "NptStrings.h"
41 #include "NptMap.h"
42 #include "NptDataBuffer.h"
43 #include "NptHash.h"
45 #if defined (NPT_CONFIG_HAVE_STDIO_H)
46 #include <stdio.h>
47 #endif
49 #if defined (NPT_CONFIG_HAVE_STRING_H)
50 #include <string.h>
51 #endif
53 #if defined(NPT_CONFIG_HAVE_STDARG_H)
54 #include <stdarg.h>
55 #endif
57 #if defined(TARGET_WINDOWS_STORE)
58 #include <string>
59 #endif
60 /*----------------------------------------------------------------------
61 | macros
62 +---------------------------------------------------------------------*/
63 #define NPT_ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
65 /*----------------------------------------------------------------------
66 | byte I/O
67 +---------------------------------------------------------------------*/
68 extern void NPT_BytesFromInt64Be(unsigned char* buffer, NPT_UInt64 value);
69 extern void NPT_BytesFromInt32Be(unsigned char* buffer, NPT_UInt32 value);
70 extern void NPT_BytesFromInt24Be(unsigned char* buffer, NPT_UInt32 value);
71 extern void NPT_BytesFromInt16Be(unsigned char* buffer, NPT_UInt16 value);
72 extern NPT_UInt64 NPT_BytesToInt64Be(const unsigned char* buffer);
73 extern NPT_UInt32 NPT_BytesToInt32Be(const unsigned char* buffer);
74 extern NPT_UInt32 NPT_BytesToInt24Be(const unsigned char* buffer);
75 extern NPT_UInt16 NPT_BytesToInt16Be(const unsigned char* buffer);
77 extern void NPT_BytesFromInt64Le(unsigned char* buffer, NPT_UInt64 value);
78 extern void NPT_BytesFromInt32Le(unsigned char* buffer, NPT_UInt32 value);
79 extern void NPT_BytesFromInt24Le(unsigned char* buffer, NPT_UInt32 value);
80 extern void NPT_BytesFromInt16Le(unsigned char* buffer, NPT_UInt16 value);
81 extern NPT_UInt64 NPT_BytesToInt64Le(const unsigned char* buffer);
82 extern NPT_UInt32 NPT_BytesToInt32Le(const unsigned char* buffer);
83 extern NPT_UInt32 NPT_BytesToInt24Le(const unsigned char* buffer);
84 extern NPT_UInt16 NPT_BytesToInt16Le(const unsigned char* buffer);
86 /*----------------------------------------------------------------------
87 | conversion utilities
88 +---------------------------------------------------------------------*/
89 extern NPT_Result
90 NPT_ParseFloat(const char* str, float& result, bool relaxed = true);
92 extern NPT_Result
93 NPT_ParseInteger(const char* str, long& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
95 extern NPT_Result
96 NPT_ParseInteger(const char* str, unsigned long& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
98 extern NPT_Result
99 NPT_ParseInteger(const char* str, int& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
101 extern NPT_Result
102 NPT_ParseInteger(const char* str, unsigned int& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
104 extern NPT_Result
105 NPT_ParseInteger32(const char* str, NPT_Int32& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
107 extern NPT_Result
108 NPT_ParseInteger32(const char* str, NPT_UInt32& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
110 extern NPT_Result
111 NPT_ParseInteger64(const char* str, NPT_Int64& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
113 extern NPT_Result
114 NPT_ParseInteger64(const char* str, NPT_UInt64& result, bool relaxed = true, NPT_Cardinal* chars_used = 0);
116 /*----------------------------------------------------------------------
117 | formatting
118 +---------------------------------------------------------------------*/
119 void
120 NPT_FormatOutput(void (*function)(void* parameter, const char* message),
121 void* function_parameter,
122 const char* format,
123 va_list args);
125 void NPT_ByteToHex(NPT_Byte b, char* buffer, bool uppercase=false);
126 NPT_Result NPT_HexToByte(const char* buffer, NPT_Byte& b);
127 NPT_Result NPT_HexToBytes(const char* hex, NPT_DataBuffer& bytes);
128 NPT_String NPT_HexString(const unsigned char* data,
129 NPT_Size data_size,
130 const char* separator = NULL,
131 bool uppercase=false);
132 char NPT_NibbleToHex(unsigned int nibble, bool uppercase = true);
133 int NPT_HexToNibble(char hex);
135 /*----------------------------------------------------------------------
136 | parsing
137 +---------------------------------------------------------------------*/
138 NPT_Result
139 NPT_ParseMimeParameters(const char* encoded,
140 NPT_Map<NPT_String, NPT_String>& parameters);
142 /*----------------------------------------------------------------------
143 | environment variables
144 +---------------------------------------------------------------------*/
145 class NPT_Environment {
146 public:
147 static NPT_Result Get(const char* name, NPT_String& value);
148 static NPT_Result Set(const char* name, const char* value);
150 // compat for older APIs
151 #define NPT_GetEnvironment(_x,_y) NPT_Environment::Get(_x,_y)
153 /*----------------------------------------------------------------------
154 | string utils
155 +---------------------------------------------------------------------*/
156 #if defined (NPT_CONFIG_HAVE_STDIO_H)
157 #include <stdio.h>
158 #endif
160 #if defined (NPT_CONFIG_HAVE_STRING_H)
161 #include <string.h>
162 #endif
164 #if defined (NPT_CONFIG_HAVE_SNPRINTF)
165 #define NPT_FormatString NPT_snprintf
166 #else
167 int NPT_FormatString(char* str, NPT_Size size, const char* format, ...);
168 #endif
170 #if defined(NPT_CONFIG_HAVE_VSNPRINTF)
171 #define NPT_FormatStringVN(s,c,f,a) NPT_vsnprintf(s,c,f,a)
172 #else
173 extern int NPT_FormatStringVN(char *buffer, size_t count, const char *format, va_list argptr);
174 #endif
176 #if defined(NPT_CONFIG_HAVE_MEMCPY)
177 #define NPT_CopyMemory memcpy
178 #else
179 extern void NPT_CopyMemory(void* dest, void* src, NPT_Size size);
180 #endif
182 #if defined(NPT_CONFIG_HAVE_STRCMP)
183 #define NPT_StringsEqual(s1, s2) (strcmp((s1), (s2)) == 0)
184 #else
185 extern int NPT_StringsEqual(const char* s1, const char* s2);
186 #endif
188 #if defined(NPT_CONFIG_HAVE_STRNCMP)
189 #define NPT_StringsEqualN(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
190 #else
191 extern int NPT_StringsEqualN(const char* s1, const char* s2, unsigned long size);
192 #endif
194 #if defined(NPT_CONFIG_HAVE_STRLEN)
195 #define NPT_StringLength(s) (NPT_Size)(strlen(s))
196 #else
197 extern unsigned long NPT_StringLength(const char* s);
198 #endif
200 #if defined(NPT_CONFIG_HAVE_STRCPY)
201 #define NPT_CopyString(dst, src) ((void)NPT_strcpy((dst), (src)))
202 #else
203 extern void NPT_CopyString(char* dst, const char* src);
204 #endif
207 * Copy up to n characters from src to dst.
208 * The destination buffer will be null-terminated, so it must
209 * have enough space for n+1 characters (n from the source plus
210 * the null terminator).
212 #if defined(NPT_CONFIG_HAVE_STRNCPY)
213 #define NPT_CopyStringN(dst, src, n) \
214 do { ((void)NPT_strncpy((dst), (src), n)); (dst)[(n)] = '\0'; } while(0)
215 #else
216 extern int NPT_CopyStringN(char* dst, const char* src, unsigned long n);
217 #endif
219 #if defined(NPT_CONFIG_HAVE_MEMSET)
220 #define NPT_SetMemory memset
221 #else
222 extern void NPT_SetMemory(void* dest, int c, NPT_Size size);
223 #endif
225 #if defined(NPT_CONFIG_HAVE_MEMCMP)
226 #define NPT_MemoryEqual(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
227 #else
228 extern int NPT_MemoryEqual(const void* s1, const void* s2, unsigned long n);
229 #endif
231 #if defined(TARGET_WINDOWS_STORE)
232 std::wstring win32ConvertUtf8ToW(const std::string &text);
233 #endif
235 #endif // _NPT_UTILS_H_