Home | History | Annotate | Download | only in Common
      1 // Common/StringConvert.h
      2 
      3 #ifndef __COMMON_STRING_CONVERT_H
      4 #define __COMMON_STRING_CONVERT_H
      5 
      6 #include "MyString.h"
      7 #include "MyWindows.h"
      8 
      9 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
     10 
     11 // optimized versions that work faster for ASCII strings
     12 void MultiByteToUnicodeString2(UString &dest, const AString &srcString, UINT codePage = CP_ACP);
     13 void UnicodeStringToMultiByte2(AString &dest, const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed);
     14 void UnicodeStringToMultiByte2(AString &dest, const UString &srcString, UINT codePage);
     15 
     16 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);
     17 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);
     18 
     19 inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)
     20   { return unicodeString; }
     21 inline const UString& GetUnicodeString(const UString &unicodeString)
     22   { return unicodeString; }
     23 inline UString GetUnicodeString(const AString &ansiString)
     24   { return MultiByteToUnicodeString(ansiString); }
     25 inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
     26   { return MultiByteToUnicodeString(multiByteString, codePage); }
     27 inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)
     28   { return unicodeString; }
     29 inline const UString& GetUnicodeString(const UString &unicodeString, UINT)
     30   { return unicodeString; }
     31 
     32 inline const char* GetAnsiString(const char* ansiString)
     33   { return ansiString; }
     34 inline const AString& GetAnsiString(const AString &ansiString)
     35   { return ansiString; }
     36 inline AString GetAnsiString(const UString &unicodeString)
     37   { return UnicodeStringToMultiByte(unicodeString); }
     38 
     39 inline const char* GetOemString(const char* oemString)
     40   { return oemString; }
     41 inline const AString& GetOemString(const AString &oemString)
     42   { return oemString; }
     43 inline AString GetOemString(const UString &unicodeString)
     44   { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }
     45 
     46 
     47 #ifdef _UNICODE
     48   inline const wchar_t* GetSystemString(const wchar_t* unicodeString)
     49     { return unicodeString;}
     50   inline const UString& GetSystemString(const UString &unicodeString)
     51     { return unicodeString;}
     52   inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)
     53     { return unicodeString;}
     54   inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)
     55     { return unicodeString;}
     56   inline UString GetSystemString(const AString &multiByteString, UINT codePage)
     57     { return MultiByteToUnicodeString(multiByteString, codePage);}
     58   inline UString GetSystemString(const AString &multiByteString)
     59     { return MultiByteToUnicodeString(multiByteString);}
     60 #else
     61   inline const char* GetSystemString(const char *ansiString)
     62     { return ansiString; }
     63   inline const AString& GetSystemString(const AString &multiByteString, UINT)
     64     { return multiByteString; }
     65   inline const char * GetSystemString(const char *multiByteString, UINT)
     66     { return multiByteString; }
     67   inline AString GetSystemString(const UString &unicodeString)
     68     { return UnicodeStringToMultiByte(unicodeString); }
     69   inline AString GetSystemString(const UString &unicodeString, UINT codePage)
     70     { return UnicodeStringToMultiByte(unicodeString, codePage); }
     71 #endif
     72 
     73 #ifndef UNDER_CE
     74 AString SystemStringToOemString(const CSysString &srcString);
     75 #endif
     76 
     77 #endif
     78