KiCad PCB EDA Suite
string_utils.h File Reference
#include "config.h"
#include <string>
#include <vector>
#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_LINE,
  CTX_FILENAME, CTX_NO_SPACE
}
 Escape/Unescape routines to safely encode reserved-characters in various contexts. More...
 

Functions

void ConvertMarkdown2Html (const wxString &aMarkdownInput, wxString &aHtmlOutput)
 
wxString ConvertToNewOverbarNotation (const wxString &aOldStr)
 Convert the old ~...~ overbar notation to the new ~{...} one. More...
 
bool ConvertSmartQuotesAndDashes (wxString *aString)
 Convert curly quotes and em/en dashes to straight quotes and dashes. More...
 
wxString EscapeString (const wxString &aSource, ESCAPE_CONTEXT aContext)
 The 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...
 
wxString TitleCaps (const wxString &aString)
 Capitalize the first letter in each word. 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 (const wxString &aString)
 Return an 8 bit UTF8 string given aString in Unicode form. More...
 
wxString EscapeHTML (const wxString &aString)
 Return a new wxString escaped for embedding in HTML. More...
 
char * GetLine (FILE *aFile, char *Line, int *LineNum=nullptr, int SizeLine=255)
 Read one line line from aFile. More...
 
bool NoPrintableChars (const wxString &aString)
 Return true if the string is empty or contains only whitespace. More...
 
int PrintableCharCount (const wxString &aString)
 Return the number of printable (ie: non-formatting) chars. 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 (const wxString &strFWord, const wxString &strSWord)
 Compare strings like the strcmp function but handle numbers and modifiers within the string text correctly for sorting. More...
 
int SplitString (const wxString &strToSplit, wxString *strBeginning, wxString *strDigits, wxString *strEnd)
 Break 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)
 
static std::vector< std::string > split (const std::string &aStr, const std::string &aDelim)
 Split the input string into a vector of output strings. More...
 
void AccumulateDescription (wxString &aDesc, const wxString &aItem)
 Utility to build comma separated lists in messages. More...
 
