~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to common/prependpath.cpp

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <macros.h>
 
3
#include <fctsys.h>
 
4
#include <wx/filename.h>
 
5
 
 
6
 
 
7
 
 
8
#if !wxCHECK_VERSION( 3, 0, 0 )
 
9
 
 
10
// implement missing wx2.8 function until >= wx3.0 pervades.
 
11
static wxString wxJoin(const wxArrayString& arr, const wxChar sep,
 
12
                const wxChar escape = '\\')
 
13
{
 
14
    size_t count = arr.size();
 
15
    if ( count == 0 )
 
16
        return wxEmptyString;
 
17
 
 
18
    wxString str;
 
19
 
 
20
    // pre-allocate memory using the estimation of the average length of the
 
21
    // strings in the given array: this is very imprecise, of course, but
 
22
    // better than nothing
 
23
    str.reserve(count*(arr[0].length() + arr[count-1].length()) / 2);
 
24
 
 
25
    if ( escape == wxT('\0') )
 
26
    {
 
27
        // escaping is disabled:
 
28
        for ( size_t i = 0; i < count; i++ )
 
29
        {
 
30
            if ( i )
 
31
                str += sep;
 
32
            str += arr[i];
 
33
        }
 
34
    }
 
35
    else // use escape character
 
36
    {
 
37
        for ( size_t n = 0; n < count; n++ )
 
38
        {
 
39
            if ( n )
 
40
                str += sep;
 
41
 
 
42
            for ( wxString::const_iterator i = arr[n].begin(),
 
43
                                         end = arr[n].end();
 
44
                  i != end;
 
45
                  ++i )
 
46
            {
 
47
                const wxChar ch = *i;
 
48
                if ( ch == sep )
 
49
                    str += escape;      // escape this separator
 
50
                str += ch;
 
51
            }
 
52
        }
 
53
    }
 
54
 
 
55
    str.Shrink(); // release extra memory if we allocated too much
 
56
    return str;
 
57
}
 
58
#endif
 
59
 
 
60
 
 
61
/// Put aPriorityPath in front of all paths in the value of aEnvVar.
 
62
const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath )
 
63
{
 
64
    wxPathList  paths;
 
65
 
 
66
    paths.AddEnvList( aEnvVar );
 
67
    paths.Insert( aPriorityPath, 0 );
 
68
 
 
69
    return wxJoin( paths, wxPATH_SEP[0] );
 
70
}