KiCad PCB EDA Suite
dsnlexer.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#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 34 of file dsnlexer.cpp.

Function Documentation

◆ isDigit()

bool isDigit ( char  cc)
inline

Definition at line 434 of file dsnlexer.cpp.

435 {
436  return '0' <= cc && cc <= '9';
437 }

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

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

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

442 {
443  return isSpace( cc ) || cc=='(' || cc==')';
444 }
static bool isSpace(char cc)
Function isSpace tests for whitespace.
Definition: dsnlexer.cpp:414

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

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

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

Variable Documentation

◆ empty_keywords

const KEYWORD empty_keywords[1] = {}
static

Definition at line 120 of file dsnlexer.cpp.