X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstringcodec%2Fcodec.h;h=a307e2ec8acc3a784d1f57ce9d7ca4516dfff4fc;hb=b011b17393069d86790b2291a759280e15c75a0f;hp=e04e909fb7a1fc5c4750db7e13f33f2d44a96f92;hpb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd;p=libs%2Fcore.git diff --git a/source/stringcodec/codec.h b/source/stringcodec/codec.h index e04e909..a307e2e 100644 --- a/source/stringcodec/codec.h +++ b/source/stringcodec/codec.h @@ -1,18 +1,11 @@ -/* $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 #include namespace Msp { -namespace Codecs { +namespace StringCodec { typedef int UnicodeChar; @@ -161,9 +154,7 @@ template 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. */ @@ -171,24 +162,14 @@ template 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 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(decode(s)); } /** Creates a codec for an encoding by name. The caller is responsible for @@ -199,7 +180,7 @@ Codec *create_codec(const std::string &); The codec must be deleted when it's no longer needed. */ Codec *detect_codec(const std::string &); -} // namespace Codecs +} // namespace StringCodec } // namespace Msp #endif