| TagLib 1.13 |  |

asfutils.h
Go to the documentation of this file.
1/***************************************************************************
2 copyright : (C) 2015 by Tsuda Kageyu
3 email : tsuda.kageyu@gmail.com
4 ***************************************************************************/
5
6/***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
25
26#ifndef TAGLIB_ASFUTILS_H
27#define TAGLIB_ASFUTILS_H
28
29// THIS FILE IS NOT A PART OF THE TAGLIB API
30
31#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header
32
33 namespace TagLib
34{
35 namespace ASF
36 {
37 namespace
38 {
39
40 inline unsigned short readWORD(File *file, bool *ok = 0)
41 {
42 const ByteVector v = file->readBlock(2);
43 if(v.size() != 2) {
44 if(ok) *ok = false;
45 return 0;
46 }
47 if(ok) *ok = true;
48 return v.toUShort(false);
49 }
50
51 inline unsigned int readDWORD(File *file, bool *ok = 0)
52 {
53 const ByteVector v = file->readBlock(4);
54 if(v.size() != 4) {
55 if(ok) *ok = false;
56 return 0;
57 }
58 if(ok) *ok = true;
59 return v.toUInt(false);
60 }
61
62 inline long long readQWORD(File *file, bool *ok = 0)
63 {
64 const ByteVector v = file->readBlock(8);
65 if(v.size() != 8) {
66 if(ok) *ok = false;
67 return 0;
68 }
69 if(ok) *ok = true;
70 return v.toLongLong(false);
71 }
72
73 inline String readString(File *file, int length)
74 {
75 ByteVector data = file->readBlock(length);
76 unsigned int size = data.size();
77 while (size >= 2) {
78 if(data[size - 1] != '\0' || data[size - 2] != '\0') {
79 break;
80 }
81 size -= 2;
82 }
83 if(size != data.size()) {
84 data.resize(size);
85 }
86 return String(data, String::UTF16LE);
87 }
88
89 inline ByteVector renderString(const String &str, bool includeLength = false)
90 {
91 ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false);
92 if(includeLength) {
93 data = ByteVector::fromShort(data.size(), false) + data;
94 }
95 return data;
96 }
97
98 }
99 }
100}
101
102#endif
103
104#endif
TagLib::ByteVector::fromShort
static ByteVector fromShort(short value, bool mostSignificantByteFirst=true)
TagLib::String::UTF16LE
@ UTF16LE
Definition: tstring.h:118
TagLib
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41