2013-11-29 18:29:41 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2009-01-19 19:08:42 +00:00
|
|
|
/**
|
|
|
|
* @file kicad_string.h
|
|
|
|
* @see common.h, string.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-12-19 21:42:55 +00:00
|
|
|
#ifndef KICAD_STRING_H_
|
|
|
|
#define KICAD_STRING_H_
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2016-11-02 14:46:45 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-12-19 21:42:55 +00:00
|
|
|
#include <wx/string.h>
|
2013-11-29 18:29:41 +00:00
|
|
|
#include <wx/filename.h>
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2011-02-27 05:43:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReadDelimitedText
|
2011-02-27 06:22:34 +00:00
|
|
|
* copies bytes from @a aSource delimited string segment to @a aDest buffer.
|
2011-02-27 05:43:19 +00:00
|
|
|
* The extracted string will be null terminated even if truncation is necessary
|
|
|
|
* because aDestSize was not large enough.
|
|
|
|
*
|
|
|
|
* @param aDest is the destination byte buffer.
|
|
|
|
* @param aSource is the source bytes as a C string.
|
|
|
|
* @param aDestSize is the size of the destination byte buffer.
|
2011-02-27 15:46:46 +00:00
|
|
|
* @return 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.
|
2011-03-24 00:15:33 +00:00
|
|
|
* @deprecated should use the one which fetches a wxString, below.
|
2009-11-23 20:18:47 +00:00
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize );
|
2011-02-27 05:43:19 +00:00
|
|
|
|
2011-03-24 00:15:33 +00:00
|
|
|
/**
|
|
|
|
* Function ReadDelimitedText
|
|
|
|
* copies bytes from @a aSource delimited string segment to @a aDest wxString.
|
|
|
|
*
|
|
|
|
* @param aDest is the destination wxString
|
|
|
|
* @param aSource is the source C string holding utf8 encoded bytes.
|
|
|
|
* @return 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.
|
|
|
|
*/
|
|
|
|
int ReadDelimitedText( wxString* aDest, const char* aSource );
|
2011-02-27 05:43:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*
|
|
|
|
* @param aString is the input string to convert.
|
|
|
|
* @return std::string - the escaped input text, without the wrapping double quotes.
|
|
|
|
*/
|
|
|
|
std::string EscapedUTF8( const wxString& aString );
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* Function GetLine
|
|
|
|
* reads one line line from \a aFile.
|
|
|
|
* @return A pointer the first useful line read by eliminating blank lines and comments.
|
2009-11-23 20:18:47 +00:00
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
char* GetLine( FILE* aFile, char* Line, int* LineNum = NULL, int SizeLine = 255 );
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
2013-11-29 18:29:41 +00:00
|
|
|
* Function StrPurge
|
2011-11-08 16:37:25 +00:00
|
|
|
* removes leading and training spaces, tabs and end of line chars in \a text
|
|
|
|
* return a pointer on the first n char in text
|
2009-11-23 20:18:47 +00:00
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
char* StrPurge( char* text );
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* Function DateAndTime
|
|
|
|
* @return a string giving the current date and time.
|
|
|
|
*/
|
2009-11-23 20:18:47 +00:00
|
|
|
wxString DateAndTime();
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* Function StrLenNumCmp
|
|
|
|
* is a routine compatible with qsort() to sort by alphabetical order.
|
|
|
|
*
|
2016-08-16 08:27:09 +00:00
|
|
|
* This function is equivalent to strncmp() or strncasecmp() if \a aIgnoreCase is true
|
2011-11-08 16:37:25 +00:00
|
|
|
* except that strings containing numbers are compared by their integer value not
|
|
|
|
* by their ASCII code.
|
|
|
|
*
|
2014-01-18 09:07:05 +00:00
|
|
|
* @param aString1 A wxString reference to the reference string.
|
|
|
|
* @param aString2 A wxString reference to the comparison string.
|
2013-11-29 18:29:41 +00:00
|
|
|
* @param aLength The number of characters to compare. Set to -1 to compare
|
2011-11-08 16:37:25 +00:00
|
|
|
* the entire string.
|
|
|
|
* @param aIgnoreCase Use true to make the comparison case insensitive.
|
|
|
|
* @return An integer value of -1 if \a aString1 is less than \a aString2, 0 if
|
|
|
|
* \a aString1 is equal to \a aString2, or 1 if \a aString1 is greater
|
|
|
|
* than \a aString2.
|
2009-11-23 20:18:47 +00:00
|
|
|
*/
|
2014-01-18 09:07:05 +00:00
|
|
|
int StrNumCmp( const wxString& aString1, const wxString& aString2, int aLength = INT_MAX,
|
2011-11-08 16:37:25 +00:00
|
|
|
bool aIgnoreCase = false );
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* Function WildCompareString
|
|
|
|
* compares a string against wild card (* and ?) pattern using the usual rules.
|
|
|
|
* @return true if pattern matched otherwise false.
|
2009-11-23 20:18:47 +00:00
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
bool WildCompareString( const wxString& pattern,
|
|
|
|
const wxString& string_to_tst,
|
|
|
|
bool case_sensitive = true );
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
/**
|
|
|
|
* Function RefDesStringCompare
|
|
|
|
* acts just like the strcmp function but treats numbers within the string text
|
|
|
|
* correctly for sorting. eg. A10 > A2
|
|
|
|
* return -1 if first string is less than the second
|
|
|
|
* return 0 if the strings are equal
|
|
|
|
* return 1 if the first string is greater than the second
|
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
int RefDesStringCompare( const wxString& lhs, const wxString& rhs );
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SplitString
|
|
|
|
* breaks a string into three parts.
|
|
|
|
* The alphabetic preamble
|
|
|
|
* The numeric part
|
|
|
|
* Any alphabetic ending
|
|
|
|
* For example C10A is split to C 10 A
|
|
|
|
*/
|
|
|
|
int SplitString( wxString strToSplit,
|
|
|
|
wxString* strBeginning,
|
|
|
|
wxString* strDigits,
|
|
|
|
wxString* strEnd );
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2013-11-29 18:29:41 +00:00
|
|
|
/**
|
|
|
|
* Function GetIllegalFileNameWxChars
|
|
|
|
* @return a wString object containing the illegal file name characters for all platforms.
|
|
|
|
*/
|
|
|
|
wxString GetIllegalFileNameWxChars();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReplaceIllegalFileNameChars
|
|
|
|
* checks \a 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 guarentees that there will be no naming conflicts when fixing footprint library names.
|
2015-08-23 12:35:49 +00:00
|
|
|
* however, if aReplaceChar is given, it will replace the illegal chars
|
2013-11-29 18:29:41 +00:00
|
|
|
*
|
|
|
|
* @param aName is a point to a std::string object containing the footprint name to verify.
|
2015-08-23 12:35:49 +00:00
|
|
|
* @param aReplaceChar (if not 0) is the replacement char.
|
2013-11-29 18:29:41 +00:00
|
|
|
* @return true if any characters have been replaced in \a aName.
|
|
|
|
*/
|
2015-08-23 12:35:49 +00:00
|
|
|
bool ReplaceIllegalFileNameChars( std::string* aName, int aReplaceChar = 0 );
|
2013-11-29 18:29:41 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
#ifndef HAVE_STRTOKR
|
|
|
|
// common/strtok_r.c optionally:
|
|
|
|
extern "C" char* strtok_r( char* str, const char* delim, char** nextp );
|
|
|
|
#endif
|
|
|
|
|
2010-12-19 21:42:55 +00:00
|
|
|
#endif // KICAD_STRING_H_
|