KiCad PCB EDA Suite
dsnlexer.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <macros.h>
#include <fctsys.h>
#include <dsnlexer.h>

Go to the source code of this file.

Macros

#define FMT_CLIPBOARD   _( "clipboard" )
 

Functions

static bool isSpace (char cc)
 Function isSpace tests for whitespace. More...
 
bool isDigit (char cc)
 
bool isSep (char cc)
 return true if cc is an s-expression separator character More...
 
static bool isNumber (const char *cp, const char *limit)
 Function isNumber returns true if the next sequence of text is a number: either an integer, fixed point, or float with exponent. More...
 

Variables

static const KEYWORD empty_keywords [1] = {}
 

Macro Definition Documentation

#define FMT_CLIPBOARD   _( "clipboard" )

Definition at line 39 of file dsnlexer.cpp.

Referenced by DSNLEXER::DSNLEXER().

Function Documentation

bool isDigit ( char  cc)
inline

Definition at line 466 of file dsnlexer.cpp.

Referenced by isNumber().

467 {
468  return '0' <= cc && cc <= '9';
469 }
static bool isNumber ( const char *  cp,
const char *  limit 
)
static

Function isNumber returns true if the next sequence of text is a number: either an integer, fixed point, or float with exponent.

Stops scanning at the first non-number character, even if it is not whitespace.

Parameters
cpis the start of the current token.
limitis the end of the current token.
Returns
bool - true if input token is a number, else false.

Definition at line 490 of file dsnlexer.cpp.

References isDigit().

Referenced by DSNLEXER::NextTok().

491 {
492  // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
493  // code traversal manually here:
494 
495  bool sawNumber = false;
496 
497  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
498  ++cp;
499 
500  while( cp < limit && isDigit( *cp ) )
501  {
502  ++cp;
503  sawNumber = true;
504  }
505 
506  if( cp < limit && *cp == '.' )
507  {
508  ++cp;
509 
510  while( cp < limit && isDigit( *cp ) )
511  {
512  ++cp;
513  sawNumber = true;
514  }
515  }
516 
517  if( sawNumber )
518  {
519  if( cp < limit && ( *cp=='E' || *cp=='e' ) )
520  {
521  ++cp;
522 
523  sawNumber = false; // exponent mandates at least one digit thereafter.
524 
525  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
526  ++cp;
527 
528  while( cp < limit && isDigit( *cp ) )
529  {
530  ++cp;
531  sawNumber = true;
532  }
533  }
534  }
535 
536  return sawNumber && cp==limit;
537 }
bool isDigit(char cc)
Definition: dsnlexer.cpp:466
bool isSep ( char  cc)
inline

return true if cc is an s-expression separator character

Definition at line 473 of file dsnlexer.cpp.

References isSpace().

Referenced by DSNLEXER::NextTok().

474 {
475  return isSpace( cc ) || cc=='(' || cc==')';
476 }
static bool isSpace(char cc)
Function isSpace tests for whitespace.
Definition: dsnlexer.cpp:446
static bool isSpace ( char  cc)
static

Function isSpace tests for whitespace.

Our whitespace, by our definition, is a subset of ASCII, i.e. no bytes with MSB on can be considered whitespace, since they are likely part of a multibyte UTF8 character.

Definition at line 446 of file dsnlexer.cpp.

Referenced by isSep(), and DSNLEXER::NextTok().

447 {
448  // cc is signed, so it is often negative.
449  // Treat negative as large positive to exclude rapidly.
450  if( (unsigned char) cc <= ' ' )
451  {
452  switch( (unsigned char) cc )
453  {
454  case ' ':
455  case '\n':
456  case '\r':
457  case '\t':
458  case '\0': // PCAD s-expression files have this.
459  return true;
460  }
461  }
462  return false;
463 }

Variable Documentation

const KEYWORD empty_keywords[1] = {}
static

Definition at line 125 of file dsnlexer.cpp.