47 for( wxString::iterator ii = aString->begin(); ii != aString->end(); ++ii )
49 if( *ii == L
'\u00B4' || *ii == L
'\u2018' || *ii == L
'\u2019' )
54 if( *ii == L
'\u201C' || *ii == L
'\u201D' )
59 if( *ii == L
'\u2013' || *ii == L
'\u2014' )
81 for( wxUniChar c: aSource )
86 converted +=
"{slash}";
87 else if( c ==
'\n' || c ==
'\r' )
95 converted +=
"{brace}";
97 converted +=
"{colon}";
98 else if( c ==
'\n' || c ==
'\r' )
106 converted +=
"{dblquote}";
112 if( c ==
'\n' || c ==
'\r' )
113 converted +=
"{return}";
120 converted +=
"{brace}";
122 converted +=
"{slash}";
124 converted +=
"{backslash}";
126 converted +=
"{dblquote}";
132 converted +=
"{bar}";
134 converted +=
"{colon}";
136 converted +=
"{tab}";
137 else if( c ==
'\n' || c ==
'\r' )
138 converted +=
"{return}";
153 size_t sourceLen = aSource.length();
155 for(
size_t i = 0; i < sourceLen; ++i )
157 if( ( aSource[i] ==
'$' || aSource[i] ==
'^' || aSource[i] ==
'_' )
158 && i + 1 < sourceLen && aSource[i+1] ==
'{' )
160 for( ; i < sourceLen; ++i )
162 newbuf += aSource[i];
164 if( aSource[i] ==
'}' )
168 else if( aSource[i] ==
'{' )
173 for( i = i + 1; i < sourceLen; ++i )
175 if( aSource[i] ==
'{' )
177 else if( aSource[i] ==
'}' )
183 token.append( aSource[i] );
186 if( token == wxS(
"dblquote" ) ) newbuf.append( wxS(
"\"" ) );
187 else if( token == wxS(
"quote" ) ) newbuf.append( wxS(
"'" ) );
188 else if( token == wxS(
"lt" ) ) newbuf.append( wxS(
"<" ) );
189 else if( token == wxS(
"gt" ) ) newbuf.append( wxS(
">" ) );
190 else if( token == wxS(
"backslash" ) ) newbuf.append( wxS(
"\\" ) );
191 else if( token == wxS(
"slash" ) ) newbuf.append( wxS(
"/" ) );
192 else if( token == wxS(
"bar" ) ) newbuf.append( wxS(
"|" ) );
193 else if( token == wxS(
"colon" ) ) newbuf.append( wxS(
":" ) );
194 else if( token == wxS(
"space" ) ) newbuf.append( wxS(
" " ) );
195 else if( token == wxS(
"dollar" ) ) newbuf.append( wxS(
"$" ) );
196 else if( token == wxS(
"tab" ) ) newbuf.append( wxS(
"\t" ) );
197 else if( token == wxS(
"return" ) ) newbuf.append( wxS(
"\n" ) );
198 else if( token == wxS(
"brace" ) ) newbuf.append( wxS(
"{" ) );
199 else if( token.IsEmpty() ) newbuf.append( wxS(
"{" ) );
207 newbuf.append( aSource[i] );
219 const char* start = aSource;
222 while( (cc = *aSource++) != 0 )
242 if( cc !=
'"' && cc !=
'\\' )
256 return aSource - start;
266 const char* start = aSource;
267 char* limit = aDest + aDestSize - 1;
270 while( (cc = *aSource++) != 0 && aDest < limit )
290 if( cc !=
'"' && cc !=
'\\' )
305 return aSource - start;
312 aString.Replace(
"\r\n",
"\r" );
313 aString.Replace(
"\n",
"\r" );
315 std::string utf8 =
TO_UTF8( aString );
321 for( std::string::const_iterator it = utf8.begin(); it!=utf8.end(); ++it )
329 else if( *it ==
'\\' )
350 for( wxUniChar c: aString )
353 converted +=
""";
355 converted +=
"'";
357 converted +=
"&";
372 return aString.Trim(
true ).Trim(
false ).IsEmpty();
378 static const char whitespace[] =
" \t\n\r\f\v";
382 while( *text && strchr( whitespace, *text ) )
385 char* cp = text + strlen( text ) - 1;
387 while( cp >= text && strchr( whitespace, *cp ) )
395 char*
GetLine( FILE* File,
char* Line,
int* LineNum,
int SizeLine )
398 if( fgets( Line, SizeLine, File ) ==
NULL )
404 }
while( Line[0] ==
'#' || Line[0] ==
'\n' || Line[0] ==
'\r' || Line[0] == 0 );
406 strtok( Line,
"\n\r" );
413 wxDateTime datetime = wxDateTime::Now();
415 datetime.SetCountry( wxDateTime::Country_Default );
416 return datetime.Format( wxDefaultDateTimeFormat, wxDateTime::Local );
420 int StrNumCmp(
const wxString& aString1,
const wxString& aString2,
bool aIgnoreCase )
422 int nb1 = 0, nb2 = 0;
424 auto str1 = aString1.begin();
425 auto str2 = aString2.begin();
427 while( str1 != aString1.end() && str2 != aString2.end() )
429 wxUniChar c1 = *str1;
430 wxUniChar c2 = *str2;
432 if( wxIsdigit( c1 ) && wxIsdigit( c2 ) )
440 nb1 = nb1 * 10 + (int) c1 -
'0';
442 }
while( str1 != aString1.end() && wxIsdigit( *str1 ) );
447 nb2 = nb2 * 10 + (int) c2 -
'0';
449 }
while( str2 != aString2.end() && wxIsdigit( *str2 ) );
457 c1 = ( str1 != aString1.end() ) ? *str1 : wxUniChar( 0 );
458 c2 = ( str2 != aString2.end() ) ? *str2 : wxUniChar( 0 );
464 if( wxToupper( c1 ) < wxToupper( c2 ) )
467 if( wxToupper( c1 ) > wxToupper( c2 ) )
479 if( str1 != aString1.end() )
482 if( str2 != aString2.end() )
486 if( str1 == aString1.end() && str2 != aString2.end() )
490 else if( str1 != aString1.end() && str2 == aString2.end() )
500 bool case_sensitive )
502 const wxChar* cp =
NULL, * mp =
NULL;
503 const wxChar* wild, * string;
504 wxString _pattern, _string_to_tst;
508 wild = pattern.GetData();
509 string = string_to_tst.GetData();
514 _pattern.MakeUpper();
515 _string_to_tst = string_to_tst;
516 _string_to_tst.MakeUpper();
517 wild = _pattern.GetData();
518 string = _string_to_tst.GetData();
521 while( ( *
string ) && ( *wild !=
'*' ) )
523 if( ( *wild != *
string ) && ( *wild !=
'?' ) )
538 else if( ( *wild == *
string ) || ( *wild ==
'?' ) )
550 while( *wild ==
'*' )
561 static const wxString modifiers( wxT(
"pnumkKM" ) );
563 if( !aString.length() )
569 if( modifiers.Find( aString[ 0 ] ) >= 0 )
571 modifier = aString[ 0 ];
572 units = aString.Mid( 1 ).Trim();
577 units = aString.Mid( 0 ).Trim();
581 && !units.CmpNoCase( wxT(
"F" ) )
582 && !units.CmpNoCase( wxT(
"hz" ) )
583 && !units.CmpNoCase( wxT(
"W" ) )
584 && !units.CmpNoCase( wxT(
"V" ) )
585 && !units.CmpNoCase( wxT(
"H" ) ) )
588 if( modifier ==
'p' )
590 if( modifier ==
'n' )
592 else if( modifier ==
'u' )
594 else if( modifier ==
'm' )
596 else if( modifier ==
'k' || modifier ==
'K' )
598 else if( modifier ==
'M' )
600 else if( modifier ==
'G' )
614 wxString strFWordBeg, strFWordMid, strFWordEnd;
615 wxString strSWordBeg, strSWordMid, strSWordEnd;
618 SplitString( strFWord, &strFWordBeg, &strFWordMid, &strFWordEnd );
619 SplitString( strSWord, &strSWordBeg, &strSWordMid, &strSWordEnd );
622 int isEqual = strFWordBeg.CmpNoCase( strSWordBeg );
626 else if( isEqual < 0 )
631 double lFirstNumber = 0;
632 double lSecondNumber = 0;
633 bool endingIsModifier =
false;
635 strFWordMid.ToDouble( &lFirstNumber );
636 strSWordMid.ToDouble( &lSecondNumber );
638 endingIsModifier |=
ApplyModifier( lFirstNumber, strFWordEnd );
639 endingIsModifier |=
ApplyModifier( lSecondNumber, strSWordEnd );
641 if( lFirstNumber > lSecondNumber )
643 else if( lFirstNumber < lSecondNumber )
646 else if( !endingIsModifier )
647 return strFWordEnd.CmpNoCase( strSWordEnd );
656 wxString* strBeginning,
660 static const wxString separators( wxT(
".," ) );
663 strBeginning->Empty();
668 if( strToSplit.length() == 0 )
674 for( ii = (strToSplit.length() - 1); ii >= 0; ii-- )
676 if( wxIsdigit( strToSplit[ii] ) )
683 *strBeginning = strToSplit;
688 *strEnd = strToSplit.substr( ii + 1 );
691 int position = ii + 1;
693 for( ; ii >= 0; ii-- )
695 if( !wxIsdigit( strToSplit[ii] ) && separators.Find( strToSplit[ii] ) < 0 )
701 *strDigits = strToSplit.substr( 0, position );
707 *strDigits = strToSplit.substr( ii + 1, position - ii - 1 );
708 *strBeginning = strToSplit.substr( 0, ii + 1 );
722 int index = aStr.Len() - 1;
726 const char chr = aStr.GetChar( index );
728 if( chr < '0' || chr >
'9' )
731 number += ( chr -
'0' ) * base;
748 bool changed =
false;
750 result.reserve( aName->length() );
752 for( std::string::iterator it = aName->begin(); it != aName->end(); ++it )
757 StrPrintf( &result,
"%c", aReplaceChar );
778 bool changed =
false;
780 result.reserve( aName.Length() );
783 for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
785 if( illWChars.Find( *it ) != wxNOT_FOUND )
788 result += aReplaceChar;
807 void wxStringSplit(
const wxString& aText, wxArrayString& aStrings, wxChar aSplitter )
811 for(
unsigned ii = 0; ii < aText.Length(); ii++ )
813 if( aText[ii] == aSplitter )
832 struct lconv* lc = localeconv();
833 char sep = lc->decimal_point[0];
834 unsigned sep_pos = aStringValue.Find( sep );
839 unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
841 while( aStringValue.Len() > min_len )
843 if( aStringValue.Last() ==
'0' )
844 aStringValue.RemoveLast();
static const char illegalFileNameChars[]
Illegal file name characters used to insure file names will be valid on all supported platforms.
ESCAPE_CONTEXT
Escape/Unescape routines to safely encode reserved-characters in various contexts.
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...
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Remove trailing zeros from a string containing a converted float number.
This file contains miscellaneous commonly used macros and functions.
std::string EscapedUTF8(wxString aString)
Return an 8 bit UTF8 string given aString in Unicode form.
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.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
int ValueStringCompare(wxString strFWord, wxString strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
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.
wxString GetIllegalFileNameWxChars()
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
char * GetLine(FILE *File, char *Line, int *LineNum, int SizeLine)
Read one line line from aFile.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
int GetTrailingInt(const wxString &aStr)
Gets the trailing int, if any, from a string.
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
bool NoPrintableChars(wxString aString)
Return true if the string is empty or contains only whitespace.
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
bool ApplyModifier(double &value, const wxString &aString)
bool ConvertSmartQuotesAndDashes(wxString *aString)
Converts curly quotes and em/en dashes to straight quotes and dashes.