From 8ad448b803823fdf96e983c576b266b4d3d3898c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 9 Apr 2021 15:07:39 +0200 Subject: [PATCH] ENH: minor adjustments to token methods for more granularity --- src/OpenFOAM/db/IOstreams/token/token.H | 10 ++++++++-- src/OpenFOAM/db/IOstreams/token/tokenI.H | 22 +++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 4f26bc3ef0..eeb0d342ef 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -87,7 +87,7 @@ public: // Pointer types WORD, //!< A Foam::word - STRING, //!< A string + STRING, //!< A string (usually double-quoted) DIRECTIVE, //!< A dictionary \c \#directive (word variant) VARIABLE, //!< A dictionary \c \$variable (string variant) VERBATIM, //!< Verbatim string content @@ -456,6 +456,9 @@ public: //- Token is LABEL inline bool isLabel() const noexcept; + //- True if token is LABEL and equal to parameter + inline bool isLabel(const label val) const noexcept; + //- Token is FLOAT inline bool isFloat() const noexcept; @@ -477,7 +480,10 @@ public: //- Token is DIRECTIVE (word variant) inline bool isDirective() const noexcept; - //- Token is STRING, VARIABLE or VERBATIM string + //- Token is (quoted) STRING (string variant) + inline bool isQuotedString() const noexcept; + + //- Token is STRING, VARIABLE or VERBATIM (string variant) inline bool isString() const noexcept; //- Token is VARIABLE (string variant) diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index fdd5916274..c55ea6ff8a 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -496,6 +496,16 @@ inline bool Foam::token::isLabel() const noexcept } +inline bool Foam::token::isLabel(const label val) const noexcept +{ + return + ( + type_ == tokenType::LABEL + && data_.labelVal == val + ); +} + + inline Foam::label Foam::token::labelToken() const { if (type_ == tokenType::LABEL) @@ -630,6 +640,12 @@ inline const Foam::word& Foam::token::wordToken() const } +inline bool Foam::token::isQuotedString() const noexcept +{ + return (type_ == tokenType::STRING); +} + + inline bool Foam::token::isString() const noexcept { return @@ -921,11 +937,7 @@ inline bool Foam::token::operator==(const std::string& s) const inline bool Foam::token::operator==(const label val) const noexcept { - return - ( - type_ == tokenType::LABEL - && data_.labelVal == val - ); + return isLabel(val); }