X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33ac7e6f01acbac1cff0ad400d8ea7f0bfd0a62f..ffafd8a55bb0b8fb4236e4522792a6b143813609:/src/common/encconv.cpp diff --git a/src/common/encconv.cpp b/src/common/encconv.cpp index 7a288485d4..b444d0794e 100644 --- a/src/common/encconv.cpp +++ b/src/common/encconv.cpp @@ -7,7 +7,7 @@ // Licence: wxWindows Licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "encconv.h" #endif @@ -18,6 +18,8 @@ #pragma hdrstop #endif +#if wxUSE_FONTMAP + #include "wx/encconv.h" #include @@ -35,6 +37,11 @@ typedef wchar_t tchar; typedef char tchar; #endif +#ifdef __WXWINCE__ +#undef LINKAGEMODE +#define LINKAGEMODE __cdecl +#endif + static wxUint16* LINKAGEMODE GetEncTable(wxFontEncoding enc) { for (int i = 0; encodings_list[i].table != NULL; i++) @@ -50,9 +57,7 @@ typedef struct { wxUint8 c; } CharsetItem; - - -static int LINKAGEMODE CompareCharsetItems(const void *i1, const void *i2) +extern "C" int LINKAGEMODE CompareCharsetItems(const void *i1, const void *i2) { return ( ((CharsetItem*)i1) -> u - ((CharsetItem*)i2) -> u ); } @@ -84,7 +89,7 @@ wxEncodingConverter::wxEncodingConverter() bool wxEncodingConverter::Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method) { unsigned i; - wxUint16 *in_tbl = NULL, *out_tbl = NULL; + wxUint16 *in_tbl, *out_tbl = NULL; if (m_Table) {delete[] m_Table; m_Table = NULL;} @@ -116,10 +121,8 @@ bool wxEncodingConverter::Init(wxFontEncoding input_enc, wxFontEncoding output_e m_Table[out_tbl[i]] = (tchar)(128 + i); m_UnicodeInput = TRUE; - return TRUE; } - - else + else // input !Unicode { if ((in_tbl = GetEncTable(input_enc)) == NULL) return FALSE; if (output_enc != wxFONTENCODING_UNICODE) @@ -135,7 +138,9 @@ bool wxEncodingConverter::Init(wxFontEncoding input_enc, wxFontEncoding output_e for (i = 0; i < 128; i++) m_Table[128 + i] = (tchar)in_tbl[i]; return TRUE; } - else + // FIXME: write a substitute for bsearch +#ifndef __WXWINCE__ + else // output !Unicode { CharsetItem *rev = BuildReverseTable(out_tbl); CharsetItem *item; @@ -155,18 +160,20 @@ bool wxEncodingConverter::Init(wxFontEncoding input_enc, wxFontEncoding output_e m_Table[128 + i] = (wchar_t)(128 + i); #else m_Table[128 + i] = (char)(128 + i); -#endif +#endif } delete[] rev; - return TRUE; } +#endif // !__WXWINCE__ } + + return TRUE; } -void wxEncodingConverter::Convert(const char* input, char* output) +void wxEncodingConverter::Convert(const char* input, char* output) const { wxASSERT_MSG(!m_UnicodeOutput, wxT("You cannot convert to unicode if output is const char*!")); wxASSERT_MSG(!m_UnicodeInput, wxT("You cannot convert from unicode if input is const char*!")); @@ -180,7 +187,7 @@ void wxEncodingConverter::Convert(const char* input, char* output) return; } - wxASSERT_MSG(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); + wxCHECK_RET(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); for (i = input, o = output; *i != 0;) *(o++) = (char)(m_Table[(wxUint8)*(i++)]); @@ -190,7 +197,7 @@ void wxEncodingConverter::Convert(const char* input, char* output) #if wxUSE_WCHAR_T -void wxEncodingConverter::Convert(const char* input, wchar_t* output) +void wxEncodingConverter::Convert(const char* input, wchar_t* output) const { wxASSERT_MSG(m_UnicodeOutput, wxT("You cannot convert to 8-bit if output is const wchar_t*!")); wxASSERT_MSG(!m_UnicodeInput, wxT("You cannot convert from unicode if input is const char*!")); @@ -206,7 +213,7 @@ void wxEncodingConverter::Convert(const char* input, wchar_t* output) return; } - wxASSERT_MSG(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); + wxCHECK_RET(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); for (i = input, o = output; *i != 0;) *(o++) = (wchar_t)(m_Table[(wxUint8)*(i++)]); @@ -215,7 +222,7 @@ void wxEncodingConverter::Convert(const char* input, wchar_t* output) -void wxEncodingConverter::Convert(const wchar_t* input, char* output) +void wxEncodingConverter::Convert(const wchar_t* input, char* output) const { wxASSERT_MSG(!m_UnicodeOutput, wxT("You cannot convert to unicode if output is const char*!")); wxASSERT_MSG(m_UnicodeInput, wxT("You cannot convert from 8-bit if input is const wchar_t*!")); @@ -231,7 +238,7 @@ void wxEncodingConverter::Convert(const wchar_t* input, char* output) return; } - wxASSERT_MSG(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); + wxCHECK_RET(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); for (i = input, o = output; *i != 0;) *(o++) = (char)(m_Table[(wxUint16)*(i++)]); @@ -240,7 +247,7 @@ void wxEncodingConverter::Convert(const wchar_t* input, char* output) -void wxEncodingConverter::Convert(const wchar_t* input, wchar_t* output) +void wxEncodingConverter::Convert(const wchar_t* input, wchar_t* output) const { wxASSERT_MSG(m_UnicodeOutput, wxT("You cannot convert to 8-bit if output is const wchar_t*!")); wxASSERT_MSG(m_UnicodeInput, wxT("You cannot convert from 8-bit if input is const wchar_t*!")); @@ -257,7 +264,7 @@ void wxEncodingConverter::Convert(const wchar_t* input, wchar_t* output) return; } - wxASSERT_MSG(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); + wxCHECK_RET(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); for (i = input, o = output; *i != 0;) *(o++) = (wchar_t)(m_Table[(wxUint8)*(i++)]); @@ -267,21 +274,27 @@ void wxEncodingConverter::Convert(const wchar_t* input, wchar_t* output) #endif // wxUSE_WCHAR_T -wxString wxEncodingConverter::Convert(const wxString& input) +wxString wxEncodingConverter::Convert(const wxString& input) const { if (m_JustCopy) return input; wxString s; const wxChar *i; - wxASSERT_MSG(m_Table != NULL, wxT("You must call wxEncodingConverter::Init() before actually converting!")); + wxCHECK_MSG(m_Table != NULL, s, + wxT("You must call wxEncodingConverter::Init() before actually converting!")); if (m_UnicodeInput) + { for (i = input.c_str(); *i != 0; i++) s << (wxChar)(m_Table[(wxUint16)*i]); + } else + { for (i = input.c_str(); *i != 0; i++) s << (wxChar)(m_Table[(wxUint8)*i]); + } + return s; } @@ -375,7 +388,14 @@ static wxFontEncoding }; - +static bool FindEncoding(const wxFontEncodingArray& arr, wxFontEncoding f) +{ + for (wxFontEncodingArray::const_iterator it = arr.begin(), en = arr.end(); + it != en; ++it) + if (*it == f) + return true; + return false; +} wxFontEncodingArray wxEncodingConverter::GetPlatformEquivalents(wxFontEncoding enc, int platform) { @@ -404,9 +424,9 @@ wxFontEncodingArray wxEncodingConverter::GetPlatformEquivalents(wxFontEncoding e if (EquivalentEncodings[clas][i][e] == enc) { for (f = EquivalentEncodings[clas][platform]; *f != STOP; f++) - if (*f == enc) arr.Add(enc); + if (*f == enc) arr.push_back(enc); for (f = EquivalentEncodings[clas][platform]; *f != STOP; f++) - if (arr.Index(*f) == wxNOT_FOUND) arr.Add(*f); + if (!FindEncoding(arr, *f)) arr.push_back(*f); i = NUM_OF_PLATFORMS/*hack*/; break; } clas++; @@ -434,7 +454,7 @@ wxFontEncodingArray wxEncodingConverter::GetAllEquivalents(wxFontEncoding enc) { for (j = 0; j < NUM_OF_PLATFORMS; j++) for (f = EquivalentEncodings[clas][j]; *f != STOP; f++) - if (arr.Index(*f) == wxNOT_FOUND) arr.Add(*f); + if (!FindEncoding(arr, *f)) arr.push_back(*f); i = NUM_OF_PLATFORMS/*hack*/; break; } clas++; @@ -442,3 +462,5 @@ wxFontEncodingArray wxEncodingConverter::GetAllEquivalents(wxFontEncoding enc) return arr; } + +#endif // wxUSE_FONTMAP