dviconv.h

Go to the documentation of this file.
00001 #ifndef DVXML_ICONV_H
00002 #define DVXML_ICONV_H
00003 // $Id: dviconv.h,v 1.2 2008/01/07 14:45:20 dvermeir Exp $
00004 
00005 #include <string>
00006 #include <stdexcept>
00007 #include <dvutil/date.h>
00008 #include <xmlwrapp/xmlwrapp.h>
00009 
00010 namespace Dv { 
00011   namespace Xml { 
00012     /** Convert source C-string between character sets.
00013      * @param to_charset character set to convert to, e.g. "UTF8"
00014      * @param from_charset character set to convert from, e.g. "ISO-8859-1"
00015      * @param target string containing new version of source string.
00016      * @param source C-string
00017      * @exception std::runtime_error if anything goes wrong.
00018      * Use iconv --list to see all supported character sets.
00019      */
00020     void iconv(const char* to_charset, const char* from_charset, 
00021       std::string& target, const char* source) throw (std::runtime_error);
00022 
00023     /** Convert source C-string between character sets.
00024      * @param to_charset character set to convert to, e.g. "UTF8"
00025      * @param from_charset character set to convert from, e.g. "ISO-8859-1"
00026      * @param target string containing new version of source string.
00027      * @param source C-string
00028      * @exception std::runtime_error if anything goes wrong.
00029      * Use iconv --list to see all supported character sets.
00030      */
00031     void iconv(const char* to_charset, const char* from_charset, 
00032       std::string& target, const std::string& source) throw (std::runtime_error);
00033     
00034     /** Convert source C-string between character sets.
00035      * @param to_charset character set to convert to, e.g. "UTF8"
00036      * @param from_charset character set to convert from, e.g. "ISO-8859-1"
00037      * @param source C-string
00038      * @return string containing new version of source string (in target character set).
00039      * @exception std::runtime_error if anything goes wrong.
00040      * Use iconv --list to see all supported character sets.
00041      */
00042     std::string iconv(const char* to_charset, const char* from_charset, 
00043       const char* source) throw (std::runtime_error);
00044     
00045     /** Convert source C-string between character sets.
00046      * @param to_charset character set to convert to, e.g. "UTF8"
00047      * @param from_charset character set to convert from, e.g. "ISO-8859-1"
00048      * @param source C-string
00049      * @return string containing new version of source string (in target character set).
00050      * @exception std::runtime_error if anything goes wrong.
00051      * Use iconv --list to see all supported character sets.
00052      */
00053     std::string iconv(const char* to_charset, const char* from_charset, 
00054       const std::string& source) throw (std::runtime_error);
00055     
00056     /** Convert "ISO-8859-1" string to "UTF8" string.
00057      * @param source string (using "ISO-8859-1" character set).
00058      * @return string containing source string (in "UTF8" character set).
00059      * @exception std::runtime_error if anything goes wrong.
00060      * Use iconv --list to see all supported character sets.
00061      */
00062     inline std::string iso2utf8(const std::string& source ) throw (std::runtime_error) {
00063       return iconv("UTF8", "ISO-8859-1", source); 
00064     }
00065 
00066     /** Convert "ISO-8859-1" C-string to "UTF8" string.
00067      * @param source string (using "ISO-8859-1" character set).
00068      * @return string containing source string (in "UTF8" character set).
00069      * @exception std::runtime_error if anything goes wrong.
00070      * Use iconv --list to see all supported character sets.
00071      */
00072     inline std::string iso2utf8(const char* source ) throw (std::runtime_error) {
00073       return iconv("UTF8", "ISO-8859-1", source); 
00074     } 
00075   }
00076 }
00077 #endif
00078 

dvxml-0.1.7 [ 7 January, 2008]