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 
59 wxString PrettyPrintForMenu( const wxString& aString );
60 
74 int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize );
75 
84 int ReadDelimitedText( wxString* aDest, const char* aSource );
85 
95 std::string EscapedUTF8( wxString aString );
96 
100 wxString EscapedHTML( const wxString& aString );
101 
107 char* GetLine( FILE* aFile, char* Line, int* LineNum = NULL, int SizeLine = 255 );
108 
114 char* StrPurge( char* text );
115 
119 wxString DateAndTime();
120 
135 int StrNumCmp( const wxString& aString1, const wxString& aString2, bool aIgnoreCase = false );
136 
142 bool WildCompareString( const wxString& pattern,
143  const wxString& string_to_tst,
144  bool case_sensitive = true );
145 
153 int ValueStringCompare( wxString strFWord, wxString strSWord );
154 
161 int SplitString( wxString strToSplit,
162  wxString* strBeginning,
163  wxString* strDigits,
164  wxString* strEnd );
165 
172 int GetTrailingInt( const wxString& aStr );
173 
177 wxString GetIllegalFileNameWxChars();
178 
193 bool ReplaceIllegalFileNameChars( std::string* aName, int aReplaceChar = 0 );
194 bool ReplaceIllegalFileNameChars( wxString& aName, int aReplaceChar = 0 );
195 
196 #ifndef HAVE_STRTOKR
197 // common/strtok_r.c optionally:
198 extern "C" char* strtok_r( char* str, const char* delim, char** nextp );
199 #endif
200 
206 {
207  bool operator() (const wxString& strA, const wxString& strB ) const
208  {
209  wxString::const_reverse_iterator sA = strA.rbegin();
210  wxString::const_reverse_iterator eA = strA.rend();
211 
212  wxString::const_reverse_iterator sB = strB.rbegin();
213  wxString::const_reverse_iterator eB = strB.rend();
214 
215  if( strA.empty() )
216  {
217  if( strB.empty() )
218  return false;
219 
220  // note: this rule implies that a null string is first in the sort order
221  return true;
222  }
223 
224  if( strB.empty() )
225  return false;
226 
227  while( sA != eA && sB != eB )
228  {
229  if( (*sA) == (*sB) )
230  {
231  ++sA;
232  ++sB;
233  continue;
234  }
235 
236  if( (*sA) < (*sB) )
237  return true;
238  else
239  return false;
240  }
241 
242  if( sB == eB )
243  return false;
244 
245  return true;
246  }
247 };
248 
249 #endif // KICAD_STRING_H_
wxString GetIllegalFileNameWxChars()
Definition: string.cpp:708
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:283
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:205
wxString DateAndTime()
Definition: string.cpp:379
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:684
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:575
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase=false)
Compare two strings with alphanumerical content.
Definition: string.cpp:388
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar=0)
Checks aName for illegal file name characters.
Definition: string.cpp:714
bool operator()(const wxString &strA, const wxString &strB) const
Definition: kicad_string.h:207
#define NULL
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:320
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:623
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:467
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:363
wxString PrettyPrintForMenu(const wxString &aString)
Remove markup (such as overbar or subscript) that we can't render to menu items.
int ReadDelimitedText(char *aDest, const char *aSource, int aDestSize)
Copy bytes from aSource delimited string segment to aDest buffer.
Definition: string.cpp:234
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:344