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

◆ FMT_CLIPBOARD

#define FMT_CLIPBOARD   _( "clipboard" )

Definition at line 39 of file dsnlexer.cpp.

Function Documentation

◆ isDigit()

bool isDigit ( char  cc)
inline

Definition at line 439 of file dsnlexer.cpp.

440 {
441  return '0' <= cc && cc <= '9';
442 }

Referenced by isNumber(), and NET_SETTINGS::ParseBusVector().

◆ isNumber()

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 463 of file dsnlexer.cpp.

464 {
465  // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
466  // code traversal manually here:
467 
468  bool sawNumber = false;
469 
470  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
471  ++cp;
472 
473  while( cp < limit && isDigit( *cp ) )
474  {
475  ++cp;
476  sawNumber = true;
477  }
478 
479  if( cp < limit && *cp == '.' )
480  {
481  ++cp;
482 
483  while( cp < limit && isDigit( *cp ) )
484  {
485  ++cp;
486  sawNumber = true;
487  }
488  }
489 
490  if( sawNumber )
491  {
492  if( cp < limit && ( *cp=='E' || *cp=='e' ) )
493  {
494  ++cp;
495 
496  sawNumber = false; // exponent mandates at least one digit thereafter.
497 
498  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
499  ++cp;
500 
501  while( cp < limit && isDigit( *cp ) )
502  {
503  ++cp;
504  sawNumber = true;
505  }
506  }
507  }
508 
509  return sawNumber && cp==limit;
510 }
bool isDigit(char cc)
Definition: dsnlexer.cpp:439

References isDigit().

Referenced by DSNLEXER::NextTok().

◆ isSep()

bool isSep ( char  cc)
inline

return true if cc is an s-expression separator character

Definition at line 446 of file dsnlexer.cpp.

447 {
448  return isSpace( cc ) || cc=='(' || cc==')';
449 }
static bool isSpace(char cc)
Function isSpace tests for whitespace.
Definition: dsnlexer.cpp:419

References isSpace().

Referenced by DSNLEXER::NextTok().

◆ isSpace()

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 419 of file dsnlexer.cpp.

420 {
421  // cc is signed, so it is often negative.
422  // Treat negative as large positive to exclude rapidly.
423  if( (unsigned char) cc <= ' ' )
424  {
425  switch( (unsigned char) cc )
426  {
427  case ' ':
428  case '\n':
429  case '\r':
430  case '\t':
431  case '\0': // PCAD s-expression files have this.
432  return true;
433  }
434  }
435  return false;
436 }

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

Variable Documentation

◆ empty_keywords

const KEYWORD empty_keywords[1] = {}
static

Definition at line 125 of file dsnlexer.cpp.