37 return c >=
'0' && c <=
'9';
41 const char*
EndsWithRev(
const char* start,
const char* tail,
char separator )
43 bool sawDigit =
false;
45 while( tail > start &&
isDigit( *--tail ) )
52 if( sawDigit && tail-3 >= start )
56 if( tail[0]==separator && tail[1]==
'r' && tail[2]==
'e' && tail[3]==
'v' )
67 int RevCmp(
const char* s1,
const char* s2 )
69 int r = strncmp( s1, s2, 3 );
71 if( r || strlen(s1)<4 || strlen(s2)<4 )
76 int rnum1 = atoi( s1+3 );
77 int rnum2 = atoi( s2+3 );
79 return -(rnum1 - rnum2);
98 if( aField.
size() >= 4 )
100 strncpy( rev,
"x/",
sizeof( rev ) );
101 strncat( rev, aField.
c_str(),
sizeof(rev)-strlen(rev)-1 );
103 if(
EndsWithRev( rev, rev + strlen(rev),
'/' ) == rev+2 )
126 const char* buffer = aId.
c_str();
136 revNdx = rev - buffer;
148 if( ( partNdx = aId.
find(
':' ) ) != aId.
npos )
163 if( partNdx >= revNdx )
166 UTF8 fpname = aId.
substr( partNdx, revNdx-partNdx );
185 const wxString& aRevision ) :
186 m_libraryName( aLibraryName ),
187 m_itemName( aItemName ),
188 m_revision( aRevision )
208 if( aTestForRev && separation != -1 )
274 if( aLibraryName.
size() )
281 wxString::FromUTF8( aLibraryName.
c_str() ), aLibraryName.
c_str(), 0, offset );
290 if( aRevision.
size() )
297 wxString::FromUTF8( aRevision.
c_str() ),
314 if(
this == &aLibId )
335 for(
auto ch : aLibItemName )
366 bool const space_allowed =
true;
367 bool const illegal_filename_chars_allowed =
false;
387 return illegal_filename_chars_allowed;
390 return space_allowed;
400 for(
unsigned ch : aLibraryName )
412 bool const space_allowed =
true;
424 return space_allowed;
438 static const char* lpids[] = {
444 for(
unsigned i=0; i<
sizeof(lpids)/
sizeof(lpids[0]); ++i )
451 printf(
"input:'%s' full:'%s' nickname: %s m_itemName:'%s' rev:'%s'\n",
453 lpid.Format().c_str(),
454 lpid.GetLibNickname().c_str(),
455 lpid.GetLibItemName().c_str(),
456 lpid.GetRevision().c_str() );
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
static constexpr std::string::size_type npos
const char * EndsWithRev(const char *start, const char *tail, char separator)
int compare(const std::string &s) const
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
UTF8 m_revision
The revision of the entry.
static int okLogical(const UTF8 &aField)
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
A logical library item identifier and consists of various portions much like a URI.
static bool isLegalLibraryNameChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID library nickname character.
static bool isLegalChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID item name character.
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
This file contains miscellaneous commonly used macros and functions.
const char * c_str() const
UTF8 GetLibItemNameAndRev() const
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
std::string::size_type find_first_of(const std::string &str, std::string::size_type pos=0) const
std::string::size_type find(char c) const
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static bool isDigit(char c)
std::string::size_type length() const
int SetRevision(const UTF8 &aRevision)
void clear()
Clear the contents of the library nickname, library entry name, and revision strings.
UTF8 m_libraryName
The nickname of the library or empty.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
UTF8 m_itemName
The name of the entry in the logical library.
std::string substr(size_t pos=0, size_t len=npos) const
std::string::size_type size() const
static int okRevision(const UTF8 &aField)
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.