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, 2019 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 
44 {
50 };
51 
52 wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext );
53 
54 wxString UnescapeString( const wxString& aSource );
55 
69 int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize );
70 
79 int ReadDelimitedText( wxString* aDest, const char* aSource );
80 
90 std::string EscapedUTF8( wxString aString );
91 
95 wxString EscapedHTML( const wxString& aString );
96 
102 char* GetLine( FILE* aFile, char* Line, int* LineNum = NULL, int SizeLine = 255 );
103 
109 char* StrPurge( char* text );
110 
114 wxString DateAndTime();
115 
130 int StrNumCmp( const wxString& aString1, const wxString& aString2, bool aIgnoreCase = false );
131 
137 bool WildCompareString( const wxString& pattern,
138  const wxString& string_to_tst,
139  bool case_sensitive = true );
140 
148 int ValueStringCompare( wxString strFWord, wxString strSWord );
149 
156 int SplitString( wxString strToSplit,
157  wxString* strBeginning,
158  wxString* strDigits,
159  wxString* strEnd );
160 
167 int GetTrailingInt( const wxString& aStr );
168 
172 wxString GetIllegalFileNameWxChars();
173 
188 bool ReplaceIllegalFileNameChars( std::string* aName, int aReplaceChar = 0 );
189 bool ReplaceIllegalFileNameChars( wxString& aName, int aReplaceChar = 0 );
190 
191 #ifndef HAVE_STRTOKR
192 // common/strtok_r.c optionally:
193 extern "C" char* strtok_r( char* str, const char* delim, char** nextp );
194 #endif
195 
201 {
202  bool operator() (const wxString& strA, const wxString& strB ) const
203  {
204  wxString::const_reverse_iterator sA = strA.rbegin();
205  wxString::const_reverse_iterator eA = strA.rend();
206 
207  wxString::const_reverse_iterator sB = strB.rbegin();
208  wxString::const_reverse_iterator eB = strB.rend();
209 
210  if( strA.empty() )
211  {
212  if( strB.empty() )
213  return false;
214 
215  // note: this rule implies that a null string is first in the sort order
216  return true;
217  }
218 
219  if( strB.empty() )
220  return false;
221 
222  while( sA != eA && sB != eB )
223  {
224  if( (*sA) == (*sB) )
225  {
226  ++sA;
227  ++sB;
228  continue;
229  }
230 
231  if( (*sA) < (*sB) )
232  return true;
233  else
234  return false;
235  }
236 
237  if( sB == eB )
238  return false;
239 
240  return true;
241  }
242 };
243 
244 #endif // KICAD_STRING_H_
wxString GetIllegalFileNameWxChars()
Definition: string.cpp:674
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
ESCAPE_CONTEXT
Escape/Unescape routines to safely encode reserved-characters in various contexts.
Definition: kicad_string.h:43
A helper for sorting strings from the rear.
Definition: kicad_string.h:200
wxString DateAndTime()
Definition: string.cpp:345
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
int GetTrailingInt(const wxString &aStr)
Gets the trailing int, if any, from a string.
Definition: string.cpp:650
int ValueStringCompare(wxString strFWord, wxString strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
Definition: string.cpp:541
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase=false)
Compare two strings with alphanumerical content.
Definition: string.cpp:354
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar=0)
Checks aName for illegal file name characters.
Definition: string.cpp:680
bool operator()(const wxString &strA, const wxString &strB) const
Definition: kicad_string.h:202
#define NULL
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:286
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
Definition: string.cpp:50
int SplitString(wxString strToSplit, wxString *strBeginning, wxString *strDigits, wxString *strEnd)
Breaks a string into three parts: he alphabetic preamble, the numeric part, and any alphabetic ending...
Definition: string.cpp:589
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive=true)
Compare a string against wild card (* and ?) pattern using the usual rules.
Definition: string.cpp:433
char * strtok_r(char *str, const char *delim, char **nextp)
char * GetLine(FILE *aFile, char *Line, int *LineNum=NULL, int SizeLine=255)
Read one line line from aFile.
Definition: string.cpp:329
int ReadDelimitedText(char *aDest, const char *aSource, int aDestSize)
Copy bytes from aSource delimited string segment to aDest buffer.
Definition: string.cpp:200
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310