00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_STRING_H
00023 #define MECHSYS_STRING_H
00024
00025 #ifdef USE_WXSTRING
00026 #include <string>
00027 #include <wx/string.h>
00028 #include <wx/intl.h>
00029
00030 class String : public wxString
00031 {
00032 public:
00033 String(){}
00034 String(std::string const & Other)
00035 {
00036 char const * ascii_str = Other.c_str();
00037 wxString string(ascii_str, wxConvUTF8);
00038 this->clear();
00039 this->append(string);
00040 }
00041 String(const char * Other)
00042 {
00043 wxString string(Other, wxConvUTF8);
00044 this->clear();
00045 this->append(string);
00046 }
00047 String(wxChar const * psz)
00048 {
00049 this->clear();
00050 this->append(psz);
00051 }
00052 std::string GetSTL() const
00053 {
00054 #if wxUSE_UNICODE
00055 return std::string(this->mb_str(wxConvUTF8));
00056 #else
00057 return std::string(this->c_str());
00058 #endif
00059 }
00060 String & operator= (wxChar const * psz)
00061 {
00062 (*this) = psz;
00063 return (*this);
00064 }
00065 private:
00066 };
00067
00068 bool operator== (String const & A, char const * B_ascii)
00069 {
00070 return A.GetSTL()==B_ascii;
00071 }
00072
00073 #include <sstream>
00074 std::istream & operator>> (std::istream & input, String & S)
00075 {
00076 std::string str;
00077 input >> str;
00078 S = str;
00079 return input;
00080 }
00081
00082 #else // (do not) USE_WXSTRING
00083 #include <string>
00084 #include <cstdarg>
00085 #include <cstdlib>
00086
00087 #define _(STRING) (STRING) // for transation
00088 #define _T(STRING) (STRING) // NO transation
00089
00090 class String : public std::string
00091 {
00092 public:
00093 String(){}
00094 String(std::string const & Other)
00095 {
00096 this->clear();
00097 this->append(Other);
00098 }
00099 String(const char * Msg)
00100 {
00101 this->clear();
00102 this->append(Msg);
00103 }
00104 int Printf(String const & Fmt, ...)
00105 {
00106 int len;
00107 va_list arg_list;
00108 va_start (arg_list, Fmt);
00109 len=_set_msg (Fmt.c_str(), arg_list);
00110 va_end (arg_list);
00111 return len;
00112 }
00113 int PrintfV(String const & Fmt, va_list ArgList)
00114 {
00115 return _set_msg (Fmt.c_str(), ArgList);
00116 }
00117 std::string GetSTL() const
00118 {
00119 return std::string((*this));
00120 }
00121 private:
00122 int _set_msg(char const * Fmt, va_list ArgList)
00123 {
00124 const int size = 4048;
00125 char buffer[size];
00126 int len = std::vsnprintf(buffer, size, Fmt, ArgList);
00127 this->clear();
00128 if (len<0) this->append("String::_set_msg: INTERNAL ERROR: std::vsnprintf FAILED");
00129 else
00130 {
00131 buffer[len]='\0';
00132 if (len>size) this->append("String::_set_msg: INTERNAL ERROR: std::vsnprintf MESSAGE TRUNCATED: ");
00133 this->append(buffer);
00134 }
00135 return len;
00136 }
00137 };
00138
00139 #endif // (do/do not) USE_WXSTRING
00140
00141 #endif // MECHSYS_STRING_H
00142
00143