26#ifndef TAGLIB_TUTILS_H
27#define TAGLIB_TUTILS_H
31#ifndef DO_NOT_DOCUMENT
42#if defined(HAVE_MSC_BYTESWAP)
44#elif defined(HAVE_GLIBC_BYTESWAP)
46#elif defined(HAVE_MAC_BYTESWAP)
47# include <libkern/OSByteOrder.h>
48#elif defined(HAVE_OPENBSD_BYTESWAP)
49# include <sys/endian.h>
70 inline String::Type textEncodingFromByte(
char c)
72 switch(
static_cast<unsigned char>(c)) {
78 return static_cast<String::Type
>(
static_cast<unsigned char>(c));
80 return String::Latin1;
87 inline uint16_t byteSwap(uint16_t x)
89#if defined(HAVE_GCC_BYTESWAP)
91 return __builtin_bswap16(x);
93#elif defined(HAVE_MSC_BYTESWAP)
95 return _byteswap_ushort(x);
97#elif defined(HAVE_GLIBC_BYTESWAP)
101#elif defined(HAVE_MAC_BYTESWAP)
103 return OSSwapInt16(x);
105#elif defined(HAVE_OPENBSD_BYTESWAP)
111 return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
119 inline uint32_t byteSwap(uint32_t x)
121#if defined(HAVE_GCC_BYTESWAP)
123 return __builtin_bswap32(x);
125#elif defined(HAVE_MSC_BYTESWAP)
127 return _byteswap_ulong(x);
129#elif defined(HAVE_GLIBC_BYTESWAP)
131 return __bswap_32(x);
133#elif defined(HAVE_MAC_BYTESWAP)
135 return OSSwapInt32(x);
137#elif defined(HAVE_OPENBSD_BYTESWAP)
143 return ((x & 0xff000000u) >> 24)
144 | ((x & 0x00ff0000u) >> 8)
145 | ((x & 0x0000ff00u) << 8)
146 | ((x & 0x000000ffu) << 24);
154 inline uint64_t byteSwap(uint64_t x)
156#if defined(HAVE_GCC_BYTESWAP)
158 return __builtin_bswap64(x);
160#elif defined(HAVE_MSC_BYTESWAP)
162 return _byteswap_uint64(x);
164#elif defined(HAVE_GLIBC_BYTESWAP)
166 return __bswap_64(x);
168#elif defined(HAVE_MAC_BYTESWAP)
170 return OSSwapInt64(x);
172#elif defined(HAVE_OPENBSD_BYTESWAP)
178 return ((x & 0xff00000000000000ull) >> 56)
179 | ((x & 0x00ff000000000000ull) >> 40)
180 | ((x & 0x0000ff0000000000ull) >> 24)
181 | ((x & 0x000000ff00000000ull) >> 8)
182 | ((x & 0x00000000ff000000ull) << 8)
183 | ((x & 0x0000000000ff0000ull) << 24)
184 | ((x & 0x000000000000ff00ull) << 40)
185 | ((x & 0x00000000000000ffull) << 56);
194 inline String formatString(
const char *format, ...)
199 static const size_t BufferSize = 128;
202 va_start(args, format);
204 char buf[BufferSize];
207 length = std::vsnprintf(buf, BufferSize, format, args);
230 constexpr ByteOrder systemByteOrder()
232 constexpr union IntCharUnion {
235 constexpr IntCharUnion(
int j) : i(j) {}
A namespace for all TagLib related classes and functions.
Definition apefile.h:41