changeset 54:f544cef2cd21 draft

safer wxGetTranslation wrapper git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@67 1a98c847-1fd6-4fd8-948a-caf3550aa51b
author s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
date Wed, 17 Feb 2010 23:55:43 +0000
parents 8b94dc81cb8d
children a71b4cffb922
files serialize.h util.cpp util.h
diffstat 3 files changed, 34 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/serialize.h
+++ b/serialize.h
@@ -19,7 +19,7 @@
 class CDataStream;
 class CAutoFile;
 
-static const int VERSION = 202;
+static const int VERSION = 203;
 static const char* pszSubVer = ".0";
 
 
--- a/util.cpp
+++ b/util.cpp
@@ -431,6 +431,35 @@
 }
 
 
+const char* wxGetTranslation(const char* pszEnglish)
+{
+    // Wrapper of wxGetTranslation returning the same const char* type as was passed in
+    static CCriticalSection cs;
+    CRITICAL_BLOCK(cs)
+    {
+        // Look in cache
+        static map<string, char*> mapCache;
+        map<string, char*>::iterator mi = mapCache.find(pszEnglish);
+        if (mi != mapCache.end())
+            return (*mi).second;
+
+        // wxWidgets translation
+        const char* pszTranslated = wxGetTranslation(wxString(pszEnglish, wxConvUTF8)).utf8_str();
+        if (strcmp(pszEnglish, pszTranslated) == 0)
+            return pszEnglish;
+
+        // Add to cache, memory doesn't need to be freed
+        char* pszCached = new char[strlen(pszTranslated)+1];
+        strcpy(pszCached, pszTranslated);
+        mapCache[pszEnglish] = pszCached;
+        return pszCached;
+    }
+}
+
+
+
+
+
 
 
 
--- a/util.h
+++ b/util.h
@@ -136,6 +136,7 @@
 vector<unsigned char> ParseHex(const char* psz);
 vector<unsigned char> ParseHex(const std::string& str);
 void ParseParameters(int argc, char* argv[]);
+const char* wxGetTranslation(const char* psz);
 int GetFilesize(FILE* file);
 void GetDataDir(char* pszDirRet);
 string GetDataDir();
@@ -340,11 +341,9 @@
         ++it;
 }
 
-inline const char* wxGetTranslation(const char* psz)
-{
-    // Return translated UTF-8 const char*
-    return wxGetTranslation(wxString(psz, wxConvUTF8)).utf8_str();
-}
+
+
+