00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #include <ximol/encoders/encoders.hpp>
00072 #include <ximol/encoders/error.hpp>
00073 #include <ximol/translation.hpp>
00074 #include <ximol/codecvt.hpp>
00075
00076
00077 XIMOL_ENCODERS_BEGIN_NAMESPACE
00078
00079
00080
00081
00082 ::std::codecvt<xchar_t, char, mbstate_t>* get_ximol_facet(::std::string const& encoding_name)
00083 {
00084 return new XIMOL_NAMESPACE_PATH::codecvt(encoding_name);
00085 }
00086
00087
00088
00089
00090 void place_ximol_facet(::std::codecvt<xchar_t, char, mbstate_t>* placement, ::std::string const & encoding_name)
00091 {
00092 new (placement) XIMOL_NAMESPACE_PATH::codecvt(encoding_name);
00093 }
00094
00095
00096
00097
00098 void change_ximol_facet_encoding(::std::codecvt<xchar_t, char, mbstate_t>* facet, ::std::string const & encoding_name)
00099 {
00100 if (facet==NULL) return;
00101 XIMOL_NAMESPACE_PATH::codecvt* the_facet=dynamic_cast<XIMOL_NAMESPACE_PATH::codecvt*>(facet);
00102
00103 if (the_facet==NULL)
00104 XIMOL_ENCODERS_THROW << _(L"XiMoL Encoder facet problem. ")
00105 << _(L"We can not retrive the XiMoL facet pointer. ")
00106 << _(L"And then, the encoding can not be changed to '%o'. ", encoding_name )
00107 << XIMOL_ENCODERS_AS_ERROR;
00108 the_facet->delete_encoding();
00109 the_facet->create_encoding(encoding_name);
00110 }
00111
00112
00113
00114
00115 void deep_change(::std::basic_ios<xchar_t>& ios, ::std::string const & encoding_name)
00116 {
00117 typedef ::std::codecvt<xchar_t,char,mbstate_t> FacetType;
00118
00119 const FacetType* pfacet=&(XIMOL_USE_FACET(ios.getloc(),FacetType));
00120
00121
00122 FacetType* the_facet=const_cast<FacetType*>(pfacet);
00123
00124 change_ximol_facet_encoding(the_facet,encoding_name);
00125 }
00126
00127
00128
00129
00130 void prepare_ios(::std::basic_ios<xchar_t>& ios, ::std::string const & encoding_name)
00131 {
00132 ios.imbue(XIMOL_ADD_FACET(ios.getloc(), get_ximol_facet(encoding_name)));
00133 }
00134
00135
00136
00137
00138 bool test_ios(::std::basic_ios<xchar_t> & ios)
00139 {
00140 typedef ::std::codecvt<xchar_t,char,mbstate_t> FacetType;
00141
00142 const FacetType* pfacet=&(XIMOL_USE_FACET(ios.getloc(),FacetType));
00143 return NULL != dynamic_cast<const XIMOL_NAMESPACE_PATH::codecvt*>(pfacet);
00144 }
00145
00146 XIMOL_ENCODERS_END_NAMESPACE