diff options
Diffstat (limited to 'lib/String.cc')
-rw-r--r-- | lib/String.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/String.cc b/lib/String.cc index b63b216..20cade9 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -17,12 +17,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: String.cc,v 1.40 2005-12-01 14:30:04 pixel Exp $ */ +/* $Id: String.cc,v 1.41 2006-01-31 17:02:39 pixel Exp $ */ #include <stdio.h> #include <string.h> #include <stdarg.h> #include <ctype.h> +#include <iconv.h> #include <iostream> #ifdef HAVE_CONFIG_H #include "config.h" @@ -558,3 +559,32 @@ String String::rtrim() const { String String::trim() const { return rtrim().ltrim(); } + +String & String::iconv(const String & from, const String & to) { + iconv_t cd; + const char * inbuf; + char * outbuf; + size_t inleft, outleft; + + if ((cd = iconv_open(to.str, from.str)) == (iconv_t) (-1)) { + return *this; + } + + LOCK; + inbuf = str; + outbuf = t; + inleft = siz; + outleft = BUFSIZ; + memset(t, 0, BUFSIZ + 1); + ::iconv (cd, &inbuf, &inleft, &outbuf, &outleft); + + free(str); + + str = Base::strdup(t); + siz = ::strlen(t); + UNLOCK; + + iconv_close(cd); + + return *this; +} |