KiCad PCB EDA Suite
string.cpp File Reference

Some useful functions to handle strings. More...

#include <fctsys.h>
#include <macros.h>
#include <richio.h>
#include <kicad_string.h>

Go to the source code of this file.

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)
 
int ReadDelimitedText (wxString *aDest, const char *aSource)
 Copy bytes from aSource delimited string segment to aDest wxString. More...
 
int ReadDelimitedText (char *aDest, const char *aSource, int aDestSize)
 Copy bytes from aSource delimited string segment to aDest buffer. 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 * StrPurge (char *text)
 Remove leading and training spaces, tabs and end of line chars in text. More...
 
char * GetLine (FILE *File, char *Line, int *LineNum, int SizeLine)
 Read one line line from aFile. More...
 
wxString DateAndTime ()
 
int StrNumCmp (const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
 Compare two strings with alphanumerical content. More...
 
bool WildCompareString (const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
 Compare a string against wild card (* and ?) pattern using the usual rules. More...
 
bool ApplyModifier (double &value, const wxString &aString)
 
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)
 Checks aName for illegal file name characters. More...
 
bool ReplaceIllegalFileNameChars (wxString &aName, int aReplaceChar)
 

Variables

static const char illegalFileNameChars [] = "\\/:\"<>|"
 Illegal file name characters used to insure file names will be valid on all supported platforms. More...
 

Detailed Description

Some useful functions to handle strings.

Definition in file string.cpp.

Function Documentation

◆ ApplyModifier()

bool ApplyModifier ( double &  value,
const wxString &  aString 
)

Definition at line 521 of file string.cpp.

522 {
523  static const wxString modifiers( wxT( "pnumkKM" ) );
524 
525  if( !aString.length() )
526  return false;
527 
528  wxChar modifier;
529  wxString units;
530 
531  if( modifiers.Find( aString[ 0 ] ) >= 0 )
532  {
533  modifier = aString[ 0 ];
534  units = aString.Mid( 1 ).Trim();
535  }
536  else
537  {
538  modifier = ' ';
539  units = aString.Mid( 0 ).Trim();
540  }
541 
542  if( units.length()
543  && !units.CmpNoCase( wxT( "F" ) )
544  && !units.CmpNoCase( wxT( "hz" ) )
545  && !units.CmpNoCase( wxT( "W" ) )
546  && !units.CmpNoCase( wxT( "V" ) )
547  && !units.CmpNoCase( wxT( "H" ) ) )
548  return false;
549 
550  if( modifier == 'p' )
551  value *= 1.0e-12;
552  if( modifier == 'n' )
553  value *= 1.0e-9;
554  else if( modifier == 'u' )
555  value *= 1.0e-6;
556  else if( modifier == 'm' )
557  value *= 1.0e-3;
558  else if( modifier == 'k' || modifier == 'K' )
559  value *= 1.0e3;
560  else if( modifier == 'M' )
561  value *= 1.0e6;
562  else if( modifier == 'G' )
563  value *= 1.0e9;
564 
565  return true;
566 }

Referenced by ValueStringCompare().

◆ DateAndTime()

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

Definition at line 373 of file string.cpp.

374 {
375  wxDateTime datetime = wxDateTime::Now();
376 
377  datetime.SetCountry( wxDateTime::Country_Default );
378  return datetime.Format( wxDefaultDateTimeFormat, wxDateTime::Local );
379 }

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 314 of file string.cpp.

315 {
316  wxString converted;
317 
318  for( wxUniChar c: aString )
319  {
320  if( c == '\"' )
321  converted += "&quot;";
322  else if( c == '\'' )
323  converted += "&apos;";
324  else if( c == '&' )
325  converted += "&amp;";
326  else if( c == '<' )
327  converted += "&lt;";
328  else if( c == '>' )
329  converted += "&gt;";
330  else
331  converted += c;
332  }
333 
334  return converted;
335 }

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 277 of file string.cpp.

278 {
279  // No new-lines allowed in quoted strings
280  aString.Replace( "\r\n", "\r" );
281  aString.Replace( "\n", "\r" );
282 
283  std::string utf8 = TO_UTF8( aString );
284 
285  std::string ret;
286 
287  ret += '"';
288 
289  for( std::string::const_iterator it = utf8.begin(); it!=utf8.end(); ++it )
290  {
291  // this escaping strategy is designed to be compatible with ReadDelimitedText():
292  if( *it == '"' )
293  {
294  ret += '\\';
295  ret += '"';
296  }
297  else if( *it == '\\' )
298  {
299  ret += '\\'; // double it up
300  ret += '\\';
301  }
302  else
303  {
304  ret += *it;
305  }
306  }
307 
308  ret += '"';
309 
310  return ret;
311 }
#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_LINE )
86  {
87  if( c == '\n' || c == '\r' )
88  converted += "{return}";
89  else
90  converted += c;
91  }
92  else if( aContext == CTX_FILENAME )
93  {
94  if( c == '{' )
95  converted += "{brace}";
96  else if( c == '/' )
97  converted += "{slash}";
98  else if( c == '\\' )
99  converted += "{backslash}";
100  else if( c == '\"' )
101  converted += "{dblquote}";
102  else if( c == '<' )
103  converted += "{lt}";
104  else if( c == '>' )
105  converted += "{gt}";
106  else if( c == '|' )
107  converted += "{bar}";
108  else if( c == ':' )
109  converted += "{colon}";
110  else if( c == '\t' )
111  converted += "{tab}";
112  else if( c == '\n' || c == '\r' )
113  converted += "{return}";
114  else
115  converted += c;
116  }
117  else
118  converted += c;
119  }
120 
121  return converted;
122 }

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

