2004-10-05 10:28:21 +00:00
|
|
|
//
|
2005-03-18 21:33:11 +00:00
|
|
|
// VMime library (http://www.vmime.org)
|
2009-09-06 12:02:10 +00:00
|
|
|
// Copyright (C) 2002-2009 Vincent Richard <vincent@vincent-richard.net>
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2009-09-06 12:02:10 +00:00
|
|
|
// published by the Free Software Foundation; either version 3 of
|
2004-10-05 10:28:21 +00:00
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program 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
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
2005-09-17 10:10:29 +00:00
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// Linking this library statically or dynamically with other modules is making
|
|
|
|
// a combined work based on this library. Thus, the terms and conditions of
|
|
|
|
// the GNU General Public License cover the whole combination.
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
|
2004-12-26 20:23:29 +00:00
|
|
|
#include "vmime/charset.hpp"
|
|
|
|
#include "vmime/exception.hpp"
|
2006-10-11 14:52:41 +00:00
|
|
|
#include "vmime/platform.hpp"
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-12-26 20:23:29 +00:00
|
|
|
#include "vmime/utility/stringUtils.hpp"
|
2004-10-21 15:05:47 +00:00
|
|
|
|
2005-10-19 11:25:57 +00:00
|
|
|
#include "vmime/charsetConverter.hpp"
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace vmime
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
charset::charset()
|
|
|
|
: m_name(charsets::US_ASCII)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
charset::charset(const string& name)
|
|
|
|
: m_name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-20 20:32:48 +00:00
|
|
|
charset::charset(const char* name)
|
|
|
|
: m_name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
void charset::parse(const string& buffer, const string::size_type position,
|
|
|
|
const string::size_type end, string::size_type* newPosition)
|
|
|
|
{
|
2006-08-25 14:36:44 +00:00
|
|
|
m_name = utility::stringUtils::trim
|
|
|
|
(string(buffer.begin() + position, buffer.begin() + end));
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-12-15 20:28:09 +00:00
|
|
|
setParsedBounds(position, end);
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
if (newPosition)
|
|
|
|
*newPosition = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void charset::generate(utility::outputStream& os, const string::size_type /* maxLineLength */,
|
|
|
|
const string::size_type curLinePos, string::size_type* newLinePos) const
|
|
|
|
{
|
|
|
|
os << m_name;
|
|
|
|
|
|
|
|
if (newLinePos)
|
|
|
|
*newLinePos = curLinePos + m_name.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void charset::convert(utility::inputStream& in, utility::outputStream& out,
|
|
|
|
const charset& source, const charset& dest)
|
|
|
|
{
|
2005-10-19 11:25:57 +00:00
|
|
|
charsetConverter conv(source, dest);
|
|
|
|
conv.convert(in, out);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void charset::convert(const string& in, string& out, const charset& source, const charset& dest)
|
|
|
|
{
|
2005-10-19 11:25:57 +00:00
|
|
|
charsetConverter conv(source, dest);
|
|
|
|
conv.convert(in, out);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const charset charset::getLocaleCharset()
|
|
|
|
{
|
2006-10-11 14:52:41 +00:00
|
|
|
return (platform::getHandler()->getLocaleCharset());
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
charset& charset::operator=(const charset& other)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
copyFrom(other);
|
2004-10-05 10:28:21 +00:00
|
|
|
return (*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-12 10:05:28 +00:00
|
|
|
bool charset::operator==(const charset& value) const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2005-01-02 17:17:12 +00:00
|
|
|
return (utility::stringUtils::isStringEqualNoCase(m_name, value.m_name));
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-12 10:05:28 +00:00
|
|
|
bool charset::operator!=(const charset& value) const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
|
|
|
return !(*this == value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-12 22:28:02 +00:00
|
|
|
ref <component> charset::clone() const
|
2004-10-21 15:05:47 +00:00
|
|
|
{
|
2005-07-12 22:28:02 +00:00
|
|
|
return vmime::create <charset>(m_name);
|
2004-10-21 15:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const string& charset::getName() const
|
|
|
|
{
|
|
|
|
return (m_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void charset::copyFrom(const component& other)
|
|
|
|
{
|
|
|
|
m_name = dynamic_cast <const charset&>(other).m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-12 22:28:02 +00:00
|
|
|
const std::vector <ref <const component> > charset::getChildComponents() const
|
2004-12-20 12:33:55 +00:00
|
|
|
{
|
2005-07-12 22:28:02 +00:00
|
|
|
return std::vector <ref <const component> >();
|
2004-12-20 12:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
} // vmime
|