-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
-Distributed under the LGPL
-*/
-
-#ifndef MSP_STRINGS_CODEC_H_
-#define MSP_STRINGS_CODEC_H_
+#ifndef MSP_STRINGCODEC_CODEC_H_
+#define MSP_STRINGCODEC_CODEC_H_
#include <string>
#include <msp/core/except.h>
namespace Msp {
-namespace Codecs {
+namespace StringCodec {
typedef int UnicodeChar;
ustring decode(const std::string &s)
{
typename C::Decoder dec;
- ustring result;
- dec.decode(s, result);
- return result;
+ return dec.decode(s);
}
/** Convenience function that encodes a string. */
std::string encode(const ustring &s)
{
typename C::Encoder enc;
- std::string result;
- enc.encode(s, result);
- enc.sync(result);
- return result;
+ return enc.encode(s);
}
/** Convenience function that transcodes a string from one codec to another. */
template<class F, class T>
std::string transcode(const std::string &s)
{
- typename F::Decoder from;
- typename T::Encoder to;
- ustring temp;
- from.decode(s, temp);
- std::string result;
- to.encode(temp, result);
- to.sync(result);
- return result;
+ return encode<T>(decode<F>(s));
}
/** Creates a codec for an encoding by name. The caller is responsible for
The codec must be deleted when it's no longer needed. */
Codec *detect_codec(const std::string &);
-} // namespace Codecs
+} // namespace StringCodec
} // namespace Msp
#endif