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"
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;
60  m_value(0)
61 {
63 }
65 String
67 {
69 }
71 String
73 {
75 }
77 void
78 Char16::writeObject(streambuf & ostrm) const
79 {
81 }
83 void
84 Char16::readObject(streambuf & istrm)
85 {
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 
UInt16 UTF8toUCS2(const char *utf8char)
Convert one UTF-8 char (possibly multiple bytes) into a UCS2 16-bit char.
Definition: UTF8Utils.cpp:122
This String class is an abstract data type that represents as NULL terminated string of characters...
Definition: String.hpp:66
void read(std::streambuf &istrm, void *dataIn, size_t dataInLen)
String toUTF8() const BLOCXX_DEPRECATED
Deprecated in favor of toString()
Definition: Char16.cpp:66
void writeObject(std::streambuf &ostrm) const
Write this object to an output stream.
Definition: Char16.cpp:78
const char * c_str() const
Definition: String.cpp:905
ostream & operator<<(ostream &ostrm, const Bool &arg)
Insert the string representation of a Bool object into a given stream.
Definition: Bool.cpp:77
String UCS2toUTF8(UInt16 ucs2char)
Convert one UCS2 16-bit char into a UTF-8 char (possibly multiple bytes)
Definition: UTF8Utils.cpp:135
The Char16 class is an abstraction for a double byte character.
Definition: Char16.hpp:56
void write(std::streambuf &ostrm, void const *dataOut, size_t dataOutLen)
UInt16 getValue() const
Definition: Char16.hpp:139
String toString() const
Convert this to UTF8.
Definition: Char16.cpp:72
Char16()
Create a new Char16 object with a value of zero.
Definition: Char16.hpp:62
void readObject(std::streambuf &istrm)
Read this object from an input stream.
Definition: Char16.cpp:84