void wxStringSplit (const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
 Split aString to a string list separated at aSplitter. More...
 
void StripTrailingZeros (wxString &aStringValue, unsigned aTrailingZeroAllowed=1)
 Remove trailing zeros from a string containing a converted float number. More...
 
std::string Double2Str (double aValue)
 Print a float number without using scientific notation and no trailing 0 We want to avoid scientific notation in S-expr files (not easy to read) for floating numbers. More...
 
wxString AngleToStringDegrees (double aAngle)
 A helper to convert the double aAngle (in internal unit) to a string in degrees. More...
 

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_LINE 
CTX_FILENAME 
CTX_NO_SPACE 

Definition at line 52 of file string_utils.h.

53 {
55  CTX_LIBID,
57  CTX_LINE,
59  CTX_NO_SPACE // to replace spaces in names that do not accept spaces
60 };

Function Documentation

◆ AccumulateDescription()

void AccumulateDescription ( wxString &  aDesc,
const wxString &  aItem 
)
inline

Utility to build comma separated lists in messages.

Definition at line 319 of file string_utils.h.

320 {
321  if( !aDesc.IsEmpty() )
322  aDesc << wxT( ", " );
323 
324  aDesc << aItem;
325 }

Referenced by ZONE::GetMsgPanelInfo().

◆ AngleToStringDegrees()

wxString AngleToStringDegrees ( double  aAngle)

A helper to convert the double aAngle (in internal unit) to a string in degrees.

Definition at line 1080 of file string_utils.cpp.

1081 {
1082  wxString text;
1083 
1084  text.Printf( wxT( "%.3f" ), aAngle / 10.0 );
1085  StripTrailingZeros( text, 1 );
1086 
1087  return text;
1088 }
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Remove trailing zeros from a string containing a converted float number.

References StripTrailingZeros(), and text.

Referenced by PANEL_EDIT_OPTIONS::TransferDataToWindow().

◆ ConvertMarkdown2Html()

void ConvertMarkdown2Html ( const wxString &  aMarkdownInput,
wxString &  aHtmlOutput 
)

◆ ConvertSmartQuotesAndDashes()

bool ConvertSmartQuotesAndDashes ( wxString *  aString)

Convert curly quotes and em/en dashes to straight quotes and dashes.

Returns
true if any characters required conversion.

Definition at line 114 of file string_utils.cpp.

115 {
116  bool retVal = false;
117 
118  for( wxString::iterator ii = aString->begin(); ii != aString->end(); ++ii )
119  {
120  if( *ii == L'\u00B4' || *ii == L'\u2018' || *ii == L'\u2019' )
121  {
122  *ii = '\'';
123  retVal = true;
124  }
125  if( *ii == L'\u201C' || *ii == L'\u201D' )
126  {
127  *ii = '"';
128  retVal = true;
129  }
130  if( *ii == L'\u2013' || *ii == L'\u2014' )
131  {
132  *ii = '-';
133  retVal = true;
134  }
135  }
136 
137  return retVal;
138 }

Referenced by WX_HTML_REPORT_PANEL::onBtnSaveToFile(), SCINTILLA_TRICKS::onCharHook(), and PANEL_SETUP_RULES::TransferDataToWindow().

◆ ConvertToNewOverbarNotation()

wxString ConvertToNewOverbarNotation ( const wxString &  aOldStr)

Convert the old ~...~ overbar notation to the new ~{...} one.

Definition at line 44 of file string_utils.cpp.

45 {
46  wxString newStr;
47  bool inOverbar = false;
48 
49  // Don't get tripped up by the legacy empty-string token.
50  if( aOldStr == "~" )
51  return aOldStr;
52 
53  for( wxString::const_iterator chIt = aOldStr.begin(); chIt != aOldStr.end(); ++chIt )
54  {
55  if( *chIt == '~' )
56  {
57  wxString::const_iterator lookahead = chIt + 1;
58 
59  if( lookahead != aOldStr.end() && *lookahead == '~' )
60  {
61  if( ++lookahead != aOldStr.end() && *lookahead == '{' )
62  {
63  // This way the subsequent opening curly brace will not start an
64  // overbar.
65  newStr << "~~{}";
66  continue;
67  }
68 
69  // Two subsequent tildes mean a tilde.
70  newStr << "~";
71  ++chIt;
72  continue;
73  }
74  else if( lookahead != aOldStr.end() && *lookahead == '{' )
75  {
76  // Could mean the user wants "{" with an overbar, but more likely this
77  // is a case of double notation conversion. Bail out.
78  return aOldStr;
79  }
80  else
81  {
82  if( inOverbar )
83  {
84  newStr << "}";
85  inOverbar = false;
86  }
87  else
88  {
89  newStr << "~{";
90  inOverbar = true;
91  }
92 
93  continue;
94  }
95  }
96  else if( ( *chIt == ' ' || *chIt == '}' || *chIt == ')' ) && inOverbar )
97  {
98  // Spaces were used to terminate overbar as well
99  newStr << "}";
100  inOverbar = false;
101  }
102 
103  newStr << *chIt;
104  }
105 
106  // Explicitly end the overbar even if there was no terminating '~' in the aOldStr.
107  if( inOverbar )
108  newStr << "}";
109 
110  return newStr;
111 }

Referenced by escapeName(), CADSTAR_ARCHIVE_PARSER::HandleTextOverbar(), SCH_LEGACY_PLUGIN_CACHE::loadField(), LEGACY_PLUGIN::loadMODULE_TEXT(), LEGACY_PLUGIN::loadNETCLASS(), LEGACY_PLUGIN::loadNETINFO_ITEM(), LEGACY_PLUGIN::loadPAD(), LEGACY_PLUGIN::loadPCB_TEXT(), SCH_LEGACY_PLUGIN_CACHE::loadPin(), SCH_LEGACY_PLUGIN::loadSheet(), SCH_LEGACY_PLUGIN::loadText(), SCH_LEGACY_PLUGIN_CACHE::loadText(), NET_SETTINGS::migrateSchema0to1(), SCH_SEXPR_PARSER::parseBusAlias(), SCH_SEXPR_PARSER::parseEDA_TEXT(), PCB_PARSER::parseEDA_TEXT(), PCB_PARSER::parseNETCLASS(), PCB_PARSER::parseNETINFO_ITEM(), PCB_PARSER::parsePAD(), SCH_SEXPR_PARSER::parsePin(), and DRAWING_SHEET_PARSER::parseText().

◆ DateAndTime()

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

Definition at line 604 of file string_utils.cpp.

605 {
606  wxDateTime datetime = wxDateTime::Now();
607 
608  datetime.SetCountry( wxDateTime::Country_Default );
609  return datetime.Format( wxDefaultDateTimeFormat, wxDateTime::Local );
610 }

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

◆ Double2Str()

std::string Double2Str ( double  aValue)

Print a float number without using scientific notation and no trailing 0 We want to avoid scientific notation in S-expr files (not easy to read) for floating numbers.

We cannot always just use the g or the f format to print a fp number this helper function uses the f format when needed, or g when f is not well working and then removes trailing 0

Definition at line 1050 of file string_utils.cpp.

1051 {
1052  char buf[50];
1053  int len;
1054 
1055  if( aValue != 0.0 && std::fabs( aValue ) <= 0.0001 )
1056  {
1057  // For these small values, %f works fine,
1058  // and %g gives an exponent
1059  len = sprintf( buf, "%.16f", aValue );
1060 
1061  while( --len > 0 && buf[len] == '0' )
1062  buf[len] = '\0';
1063 
1064  if( buf[len] == '.' )
1065  buf[len] = '\0';
1066  else
1067  ++len;
1068  }
1069  else
1070  {
1071  // For these values, %g works fine, and sometimes %f
1072  // gives a bad value (try aValue = 1.222222222222, with %.16f format!)
1073  len = sprintf( buf, "%.10g", aValue );
1074  }
1075 
1076  return std::string( buf, len );
1077 }

Referenced by PANEL_SETUP_BOARD_STACKUP::createRowData(), GBR_TO_PCB_EXPORTER::export_non_copper_item(), GBR_TO_PCB_EXPORTER::export_via(), PCB_PLUGIN::format(), BOARD_STACKUP::FormatBoardStackup(), DIELECTRIC_SUBSTRATE::FormatEpsilonR(), BOARD_STACKUP_ITEM::FormatEpsilonR(), DIELECTRIC_SUBSTRATE::FormatLossTangent(), BOARD_STACKUP_ITEM::FormatLossTangent(), PCB_PLUGIN::formatSetup(), formatStroke(), NUMERIC_EVALUATOR::parseSetResult(), SCH_SEXPR_PLUGIN::saveJunction(), PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard(), GBR_TO_PCB_EXPORTER::writeCopperLineItem(), GBR_TO_PCB_EXPORTER::writePcbFilledCircle(), GBR_TO_PCB_EXPORTER::writePcbPolygon(), and GBR_TO_PCB_EXPORTER::writePcbZoneItem().

◆ EscapedUTF8()

std::string EscapedUTF8 ( const wxString &  aString)

Return 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
the escaped input text, without the wrapping double quotes.

Definition at line 414 of file string_utils.cpp.

415 {
416  wxString str = aString;
417 
418  // No new-lines allowed in quoted strings
419  str.Replace( "\r\n", "\r" );
420  str.Replace( "\n", "\r" );
421 
422  std::string utf8 = TO_UTF8( aString );
423 
424  std::string ret;
425 
426  ret += '"';
427 
428  for( std::string::const_iterator it = utf8.begin(); it!=utf8.end(); ++it )
429  {
430  // this escaping strategy is designed to be compatible with ReadDelimitedText():
431  if( *it == '"' )
432  {
433  ret += '\\';
434  ret += '"';
435  }
436  else if( *it == '\\' )
437  {
438  ret += '\\'; // double it up
439  ret += '\\';
440  }
441  else
442  {
443  ret += *it;
444  }
445  }
446 
447  ret += '"';
448 
449  return ret;
450 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96

References TO_UTF8.

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

◆ EscapeHTML()

wxString EscapeHTML ( const wxString &  aString)

Return a new wxString escaped for embedding in HTML.

Definition at line 453 of file string_utils.cpp.

454 {
455  wxString converted;
456 
457  for( wxUniChar c : aString )
458  {
459  if( c == '\"' )
460  converted += "&quot;";
461  else if( c == '\'' )
462  converted += "&apos;";
463  else if( c == '&' )
464  converted += "&amp;";
465  else if( c == '<' )
466  converted += "&lt;";
467  else if( c == '>' )
468  converted += "&gt;";
469  else
470  converted += c;
471  }
472 
473  return converted;
474 }

Referenced by DRC_ENGINE::EvalRules(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), FOOTPRINT_INFO_GENERATOR::GetHtmlFieldRow(), BOARD_INSPECTION_TOOL::InspectClearance(), BOARD_INSPECTION_TOOL::InspectConstraints(), BOARD_INSPECTION_TOOL::InspectDRCError(), FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf(), FOOTPRINT_INFO_GENERATOR::SetHtmlDesc(), FOOTPRINT_INFO_GENERATOR::SetHtmlKeywords(), FOOTPRINT_INFO_GENERATOR::SetHtmlName(), and PANEL_PACKAGES_VIEW::setPackageDetails().

◆ EscapeString()

wxString EscapeString ( const wxString &  aSource,
ESCAPE_CONTEXT  aContext 
)

The 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 141 of file string_utils.cpp.

142 {
143  wxString converted;
144 
145  for( wxUniChar c: aSource )
146  {
147  if( aContext == CTX_NETNAME )
148  {
149  if( c == '/' )
150  converted += "{slash}";
151  else if( c == '\n' || c == '\r' )
152  converted += ""; // drop
153  else
154  converted += c;
155  }
156  else if( aContext == CTX_LIBID )
157  {
158  if( c == '{' )
159  converted += "{brace}";
160  else if( c == '/' )
161  converted += "{slash}";
162  else if( c == '\\' )
163  converted += "{backslash}";
164  else if( c == '<' )
165  converted += "{lt}";
166  else if( c == '>' )
167  converted += "{gt}";
168  else if( c == ':' )
169  converted += "{colon}";
170  else if( c == '\"' )
171  converted += "{dblquote}";
172  else if( c == '\n' || c == '\r' )
173  converted += ""; // drop
174  else
175  converted += c;
176  }
177  else if( aContext == CTX_QUOTED_STR )
178  {
179  if( c == '\"' )
180  converted += "{dblquote}";
181  else
182  converted += c;
183  }
184  else if( aContext == CTX_LINE )
185  {
186  if( c == '\n' || c == '\r' )
187  converted += "{return}";
188  else
189  converted += c;
190  }
191  else if( aContext == CTX_FILENAME )
192  {
193  if( c == '{' )
194  converted += "{brace}";
195  else if( c == '/' )
196  converted += "{slash}";
197  else if( c == '\\' )
198  converted += "{backslash}";
199  else if( c == '\"' )
200  converted += "{dblquote}";
201  else if( c == '<' )
202  converted += "{lt}";
203  else if( c == '>' )
204  converted += "{gt}";
205  else if( c == '|' )
206  converted += "{bar}";
207  else if( c == ':' )
208  converted += "{colon}";
209  else if( c == '\t' )
210  converted += "{tab}";
211  else if( c == '\n' || c == '\r' )
212  converted += "{return}";
213  else
214  converted += c;
215  }
216  else if( aContext == CTX_NO_SPACE )
217  {
218  if( c == ' ' )
219  converted += "{space}";
220  else if( c == '{' )
221  converted += "{brace}";
222  else
223  converted += c;
224  }
225  else
226  converted += c;
227  }
228 
229  return converted;
230 }

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

Referenced by AltiumToKiCadLibID(), SCH_EDIT_TOOL::ChangeTextType(), SYMBOL_VIEWER_FRAME::ClickOnCmpList(), SYMBOL_VIEWER_FRAME::ClickOnLibList(), PANEL_SYM_LIB_TABLE::convertLibrary(), CONNECTION_SUBGRAPH::driverName(), SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties(), CONNECTION_GRAPH::ercCheckBusToNetConflicts(), CONNECTION_GRAPH::ercCheckLabels(), TEXT_BUTTON_SYMBOL_CHOOSER::escapeLibId(), SYMBOL_VIEWER_FRAME::FinishModal(), getLibIdValue(), DIALOG_LIB_NEW_SYMBOL::GetName(), DIALOG_LIB_NEW_SYMBOL::GetParentSymbolName(), SYMBOL_EDIT_FRAME::ImportSymbol(), SCH_LEGACY_PLUGIN_CACHE::loadField(), SCH_EAGLE_PLUGIN::loadInstance(), SCH_EAGLE_PLUGIN::loadLibrary(), SCH_LEGACY_PLUGIN_CACHE::LoadPart(), CADSTAR_SCH_ARCHIVE_LOADER::loadPartsLibrary(), CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances(), SCH_EAGLE_PLUGIN::loadSegments(), DIALOG_NET_INSPECTOR::onRenameNet(), NET_SETTINGS::ParseBusGroup(), SCH_SEXPR_PLUGIN_CACHE::saveDcmInfoAsFields(), SIM_PLOT_FRAME::saveWorkbook(), LIB_TABLE_GRID::SetValue(), FIELDS_GRID_TABLE< SCH_FIELD >::SetValue(), DIALOG_SHEET_PIN_PROPERTIES::TransferDataFromWindow(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow(), DIALOG_LIB_FIELD_PROPERTIES::UpdateField(), and FOOTPRINT_LIST_IMPL::WriteCacheToFile().

◆ GetIllegalFileNameWxChars()

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

Definition at line 938 of file string_utils.cpp.

939 {
941 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const char illegalFileNameChars[]
Illegal file name characters used to ensure file names will be valid on all supported platforms.

References FROM_UTF8(), and illegalFileNameChars.

Referenced by ReplaceIllegalFileNameChars().

◆ GetLine()

char* GetLine ( FILE *  aFile,
char *  Line,
int *  LineNum = nullptr,
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 588 of file string_utils.cpp.

589 {
590  do {
591  if( fgets( Line, SizeLine, File ) == nullptr )
592  return nullptr;
593 
594  if( LineNum )
595  *LineNum += 1;
596 
597  } while( Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r' || Line[0] == 0 );
598 
599  strtok( Line, "\n\r" );
600  return Line;
601 }

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 914 of file string_utils.cpp.

915 {
916  int number = 0;
917  int base = 1;
918 
919  // Trim and extract the trailing numeric part
920  int index = aStr.Len() - 1;
921 
922  while( index >= 0 )
923  {
924  const char chr = aStr.GetChar( index );
925 
926  if( chr < '0' || chr > '9' )
927  break;
928 
929  number += ( chr - '0' ) * base;
930  base *= 10;
931  index--;
932  }
933 
934  return number;
935 }

Referenced by BOOST_AUTO_TEST_CASE(), FOOTPRINT::GetNextPadNumber(), and FOOTPRINT::IncrementReference().

◆ NoPrintableChars()

bool NoPrintableChars ( const wxString &  aString)

Return true if the string is empty or contains only whitespace.

Definition at line 477 of file string_utils.cpp.

478 {
479  wxString tmp = aString;
480 
481  return tmp.Trim( true ).Trim( false ).IsEmpty();
482 }

Referenced by SCH_DRAWING_TOOLS::createNewText(), SCH_DRAWING_TOOLS::createSheetPin(), DRAWING_TOOL::PlaceText(), and SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace().

◆ PrettyPrintForMenu()

wxString PrettyPrintForMenu ( const wxString &  aString)

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

◆ PrintableCharCount()

int PrintableCharCount ( const wxString &  aString)

Return the number of printable (ie: non-formatting) chars.

Used to approximate rendered text size when speed is more important than accuracy.

Definition at line 489 of file string_utils.cpp.

490 {
491  int char_count = 0;
492  int overbarDepth = -1;
493  int superSubDepth = -1;
494  int braceNesting = 0;
495 
496  for( auto chIt = aString.begin(), end = aString.end(); chIt < end; ++chIt )
497  {
498  if( *chIt == '\t' )
499  {
500  // We don't format tabs in bitmap text (where this is currently used), so just
501  // drop them from the count.
502  continue;
503  }
504  else if( *chIt == '^' && superSubDepth == -1 )
505  {
506  auto lookahead = chIt;
507 
508  if( ++lookahead != end && *lookahead == '{' )
509  {
510  chIt = lookahead;
511  superSubDepth = braceNesting;
512  braceNesting++;
513  continue;
514  }
515  }
516  else if( *chIt == '_' && superSubDepth == -1 )
517  {
518  auto lookahead = chIt;
519 
520  if( ++lookahead != end && *lookahead == '{' )
521  {
522  chIt = lookahead;
523  superSubDepth = braceNesting;
524  braceNesting++;
525  continue;
526  }
527  }
528  else if( *chIt == '~' && overbarDepth == -1 )
529  {
530  auto lookahead = chIt;
531 
532  if( ++lookahead != end && *lookahead == '{' )
533  {
534  chIt = lookahead;
535  overbarDepth = braceNesting;
536  braceNesting++;
537  continue;
538  }
539  }
540  else if( *chIt == '{' )
541  {
542  braceNesting++;
543  }
544  else if( *chIt == '}' )
545  {
546  if( braceNesting > 0 )
547  braceNesting--;
548 
549  if( braceNesting == superSubDepth )
550  {
551  superSubDepth = -1;
552  continue;
553  }
554 
555  if( braceNesting == overbarDepth )
556  {
557  overbarDepth = -1;
558  continue;
559  }
560  }
561 
562  char_count++;
563  }
564 
565  return char_count;
566 }

Referenced by KIGFX::PCB_PAINTER::draw().

◆ 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
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 365 of file string_utils.cpp.

366 {
367  if( aDestSize <= 0 )
368  return 0;
369 
370  bool inside = false;
371  const char* start = aSource;
372  char* limit = aDest + aDestSize - 1;
373  char cc;
374 
375  while( (cc = *aSource++) != 0 && aDest < limit )
376  {
377  if( cc == '"' )
378  {
379  if( inside )
380  break; // 2nd double quote is end of delimited text
381 
382  inside = true; // first delimiter found, make note, do not copy
383  }
384 
385  else if( inside )
386  {
387  if( cc == '\\' )
388  {
389  cc = *aSource++;
390 
391  if( !cc )
392  break;
393 
394  // do no copy the escape byte if it is followed by \ or "
395  if( cc != '"' && cc != '\\' )
396  *aDest++ = '\\';
397 
398  if( aDest < limit )
399  *aDest++ = cc;
400  }
401  else
402  {
403  *aDest++ = cc;
404  }
405  }
406  }
407 
408  *aDest = 0;
409 
410  return aSource - start;
411 }

◆ 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
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 320 of file string_utils.cpp.

321 {
322  std::string utf8; // utf8 but without escapes and quotes.
323  bool inside = false;
324  const char* start = aSource;
325  char cc;
326 
327  while( (cc = *aSource++) != 0 )
328  {
329  if( cc == '"' )
330  {
331  if( inside )
332  break; // 2nd double quote is end of delimited text
333 
334  inside = true; // first delimiter found, make note, do not copy
335  }
336 
337  else if( inside )
338  {
339  if( cc == '\\' )
340  {
341  cc = *aSource++;
342 
343  if( !cc )
344  break;
345 
346  // do no copy the escape byte if it is followed by \ or "
347  if( cc != '"' && cc != '\\' )
348  utf8 += '\\';
349 
350  utf8 += cc;
351  }
352  else
353  {
354  utf8 += cc;
355  }
356  }
357  }
358 
359  *aDest = FROM_UTF8( utf8.c_str() );
360 
361  return aSource - start;
362 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110

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 944 of file string_utils.cpp.

945 {
946  bool changed = false;
947  std::string result;
948  result.reserve( aName->length() );
949 
950  for( std::string::iterator it = aName->begin(); it != aName->end(); ++it )
951  {
952  if( strchr( illegalFileNameChars, *it ) )
953  {
954  if( aReplaceChar )
955  StrPrintf( &result, "%c", aReplaceChar );
956  else
957  StrPrintf( &result, "%%%02x", *it );
958 
959  changed = true;
960  }
961  else
962  {
963  result += *it;
964  }
965  }
966 
967  if( changed )
968  *aName = result;
969 
970  return changed;
971 }
static const char illegalFileNameChars[]
Illegal file name characters used to ensure file names will be valid on all supported platforms.
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
Definition: richio.cpp:79

References illegalFileNameChars, and StrPrintf().

Referenced by EDEVICE::EDEVICE(), EELEMENT::EELEMENT(), LEGACY_PLUGIN::loadAllSections(), FABMASTER::loadFootprints(), EAGLE_PLUGIN::loadLibrary(), LP_CACHE::LoadModules(), SCH_EAGLE_PLUGIN::loadSheet(), CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets(), and CADSTAR_SCH_ARCHIVE_LOADER::loadSheets().

◆ ReplaceIllegalFileNameChars() [2/2]

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

Definition at line 974 of file string_utils.cpp.

975 {
976  bool changed = false;
977  wxString result;
978  result.reserve( aName.Length() );
979  wxString illWChars = GetIllegalFileNameWxChars();
980 
981  for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
982  {
983  if( illWChars.Find( *it ) != wxNOT_FOUND )
984  {
985  if( aReplaceChar )
986  result += aReplaceChar;
987  else
988  result += wxString::Format( "%%%02x", *it );
989 
990  changed = true;
991  }
992  else
993  {
994  result += *it;
995  }
996  }
997 
998  if( changed )
999  aName = result;
1000 
1001  return changed;
1002 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString GetIllegalFileNameWxChars()

References Format(), and GetIllegalFileNameWxChars().

◆ split()

static std::vector<std::string> split ( const std::string &  aStr,
const std::string &  aDelim 
)
inlinestatic

Split the input string into a vector of output strings.

Note
Multiple delimiters are considered to be separate records with empty strings
Parameters
aStrInput string with 0 or more delimiters.
aDelimThe string of delimiter. Multiple characters here denote alternate delimiters.
Returns
a vector of strings

Definition at line 293 of file string_utils.h.

294 {
295  size_t pos = 0;
296  size_t last_pos = 0;
297  size_t len;
298 
299  std::vector<std::string> tokens;
300 
301  while( pos < aStr.size() )
302  {
303  pos = aStr.find_first_of( aDelim, last_pos );
304 
305  if( pos == std::string::npos )
306  pos = aStr.size();
307 
308  len = pos - last_pos;
309 
310  tokens.push_back( aStr.substr( last_pos, len ) );
311 
312  last_pos = pos + 1;
313  }
314 
315  return tokens;
316 }

Referenced by CompareToBucket::CompareToBucket(), HLBVH_SAH_Evaluator::HLBVH_SAH_Evaluator(), PCB_EDIT_FRAME::KiwayMailIn(), SCH_EDIT_FRAME::KiwayMailIn(), FABMASTER::processText(), and PNS::NODE::rebuildJoint().

◆ SplitString()

int SplitString ( const wxString &  strToSplit,
wxString *  strBeginning,
wxString *  strDigits,
wxString *  strEnd 
)

Break 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 853 of file string_utils.cpp.

857 {
858  static const wxString separators( wxT( ".," ) );
859 
860  // Clear all the return strings
861  strBeginning->Empty();
862  strDigits->Empty();
863  strEnd->Empty();
864 
865  // There no need to do anything if the string is empty
866  if( strToSplit.length() == 0 )
867  return 0;
868 
869  // Starting at the end of the string look for the first digit
870  int ii;
871 
872  for( ii = (strToSplit.length() - 1); ii >= 0; ii-- )
873  {
874  if( wxIsdigit( strToSplit[ii] ) )
875  break;
876  }
877 
878  // If there were no digits then just set the single string
879  if( ii < 0 )
880  {
881  *strBeginning = strToSplit;
882  }
883  else
884  {
885  // Since there is at least one digit this is the trailing string
886  *strEnd = strToSplit.substr( ii + 1 );
887 
888  // Go to the end of the digits
889  int position = ii + 1;
890 
891  for( ; ii >= 0; ii-- )
892  {
893  if( !wxIsdigit( strToSplit[ii] ) && separators.Find( strToSplit[ii] ) < 0 )
894  break;
895  }
896 
897  // If all that was left was digits, then just set the digits string
898  if( ii < 0 )
899  *strDigits = strToSplit.substr( 0, position );
900 
901  /* We were only looking for the last set of digits everything else is
902  * part of the preamble */
903  else
904  {
905  *strDigits = strToSplit.substr( ii + 1, position - ii - 1 );
906  *strBeginning = strToSplit.substr( 0, ii + 1 );
907  }
908  }
909 
910  return 0;
911 }

Referenced by ValueStringCompare().

◆ StripTrailingZeros()

void StripTrailingZeros ( wxString &  aStringValue,
unsigned  aTrailingZeroAllowed = 1 
)

Remove trailing zeros from a string containing a converted float number.

The trailing zeros are removed if the mantissa has more than aTrailingZeroAllowed digits and some trailing zeros.

Definition at line 1028 of file string_utils.cpp.

1029 {
1030  struct lconv* lc = localeconv();
1031  char sep = lc->decimal_point[0];
1032  unsigned sep_pos = aStringValue.Find( sep );
1033 
1034  if( sep_pos > 0 )
1035  {
1036  // We want to keep at least aTrailingZeroAllowed digits after the separator
1037  unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
1038 
1039  while( aStringValue.Len() > min_len )
1040  {
1041  if( aStringValue.Last() == '0' )
1042  aStringValue.RemoveLast();
1043  else
1044  break;
1045  }
1046  }
1047 }

Referenced by AngleToStringDegrees().

◆ 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 613 of file string_utils.cpp.

614 {
615  int nb1 = 0, nb2 = 0;
616 
617  auto str1 = aString1.begin();
618  auto str2 = aString2.begin();
619 
620  while( str1 != aString1.end() && str2 != aString2.end() )
621  {
622  wxUniChar c1 = *str1;
623  wxUniChar c2 = *str2;
624 
625  if( wxIsdigit( c1 ) && wxIsdigit( c2 ) ) // Both characters are digits, do numeric compare.
626  {
627  nb1 = 0;
628  nb2 = 0;
629 
630  do
631  {
632  c1 = *str1;
633  nb1 = nb1 * 10 + (int) c1 - '0';
634  ++str1;
635  } while( str1 != aString1.end() && wxIsdigit( *str1 ) );
636 
637  do
638  {
639  c2 = *str2;
640  nb2 = nb2 * 10 + (int) c2 - '0';
641  ++str2;
642  } while( str2 != aString2.end() && wxIsdigit( *str2 ) );
643 
644  if( nb1 < nb2 )
645  return -1;
646 
647  if( nb1 > nb2 )
648  return 1;
649 
650  c1 = ( str1 != aString1.end() ) ? *str1 : wxUniChar( 0 );
651  c2 = ( str2 != aString2.end() ) ? *str2 : wxUniChar( 0 );
652  }
653 
654  // Any numerical comparisons to here are identical.
655  if( aIgnoreCase )
656  {
657  if( wxToupper( c1 ) < wxToupper( c2 ) )
658  return -1;
659 
660  if( wxToupper( c1 ) > wxToupper( c2 ) )
661  return 1;
662  }
663  else
664  {
665  if( c1 < c2 )
666  return -1;
667 
668  if( c1 > c2 )
669  return 1;
670  }
671 
672  if( str1 != aString1.end() )
673  ++str1;
674 
675  if( str2 != aString2.end() )
676  ++str2;
677  }
678 
679  if( str1 == aString1.end() && str2 != aString2.end() )
680  {
681  return -1; // Identical to here but aString1 is longer.
682  }
683  else if( str1 != aString1.end() && str2 == aString2.end() )
684  {
685  return 1; // Identical to here but aString2 is longer.
686  }
687 
688  return 0;
689 }

Referenced by REGULATOR_LIST::Add(), LIB_TREE_NODE::AssignIntrinsicRanks(), BOOST_AUTO_TEST_CASE(), ChangeArrayCompare(), FIELDS_EDITOR_GRID_DATA_MODEL::cmp(), SCH_PIN_TABLE_DATA_MODEL::compare(), PIN_TABLE_DATA_MODEL::compare(), SCH_SHEET::ComparePageNum(), SCH_FIELD::DoHypertextMenu(), PLACE_FILE_EXPORTER::GenReportData(), FP_TREE_MODEL_ADAPTER::getFootprints(), FIELDS_EDITOR_GRID_DATA_MODEL::GetValue(), NETLIST_EXPORTER_XML::makeListOfNets(), NETLIST_EXPORTER_XML::makeSymbols(), myCompareFunction(), FOOTPRINT::cmp_pads::operator()(), operator<(), BOARD_REANNOTATE_TOOL::ReannotateDuplicates(), SCH_GLOBALLABEL::ResolveTextVar(), SCH_REFERENCE_LIST::sortByReferenceOnly(), sortFPlist(), sortPinsByNum(), sortPinsByNumber(), 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 569 of file string_utils.cpp.

570 {
571  static const char whitespace[] = " \t\n\r\f\v";
572 
573  if( text )
574  {
575  while( *text && strchr( whitespace, *text ) )
576  ++text;
577 
578  char* cp = text + strlen( text ) - 1;
579 
580  while( cp >= text && strchr( whitespace, *cp ) )
581  *cp-- = '\0';
582  }
583 
584  return text;
585 }

References text.

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

◆ strtok_r()

◆ TitleCaps()

wxString TitleCaps ( const wxString &  aString)

Capitalize the first letter in each word.

Definition at line 301 of file string_utils.cpp.

302 {
303  wxArrayString words;
304  wxString result;
305 
306  wxStringSplit( aString, words, ' ' );
307 
308  for( const wxString& word : words )
309  {
310  if( !result.IsEmpty() )
311  result += wxT( " " );
312 
313  result += word.Capitalize();
314  }
315 
316  return result;
317 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.

References wxStringSplit().

Referenced by SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties(), and SCH_EDIT_TOOL::editFieldText().

◆ UnescapeString()

wxString UnescapeString ( const wxString &  aSource)

Definition at line 233 of file string_utils.cpp.

234 {
235  wxString newbuf;
236  size_t sourceLen = aSource.length();
237 
238  for( size_t i = 0; i < sourceLen; ++i )
239  {
240  wxUniChar ch = aSource[i];
241  if( ( ch == '$' || ch == '^' || ch == '_' )
242  && i + 1 < sourceLen && aSource[i+1] == '{' )
243  {
244  for( ; i < sourceLen; ++i )
245  {
246  ch = aSource[i];
247  newbuf += ch;
248 
249  if( ch == '}' )
250  break;
251  }
252  }
253  else if( ch == '{' )
254  {
255  wxString token;
256  int depth = 1;
257 
258  for( i = i + 1; i < sourceLen; ++i )
259  {
260  ch = aSource[i];
261  if( ch == '{' )
262  depth++;
263  else if( ch == '}' )
264  depth--;
265 
266  if( depth <= 0 )
267  break;
268  else
269  token.append( ch );
270  }
271 
272  if( token == wxS( "dblquote" ) ) newbuf.append( wxS( "\"" ) );
273  else if( token == wxS( "quote" ) ) newbuf.append( wxS( "'" ) );
274  else if( token == wxS( "lt" ) ) newbuf.append( wxS( "<" ) );
275  else if( token == wxS( "gt" ) ) newbuf.append( wxS( ">" ) );
276  else if( token == wxS( "backslash" ) ) newbuf.append( wxS( "\\" ) );
277  else if( token == wxS( "slash" ) ) newbuf.append( wxS( "/" ) );
278  else if( token == wxS( "bar" ) ) newbuf.append( wxS( "|" ) );
279  else if( token == wxS( "colon" ) ) newbuf.append( wxS( ":" ) );
280  else if( token == wxS( "space" ) ) newbuf.append( wxS( " " ) );
281  else if( token == wxS( "dollar" ) ) newbuf.append( wxS( "$" ) );
282  else if( token == wxS( "tab" ) ) newbuf.append( wxS( "\t" ) );
283  else if( token == wxS( "return" ) ) newbuf.append( wxS( "\n" ) );
284  else if( token == wxS( "brace" ) ) newbuf.append( wxS( "{" ) );
285  else if( token.IsEmpty() ) newbuf.append( wxS( "{" ) );
286  else
287  {
288  newbuf.append( "{" + UnescapeString( token ) + "}" );
289  }
290  }
291  else
292  {
293  newbuf.append( ch );
294  }
295  }
296 
297  return newbuf;
298 }
wxString UnescapeString(const wxString &aSource)

References UnescapeString().

Referenced by NET_SELECTOR_COMBOPOPUP::Accept(), DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid(), NETLIST_EXPORTER_XML::addSymbolFields(), SCH_CONNECTION::AppendInfoToMsgPanel(), EDA_TEXT::cacheShownText(), SCH_EDIT_TOOL::ChangeTextType(), NETLIST_EXPORTER_PSPICE_SIM::ComponentToVector(), SCH_CONNECTION::ConfigureFromLabel(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES(), DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL(), DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS(), GRID_CELL_ESCAPED_TEXT_RENDERER::Draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), CONNECTION_GRAPH::ercCheckHierSheets(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), SYMBOL_EDIT_FRAME::ExportSymbol(), NETLIST_EXPORTER_PSPICE::Format(), DIALOG_NET_INSPECTOR::formatNetName(), GRID_CELL_ESCAPED_TEXT_RENDERER::GetBestSize(), PCB_TEXT::GetMsgPanelInfo(), LIB_TEXT::GetMsgPanelInfo(), ZONE::GetMsgPanelInfo(), LIB_FIELD::GetMsgPanelInfo(), NETINFO_ITEM::GetMsgPanelInfo(), LIB_PIN::GetMsgPanelInfo(), FP_TEXT::GetMsgPanelInfo(), SCH_FIELD::GetMsgPanelInfo(), GERBER_DRAW_ITEM::GetMsgPanelInfo(), SCH_TEXT::GetMsgPanelInfo(), SCH_SYMBOL::GetMsgPanelInfo(), PAD::GetMsgPanelInfo(), PCB_TRACK::GetMsgPanelInfoBase_Common(), BOARD_CONNECTED_ITEM::GetNetnameMsg(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetRootSymbolNames(), LIB_PIN::GetSelectMenuText(), SCH_SYMBOL::GetSelectMenuText(), DIALOG_COPPER_ZONE::getUnescapedNetName(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), LIB_TABLE_GRID::GetValue(), FIELDS_GRID_TABLE< SCH_FIELD >::GetValue(), LIB_TREE_MODEL_ADAPTER::GetValue(), GERBVIEW_CONTROL::HighlightControl(), SCH_CONNECTION::IsBusLabel(), SYMBOL_EDIT_FRAME::KiwayMailIn(), DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser(), DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser(), DIALOG_NET_INSPECTOR::LIST_ITEM::LIST_ITEM(), SCH_EAGLE_PLUGIN::loadInstance(), SIM_PLOT_FRAME::loadWorkbook(), SCH_CONNECTION::MightBeBusLabel(), NET_SETTINGS::NET_SETTINGS(), DIALOG_NET_INSPECTOR::netFilterMatches(), TEXT_BUTTON_SYMBOL_CHOOSER::OnButtonClick(), DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton(), DIALOG_NET_INSPECTOR::onRenameNet(), SCH_SEXPR_PARSER::parseProperty(), DIALOG_CHANGE_SYMBOLS::processSymbol(), FOOTPRINT_LIST_IMPL::ReadCacheFromFile(), NET_SELECTOR_COMBOPOPUP::rebuildList(), SYMBOL_VIEWER_FRAME::ReCreateLibList(), SYMBOL_VIEWER_FRAME::ReCreateSymbolList(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer(), SYMBOL_EDIT_FRAME::SetCurSymbol(), FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf(), FOOTPRINT_INFO_GENERATOR::SetHtmlName(), DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser(), DIALOG_LIB_NEW_SYMBOL::SetName(), SYMBOL_VIEWER_FRAME::SetSelectedLibrary(), NET_SELECTOR::SetSelectedNet(), NET_SELECTOR::SetSelectedNetcode(), SYMBOL_VIEWER_FRAME::SetSelectedSymbol(), SYMBOL_VIEWER_FRAME::ShowModal(), ERC_TESTER::TestLibSymbolIssues(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow(), DIALOG_SIGNAL_LIST::TransferDataToWindow(), DIALOG_SHEET_PIN_PROPERTIES::TransferDataToWindow(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataToWindow(), DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow(), UnescapeString(), HIGHLIGHT_MENU::update(), SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties(), BOARD_NETLIST_UPDATER::updateComponentPadConnections(), BOARD_NETLIST_UPDATER::updateCopperZoneNets(), SCH_SYMBOL::UpdateFields(), SCH_EDIT_FRAME::UpdateNetHighlightStatus(), GERBVIEW_FRAME::updateNetnameListSelectBox(), SYMBOL_VIEWER_FRAME::updatePreviewSymbol(), LIB_TREE_NODE_LIB_ID::UpdateScore(), SCH_SCREEN::UpdateSymbolLinks(), SYMBOL_EDIT_FRAME::UpdateSymbolMsgPanelInfo(), SYMBOL_EDIT_FRAME::updateTitle(), ValueStringCompare(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ ValueStringCompare()

int ValueStringCompare ( const wxString &  strFWord,
const 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 801 of file string_utils.cpp.

802 {
803  // Compare unescaped text
804  wxString fWord = UnescapeString( strFWord );
805  wxString sWord = UnescapeString( strSWord );
806 
807  // The different sections of the two strings
808  wxString strFWordBeg, strFWordMid, strFWordEnd;
809  wxString strSWordBeg, strSWordMid, strSWordEnd;
810 
811  // Split the two strings into separate parts
812  SplitString( fWord, &strFWordBeg, &strFWordMid, &strFWordEnd );
813  SplitString( sWord, &strSWordBeg, &strSWordMid, &strSWordEnd );
814 
815  // Compare the Beginning section of the strings
816  int isEqual = strFWordBeg.CmpNoCase( strSWordBeg );
817 
818  if( isEqual > 0 )
819  {
820  return 1;
821  }
822  else if( isEqual < 0 )
823  {
824  return -1;
825  }
826  else
827  {
828  // If the first sections are equal compare their digits
829  double lFirstNumber = 0;
830  double lSecondNumber = 0;
831  bool endingIsModifier = false;
832 
833  strFWordMid.ToDouble( &lFirstNumber );
834  strSWordMid.ToDouble( &lSecondNumber );
835 
836  endingIsModifier |= ApplyModifier( lFirstNumber, strFWordEnd );
837  endingIsModifier |= ApplyModifier( lSecondNumber, strSWordEnd );
838 
839  if( lFirstNumber > lSecondNumber )
840  return 1;
841  else if( lFirstNumber < lSecondNumber )
842  return -1;
843  // If the first two sections are equal and the endings are modifiers then compare them
844  else if( !endingIsModifier )
845  return strFWordEnd.CmpNoCase( strSWordEnd );
846  // Ran out of things to compare; they must match
847  else
848  return 0;
849  }
850 }
bool ApplyModifier(double &value, const wxString &aString)
wxString UnescapeString(const wxString &aSource)
int SplitString(const wxString &strToSplit, wxString *strBeginning, wxString *strDigits, wxString *strEnd)
Break a string into three parts: he alphabetic preamble, the numeric part, and any alphabetic ending.

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 692 of file string_utils.cpp.

694 {
695  const wxChar* cp = nullptr, * mp = nullptr;
696  const wxChar* wild, * str;
697  wxString _pattern, _string_to_tst;
698 
699  if( case_sensitive )
700  {
701  wild = pattern.GetData();
702  str = string_to_tst.GetData();
703  }
704  else
705  {
706  _pattern = pattern;
707  _pattern.MakeUpper();
708  _string_to_tst = string_to_tst;
709  _string_to_tst.MakeUpper();
710  wild = _pattern.GetData();
711  str = _string_to_tst.GetData();
712  }
713 
714  while( ( *str ) && ( *wild != '*' ) )
715  {
716  if( ( *wild != *str ) && ( *wild != '?' ) )
717  return false;
718 
719  wild++;
720  str++;
721  }
722 
723  while( *str )
724  {
725  if( *wild == '*' )
726  {
727  if( !*++wild )
728  return 1;
729  mp = wild;
730  cp = str + 1;
731  }
732  else if( ( *wild == *str ) || ( *wild == '?' ) )
733  {
734  wild++;
735  str++;
736  }
737  else
738  {
739  wild = mp;
740  str = cp++;
741  }
742  }
743 
744  while( *wild == '*' )
745  {
746  wild++;
747  }
748 
749  return !*wild;
750 }

Referenced by FROM_TO_CACHE::cacheFromToPaths(), LIBEVAL::VALUE::EqualTo(), DIALOG_EXCHANGE_FOOTPRINTS::isMatch(), DIALOG_CHANGE_SYMBOLS::isMatch(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ wxStringSplit()

void wxStringSplit ( const wxString &  aText,
wxArrayString &  aStrings,
wxChar  aSplitter 
)

Split aString to a string list separated at aSplitter.

Parameters
aTextis the text to split.
aStringswill contain the split lines.
aSplitteris the 'split' character.

Definition at line 1005 of file string_utils.cpp.

1006 {
1007  wxString tmp;
1008 
1009  for( unsigned ii = 0; ii < aText.Length(); ii++ )
1010  {
1011  if( aText[ii] == aSplitter )
1012  {
1013  aStrings.Add( tmp );
1014  tmp.Clear();
1015  }
1016 
1017  else
1018  tmp << aText[ii];
1019  }
1020 
1021  if( !tmp.IsEmpty() )
1022  {
1023  aStrings.Add( tmp );
1024  }
1025 }

Referenced by EDA_TEXT::GetTextBox(), HTML_MESSAGE_BOX::ListSet(), CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary(), PANEL_SETUP_RULES::OnErrorLinkClicked(), pcbnewGetWizardsBackTrace(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotPcbText(), EDA_TEXT::Print(), TitleCaps(), and EDA_TEXT::TransformToSegmentList().