KiCad PCB EDA Suite
lib_id.cpp File Reference
#include <cstring>
#include <memory>
#include <wx/wx.h>
#include <macros.h>
#include <lib_id.h>
#include <kicad_string.h>

Go to the source code of this file.

Functions

static bool isDigit (char c)
 
const char * EndsWithRev (const char *start, const char *tail, char separator)
 
static int okLogical (const std::string &aField)
 
static int okRevision (const std::string &aField)
 

Function Documentation

const char* EndsWithRev ( const char *  start,
const char *  tail,
char  separator 
)

Definition at line 41 of file lib_id.cpp.

References isDigit().

Referenced by okRevision(), and LIB_ID::Parse().

42 {
43  bool sawDigit = false;
44 
45  while( tail > start && isDigit( *--tail ) )
46  {
47  sawDigit = true;
48  }
49 
50  // if sawDigit, tail points to the 'v' here.
51 
52  if( sawDigit && tail-3 >= start )
53  {
54  tail -= 3;
55 
56  if( tail[0]==separator && tail[1]=='r' && tail[2]=='e' && tail[3]=='v' )
57  {
58  return tail+1; // omit separator, return "revN[N..]"
59  }
60  }
61 
62  return 0;
63 }
static bool isDigit(char c)
Definition: lib_id.cpp:35
static bool isDigit ( char  c)
inlinestatic

Definition at line 35 of file lib_id.cpp.

Referenced by EndsWithRev().

36 {
37  return c >= '0' && c <= '9';
38 }
static int okLogical ( const std::string &  aField)
inlinestatic

Definition at line 86 of file lib_id.cpp.

Referenced by LIB_ID::SetLibNickname().

87 {
88  // std::string::npos is largest positive number, casting to int makes it -1.
89  // Returning that means success.
90  return int( aField.find_first_of( ":" ) );
91 }
static int okRevision ( const std::string &  aField)
static

Definition at line 94 of file lib_id.cpp.

References EndsWithRev().

Referenced by LIB_ID::SetRevision().

95 {
96  char rev[32]; // C string for speed
97 
98  if( aField.size() >= 4 )
99  {
100  strcpy( rev, "x/" );
101  strncat( rev, aField.c_str(), sizeof(rev)-strlen(rev)-1 );
102 
103  if( EndsWithRev( rev, rev + strlen(rev), '/' ) == rev+2 )
104  return -1; // success
105  }
106 
107  return 0; // first character position "is in error", is best we can do.
108 }
const char * EndsWithRev(const char *start, const char *tail, char separator)
Definition: lib_id.cpp:41