KiCad PCB EDA Suite
kicad_string.h File Reference
#include "config.h"
#include <wx/string.h>
#include <wx/filename.h>

Go to the source code of this file.

Classes

struct  rsort_wxString
 A helper for sorting strings from the rear. More...
 

Enumerations

enum  ESCAPE_CONTEXT {
  CTX_NETNAME, CTX_LIBID, CTX_QUOTED_STR, CTX_DELIMITED_STR,
  CTX_FILENAME
}
 Escape/Unescape routines to safely encode reserved-characters in various contexts. More...
 

Functions

wxString EscapeString (const wxString &aSource, ESCAPE_CONTEXT aContext)
 These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are: (a) not legal in filenames (b) used as control characters in LIB_IDs (c) used to delineate hierarchical paths. More...
 
wxString UnescapeString (const wxString &aSource)
 
wxString PrettyPrintForMenu (const wxString &aString)
 Remove markup (such as overbar or subscript) that we can't render to menu items. More...
 
int ReadDelimitedText (char *aDest, const char *aSource, int aDestSize)
 Copy bytes from aSource delimited string segment to aDest buffer. More...
 
int ReadDelimitedText (wxString *aDest, const char *aSource)
 Copy bytes from aSource delimited string segment to aDest wxString. More...
 
std::string EscapedUTF8 (wxString aString)
 Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form. More...
 
wxString EscapedHTML (const wxString &aString)
 Return a new wxString escaped for embedding in HTML. More...
 
char * GetLine (FILE *aFile, char *Line, int *LineNum=NULL, int SizeLine=255)
 Read one line line from aFile. More...
 
char * StrPurge (char *text)
 Remove leading and training spaces, tabs and end of line chars in text. More...
 
wxString DateAndTime ()
 
int StrNumCmp (const wxString &aString1, const wxString &aString2, bool aIgnoreCase=false)
 Compare two strings with alphanumerical content. More...
 
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. More...
 
int ValueStringCompare (wxString strFWord, wxString strSWord)
 Compare strings like the strcmp function but handle numbers and modifiers within the string text correctly for sorting. More...
 
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. More...
 
int GetTrailingInt (const wxString &aStr)
 Gets the trailing int, if any, from a string. More...
 
wxString GetIllegalFileNameWxChars ()
 
bool ReplaceIllegalFileNameChars (std::string *aName, int aReplaceChar=0)
 Checks aName for illegal file name characters. More...
 
bool ReplaceIllegalFileNameChars (wxString &aName, int aReplaceChar=0)
 
char * strtok_r (char *str, const char *delim, char **nextp)
 

Detailed Description

See also
common.h, string.cpp

Definition in file kicad_string.h.

Enumeration Type Documentation

◆ ESCAPE_CONTEXT

Escape/Unescape routines to safely encode reserved-characters in various contexts.

Enumerator
CTX_NETNAME 
CTX_LIBID 
CTX_QUOTED_STR 
CTX_DELIMITED_STR 
CTX_FILENAME 

Definition at line 43 of file kicad_string.h.

Function Documentation

◆ DateAndTime()

wxString DateAndTime ( )
Returns
a string giving the current date and time.

Definition at line 379 of file string.cpp.

380 {
381  wxDateTime datetime = wxDateTime::Now();
382 
383  datetime.SetCountry( wxDateTime::Country_Default );
384  return datetime.Format( wxDefaultDateTimeFormat, wxDateTime::Local );
385 }

