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.

Macros

#define BASE_ILLEGAL_CHARS   '\t', '\n', '\r', ':', '/', '\\'
 

Set of characters not accepted in library and entry names

More...
 
#define ILL_CHAR_SIZE   (sizeof(schIllegalChars) / sizeof(int))
 

Functions

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

Variables

const unsigned schIllegalChars [] = { BASE_ILLEGAL_CHARS, ' ' }
 
const unsigned pcbIllegalChars [] = { BASE_ILLEGAL_CHARS, 0 }
 

Macro Definition Documentation

#define BASE_ILLEGAL_CHARS   '\t', '\n', '\r', ':', '/', '\\'

Set of characters not accepted in library and entry names

Definition at line 401 of file lib_id.cpp.

#define ILL_CHAR_SIZE   (sizeof(schIllegalChars) / sizeof(int))

Definition at line 404 of file lib_id.cpp.

Referenced by LIB_ID::isLegalChar().

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 UTF8 aField)
inlinestatic

Definition at line 86 of file lib_id.cpp.

References UTF8::find_first_of().

Referenced by LIB_ID::Format(), and 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 }
std::string::size_type find_first_of(const std::string &str, std::string::size_type pos=0) const
Definition: utf8.h:122
static int okRevision ( const UTF8 aField)
static

Definition at line 94 of file lib_id.cpp.

References UTF8::c_str(), EndsWithRev(), and UTF8::size().

Referenced by LIB_ID::Format(), and LIB_ID::SetRevision().

95 {
96  char rev[32]; // C string for speed
97 
98  if( aField.size() >= 4 )
99  {
100  strncpy( rev, "x/", sizeof( rev ) );
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
std::string::size_type size() const
Definition: utf8.h:115
const char * c_str() const
Definition: utf8.h:107

Variable Documentation

const unsigned pcbIllegalChars[] = { BASE_ILLEGAL_CHARS, 0 }

Definition at line 403 of file lib_id.cpp.

Referenced by LIB_ID::isLegalChar().

const unsigned schIllegalChars[] = { BASE_ILLEGAL_CHARS, ' ' }

Definition at line 402 of file lib_id.cpp.

Referenced by LIB_ID::isLegalChar().