Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin1/common/wxPlatform.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00027 #ifndef HUGIN_WXPLATFORM_H 00028 #define HUGIN_WXPLATFORM_H 00029 00030 #include <wx/wxchar.h> 00031 #include <wx/string.h> 00032 #include "utils.h" 00033 00034 namespace utils { 00035 00036 template <class str> 00037 str wxQuoteStringInternal(const str & arg, const str & quotechar, 00038 const str & replacements) 00039 { 00040 // loop over all chars.. 00041 str ret(arg); 00042 size_t len = replacements.size(); 00043 for (size_t i = 0; i < len; i++) { 00044 str source(replacements.substr(i,1)); 00045 str dest(quotechar + source); 00046 size_t idx = 0; 00047 do { 00048 idx = ret.find(source,idx); 00049 if (idx != str::npos) { 00050 ret.replace(idx, 1, dest); 00051 // skip to next unknown char. 00052 idx += 2; 00053 } 00054 } while (idx != str::npos); 00055 } 00056 return ret; 00057 } 00058 00066 template <class str> 00067 str wxQuoteString(const str & arg) 00068 { 00069 #ifdef WIN32 00070 // escape all strange chars with ^ 00071 // is this true for create process? 00072 return wxQuoteStringInternal(arg, str(wxT("^")), str(wxT("^ \"$|()"))); 00073 #else 00074 return wxQuoteStringInternal(arg, str(wxT("\\")), str(wxT("\\ ~$\"|'`{}[]()"))); 00075 #endif 00076 } 00077 00082 template <class str> 00083 str wxQuoteFilename(const str & arg) 00084 { 00085 #ifdef WIN32 00086 str ret; 00087 // just a guess 00088 ret = wxQuoteStringInternal(arg, str(wxT("^")), str(wxT("\""))); 00089 return str(wxT("\"")) + ret + str(wxT("\"")); 00090 #else 00091 str ret; 00092 ret = wxQuoteStringInternal(arg, str(wxT("\\")), str(wxT("\""))); 00093 return str(wxT("\"")) + ret + str(wxT("\"")); 00094 #endif 00095 } 00096 00097 inline wxString doubleTowxString(double d, int digits=-1) 00098 { 00099 std::string t = doubleToString(d, digits); 00100 return wxString(t.c_str(), wxConvLocal); 00101 } 00102 00103 } // namespace 00104 00105 #endif // HUGIN_WXPLATFORM_H
1.3.9.1