blocxx
Main Page
Namespaces
Classes
Files
File List
File Members
src
blocxx
Char16.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3
* Copyright (C) 2006, Novell, Inc. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* * Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* * Neither the name of
14
* Vintela, Inc.,
15
* nor Novell, Inc.,
16
* nor the names of its contributors or employees may be used to
17
* endorse or promote products derived from this software without
18
* specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*******************************************************************************/
32
33
39
#include "blocxx/BLOCXX_config.h"
40
#include "
blocxx/Char16.hpp
"
41
#include "
blocxx/String.hpp
"
42
#include "
blocxx/ByteSwap.hpp
"
43
#include "
blocxx/BinarySerialization.hpp
"
44
#include "
blocxx/UTF8Utils.hpp
"
45
#include <cstdio>
46
#include <cstring>
47
#ifdef BLOCXX_HAVE_OSTREAM
48
#include <ostream>
49
#else
50
#include <iostream>
51
#endif
52
53
namespace
BLOCXX_NAMESPACE
54
{
55
56
using
std::ostream;
57
using
std::streambuf;
59
Char16::Char16
(
const
String
& x) :
60
m_value(0)
61
{
62
m_value
=
UTF8Utils::UTF8toUCS2
(x.
c_str
());
63
}
65
String
66
Char16::toUTF8
()
const
67
{
68
return
UTF8Utils::UCS2toUTF8
(
m_value
);
69
}
71
String
72
Char16::toString
()
const
73
{
74
return
UTF8Utils::UCS2toUTF8
(
m_value
);
75
}
77
void
78
Char16::writeObject
(streambuf & ostrm)
const
79
{
80
BinarySerialization::write
(ostrm,
m_value
);
81
}
83
void
84
Char16::readObject
(streambuf & istrm)
85
{
86
BinarySerialization::read
(istrm,
m_value
);
87
}
89
std::ostream&
90
operator<<
(std::ostream& ostrm,
const
Char16
& arg)
91
{
92
UInt16 val = arg.
getValue
();
93
if
(val > 0 && val <= 127)
94
{
95
ostrm << static_cast<char>(val);
96
}
97
else
98
{
99
// Print in hex format:
100
char
bfr[8];
101
sprintf(bfr,
"\\x%04X"
, val);
102
ostrm << bfr;
103
}
104
return
ostrm;
105
}
106
107
}
// end namespace BLOCXX_NAMESPACE
108
Generated by
1.8.2