KiCad PCB EDA Suite
str_rsort.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 #ifndef STR_RSORT_H
31 #define STR_RSORT_H
32 
33 #include <wx/string.h>
34 
35 namespace S3D
36 {
37 
39  {
40  bool operator() (const wxString& strA, const wxString& strB ) const
41  {
42  // sort a wxString using the reverse character order; for 3d model
43  // filenames this will typically be a much faster operation than
44  // a normal alphabetic sort
45  wxString::const_reverse_iterator sA = strA.rbegin();
46  wxString::const_reverse_iterator eA = strA.rend();
47 
48  wxString::const_reverse_iterator sB = strB.rbegin();
49  wxString::const_reverse_iterator eB = strB.rend();
50 
51  if( strA.empty() )
52  {
53  if( strB.empty() )
54  return false;
55 
56  // note: this rule implies that a null string is first in the sort order
57  return true;
58  }
59 
60  if( strB.empty() )
61  return false;
62 
63  while( sA != eA && sB != eB )
64  {
65  if( (*sA) == (*sB) )
66  {
67  ++sA;
68  ++sB;
69  continue;
70  }
71 
72  if( (*sA) < (*sB) )
73  return true;
74  else
75  return false;
76  }
77 
78  if( sB == eB )
79  return false;
80 
81  return true;
82  }
83  };
84 
85 }; // end NAMESPACE
86 
87 #endif // STR_RSORT_H
bool operator()(const wxString &strA, const wxString &strB) const
Definition: str_rsort.h:40