Bumped copyright dates for 2013
[barry.git] / src / iconvwin.cc
blobf46da8723d60d9493cbd354ae812c2de056c05ec
1 ///
2 /// \file iconvwin.cc
3 /// iconv wrapper class for Windows
4 ///
6 /*
7 Copyright (C) 2008-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "iconv.h"
23 #include "common.h"
24 #include "error.h"
25 #include <errno.h>
26 #include <string>
27 #include <assert.h>
28 #include <stdexcept>
30 using namespace std;
32 namespace Barry {
34 //////////////////////////////////////////////////////////////////////////////
35 // IConvHandlePrivate class
36 class IConvHandlePrivate
38 public:
41 //////////////////////////////////////////////////////////////////////////////
42 // IConvHandle class
44 IConvHandle::IConvHandle(const char *fromcode,
45 const char *tocode,
46 bool throw_on_conv_err)
47 : m_priv( new IConvHandlePrivate )
48 , m_throw_on_conv_err(throw_on_conv_err)
52 IConvHandle::IConvHandle(const char *fromcode,
53 const IConverter &ic,
54 bool throw_on_conv_err)
55 : m_priv( new IConvHandlePrivate )
56 , m_throw_on_conv_err(throw_on_conv_err)
60 IConvHandle::IConvHandle(const IConverter &ic,
61 const char *tocode,
62 bool throw_on_conv_err)
63 : m_priv( new IConvHandlePrivate )
64 , m_throw_on_conv_err(throw_on_conv_err)
68 IConvHandle::IConvHandle(const IConvHandle &other)
70 /* This is private to prevent copying, so shouldn't ever be called.
71 * However MSCL still generates refernces to it, so it needs to be provided. */
72 throw std::logic_error("IConvHandle copy constructor: should never be called.");
75 IConvHandle::~IConvHandle()
80 IConvHandle& IConvHandle::operator=(const IConvHandle &other)
82 /* This is private to prevent copying, so shouldn't ever be called.
83 * However MSCL still generates refernces to it, so it needs to be provided. */
84 throw std::logic_error("IConvHandle operator=(): should never be called.");
87 std::string IConvHandle::Convert(Data &tmp, const std::string &str) const
89 // FIXME - need to add Windows support
90 return str;
94 //////////////////////////////////////////////////////////////////////////////
95 // IConvHandle class
97 IConverter::IConverter(const char *tocode, bool throw_on_conv_err)
98 : m_from(BLACKBERRY_CHARSET, tocode, throw_on_conv_err)
99 , m_to(tocode, BLACKBERRY_CHARSET, throw_on_conv_err)
100 , m_tocode(tocode)
104 IConverter::~IConverter()
108 std::string IConverter::FromBB(const std::string &str) const
110 return m_from.Convert(m_buffer, str);
113 std::string IConverter::ToBB(const std::string &str) const
115 return m_to.Convert(m_buffer, str);
118 std::string IConverter::Convert(const IConvHandle &custom, const std::string &str) const
120 return custom.Convert(m_buffer, str);
123 } // namespace Barry