diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 33c61229..04c54956 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -50,7 +50,7 @@ namespace bool unicodeStrings = true; bool stringManagementEnabled = true; - inline char *stringToCharArray(const String &s) + char *stringToCharArray(const String &s) { const std::string str = s.to8Bit(unicodeStrings); @@ -65,7 +65,7 @@ namespace #endif } - inline String charArrayToString(const char *s) + String charArrayToString(const char *s) { return String(s, unicodeStrings ? String::UTF8 : String::Latin1); } diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index 26efd15f..dee7e8c0 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -133,7 +133,7 @@ unsigned int APE::Properties::sampleFrames() const namespace { - inline int headerVersion(const ByteVector &header) + int headerVersion(const ByteVector &header) { if(header.size() < 6 || !header.startsWith("MAC ")) return -1; diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index d49d0700..dfbd3076 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -47,7 +47,7 @@ using namespace APE; namespace { - inline bool isKeyValid(const char *key, size_t length) + bool isKeyValid(const char *key, size_t length) { const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 }; diff --git a/taglib/asf/asfutils.h b/taglib/asf/asfutils.h index e3595a70..a8ecd70d 100644 --- a/taglib/asf/asfutils.h +++ b/taglib/asf/asfutils.h @@ -34,65 +34,68 @@ namespace TagLib { namespace ASF { - - inline unsigned short readWORD(File *file, bool *ok = 0) + namespace { - const ByteVector v = file->readBlock(2); - if(v.size() != 2) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toUShort(false); - } - inline unsigned int readDWORD(File *file, bool *ok = 0) - { - const ByteVector v = file->readBlock(4); - if(v.size() != 4) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toUInt(false); - } - - inline long long readQWORD(File *file, bool *ok = 0) - { - const ByteVector v = file->readBlock(8); - if(v.size() != 8) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toLongLong(false); - } - - inline String readString(File *file, int length) - { - ByteVector data = file->readBlock(length); - unsigned int size = data.size(); - while (size >= 2) { - if(data[size - 1] != '\0' || data[size - 2] != '\0') { - break; + inline unsigned short readWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(2); + if(v.size() != 2) { + if(ok) *ok = false; + return 0; } - size -= 2; + if(ok) *ok = true; + return v.toUShort(false); } - if(size != data.size()) { - data.resize(size); - } - return String(data, String::UTF16LE); - } - inline ByteVector renderString(const String &str, bool includeLength = false) - { - ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false); - if(includeLength) { - data = ByteVector::fromShort(data.size(), false) + data; + inline unsigned int readDWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(4); + if(v.size() != 4) { + if(ok) *ok = false; + return 0; + } + if(ok) *ok = true; + return v.toUInt(false); } - return data; - } + inline long long readQWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(8); + if(v.size() != 8) { + if(ok) *ok = false; + return 0; + } + if(ok) *ok = true; + return v.toLongLong(false); + } + + inline String readString(File *file, int length) + { + ByteVector data = file->readBlock(length); + unsigned int size = data.size(); + while (size >= 2) { + if(data[size - 1] != '\0' || data[size - 2] != '\0') { + break; + } + size -= 2; + } + if(size != data.size()) { + data.resize(size); + } + return String(data, String::UTF16LE); + } + + inline ByteVector renderString(const String &str, bool includeLength = false) + { + ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false); + if(includeLength) { + data = ByteVector::fromShort(data.size(), false) + data; + } + return data; + } + + } } } diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 950b3f8a..3a7f2c65 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -62,42 +62,42 @@ namespace // Templatized internal functions. T should be String or IOStream*. template - inline FileName toFileName(T arg) + FileName toFileName(T arg) { debug("FileRef::toFileName(): This version should never be called."); return FileName(L""); } template <> - inline FileName toFileName(IOStream *arg) + FileName toFileName(IOStream *arg) { return arg->name(); } template <> - inline FileName toFileName(FileName arg) + FileName toFileName(FileName arg) { return arg; } template - inline File *resolveFileType(T arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(T arg, bool readProperties, + AudioProperties::ReadStyle style) { debug("FileRef::resolveFileType(): This version should never be called."); return 0; } template <> - inline File *resolveFileType(IOStream *arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(IOStream *arg, bool readProperties, + AudioProperties::ReadStyle style) { return 0; } template <> - inline File *resolveFileType(FileName arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(FileName arg, bool readProperties, + AudioProperties::ReadStyle style) { ResolverList::ConstIterator it = fileTypeResolvers.begin(); for(; it != fileTypeResolvers.end(); ++it) { diff --git a/taglib/mp4/mp4file.cpp b/taglib/mp4/mp4file.cpp index d0a6c4c6..3733fb40 100644 --- a/taglib/mp4/mp4file.cpp +++ b/taglib/mp4/mp4file.cpp @@ -34,7 +34,7 @@ using namespace TagLib; namespace { - inline bool checkValid(const MP4::AtomList &list) + bool checkValid(const MP4::AtomList &list) { for(MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) { diff --git a/taglib/mpeg/mpegutils.h b/taglib/mpeg/mpegutils.h index 5a7e0e6a..e35f752f 100644 --- a/taglib/mpeg/mpegutils.h +++ b/taglib/mpeg/mpegutils.h @@ -34,25 +34,27 @@ namespace TagLib { namespace MPEG { - - /*! - * MPEG frames can be recognized by the bit pattern 11111111 111, so the - * first byte is easy to check for, however checking to see if the second byte - * starts with \e 111 is a bit more tricky, hence these functions. - */ - - inline bool firstSyncByte(unsigned char byte) + namespace { - return (byte == 0xFF); + + /*! + * MPEG frames can be recognized by the bit pattern 11111111 111, so the + * first byte is easy to check for, however checking to see if the second byte + * starts with \e 111 is a bit more tricky, hence these functions. + */ + inline bool firstSyncByte(unsigned char byte) + { + return (byte == 0xFF); + } + + inline bool secondSynchByte(unsigned char byte) + { + // 0xFF is possible in theory, but it's very unlikely be a header. + + return (byte != 0xFF && ((byte & 0xE0) == 0xE0)); + } + } - - inline bool secondSynchByte(unsigned char byte) - { - // 0xFF is possible in theory, but it's very unlikely be a header. - - return (byte != 0xFF && ((byte & 0xE0) == 0xE0)); - } - } } diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index 6520cc32..86b0b076 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -37,7 +37,7 @@ using namespace TagLib; namespace { // Returns the first packet index of the right next page to the given one. - inline unsigned int nextPacketIndex(const Ogg::Page *page) + unsigned int nextPacketIndex(const Ogg::Page *page) { if(page->header()->lastPacketCompleted()) return page->firstPacketIndex() + page->packetCount(); diff --git a/taglib/riff/riffutils.h b/taglib/riff/riffutils.h index 14b8508e..ecb985a4 100644 --- a/taglib/riff/riffutils.h +++ b/taglib/riff/riffutils.h @@ -34,18 +34,23 @@ namespace TagLib { namespace RIFF { - inline bool isValidChunkName(const ByteVector &name) + namespace { - if(name.size() != 4) - return false; - for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) { - const int c = static_cast(*it); - if(c < 32 || 127 < c) + inline bool isValidChunkName(const ByteVector &name) + { + if(name.size() != 4) return false; + + for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) { + const int c = static_cast(*it); + if(c < 32 || 127 < c) + return false; + } + + return true; } - return true; } } } diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index e20412f2..5205bae0 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -47,7 +47,7 @@ namespace const FileHandle InvalidFileHandle = INVALID_HANDLE_VALUE; - inline FileHandle openFile(const FileName &path, bool readOnly) + FileHandle openFile(const FileName &path, bool readOnly) { const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE); @@ -59,12 +59,12 @@ namespace return InvalidFileHandle; } - inline void closeFile(FileHandle file) + void closeFile(FileHandle file) { CloseHandle(file); } - inline size_t readFile(FileHandle file, ByteVector &buffer) + size_t readFile(FileHandle file, ByteVector &buffer) { DWORD length; if(ReadFile(file, buffer.data(), static_cast(buffer.size()), &length, NULL)) @@ -73,7 +73,7 @@ namespace return 0; } - inline size_t writeFile(FileHandle file, const ByteVector &buffer) + size_t writeFile(FileHandle file, const ByteVector &buffer) { DWORD length; if(WriteFile(file, buffer.data(), static_cast(buffer.size()), &length, NULL)) @@ -94,22 +94,22 @@ namespace const FileHandle InvalidFileHandle = 0; - inline FileHandle openFile(const FileName &path, bool readOnly) + FileHandle openFile(const FileName &path, bool readOnly) { return fopen(path, readOnly ? "rb" : "rb+"); } - inline void closeFile(FileHandle file) + void closeFile(FileHandle file) { fclose(file); } - inline size_t readFile(FileHandle file, ByteVector &buffer) + size_t readFile(FileHandle file, ByteVector &buffer) { return fread(buffer.data(), sizeof(char), buffer.size(), file); } - inline size_t writeFile(FileHandle file, const ByteVector &buffer) + size_t writeFile(FileHandle file, const ByteVector &buffer) { return fwrite(buffer.data(), sizeof(char), buffer.size(), file); } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 8a596e4c..56daf33f 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -29,12 +29,6 @@ # include #endif -#include "tstring.h" -#include "tdebug.h" -#include "tstringlist.h" -#include "trefcounter.h" -#include "tutils.h" - #include #include #include @@ -47,12 +41,17 @@ # include "unicode.h" #endif +#include +#include +#include +#include +#include + namespace { using namespace TagLib; - inline size_t UTF16toUTF8( - const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) + size_t UTF16toUTF8(const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) { size_t len = 0; @@ -84,8 +83,7 @@ namespace return len; } - inline size_t UTF8toUTF16( - const char *src, size_t srcLength, wchar_t *dst, size_t dstLength) + size_t UTF8toUTF16(const char *src, size_t srcLength, wchar_t *dst, size_t dstLength) { size_t len = 0; @@ -118,7 +116,7 @@ namespace } // Returns the native format of std::wstring. - inline String::Type wcharByteOrder() + String::Type wcharByteOrder() { if(Utils::systemByteOrder() == Utils::LittleEndian) return String::UTF16LE; @@ -128,7 +126,7 @@ namespace // Converts a Latin-1 string into UTF-16(without BOM/CPU byte order) // and copies it to the internal buffer. - inline void copyFromLatin1(std::wstring &data, const char *s, size_t length) + void copyFromLatin1(std::wstring &data, const char *s, size_t length) { data.resize(length); @@ -138,7 +136,7 @@ namespace // Converts a UTF-8 string into UTF-16(without BOM/CPU byte order) // and copies it to the internal buffer. - inline void copyFromUTF8(std::wstring &data, const char *s, size_t length) + void copyFromUTF8(std::wstring &data, const char *s, size_t length) { data.resize(length); @@ -150,7 +148,7 @@ namespace // Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into // UTF-16(without BOM/CPU byte order) and copies it to the internal buffer. - inline void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t) + void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t) { bool swap; if(t == String::UTF16) { @@ -184,7 +182,7 @@ namespace // Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into // UTF-16(without BOM/CPU byte order) and copies it to the internal buffer. - inline void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t) + void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t) { bool swap; if(t == String::UTF16) { diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index bacbc2dd..6653e47b 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -55,235 +55,237 @@ namespace TagLib { namespace Utils { - - /*! - * Reverses the order of bytes in an 16-bit integer. - */ - inline unsigned short byteSwap(unsigned short x) + namespace { + + /*! + * Reverses the order of bytes in an 16-bit integer. + */ + inline unsigned short byteSwap(unsigned short x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(x); + return boost::endian::endian_reverse(x); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap16(x); + return __builtin_bswap16(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_ushort(x); + return _byteswap_ushort(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_16(x); + return __bswap_16(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt16(x); + return OSSwapInt16(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap16(x); + return swap16(x); #else - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); + return ((x >> 8) & 0xff) | ((x & 0xff) << 8); #endif - } + } - /*! - * Reverses the order of bytes in an 32-bit integer. - */ - inline unsigned int byteSwap(unsigned int x) - { + /*! + * Reverses the order of bytes in an 32-bit integer. + */ + inline unsigned int byteSwap(unsigned int x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(x); + return boost::endian::endian_reverse(x); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap32(x); + return __builtin_bswap32(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_ulong(x); + return _byteswap_ulong(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_32(x); + return __bswap_32(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt32(x); + return OSSwapInt32(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap32(x); + return swap32(x); #else - return ((x & 0xff000000u) >> 24) - | ((x & 0x00ff0000u) >> 8) - | ((x & 0x0000ff00u) << 8) - | ((x & 0x000000ffu) << 24); + return ((x & 0xff000000u) >> 24) + | ((x & 0x00ff0000u) >> 8) + | ((x & 0x0000ff00u) << 8) + | ((x & 0x000000ffu) << 24); #endif - } + } - /*! - * Reverses the order of bytes in an 64-bit integer. - */ - inline unsigned long long byteSwap(unsigned long long x) - { + /*! + * Reverses the order of bytes in an 64-bit integer. + */ + inline unsigned long long byteSwap(unsigned long long x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(x); + return boost::endian::endian_reverse(x); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap64(x); + return __builtin_bswap64(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_uint64(x); + return _byteswap_uint64(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_64(x); + return __bswap_64(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt64(x); + return OSSwapInt64(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap64(x); + return swap64(x); #else - return ((x & 0xff00000000000000ull) >> 56) - | ((x & 0x00ff000000000000ull) >> 40) - | ((x & 0x0000ff0000000000ull) >> 24) - | ((x & 0x000000ff00000000ull) >> 8) - | ((x & 0x00000000ff000000ull) << 8) - | ((x & 0x0000000000ff0000ull) << 24) - | ((x & 0x000000000000ff00ull) << 40) - | ((x & 0x00000000000000ffull) << 56); + return ((x & 0xff00000000000000ull) >> 56) + | ((x & 0x00ff000000000000ull) >> 40) + | ((x & 0x0000ff0000000000ull) >> 24) + | ((x & 0x000000ff00000000ull) >> 8) + | ((x & 0x00000000ff000000ull) << 8) + | ((x & 0x0000000000ff0000ull) << 24) + | ((x & 0x000000000000ff00ull) << 40) + | ((x & 0x00000000000000ffull) << 56); #endif - } + } - /*! - * Returns a formatted string just like standard sprintf(), but makes use of - * safer functions such as snprintf() if available. - */ - inline String formatString(const char *format, ...) - { - // Sufficient buffer size for the current internal uses. - // Consider changing this value when you use this function. + /*! + * Returns a formatted string just like standard sprintf(), but makes use of + * safer functions such as snprintf() if available. + */ + inline String formatString(const char *format, ...) + { + // Sufficient buffer size for the current internal uses. + // Consider changing this value when you use this function. - static const size_t BufferSize = 128; + static const size_t BufferSize = 128; - va_list args; - va_start(args, format); + va_list args; + va_start(args, format); - char buf[BufferSize]; - int length; + char buf[BufferSize]; + int length; #if defined(HAVE_VSNPRINTF) - length = vsnprintf(buf, BufferSize, format, args); + length = vsnprintf(buf, BufferSize, format, args); #elif defined(HAVE_VSPRINTF_S) - length = vsprintf_s(buf, format, args); + length = vsprintf_s(buf, format, args); #else - // The last resort. May cause a buffer overflow. + // The last resort. May cause a buffer overflow. - length = vsprintf(buf, format, args); - if(length >= BufferSize) { - debug("Utils::formatString() - Buffer overflow! Returning an empty string."); - length = -1; - } + length = vsprintf(buf, format, args); + if(length >= BufferSize) { + debug("Utils::formatString() - Buffer overflow! Returning an empty string."); + length = -1; + } #endif - va_end(args); + va_end(args); - if(length > 0) - return String(buf); - else - return String(); - } - - /*! - * Returns whether the two strings s1 and s2 are equal, ignoring the case of - * the characters. - * - * We took the trouble to define this one here, since there are some - * incompatible variations of case insensitive strcmp(). - */ - inline bool equalsIgnoreCase(const char *s1, const char *s2) - { - while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) { - s1++; - s2++; + if(length > 0) + return String(buf); + else + return String(); } - return (*s1 == '\0' && *s2 == '\0'); + /*! + * Returns whether the two strings s1 and s2 are equal, ignoring the case of + * the characters. + * + * We took the trouble to define this one here, since there are some + * incompatible variations of case insensitive strcmp(). + */ + inline bool equalsIgnoreCase(const char *s1, const char *s2) + { + while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) { + s1++; + s2++; + } + + return (*s1 == '\0' && *s2 == '\0'); + } + + /*! + * The types of byte order of the running system. + */ + enum ByteOrder + { + //! Little endian systems. + LittleEndian, + //! Big endian systems. + BigEndian + }; + + /*! + * Returns the integer byte order of the system. + */ + inline ByteOrder systemByteOrder() + { + union { + int i; + char c; + } u; + + u.i = 1; + if(u.c == 1) + return LittleEndian; + else + return BigEndian; + } + + /*! + * Returns the IEEE754 byte order of the system. + */ + inline ByteOrder floatByteOrder() + { + union { + double d; + char c; + } u; + + // 1.0 is stored in memory like 0x3FF0000000000000 in canonical form. + // So the first byte is zero if little endian. + + u.d = 1.0; + if(u.c == 0) + return LittleEndian; + else + return BigEndian; + } } - - /*! - * The types of byte order of the running system. - */ - enum ByteOrder - { - //! Little endian systems. - LittleEndian, - //! Big endian systems. - BigEndian - }; - - /*! - * Returns the integer byte order of the system. - */ - inline ByteOrder systemByteOrder() - { - union { - int i; - char c; - } u; - - u.i = 1; - if(u.c == 1) - return LittleEndian; - else - return BigEndian; - } - - /*! - * Returns the IEEE754 byte order of the system. - */ - inline ByteOrder floatByteOrder() - { - union { - double d; - char c; - } u; - - // 1.0 is stored in memory like 0x3FF0000000000000 in canonical form. - // So the first byte is zero if little endian. - - u.d = 1.0; - if(u.c == 0) - return LittleEndian; - else - return BigEndian; - } - } }