Formatting. (No functional changes.)

This commit is contained in:
Jeff Young 2022-10-13 12:07:50 +01:00
parent d6f8ca9a2e
commit 390069cee9
1 changed files with 71 additions and 65 deletions

View File

@ -195,88 +195,94 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
if( m_token.pos >= m_token.inputLen ) if( m_token.pos >= m_token.inputLen )
return retval; return retval;
auto isDecimalSeparator = [ & ]( char ch ) -> bool { auto isDecimalSeparator =
return ( ch == m_localeDecimalSeparator || ch == '.' || ch == ',' ); [&]( char ch ) -> bool
}; {
return ( ch == m_localeDecimalSeparator || ch == '.' || ch == ',' );
};
// Lambda: get value as string, store into clToken.token and update current index. // Lambda: get value as string, store into clToken.token and update current index.
auto extractNumber = [ & ]() { auto extractNumber =
bool haveSeparator = false; [&]()
idx = 0; {
auto ch = m_token.input[ m_token.pos ]; bool haveSeparator = false;
idx = 0;
char ch = m_token.input[ m_token.pos ];
do do
{ {
if( isDecimalSeparator( ch ) && haveSeparator ) if( isDecimalSeparator( ch ) && haveSeparator )
break; break;
m_token.token[ idx++ ] = ch; m_token.token[ idx++ ] = ch;
if( isDecimalSeparator( ch ) ) if( isDecimalSeparator( ch ) )
haveSeparator = true; haveSeparator = true;
ch = m_token.input[ ++m_token.pos ]; ch = m_token.input[ ++m_token.pos ];
} while( isdigit( ch ) || isDecimalSeparator( ch ) ); } while( isdigit( ch ) || isDecimalSeparator( ch ) );
m_token.token[ idx ] = 0; m_token.token[ idx ] = 0;
// Ensure that the systems decimal separator is used // Ensure that the systems decimal separator is used
for( int i = strlen( m_token.token ); i; i-- ) for( int i = strlen( m_token.token ); i; i-- )
{ {
if( isDecimalSeparator( m_token.token[ i - 1 ] ) ) if( isDecimalSeparator( m_token.token[ i - 1 ] ) )
m_token.token[ i - 1 ] = m_localeDecimalSeparator; m_token.token[ i - 1 ] = m_localeDecimalSeparator;
} }
}; };
// Lamda: Get unit for current token. // Lamda: Get unit for current token.
// Valid units are ", in, mm, mil and thou. Returns Unit::Invalid otherwise. // Valid units are ", in, mm, mil and thou. Returns Unit::Invalid otherwise.
auto checkUnit = [ this ]() -> Unit { auto checkUnit =
char ch = m_token.input[ m_token.pos ]; [this]() -> Unit
{
char ch = m_token.input[ m_token.pos ];
if( ch == '"' ) if( ch == '"' )
{ {
m_token.pos++; m_token.pos++;
return Unit::Inch; return Unit::Inch;
} }
// Do not use strcasecmp() as it is not available on all platforms // Do not use strcasecmp() as it is not available on all platforms
const char* cptr = &m_token.input[ m_token.pos ]; const char* cptr = &m_token.input[ m_token.pos ];
const auto sizeLeft = m_token.inputLen - m_token.pos; const auto sizeLeft = m_token.inputLen - m_token.pos;
if( sizeLeft >= 2 && ch == 'm' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) ) if( sizeLeft >= 2 && ch == 'm' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) )
{ {
m_token.pos += 2; m_token.pos += 2;
return Unit::MM; return Unit::MM;
} }
if( sizeLeft >= 2 && ch == 'c' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) ) if( sizeLeft >= 2 && ch == 'c' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) )
{ {
m_token.pos += 2; m_token.pos += 2;
return Unit::CM; return Unit::CM;
} }
if( sizeLeft >= 2 && ch == 'i' && cptr[ 1 ] == 'n' && !isalnum( cptr[ 2 ] ) ) if( sizeLeft >= 2 && ch == 'i' && cptr[ 1 ] == 'n' && !isalnum( cptr[ 2 ] ) )
{ {
m_token.pos += 2; m_token.pos += 2;
return Unit::Inch; return Unit::Inch;
} }
if( sizeLeft >= 3 && ch == 'm' && cptr[ 1 ] == 'i' && cptr[ 2 ] == 'l' if( sizeLeft >= 3 && ch == 'm' && cptr[ 1 ] == 'i' && cptr[ 2 ] == 'l'
&& !isalnum( cptr[ 3 ] ) ) && !isalnum( cptr[ 3 ] ) )
{ {
m_token.pos += 3; m_token.pos += 3;
return Unit::Mil; return Unit::Mil;
} }
if( sizeLeft >= 4 && ch == 't' && cptr[ 1 ] == 'h' && cptr[ 2 ] == 'o' if( sizeLeft >= 4 && ch == 't' && cptr[ 1 ] == 'h' && cptr[ 2 ] == 'o'
&& cptr[ 3 ] == 'u' && !isalnum( cptr[ 4 ] ) ) && cptr[ 3 ] == 'u' && !isalnum( cptr[ 4 ] ) )
{ {
m_token.pos += 4; m_token.pos += 4;
return Unit::Mil; return Unit::Mil;
} }
return Unit::Invalid; return Unit::Invalid;
}; };
char ch; char ch;
@ -304,7 +310,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
retval.token = VALUE; retval.token = VALUE;
retval.value.dValue = atof( m_token.token ); retval.value.dValue = atof( m_token.token );
} }
else if(( convertFrom = checkUnit()) != Unit::Invalid ) else if( ( convertFrom = checkUnit() ) != Unit::Invalid )
{ {
// UNIT // UNIT
// Units are appended to a VALUE. // Units are appended to a VALUE.
@ -348,7 +354,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
} }
} }
} }
else if( isalpha( ch )) else if( isalpha( ch ) )
{ {
// VAR // VAR
const char* cptr = &m_token.input[ m_token.pos ]; const char* cptr = &m_token.input[ m_token.pos ];