Referenced by SCH_EDIT_TOOL::ChangeTextType(), CONNECTION_GRAPH::ercCheckBusToNetConflicts(), CONNECTION_GRAPH::ercCheckLabels(), CONNECTION_SUBGRAPH::GetNameForDriver(), SCHEMATIC::GetNetClassAssignmentCandidates(), DIALOG_SELECT_NET_FROM_LIST::onRenameNet(), BACK_ANNOTATE::processNetNameChange(), DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), PANEL_SETUP_NETCLASSES::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 702 of file string.cpp.

703 {
705 }
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 357 of file string.cpp.

358 {
359  do {
360  if( fgets( Line, SizeLine, File ) == NULL )
361  return NULL;
362 
363  if( LineNum )
364  *LineNum += 1;
365 
366  } while( Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r' || Line[0] == 0 );
367 
368  strtok( Line, "\n\r" );
369  return Line;
370 }
#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 678 of file string.cpp.

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

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

◆ ReadDelimitedText() [1/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 183 of file string.cpp.

184 {
185  std::string utf8; // utf8 but without escapes and quotes.
186  bool inside = false;
187  const char* start = aSource;
188  char cc;
189 
190  while( (cc = *aSource++) != 0 )
191  {
192  if( cc == '"' )
193  {
194  if( inside )
195  break; // 2nd double quote is end of delimited text
196 
197  inside = true; // first delimiter found, make note, do not copy
198  }
199 
200  else if( inside )
201  {
202  if( cc == '\\' )
203  {
204  cc = *aSource++;
205 
206  if( !cc )
207  break;
208 
209  // do no copy the escape byte if it is followed by \ or "
210  if( cc != '"' && cc != '\\' )
211  utf8 += '\\';
212 
213  utf8 += cc;
214  }
215  else
216  {
217  utf8 += cc;
218  }
219  }
220  }
221 
222  *aDest = FROM_UTF8( utf8.c_str() );
223 
224  return aSource - start;
225 }
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().

◆ ReadDelimitedText() [2/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 228 of file string.cpp.

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

◆ 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 708 of file string.cpp.

709 {
710  bool changed = false;
711  std::string result;
712  result.reserve( aName->length() );
713 
714  for( std::string::iterator it = aName->begin(); it != aName->end(); ++it )
715  {
716  if( strchr( illegalFileNameChars, *it ) )
717  {
718  if( aReplaceChar )
719  StrPrintf( &result, "%c", aReplaceChar );
720  else
721  StrPrintf( &result, "%%%02x", *it );
722 
723  changed = true;
724  }
725  else
726  {
727  result += *it;
728  }
729  }
730 
731  if( changed )
732  *aName = result;
733 
734  return changed;
735 }
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 
)

Definition at line 738 of file string.cpp.

739 {
740  bool changed = false;
741  wxString result;
742  result.reserve( aName.Length() );
743  wxString illWChars = GetIllegalFileNameWxChars();
744 
745  for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
746  {
747  if( illWChars.Find( *it ) != wxNOT_FOUND )
748  {
749  if( aReplaceChar )
750  result += aReplaceChar;
751  else
752  result += wxString::Format( "%%%02x", *it );
753 
754  changed = true;
755  }
756  else
757  {
758  result += *it;
759  }
760  }
761 
762  if( changed )
763  aName = result;
764 
765  return changed;
766 }
wxString GetIllegalFileNameWxChars()
Definition: string.cpp:702
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 617 of file string.cpp.

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

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 382 of file string.cpp.

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

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(), MODULE::cmp_pads::operator()(), 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 338 of file string.cpp.

339 {
340  static const char whitespace[] = " \t\n\r\f\v";
341 
342  if( text )
343  {
344  while( *text && strchr( whitespace, *text ) )
345  ++text;
346 
347  char* cp = text + strlen( text ) - 1;
348 
349  while( cp >= text && strchr( whitespace, *cp ) )
350  *cp-- = '\0';
351  }
352 
353  return text;
354 }

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().

◆ UnescapeString()

wxString UnescapeString ( const wxString &  aSource)

Definition at line 125 of file string.cpp.

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

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::IsBusLabel(), SCH_CONNECTION::MightBeBusLabel(), DIALOG_SELECT_NET_FROM_LIST::netFilterMatches(), DIALOG_SELECT_NET_FROM_LIST::onRenameNet(), GERBVIEW_FRAME::Process_Special_Functions(), FOOTPRINT_LIST_IMPL::ReadCacheFromFile(), NET_SELECTOR_COMBOPOPUP::rebuildList(), UTIL::RefDesStringCompare(), EDA_TEXT::Replace(), NET_SETTINGS::ResolveNetClassAssignments(), 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 569 of file string.cpp.

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

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 461 of file string.cpp.

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

References NULL.

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

Variable Documentation

◆ illegalFileNameChars

const char illegalFileNameChars[] = "\\/:\"<>|"
static

Illegal file name characters used to insure file names will be valid on all supported platforms.

This is the list of illegal file name characters for Windows which includes the illegal file name characters for Linux and OSX.

Definition at line 40 of file string.cpp.

Referenced by GetIllegalFileNameWxChars(), and ReplaceIllegalFileNameChars().