00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00039
00040
00041 #ifndef _MBOTSTRING_H
00042 #define _MBOTSTRING_H
00043
00044 #include "Mbo.h"
00045 #include "MboDebugTrace.h"
00046 #include <locale>
00047 #include <string>
00048 #include <stdexcept>
00049 #include <stdlib.h>
00050 #if _MSC_VER
00051 # include <tchar.h>
00052 #endif
00053
00054 namespace mbo
00055 {
00056
00057 #ifndef _TCHAR_DEFINED
00058 # define _TCHAR_DEFINED
00059 typedef char TCHAR;
00060 #endif
00061
00062 typedef std::basic_string<TCHAR> tstring;
00063
00064 #ifndef MBO_STRING_DEFINED
00065 #define MBO_STRING_DEFINED
00066
00067 typedef mbo::tstring MboString;
00068
00069 #endif // MBO_STRING_DEFINED
00070
00071
00072 #if defined(_MSC_VER) && _MSC_VER < 1300
00073 # define __USE_FACET , NULL, 1
00074 #else
00075 # define __USE_FACET
00076 #endif
00077
00078 #ifdef _MT
00079 #define MBO_MT_LOCAL_OR_STATIC
00080 #else
00081 #define MBO_MT_LOCAL_OR_STATIC static
00082 #endif
00083
00084 #ifdef _STLPORT_VERSION
00085 template<class _E>
00086 inline const std::ctype& get_facet()
00087 {
00088 MBO_MT_LOCAL_OR_STATIC const std::ctype& facet = std::use_facet<std::ctype>(std::locale::empty());
00089 return facet;
00090 }
00091 #else
00092 template<class _E>
00093 inline const std::ctype<_E>& get_facet()
00094 {
00095 MBO_MT_LOCAL_OR_STATIC const std::ctype<_E>& facet = std::use_facet<std::ctype<_E> >(std::locale::empty() __USE_FACET);
00096 return facet;
00097 }
00098 #endif
00099
00100 template<class _E, class _Tr, class _A>
00101 inline std::basic_string<_E, _Tr, _A> StrCreate(_IN const char *sz)
00102 {
00103 const std::ctype<_E>& facet = get_facet<_E>();
00104
00105 std::basic_string<_E, _Tr, _A> str;
00106
00107 while (*sz)
00108 {
00109 str.append(1, facet.widen(*sz++));
00110 }
00111 return str;
00112 }
00113
00114 template<>
00115 inline std::basic_string<char> StrCreate(_IN const char *sz)
00116 {
00117 return std::basic_string<char>(sz);
00118 }
00119
00120 MBO_API mbo::tstring TStrCreate(_IN const char *sz);
00121
00122 #define _TS(text) mbo::TStrCreate(text)
00123
00124 class string_conversion_error: public mbo::runtime_error
00125 {
00126 public:
00127 string_conversion_error()
00128 : mbo::runtime_error("String cannot be converted")
00129 {
00130 }
00131 };
00132
00133 MBO_API std::basic_string<char> WStrToStr(_IN const std::basic_string<wchar_t> & wstr);
00134
00135 MBO_API std::basic_string<wchar_t> StrToWStr(_IN const std::basic_string<char> & str);
00136
00137 template<typename _ValType>
00138 tstring TStrFrom(_IN const _ValType & val)
00139 {
00140 return StrFrom<tstring::value_type, _ValType>(val);
00141 }
00142
00143 };
00144
00145 #endif // _MBOTSTRING_H