Referenced by GENDRILL_WRITER_BASE::GenDrillReportFile(), PLACE_FILE_EXPORTER::GenPositionData(), PLACE_FILE_EXPORTER::GenReportData(), NETLIST_EXPORTER_GENERIC::makeDesignHeader(), RecreateCmpFile(), EXCELLON_WRITER::writeEXCELLONHeader(), PCB_CALCULATOR_DATAFILE::WriteHeader(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and DIALOG_ERC::writeReport().

◆ EscapedHTML()

wxString EscapedHTML ( const wxString &  aString)

Return a new wxString escaped for embedding in HTML.

Definition at line 320 of file string.cpp.

321 {
322  wxString converted;
323 
324  for( wxUniChar c: aString )
325  {
326  if( c == '\"' )
327  converted += "&quot;";
328  else if( c == '\'' )
329  converted += "&apos;";
330  else if( c == '&' )
331  converted += "&amp;";
332  else if( c == '<' )
333  converted += "&lt;";
334  else if( c == '>' )
335  converted += "&gt;";
336  else
337  converted += c;
338  }
339 
340  return converted;
341 }

Referenced by FOOTPRINT_INFO_GENERATOR::GenerateHtml(), FOOTPRINT_INFO_GENERATOR::GetHtmlFieldRow(), FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf(), FOOTPRINT_INFO_GENERATOR::SetHtmlDesc(), FOOTPRINT_INFO_GENERATOR::SetHtmlKeywords(), and FOOTPRINT_INFO_GENERATOR::SetHtmlName().

◆ EscapedUTF8()

std::string EscapedUTF8 ( wxString  aString)

Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.

Any double quoted or back slashes are prefixed with a '\' byte and the form of this UTF8 byte string is compatible with function ReadDelimitedText().

Parameters
aStringis the input string to convert.
Returns
std::string - the escaped input text, without the wrapping double quotes.

Definition at line 283 of file string.cpp.

284 {
285  // No new-lines allowed in quoted strings
286  aString.Replace( "\r\n", "\r" );
287  aString.Replace( "\n", "\r" );
288 
289  std::string utf8 = TO_UTF8( aString );
290 
291  std::string ret;
292 
293  ret += '"';
294 
295  for( std::string::const_iterator it = utf8.begin(); it!=utf8.end(); ++it )
296  {
297  // this escaping strategy is designed to be compatible with ReadDelimitedText():
298  if( *it == '"' )
299  {
300  ret += '\\';
301  ret += '"';
302  }
303  else if( *it == '\\' )
304  {
305  ret += '\\'; // double it up
306  ret += '\\';
307  }
308  else
309  {
310  ret += *it;
311  }
312  }
313 
314  ret += '"';
315 
316  return ret;
317 }
#define TO_UTF8(wxstring)

References TO_UTF8.

Referenced by SCH_LEGACY_PLUGIN::Format(), PLACE_FILE_EXPORTER::GenReportData(), SCH_LEGACY_PLUGIN::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveField(), LEGACY_PLUGIN::SaveModule3D(), SCH_SEXPR_PLUGIN::saveSheet(), and SCH_LEGACY_PLUGIN::saveSheet().

◆ EscapeString()

wxString EscapeString ( const wxString &  aSource,
ESCAPE_CONTEXT  aContext 
)

These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are: (a) not legal in filenames (b) used as control characters in LIB_IDs (c) used to delineate hierarchical paths.

Definition at line 50 of file string.cpp.

51 {
52  wxString converted;
53 
54  for( wxUniChar c: aSource )
55  {
56  if( aContext == CTX_NETNAME )
57  {
58  if( c == '/' )
59  converted += "{slash}";
60  else if( c == '\n' || c == '\r' )
61  converted += ""; // drop
62  else
63  converted += c;
64  }
65  else if( aContext == CTX_LIBID )
66  {
67  if( c == '{' )
68  converted += "{brace}";
69  else if( c == ':' )
70  converted += "{colon}";
71  else if( c == '\n' || c == '\r' )
72  converted += ""; // drop
73  else
74  converted += c;
75  }
76  else if( aContext == CTX_QUOTED_STR )
77  {
78  if( c == '{' )
79  converted += "{brace}";
80  else if( c == '\"' )
81  converted += "{dblquote}";
82  else
83  converted += c;
84  }
85  else if( aContext == CTX_DELIMITED_STR )
86  {
87  if( c == '{' )
88  converted += "{brace}";
89  else if( c == ' ' )
90  converted += "{space}";
91  else if( c == '\t' )
92  converted += "{tab}";
93  else if( c == '\n' || c == '\r' )
94  converted += "{return}";
95  else
96  converted += c;
97  }
98  else if( aContext == CTX_FILENAME )
99  {
100  if( c == '{' )
101  converted += "{brace}";
102  else if( c == '/' )
103  converted += "{slash}";
104  else if( c == '\\' )
105  converted += "{backslash}";
106  else if( c == '\"' )
107  converted += "{dblquote}";
108  else if( c == '<' )
109  converted += "{lt}";
110  else if( c == '>' )
111  converted += "{gt}";
112  else if( c == '|' )
113  converted += "{bar}";
114  else if( c == ':' )
115  converted += "{colon}";
116  else if( c == '\t' )
117  converted += "{tab}";
118  else if( c == '\n' || c == '\r' )
119  converted += "{return}";
120  else
121  converted += c;
122  }
123  else
124  converted += c;
125  }
126 
127  return converted;
128 }

References CTX_DELIMITED_STR, CTX_FILENAME, CTX_LIBID, CTX_NETNAME, and CTX_QUOTED_STR.

Referenced by SCH_EDIT_TOOL::ChangeTextType(), DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), and FOOTPRINT_LIST_IMPL::WriteCacheToFile().

