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 (const 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 481 of file string.cpp.

482 {
483  static const wxString modifiers( wxT( "pnumkKM" ) );
484 
485  if( !aString.length() )
486  return false;
487 
488  wxChar modifier;
489  wxString units;
490 
491  if( modifiers.Find( aString[ 0 ] ) >= 0 )
492  {
493  modifier = aString[ 0 ];
494  units = aString.Mid( 1 ).Trim();
495  }
496  else
497  {
498  modifier = ' ';
499  units = aString.Mid( 0 ).Trim();
500  }
501 
502  if( units.length()
503  && !units.CmpNoCase( wxT( "F" ) )
504  && !units.CmpNoCase( wxT( "hz" ) )
505  && !units.CmpNoCase( wxT( "W" ) )
506  && !units.CmpNoCase( wxT( "V" ) )
507  && !units.CmpNoCase( wxT( "H" ) ) )
508  return false;
509 
510  if( modifier == 'p' )
511  value *= 1.0e-12;
512  if( modifier == 'n' )
513  value *= 1.0e-9;
514  else if( modifier == 'u' )
515  value *= 1.0e-6;
516  else if( modifier == 'm' )
517  value *= 1.0e-3;
518  else if( modifier == 'k' || modifier == 'K' )
519  value *= 1.0e3;
520  else if( modifier == 'M' )
521  value *= 1.0e6;
522  else if( modifier == 'G' )
523  value *= 1.0e9;
524 
525  return true;
526 }

Referenced by ValueStringCompare().

◆ DateAndTime()

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

Definition at line 333 of file string.cpp.

334 {
335  wxDateTime datetime = wxDateTime::Now();
336 
337  datetime.SetCountry( wxDateTime::Country_Default );
338  return datetime.Format( wxDefaultDateTimeFormat, wxDateTime::Local );
339 }

Referenced by PROJECT::ConfigSave(), GENDRILL_WRITER_BASE::GenDrillReportFile(), PLACE_FILE_EXPORTER::GenPositionData(), PLACE_FILE_EXPORTER::GenReportData(), NETLIST_EXPORTER_GENERIC::makeDesignHeader(), RecreateCmpFile(), WriteDiagnosticERC(), EXCELLON_WRITER::writeEXCELLONHeader(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ EscapedHTML()

wxString EscapedHTML ( const wxString &  aString)

Return a new wxString escaped for embedding in HTML.

Definition at line 274 of file string.cpp.

275 {
276  wxString converted;
277 
278  for( wxUniChar c: aString )
279  {
280  if( c == '\"' )
281  converted += "&quot;";
282  else if( c == '\'' )
283  converted += "&apos;";
284  else if( c == '&' )
285  converted += "&amp;";
286  else if( c == '<' )
287  converted += "&lt;";
288  else if( c == '>' )
289  converted += "&gt;";
290  else
291  converted += c;
292  }
293 
294  return converted;
295 }

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 ( const 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 241 of file string.cpp.

242 {
243  std::string utf8 = TO_UTF8( aString );
244 
245  std::string ret;
246 
247  ret += '"';
248 
249  for( std::string::const_iterator it = utf8.begin(); it!=utf8.end(); ++it )
250  {
251  // this escaping strategy is designed to be compatible with ReadDelimitedText():
252  if( *it == '"' )
253  {
254  ret += '\\';
255  ret += '"';
256  }
257  else if( *it == '\\' )
258  {
259  ret += '\\'; // double it up
260  ret += '\\';
261  }
262  else
263  {
264  ret += *it;
265  }
266  }
267 
268  ret += '"';
269 
270  return ret;
271 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48

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(), 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( c == '{' )
57  {
58  converted += "{brace}";
59  }
60  else if( aContext == CTX_NETNAME )
61  {
62  if( c == '/' )
63  converted += "{slash}";
64  else
65  converted += c;
66  }
67  else if( aContext == CTX_LIBID )
68  {
69  if( c == ':' )
70  converted += "{colon}";
71  else
72  converted += c;
73  }
74  else if( aContext == CTX_QUOTED_STR )
75  {
76  if( c == '\"' )
77  converted += "{dblquote}";
78  else
79  converted += c;
80  }
81  else if( aContext == CTX_DELIMITED_STR )
82  {
83  if( c == ' ' )
84  converted += "{space}";
85  else if( c == '\t' )
86  converted += "{tab}";
87  else 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 += "{slash}";
96  else if( c == '\\' )
97  converted += "{backslash}";
98  else if( c == '\"' )
99  converted += "{dblquote}";
100  else if( c == '<' )
101  converted += "{lt}";
102  else if( c == '>' )
103  converted += "{gt}";
104  else if( c == '|' )
105  converted += "{bar}";
106  else if( c == ':' )
107  converted += "{colon}";
108  else if( c == '\t' )
109  converted += "{tab}";
110  else if( c == '\n' || c == '\r' )
111  converted += "{return}";
112  else
113  converted += c;
114  }
115  else
116  converted += c;
117  }
118 
119  return converted;
120 }

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

Referenced by SCH_EDIT_FRAME::ConvertTextType(), 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 662 of file string.cpp.

663 {
665 }
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:62

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

318 {
319  do {
320  if( fgets( Line, SizeLine, File ) == NULL )
321  return NULL;
322 
323  if( LineNum )
324  *LineNum += 1;
325 
326  } while( Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r' || Line[0] == 0 );
327 
328  strtok( Line, "\n\r" );
329  return Line;
330 }

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

639 {
640  int number = 0;
641  int base = 1;
642 
643  // Trim and extract the trailing numeric part
644  int index = aStr.Len() - 1;
645 
646  while( index >= 0 )
647  {
648  const char chr = aStr.GetChar( index );
649 
650  if( chr < '0' || chr > '9' )
651  break;
652 
653  number += ( chr - '0' ) * base;
654  base *= 10;
655  index--;
656  }
657 
658  return number;
659 }

Referenced by 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 147 of file string.cpp.

148 {
149  std::string utf8; // utf8 but without escapes and quotes.
150  bool inside = false;
151  const char* start = aSource;
152  char cc;
153 
154  while( (cc = *aSource++) != 0 )
155  {
156  if( cc == '"' )
157  {
158  if( inside )
159  break; // 2nd double quote is end of delimited text
160 
161  inside = true; // first delimiter found, make note, do not copy
162  }
163 
164  else if( inside )
165  {
166  if( cc == '\\' )
167  {
168  cc = *aSource++;
169 
170  if( !cc )
171  break;
172 
173  // do no copy the escape byte if it is followed by \ or "
174  if( cc != '"' && cc != '\\' )
175  utf8 += '\\';
176 
177  utf8 += cc;
178  }
179  else
180  {
181  utf8 += cc;
182  }
183  }
184  }
185 
186  *aDest = FROM_UTF8( utf8.c_str() );
187 
188  return aSource - start;
189 }
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:62

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

193 {
194  if( aDestSize <= 0 )
195  return 0;
196 
197  bool inside = false;
198  const char* start = aSource;
199  char* limit = aDest + aDestSize - 1;
200  char cc;
201 
202  while( (cc = *aSource++) != 0 && aDest < limit )
203  {
204  if( cc == '"' )
205  {
206  if( inside )
207  break; // 2nd double quote is end of delimited text
208 
209  inside = true; // first delimiter found, make note, do not copy
210  }
211 
212  else if( inside )
213  {
214  if( cc == '\\' )
215  {
216  cc = *aSource++;
217 
218  if( !cc )
219  break;
220 
221  // do no copy the escape byte if it is followed by \ or "
222  if( cc != '"' && cc != '\\' )
223  *aDest++ = '\\';
224 
225  if( aDest < limit )
226  *aDest++ = cc;
227  }
228  else
229  {
230  *aDest++ = cc;
231  }
232  }
233  }
234 
235  *aDest = 0;
236 
237  return aSource - start;
238 }

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

669 {
670  bool changed = false;
671  std::string result;
672  result.reserve( aName->length() );
673 
674  for( std::string::iterator it = aName->begin(); it != aName->end(); ++it )
675  {
676  if( strchr( illegalFileNameChars, *it ) )
677  {
678  if( aReplaceChar )
679  StrPrintf( &result, "%c", aReplaceChar );
680  else
681  StrPrintf( &result, "%%%02x", *it );
682 
683  changed = true;
684  }
685  else
686  {
687  result += *it;
688  }
689  }
690 
691  if( changed )
692  *aName = result;
693 
694  return changed;
695 }
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(), and SCH_EAGLE_PLUGIN::loadSheet().

◆ ReplaceIllegalFileNameChars() [2/2]

bool ReplaceIllegalFileNameChars ( wxString &  aName,
int  aReplaceChar 
)

Definition at line 698 of file string.cpp.

699 {
700  bool changed = false;
701  wxString result;
702  result.reserve( aName.Length() );
703  wxString illWChars = GetIllegalFileNameWxChars();
704 
705  for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
706  {
707  if( illWChars.Find( *it ) != wxNOT_FOUND )
708  {
709  if( aReplaceChar )
710  result += aReplaceChar;
711  else
712  result += wxString::Format( "%%%02x", *it );
713 
714  changed = true;
715  }
716  else
717  {
718  result += *it;
719  }
720  }
721 
722  if( changed )
723  aName = result;
724 
725  return changed;
726 }
wxString GetIllegalFileNameWxChars()
Definition: string.cpp:662
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 577 of file string.cpp.

581 {
582  static const wxString separators( wxT( ".," ) );
583 
584  // Clear all the return strings
585  strBeginning->Empty();
586  strDigits->Empty();
587  strEnd->Empty();
588 
589  // There no need to do anything if the string is empty
590  if( strToSplit.length() == 0 )
591  return 0;
592 
593  // Starting at the end of the string look for the first digit
594  int ii;
595 
596  for( ii = (strToSplit.length() - 1); ii >= 0; ii-- )
597  {
598  if( wxIsdigit( strToSplit[ii] ) )
599  break;
600  }
601 
602  // If there were no digits then just set the single string
603  if( ii < 0 )
604  {
605  *strBeginning = strToSplit;
606  }
607  else
608  {
609  // Since there is at least one digit this is the trailing string
610  *strEnd = strToSplit.substr( ii + 1 );
611 
612  // Go to the end of the digits
613  int position = ii + 1;
614 
615  for( ; ii >= 0; ii-- )
616  {
617  if( !wxIsdigit( strToSplit[ii] ) && separators.Find( strToSplit[ii] ) < 0 )
618  break;
619  }
620 
621  // If all that was left was digits, then just set the digits string
622  if( ii < 0 )
623  *strDigits = strToSplit.substr( 0, position );
624 
625  /* We were only looking for the last set of digits everything else is
626  * part of the preamble */
627  else
628  {
629  *strDigits = strToSplit.substr( ii + 1, position - ii - 1 );
630  *strBeginning = strToSplit.substr( 0, ii + 1 );
631  }
632  }
633 
634  return 0;
635 }

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

343 {
344  int nb1 = 0, nb2 = 0;
345 
346  auto str1 = aString1.begin();
347  auto str2 = aString2.begin();
348 
349  while( str1 != aString1.end() && str2 != aString2.end() )
350  {
351  wxUniChar c1 = *str1;
352  wxUniChar c2 = *str2;
353 
354  if( wxIsdigit( c1 ) && wxIsdigit( c2 ) ) // Both characters are digits, do numeric compare.
355  {
356  nb1 = 0;
357  nb2 = 0;
358 
359  do
360  {
361  c1 = *str1;
362  nb1 = nb1 * 10 + (int) c1 - '0';
363  ++str1;
364  } while( str1 != aString1.end() && wxIsdigit( *str1 ) );
365 
366  do
367  {
368  c2 = *str2;
369  nb2 = nb2 * 10 + (int) c2 - '0';
370  ++str2;
371  } while( str2 != aString2.end() && wxIsdigit( *str2 ) );
372 
373  if( nb1 < nb2 )
374  return -1;
375 
376  if( nb1 > nb2 )
377  return 1;
378 
379  c1 = ( str1 != aString1.end() ) ? *str1 : wxUniChar( 0 );
380  c2 = ( str2 != aString2.end() ) ? *str2 : wxUniChar( 0 );
381  }
382 
383  // Any numerical comparisons to here are identical.
384  if( aIgnoreCase )
385  {
386  if( wxToupper( c1 ) < wxToupper( c2 ) )
387  return -1;
388 
389  if( wxToupper( c1 ) > wxToupper( c2 ) )
390  return 1;
391  }
392  else
393  {
394  if( c1 < c2 )
395  return -1;
396 
397  if( c1 > c2 )
398  return 1;
399  }
400 
401  if( str1 != aString1.end() )
402  ++str1;
403 
404  if( str2 != aString2.end() )
405  ++str2;
406  }
407 
408  if( str1 == aString1.end() && str2 != aString2.end() )
409  {
410  return -1; // Identical to here but aString1 is longer.
411  }
412  else if( str1 != aString1.end() && str2 == aString2.end() )
413  {
414  return 1; // Identical to here but aString2 is longer.
415  }
416 
417  return 0;
418 }

Referenced by LIB_TREE_NODE::AssignIntrinsicRanks(), PIN_TABLE_DATA_MODEL::compare(), 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 298 of file string.cpp.

299 {
300  static const char whitespace[] = " \t\n\r\f\v";
301 
302  if( text )
303  {
304  while( *text && strchr( whitespace, *text ) )
305  ++text;
306 
307  char* cp = text + strlen( text ) - 1;
308 
309  while( cp >= text && strchr( whitespace, *cp ) )
310  *cp-- = '\0';
311  }
312 
313  return text;
314 }

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

124 {
125  wxString converted = aSource;
126 
127  converted.Replace( "{dblquote}", "\"" );
128  converted.Replace( "{quote}", "'" );
129  converted.Replace( "{lt}", "<" );
130  converted.Replace( "{gt}", ">" );
131  converted.Replace( "{backslash}", "\\" );
132  converted.Replace( "{slash}", "/" );
133  converted.Replace( "{bar}", "|" );
134  converted.Replace( "{colon}", ":" );
135  converted.Replace( "{space}", " " );
136  converted.Replace( "{dollar}", "$" );
137  converted.Replace( "{tab}", "\t" );
138  converted.Replace( "{return}", "\n" );
139 
140  // must be done last
141  converted.Replace( "{brace}", "{" );
142 
143  return converted;
144 }

Referenced by DIALOG_SELECT_NET_FROM_LIST::buildNetsList(), SCH_EDIT_FRAME::ConvertTextType(), BOARD_NETLIST_UPDATER::deleteSinglePadNets(), KIGFX::PCB_PAINTER::draw(), EDA_TEXT::EDA_TEXT(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), NETLIST_EXPORTER_PSPICE::Format(), ZONE_CONTAINER::GetMsgPanelInfo(), GERBER_DRAW_ITEM::GetMsgPanelInfo(), D_PAD::GetMsgPanelInfo(), TRACK::GetMsgPanelInfoBase_Common(), BOARD_CONNECTED_ITEM::GetNetnameMsg(), NETLIST_EXPORTER_PSPICE_SIM::GetSpiceVector(), GERBVIEW_CONTROL::HighlightControl(), highlightNet(), VIA::Print(), D_PAD::PrintShape(), GERBVIEW_FRAME::Process_Special_Functions(), FOOTPRINT_LIST_IMPL::ReadCacheFromFile(), NET_SELECTOR_COMBOPOPUP::rebuildList(), UTIL::RefDesStringCompare(), EDA_TEXT::SetText(), BOARD::SortedNetnamesList(), DIALOG_SIGNAL_LIST::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 529 of file string.cpp.

530 {
531  // Compare unescaped text
532  strFWord = UnescapeString( strFWord );
533  strSWord = UnescapeString( strSWord );
534 
535  // The different sections of the two strings
536  wxString strFWordBeg, strFWordMid, strFWordEnd;
537  wxString strSWordBeg, strSWordMid, strSWordEnd;
538 
539  // Split the two strings into separate parts
540  SplitString( strFWord, &strFWordBeg, &strFWordMid, &strFWordEnd );
541  SplitString( strSWord, &strSWordBeg, &strSWordMid, &strSWordEnd );
542 
543  // Compare the Beginning section of the strings
544  int isEqual = strFWordBeg.CmpNoCase( strSWordBeg );
545 
546  if( isEqual > 0 )
547  return 1;
548  else if( isEqual < 0 )
549  return -1;
550  else
551  {
552  // If the first sections are equal compare their digits
553  double lFirstNumber = 0;
554  double lSecondNumber = 0;
555  bool endingIsModifier = false;
556 
557  strFWordMid.ToDouble( &lFirstNumber );
558  strSWordMid.ToDouble( &lSecondNumber );
559 
560  endingIsModifier |= ApplyModifier( lFirstNumber, strFWordEnd );
561  endingIsModifier |= ApplyModifier( lSecondNumber, strSWordEnd );
562 
563  if( lFirstNumber > lSecondNumber )
564  return 1;
565  else if( lFirstNumber < lSecondNumber )
566  return -1;
567  // If the first two sections are equal and the endings are modifiers then compare them
568  else if( !endingIsModifier )
569  return strFWordEnd.CmpNoCase( strSWordEnd );
570  // Ran out of things to compare; they must match
571  else
572  return 0;
573  }
574 }
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:577
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:123
bool ApplyModifier(double &value, const wxString &aString)
Definition: string.cpp:481

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

423 {
424  const wxChar* cp = NULL, * mp = NULL;
425  const wxChar* wild, * string;
426  wxString _pattern, _string_to_tst;
427 
428  if( case_sensitive )
429  {
430  wild = pattern.GetData();
431  string = string_to_tst.GetData();
432  }
433  else
434  {
435  _pattern = pattern;
436  _pattern.MakeUpper();
437  _string_to_tst = string_to_tst;
438  _string_to_tst.MakeUpper();
439  wild = _pattern.GetData();
440  string = _string_to_tst.GetData();
441  }
442 
443  while( ( *string ) && ( *wild != '*' ) )
444  {
445  if( ( *wild != *string ) && ( *wild != '?' ) )
446  return false;
447 
448  wild++; string++;
449  }
450 
451  while( *string )
452  {
453  if( *wild == '*' )
454  {
455  if( !*++wild )
456  return 1;
457  mp = wild;
458  cp = string + 1;
459  }
460  else if( ( *wild == *string ) || ( *wild == '?' ) )
461  {
462  wild++;
463  string++;
464  }
465  else
466  {
467  wild = mp;
468  string = cp++;
469  }
470  }
471 
472  while( *wild == '*' )
473  {
474  wild++;
475  }
476 
477  return !*wild;
478 }

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