~ubuntu-branches/ubuntu/precise/amule-adunanza/precise

« back to all changes in this revision

Viewing changes to src/libs/common/StringFunctions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-18 21:16:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100218211623-gptwe60zx1knfkmu
Tags: 2010.1+2.2.6-0ubuntu1
* New upstream release (LP: #524697)
  - Drop manpages_spelling_fixes.diff fixed by upstream
  - Drop cryptopp-reference.diff fixed by upstream
  - Bump Standards-Version no changes required
  - Update install files (amule -> amuleadunanza)
  - debian/rules: amule.xpm -> amuleadunanza.xpm
  - Add README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// This file is part of the aMule Project.
3
3
//
4
 
// Copyright (c) 2004-2008 Angel Vidal Veiga - Kry (kry@amule.org)
5
 
// Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
 
4
// Copyright (c) 2004-2009 Angel Vidal Veiga - Kry (kry@amule.org)
 
5
// Copyright (c) 2003-2009 aMule Team ( admin@amule.org / http://www.amule.org )
6
6
//
7
7
// Any parts of this program derived from the xMule, lMule or eMule project,
8
8
// or contributed by third-party developers are copyrighted by their
34
34
#include <wx/uri.h>             // Needed for wxURI
35
35
 
36
36
// Implementation of the non-inlines
 
37
 
 
38
// ADUNANZA BEGIN
 
39
// Backport da aMule SVN r9992 per client testuali e console non-UTF8
 
40
 
 
41
//
 
42
// Conversion of wxString so it can be used by printf() in a console
 
43
// On some platforms (Windows) the console allows only "plain" characters,
 
44
// so try to convert as much as possible and replace the others with '?'.
 
45
// On other platforms (some Linux) wxConvLocal silently converts to UTF8
 
46
// so the console can show even Chinese chars.
 
47
//
 
48
Unicode2CharBuf unicode2char(const wxChar* s)
 
49
{
 
50
        // First try the straight way.
 
51
        Unicode2CharBuf buf1(wxConvLocal.cWX2MB(s));
 
52
        if ((const char *) buf1) {
 
53
                return buf1;
 
54
        }
 
55
        // Failed. Try to convert as much as possible.
 
56
        size_t len = wxStrlen(s);
 
57
        size_t maxlen = len * 4;                // Allow for an encoding of up to 4 byte per char.
 
58
        wxCharBuffer buf(maxlen + 1);   // This is wasteful, but the string is used temporary anyway.
 
59
        char * data = buf.data();
 
60
        for (size_t i = 0, pos = 0; i < len; i++) {
 
61
                size_t len_char = wxConvLocal.FromWChar(data + pos, maxlen - pos, s + i, 1);
 
62
                if (len_char != wxCONV_FAILED) {
 
63
                        pos += len_char - 1;
 
64
                } else if (pos < maxlen) {
 
65
                        data[pos++] = '?';
 
66
                        data[pos] = 0;
 
67
                }
 
68
        }
 
69
        return buf;
 
70
}
 
71
 
 
72
// ADUNANZA END
 
73
 
37
74
static byte base16Chars[17] = "0123456789ABCDEF";
38
75
 
39
76
wxString URLEncode(const wxString& sIn)