◆ GetIllegalFileNameWxChars()

wxString GetIllegalFileNameWxChars ( )
Returns
a wxString object containing the illegal file name characters for all platforms.

Definition at line 708 of file string.cpp.

709 {
711 }
static const char illegalFileNameChars[]
Illegal file name characters used to insure file names will be valid on all supported platforms.
Definition: string.cpp:40
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114

References FROM_UTF8(), and illegalFileNameChars.

Referenced by ReplaceIllegalFileNameChars().

◆ GetLine()

char* GetLine ( FILE *  aFile,
char *  Line,
int *  LineNum = NULL,
int  SizeLine = 255 
)

Read one line line from aFile.

Returns
a pointer the first useful line read by eliminating blank lines and comments.

Definition at line 363 of file string.cpp.

364 {
365  do {
366  if( fgets( Line, SizeLine, File ) == NULL )
367  return NULL;
368 
369  if( LineNum )
370  *LineNum += 1;
371 
372  } while( Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r' || Line[0] == 0 );
373 
374  strtok( Line, "\n\r" );
375  return Line;
376 }
#define NULL

References NULL.

Referenced by CVPCB_MAINFRAME::buildEquivalenceList().

◆ GetTrailingInt()

int GetTrailingInt ( const wxString &  aStr)

Gets the trailing int, if any, from a string.

Parameters
aStrthe string to check
Returns
the trailing int or 0 if none found

Definition at line 684 of file string.cpp.

685 {
686  int number = 0;
687  int base = 1;
688 
689  // Trim and extract the trailing numeric part
690  int index = aStr.Len() - 1;
691 
692  while( index >= 0 )
693  {
694  const char chr = aStr.GetChar( index );
695 
696  if( chr < '0' || chr > '9' )
697  break;
698 
699  number += ( chr - '0' ) * base;
700  base *= 10;
701  index--;
702  }
703 
704  return number;
705 }

Referenced by BOOST_AUTO_TEST_CASE(), MODULE::GetNextPadName(), and MODULE::IncrementReference().

◆ PrettyPrintForMenu()

wxString PrettyPrintForMenu ( const wxString &  aString)

Remove markup (such as overbar or subscript) that we can't render to menu items.

◆ ReadDelimitedText() [1/2]

int ReadDelimitedText ( char *  aDest,
const char *  aSource,
int  aDestSize 
)

Copy bytes from aSource delimited string segment to aDest buffer.

The extracted string will be null terminated even if truncation is necessary because aDestSize was not large enough.

Parameters
aDestis the destination byte buffer.
aSourceis the source bytes as a C string.
aDestSizeis the size of the destination byte buffer.
Returns
int - the number of bytes read from source, which may be more than the number copied, due to escaping of double quotes and the escape byte itself.
Deprecated:
should use the one which fetches a wxString, below.

Definition at line 234 of file string.cpp.

235 {
236  if( aDestSize <= 0 )
237  return 0;
238 
239  bool inside = false;
240  const char* start = aSource;
241  char* limit = aDest + aDestSize - 1;
242  char cc;
243 
244  while( (cc = *aSource++) != 0 && aDest < limit )
245  {
246  if( cc == '"' )
247  {
248  if( inside )
249  break; // 2nd double quote is end of delimited text
250 
251  inside = true; // first delimiter found, make note, do not copy
252  }
253 
254  else if( inside )
255  {
256  if( cc == '\\' )
257  {
258  cc = *aSource++;
259 
260  if( !cc )
261  break;
262 
263  // do no copy the escape byte if it is followed by \ or "
264  if( cc != '"' && cc != '\\' )
265  *aDest++ = '\\';
266 
267  if( aDest < limit )
268  *aDest++ = cc;
269  }
270  else
271  {
272  *aDest++ = cc;
273  }
274  }
275  }
276 
277  *aDest = 0;
278 
279  return aSource - start;
280 }

◆ ReadDelimitedText() [2/2]

int ReadDelimitedText ( wxString *  aDest,
const char *  aSource 
)

Copy bytes from aSource delimited string segment to aDest wxString.

Parameters
aDestis the destination wxString
aSourceis the source C string holding utf8 encoded bytes.
Returns
int - the number of bytes read from source, which may be more than the number copied, due to escaping of double quotes and the escape byte itself.

Definition at line 189 of file string.cpp.

190 {
191  std::string utf8; // utf8 but without escapes and quotes.
192  bool inside = false;
193  const char* start = aSource;
194  char cc;
195 
196  while( (cc = *aSource++) != 0 )
197  {
198  if( cc == '"' )
199  {
200  if( inside )
201  break; // 2nd double quote is end of delimited text
202 
203  inside = true; // first delimiter found, make note, do not copy
204  }
205 
206  else if( inside )
207  {
208  if( cc == '\\' )
209  {
210  cc = *aSource++;
211 
212  if( !cc )
213  break;
214 
215  // do no copy the escape byte if it is followed by \ or "
216  if( cc != '"' && cc != '\\' )
217  utf8 += '\\';
218 
219  utf8 += cc;
220  }
221  else
222  {
223  utf8 += cc;
224  }
225  }
226  }
227 
228  *aDest = FROM_UTF8( utf8.c_str() );
229 
230  return aSource - start;
231 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114

References FROM_UTF8().

Referenced by LEGACY_PLUGIN::load3D(), LEGACY_PLUGIN::loadDIMENSION(), LEGACY_PLUGIN::loadMODULE_TEXT(), LEGACY_PLUGIN::loadNETCLASS(), LEGACY_PLUGIN::loadNETINFO_ITEM(), LEGACY_PLUGIN::loadPAD(), LEGACY_PLUGIN::loadPCB_TEXT(), LEGACY_PLUGIN::loadSHEET(), and LEGACY_PLUGIN::loadZONE_CONTAINER().

◆ ReplaceIllegalFileNameChars() [1/2]

bool ReplaceIllegalFileNameChars ( std::string *  aName,
int  aReplaceChar = 0 
)

Checks aName for illegal file name characters.

The Windows (DOS) file system forbidden characters already include the forbidden file name characters for both Posix and OSX systems. The characters \/?*|"<> are illegal and are replaced with xx where xx the hexadecimal equivalent of the replaced character. This replacement may not be as elegant as using an underscore ('_') or hyphen ('-') but it guarantees that there will be no naming conflicts when fixing footprint library names. however, if aReplaceChar is given, it will replace the illegal chars

Parameters
aNameis a point to a std::string object containing the footprint name to verify.
aReplaceChar(if not 0) is the replacement char.
Returns
true if any characters have been replaced in aName.

Definition at line 714 of file string.cpp.

715 {
716  bool changed = false;
717  std::string result;
718  result.reserve( aName->length() );
719 
720  for( std::string::iterator it = aName->begin(); it != aName->end(); ++it )
721  {
722  if( strchr( illegalFileNameChars, *it ) )
723  {
724  if( aReplaceChar )
725  StrPrintf( &result, "%c", aReplaceChar );
726  else
727  StrPrintf( &result, "%%%02x", *it );
728 
729  changed = true;
730  }
731  else
732  {
733  result += *it;
734  }
735  }
736 
737  if( changed )
738  *aName = result;
739 
740  return changed;
741 }
static const char illegalFileNameChars[]
Illegal file name characters used to insure file names will be valid on all supported platforms.
Definition: string.cpp:40
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74

References illegalFileNameChars, and numEval::StrPrintf().

Referenced by EDEVICE::EDEVICE(), EELEMENT::EELEMENT(), LEGACY_PLUGIN::loadAllSections(), EAGLE_PLUGIN::loadLibrary(), LP_CACHE::LoadModules(), SCH_EAGLE_PLUGIN::loadSheet(), and ALTIUM_PCB::ParseComponents6Data().

◆ ReplaceIllegalFileNameChars() [2/2]

bool ReplaceIllegalFileNameChars ( wxString &  aName,
int  aReplaceChar = 0 
)

Definition at line 744 of file string.cpp.

745 {
746  bool changed = false;
747  wxString result;
748  result.reserve( aName.Length() );
749  wxString illWChars = GetIllegalFileNameWxChars();
750 
751  for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
752  {
753  if( illWChars.Find( *it ) != wxNOT_FOUND )
754  {
755  if( aReplaceChar )
756  result += aReplaceChar;
757  else
758  result += wxString::Format( "%%%02x", *it );
759 
760  changed = true;
761  }
762  else
763  {
764  result += *it;
765  }
766  }
767 
768  if( changed )
769  aName = result;
770 
771  return changed;
772 }
wxString GetIllegalFileNameWxChars()
Definition: string.cpp:708
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), and GetIllegalFileNameWxChars().

◆ SplitString()

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.

For example C10A is split to C 10 A

Definition at line 623 of file string.cpp.

627 {
628  static const wxString separators( wxT( ".," ) );
629 
630  // Clear all the return strings
631  strBeginning->Empty();
632  strDigits->Empty();
633  strEnd->Empty();
634 
635  // There no need to do anything if the string is empty
636  if( strToSplit.length() == 0 )
637  return 0;
638 
639  // Starting at the end of the string look for the first digit
640  int ii;
641 
642  for( ii = (strToSplit.length() - 1); ii >= 0; ii-- )
643  {
644  if( wxIsdigit( strToSplit[ii] ) )
645  break;
646  }
647 
648  // If there were no digits then just set the single string
649  if( ii < 0 )
650  {
651  *strBeginning = strToSplit;
652  }
653  else
654  {
655  // Since there is at least one digit this is the trailing string
656  *strEnd = strToSplit.substr( ii + 1 );
657 
658  // Go to the end of the digits
659  int position = ii + 1;
660 
661  for( ; ii >= 0; ii-- )
662  {
663  if( !wxIsdigit( strToSplit[ii] ) && separators.Find( strToSplit[ii] ) < 0 )
664  break;
665  }
666 
667  // If all that was left was digits, then just set the digits string
668  if( ii < 0 )
669  *strDigits = strToSplit.substr( 0, position );
670 
671  /* We were only looking for the last set of digits everything else is
672  * part of the preamble */
673  else
674  {
675  *strDigits = strToSplit.substr( ii + 1, position - ii - 1 );
676  *strBeginning = strToSplit.substr( 0, ii + 1 );
677  }
678  }
679 
680  return 0;
681 }

Referenced by UTIL::RefDesStringCompare(), and ValueStringCompare().

◆ StrNumCmp()

int StrNumCmp ( const wxString &  aString1,
const wxString &  aString2,
bool  aIgnoreCase = false 
)

Compare two strings with alphanumerical content.

This function is equivalent to strncmp() or strncasecmp() if aIgnoreCase is true except that strings containing numbers are compared by their integer value not by their ASCII code. In other words U10 would be greater than U2.

Parameters
aString1A wxString reference to the reference string.
aString2A wxString reference to the comparison string.
aIgnoreCaseUse true to make the comparison case insensitive.
Returns
An integer value of -1 if aString1 is less than aString2, 0 if aString1 is equal to aString2, or 1 if aString1 is greater than aString2.

Definition at line 388 of file string.cpp.

389 {
390  int nb1 = 0, nb2 = 0;
391 
392  auto str1 = aString1.begin();
393  auto str2 = aString2.begin();
394 
395  while( str1 != aString1.end() && str2 != aString2.end() )
396  {
397  wxUniChar c1 = *str1;
398  wxUniChar c2 = *str2;
399 
400  if( wxIsdigit( c1 ) && wxIsdigit( c2 ) ) // Both characters are digits, do numeric compare.
401  {
402  nb1 = 0;
403  nb2 = 0;
404 
405  do
406  {
407  c1 = *str1;
408  nb1 = nb1 * 10 + (int) c1 - '0';
409  ++str1;
410  } while( str1 != aString1.end() && wxIsdigit( *str1 ) );
411 
412  do
413  {
414  c2 = *str2;
415  nb2 = nb2 * 10 + (int) c2 - '0';
416  ++str2;
417  } while( str2 != aString2.end() && wxIsdigit( *str2 ) );
418 
419  if( nb1 < nb2 )
420  return -1;
421 
422  if( nb1 > nb2 )
423  return 1;
424 
425  c1 = ( str1 != aString1.end() ) ? *str1 : wxUniChar( 0 );
426  c2 = ( str2 != aString2.end() ) ? *str2 : wxUniChar( 0 );
427  }
428 
429  // Any numerical comparisons to here are identical.
430  if( aIgnoreCase )
431  {
432  if( wxToupper( c1 ) < wxToupper( c2 ) )
433  return -1;
434 
435  if( wxToupper( c1 ) > wxToupper( c2 ) )
436  return 1;
437  }
438  else
439  {
440  if( c1 < c2 )
441  return -1;
442 
443  if( c1 > c2 )
444  return 1;
445  }
446 
447  if( str1 != aString1.end() )
448  ++str1;
449 
450  if( str2 != aString2.end() )
451  ++str2;
452  }
453 
454  if( str1 == aString1.end() && str2 != aString2.end() )
455  {
456  return -1; // Identical to here but aString1 is longer.
457  }
458  else if( str1 != aString1.end() && str2 == aString2.end() )
459  {
460  return 1; // Identical to here but aString2 is longer.
461  }
462 
463  return 0;
464 }

Referenced by LIB_TREE_NODE::AssignIntrinsicRanks(), BOOST_AUTO_TEST_CASE(), PIN_TABLE_DATA_MODEL::compare(), PLACE_FILE_EXPORTER::GenReportData(), FP_TREE_MODEL_ADAPTER::getFootprints(), myCompareFunction(), operator<(), sortFPlist(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ StrPurge()

char* StrPurge ( char *  text)

Remove leading and training spaces, tabs and end of line chars in text.

Returns
a pointer on the first n char in text

Definition at line 344 of file string.cpp.

345 {
346  static const char whitespace[] = " \t\n\r\f\v";
347 
348  if( text )
349  {
350  while( *text && strchr( whitespace, *text ) )
351  ++text;
352 
353  char* cp = text + strlen( text ) - 1;
354 
355  while( cp >= text && strchr( whitespace, *cp ) )
356  *cp-- = '\0';
357  }
358 
359  return text;
360 }

Referenced by detect_file_type(), LEGACY_PLUGIN::loadAllSections(), EXCELLON_IMAGE::LoadFile(), GERBER_FILE_IMAGE::LoadGerberFile(), LEGACY_PLUGIN::loadMODULE(), LP_CACHE::LoadModules(), LEGACY_NETLIST_READER::LoadNetlist(), and LEGACY_PLUGIN::loadPAD().

◆ strtok_r()

◆ UnescapeString()

wxString UnescapeString ( const wxString &  aSource)

Definition at line 131 of file string.cpp.

132 {
133  wxString newbuf;
134  size_t sourceLen = aSource.length();
135 
136  for( size_t i = 0; i < sourceLen; ++i )
137  {
138  if( ( aSource[i] == '$' || aSource[i] == '^' || aSource[i] == '_' )
139  && i + 1 < sourceLen && aSource[i+1] == '{' )
140  {
141  for( ; i < sourceLen; ++i )
142  {
143  newbuf += aSource[i];
144 
145  if( aSource[i] == '}' )
146  break;
147  }
148  }
149  else if( aSource[i] == '{' )
150  {
151  wxString token;
152 
153  for( i = i + 1; i < sourceLen; ++i )
154  {
155  if( aSource[i] == '}' )
156  break;
157  else
158  token.append( aSource[i] );
159  }
160 
161  if( token == wxS( "dblquote" ) ) newbuf.append( wxS( "\"" ) );
162  else if( token == wxS( "quote" ) ) newbuf.append( wxS( "'" ) );
163  else if( token == wxS( "lt" ) ) newbuf.append( wxS( "<" ) );
164  else if( token == wxS( "gt" ) ) newbuf.append( wxS( ">" ) );
165  else if( token == wxS( "backslash" ) ) newbuf.append( wxS( "\\" ) );
166  else if( token == wxS( "slash" ) ) newbuf.append( wxS( "/" ) );
167  else if( token == wxS( "bar" ) ) newbuf.append( wxS( "|" ) );
168  else if( token == wxS( "colon" ) ) newbuf.append( wxS( ":" ) );
169  else if( token == wxS( "space" ) ) newbuf.append( wxS( " " ) );
170  else if( token == wxS( "dollar" ) ) newbuf.append( wxS( "$" ) );
171  else if( token == wxS( "tab" ) ) newbuf.append( wxS( "\t" ) );
172  else if( token == wxS( "return" ) ) newbuf.append( wxS( "\n" ) );
173  else if( token == wxS( "brace" ) ) newbuf.append( wxS( "{" ) );
174  else
175  {
176  newbuf.append( "{" + token + "}" );
177  }
178  }
179  else
180  {
181  newbuf.append( aSource[i] );
182  }
183  }
184 
185  return newbuf;
186 }

Referenced by SCH_CONNECTION::AppendInfoToMsgPanel(), SCH_EDIT_TOOL::ChangeTextType(), NETLIST_EXPORTER_PSPICE_SIM::ComponentToVector(), SCH_CONNECTION::ConfigureFromLabel(), BOARD_NETLIST_UPDATER::deleteSinglePadNets(), KIGFX::PCB_PAINTER::draw(), EDA_TEXT::EDA_TEXT(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), NETLIST_EXPORTER_PSPICE::Format(), DIALOG_SELECT_NET_FROM_LIST::formatNetName(), ZONE_CONTAINER::GetMsgPanelInfo(), GERBER_DRAW_ITEM::GetMsgPanelInfo(), D_PAD::GetMsgPanelInfo(), TRACK::GetMsgPanelInfoBase_Common(), BOARD_CONNECTED_ITEM::GetNetnameMsg(), GERBVIEW_CONTROL::HighlightControl(), highlightNet(), SCH_CONNECTION::MightBeBusLabel(), DIALOG_SELECT_NET_FROM_LIST::netFilterMatches(), GERBVIEW_FRAME::Process_Special_Functions(), FOOTPRINT_LIST_IMPL::ReadCacheFromFile(), NET_SELECTOR_COMBOPOPUP::rebuildList(), UTIL::RefDesStringCompare(), EDA_TEXT::Replace(), EDA_TEXT::SetText(), BOARD::SortedNetnamesList(), DIALOG_SIGNAL_LIST::TransferDataToWindow(), DIALOG_EDIT_SHEET_PIN::TransferDataToWindow(), DIALOG_LABEL_EDITOR::TransferDataToWindow(), PANEL_SETUP_NETCLASSES::TransferDataToWindow(), HIGHLIGHT_MENU::update(), BOARD_NETLIST_UPDATER::updateComponentPadConnections(), BOARD_NETLIST_UPDATER::updateCopperZoneNets(), GERBVIEW_FRAME::updateNetnameListSelectBox(), and ValueStringCompare().

◆ ValueStringCompare()

int ValueStringCompare ( wxString  strFWord,
wxString  strSWord 
)

Compare strings like the strcmp function but handle numbers and modifiers within the string text correctly for sorting.

eg. 1mF > 55uF

Returns
-1 if first string is less than the second, 0 if the strings are equal, or 1 if the first string is greater than the second.

Definition at line 575 of file string.cpp.

576 {
577  // Compare unescaped text
578  strFWord = UnescapeString( strFWord );
579  strSWord = UnescapeString( strSWord );
580 
581  // The different sections of the two strings
582  wxString strFWordBeg, strFWordMid, strFWordEnd;
583  wxString strSWordBeg, strSWordMid, strSWordEnd;
584 
585  // Split the two strings into separate parts
586  SplitString( strFWord, &strFWordBeg, &strFWordMid, &strFWordEnd );
587  SplitString( strSWord, &strSWordBeg, &strSWordMid, &strSWordEnd );
588 
589  // Compare the Beginning section of the strings
590  int isEqual = strFWordBeg.CmpNoCase( strSWordBeg );
591 
592  if( isEqual > 0 )
593  return 1;
594  else if( isEqual < 0 )
595  return -1;
596  else
597  {
598  // If the first sections are equal compare their digits
599  double lFirstNumber = 0;
600  double lSecondNumber = 0;
601  bool endingIsModifier = false;
602 
603  strFWordMid.ToDouble( &lFirstNumber );
604  strSWordMid.ToDouble( &lSecondNumber );
605 
606  endingIsModifier |= ApplyModifier( lFirstNumber, strFWordEnd );
607  endingIsModifier |= ApplyModifier( lSecondNumber, strSWordEnd );
608 
609  if( lFirstNumber > lSecondNumber )
610  return 1;
611  else if( lFirstNumber < lSecondNumber )
612  return -1;
613  // If the first two sections are equal and the endings are modifiers then compare them
614  else if( !endingIsModifier )
615  return strFWordEnd.CmpNoCase( strSWordEnd );
616  // Ran out of things to compare; they must match
617  else
618  return 0;
619  }
620 }
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
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
bool ApplyModifier(double &value, const wxString &aString)
Definition: string.cpp:527

References ApplyModifier(), SplitString(), and UnescapeString().

Referenced by FIELDS_EDITOR_GRID_DATA_MODEL::cmp().

◆ WildCompareString()

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.

Returns
true if pattern matched otherwise false.

Definition at line 467 of file string.cpp.

469 {
470  const wxChar* cp = NULL, * mp = NULL;
471  const wxChar* wild, * string;
472  wxString _pattern, _string_to_tst;
473 
474  if( case_sensitive )
475  {
476  wild = pattern.GetData();
477  string = string_to_tst.GetData();
478  }
479  else
480  {
481  _pattern = pattern;
482  _pattern.MakeUpper();
483  _string_to_tst = string_to_tst;
484  _string_to_tst.MakeUpper();
485  wild = _pattern.GetData();
486  string = _string_to_tst.GetData();
487  }
488 
489  while( ( *string ) && ( *wild != '*' ) )
490  {
491  if( ( *wild != *string ) && ( *wild != '?' ) )
492  return false;
493 
494  wild++; string++;
495  }
496 
497  while( *string )
498  {
499  if( *wild == '*' )
500  {
501  if( !*++wild )
502  return 1;
503  mp = wild;
504  cp = string + 1;
505  }
506  else if( ( *wild == *string ) || ( *wild == '?' ) )
507  {
508  wild++;
509  string++;
510  }
511  else
512  {
513  wild = mp;
514  string = cp++;
515  }
516  }
517 
518  while( *wild == '*' )
519  {
520  wild++;
521  }
522 
523  return !*wild;
524 }
#define NULL

References NULL.

Referenced by DIALOG_EXCHANGE_FOOTPRINTS::isMatch(), PCB_EDIT_FRAME::LockModule(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().