KiCad PCB EDA Suite
kicad_string.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) 2004 KiCad Developers, see change_log.txt for contributors.
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 KICAD_STRING_H_
31 #define KICAD_STRING_H_
32 
33 #include "config.h"
34 
35 #include <wx/string.h>
36 #include <wx/filename.h>
37 
38 
46 wxString EscapeString( const wxString& aSource );
47 
48 wxString UnescapeString( const wxString& aSource );
49 
63 int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize );
64 
74 int ReadDelimitedText( wxString* aDest, const char* aSource );
75 
85 std::string EscapedUTF8( const wxString& aString );
86 
90 wxString EscapedHTML( const wxString& aString );
91 
97 char* GetLine( FILE* aFile, char* Line, int* LineNum = NULL, int SizeLine = 255 );
98 
104 char* StrPurge( char* text );
105 
110 wxString DateAndTime();
111 
129 int StrNumCmp( const wxString& aString1, const wxString& aString2, int aLength = INT_MAX,
130  bool aIgnoreCase = false );
131 
137 bool WildCompareString( const wxString& pattern,
138  const wxString& string_to_tst,
139  bool case_sensitive = true );
140 
149 int ValueStringCompare( wxString strFWord, wxString strSWord );
150 
159 int RefDesStringCompare( wxString lhs, wxString rhs );
160 
169 int SplitString( wxString strToSplit,
170  wxString* strBeginning,
171  wxString* strDigits,
172  wxString* strEnd );
173 
178 wxString GetIllegalFileNameWxChars();
179 
195 bool ReplaceIllegalFileNameChars( std::string* aName, int aReplaceChar = 0 );
196 bool ReplaceIllegalFileNameChars( wxString& aName, int aReplaceChar = 0 );
197 
198 #ifndef HAVE_STRTOKR
199 // common/strtok_r.c optionally:
200 extern "C" char* strtok_r( char* str, const char* delim, char** nextp );
201 #endif
202 
208 {
209  bool operator() (const wxString& strA, const wxString& strB ) const
210  {
211  wxString::const_reverse_iterator sA = strA.rbegin();
212  wxString::const_reverse_iterator eA = strA.rend();
213 
214  wxString::const_reverse_iterator sB = strB.rbegin();
215  wxString::const_reverse_iterator eB = strB.rend();
216 
217  if( strA.empty() )
218  {
219  if( strB.empty() )
220  return false;
221 
222  // note: this rule implies that a null string is first in the sort order
223  return true;
224  }
225 
226  if( strB.empty() )
227  return false;
228 
229  while( sA != eA && sB != eB )
230  {
231  if( (*sA) == (*sB) )
232  {
233  ++sA;
234  ++sB;
235  continue;
236  }
237 
238  if( (*sA) < (*sB) )
239  return true;
240  else
241  return false;
242  }
243 
244  if( sB == eB )
245  return false;
246 
247  return true;
248  }
249 };
250 
251 #endif // KICAD_STRING_H_
wxString GetIllegalFileNameWxChars()
Function GetIllegalFileNameWxChars.
Definition: string.cpp:644
A helper for sorting strings from the rear.
Definition: kicad_string.h:207
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:306
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:214
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:93
bool operator()(const wxString &strA, const wxString &strB) const
Definition: kicad_string.h:209
int ValueStringCompare(wxString strFWord, wxString strSWord)
Function ValueStringCompare acts just like the strcmp function but handles numbers and modifiers with...
Definition: string.cpp:494
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar=0)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:650
const string & str
Definition: json11.cpp:596
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:247
int SplitString(wxString strToSplit, wxString *strBeginning, wxString *strDigits, wxString *strEnd)
Function SplitString breaks a string into three parts.
Definition: string.cpp:583
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive=true)
Function WildCompareString compares a string against wild card (* and ?) pattern using the usual rule...
Definition: string.cpp:377
YYCODETYPE lhs
char * strtok_r(char *str, const char *delim, char **nextp)
char * GetLine(FILE *aFile, char *Line, int *LineNum=NULL, int SizeLine=255)
Function GetLine reads one line line from aFile.
Definition: string.cpp:290
wxString EscapeString(const wxString &aSource)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
Definition: string.cpp:49
int ReadDelimitedText(char *aDest, const char *aSource, int aDestSize)
Function ReadDelimitedText copies bytes from aSource delimited string segment to aDest buffer...
Definition: string.cpp:165
int StrNumCmp(const wxString &aString1, const wxString &aString2, int aLength=INT_MAX, bool aIgnoreCase=false)
Function StrNumCmp is a routine compatible with qsort() to sort by alphabetical order.
Definition: string.cpp:315
char * StrPurge(char *text)
Function StrPurge removes leading and training spaces, tabs and end of line chars in text return a po...
Definition: string.cpp:271
int RefDesStringCompare(wxString lhs, wxString rhs)
Function RefDesStringCompare acts just like the strcmp function but treats numbers within the string ...
Definition: string.cpp:542