26 #ifndef TAGLIB_TUTILS_H 27 #define TAGLIB_TUTILS_H 31 #ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header 37 #if defined(HAVE_BOOST_BYTESWAP) 38 # include <boost/endian/conversion.hpp> 39 #elif defined(HAVE_MSC_BYTESWAP) 41 #elif defined(HAVE_GLIBC_BYTESWAP) 42 # include <byteswap.h> 43 #elif defined(HAVE_MAC_BYTESWAP) 44 # include <libkern/OSByteOrder.h> 45 #elif defined(HAVE_OPENBSD_BYTESWAP) 46 # include <sys/endian.h> 64 inline unsigned short byteSwap(
unsigned short x)
66 #if defined(HAVE_BOOST_BYTESWAP) 68 return boost::endian::endian_reverse(static_cast<uint16_t>(x));
70 #elif defined(HAVE_GCC_BYTESWAP) 72 return __builtin_bswap16(x);
74 #elif defined(HAVE_MSC_BYTESWAP) 76 return _byteswap_ushort(x);
78 #elif defined(HAVE_GLIBC_BYTESWAP) 82 #elif defined(HAVE_MAC_BYTESWAP) 84 return OSSwapInt16(x);
86 #elif defined(HAVE_OPENBSD_BYTESWAP) 92 return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
100 inline unsigned int byteSwap(
unsigned int x)
102 #if defined(HAVE_BOOST_BYTESWAP) 104 return boost::endian::endian_reverse(static_cast<uint32_t>(x));
106 #elif defined(HAVE_GCC_BYTESWAP) 108 return __builtin_bswap32(x);
110 #elif defined(HAVE_MSC_BYTESWAP) 112 return _byteswap_ulong(x);
114 #elif defined(HAVE_GLIBC_BYTESWAP) 116 return __bswap_32(x);
118 #elif defined(HAVE_MAC_BYTESWAP) 120 return OSSwapInt32(x);
122 #elif defined(HAVE_OPENBSD_BYTESWAP) 128 return ((x & 0xff000000u) >> 24)
129 | ((x & 0x00ff0000u) >> 8)
130 | ((x & 0x0000ff00u) << 8)
131 | ((x & 0x000000ffu) << 24);
139 inline unsigned long long byteSwap(
unsigned long long x)
141 #if defined(HAVE_BOOST_BYTESWAP) 143 return boost::endian::endian_reverse(static_cast<uint64_t>(x));
145 #elif defined(HAVE_GCC_BYTESWAP) 147 return __builtin_bswap64(x);
149 #elif defined(HAVE_MSC_BYTESWAP) 151 return _byteswap_uint64(x);
153 #elif defined(HAVE_GLIBC_BYTESWAP) 155 return __bswap_64(x);
157 #elif defined(HAVE_MAC_BYTESWAP) 159 return OSSwapInt64(x);
161 #elif defined(HAVE_OPENBSD_BYTESWAP) 167 return ((x & 0xff00000000000000ull) >> 56)
168 | ((x & 0x00ff000000000000ull) >> 40)
169 | ((x & 0x0000ff0000000000ull) >> 24)
170 | ((x & 0x000000ff00000000ull) >> 8)
171 | ((x & 0x00000000ff000000ull) << 8)
172 | ((x & 0x0000000000ff0000ull) << 24)
173 | ((x & 0x000000000000ff00ull) << 40)
174 | ((x & 0x00000000000000ffull) << 56);
183 inline String formatString(
const char *format, ...)
188 static const size_t BufferSize = 128;
191 va_start(args, format);
193 char buf[BufferSize];
196 #if defined(HAVE_VSNPRINTF) 198 length = vsnprintf(buf, BufferSize, format, args);
200 #elif defined(HAVE_VSPRINTF_S) 202 length = vsprintf_s(buf, format, args);
208 length = vsprintf(buf, format, args);
209 if(length >= BufferSize) {
210 debug(
"Utils::formatString() - Buffer overflow! Returning an empty string.");
231 inline bool equalsIgnoreCase(
const char *s1,
const char *s2)
233 while(*s1 !=
'\0' && *s2 !=
'\0' && ::tolower(*s1) == ::tolower(*s2)) {
238 return (*s1 ==
'\0' && *s2 ==
'\0');
255 inline ByteOrder systemByteOrder()
272 inline ByteOrder floatByteOrder()
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41