blob: 613dbda860a023ef3383d73b974a257e060f2e12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/*
* Copyright (C) 2012 Research In Motion Limited. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ReadOnlyLatin1String_h
#define ReadOnlyLatin1String_h
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ReadOnlyLatin1String {
public:
explicit ReadOnlyLatin1String(const String& string)
{
if (string.is8Bit())
m_string = string;
else {
ASSERT(string.containsOnlyLatin1());
m_cstring = string.latin1();
}
}
const char* data() const { return m_string.isNull() ? m_cstring.data() : reinterpret_cast<const char*>(m_string.characters8()); }
size_t length() const { return m_string.isNull() ? m_cstring.length() : m_string.length(); }
private:
String m_string;
CString m_cstring;
};
} // namespace WebCore
#endif
|