diff options
-rw-r--r-- | src/core/common/Token.cpp | 26 | ||||
-rw-r--r-- | src/core/common/Token.hpp | 16 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/core/common/Token.cpp b/src/core/common/Token.cpp index 17ce03e..f9e60ce 100644 --- a/src/core/common/Token.cpp +++ b/src/core/common/Token.cpp @@ -20,5 +20,31 @@ namespace ousia { +std::string Token::name() const +{ + if (isSpecial()) { + return specialName(id); + } + return content; +} + +const char* Token::specialName(TokenId id) +{ + switch (id) { + case Tokens::Newline: + return "newline"; + case Tokens::Paragraph: + return "paragraph"; + case Tokens::Section: + return "section"; + case Tokens::Indent: + return "indent"; + case Tokens::Dedent: + return "dedent"; + } + return ""; +} + + } diff --git a/src/core/common/Token.hpp b/src/core/common/Token.hpp index ad36e14..ccbc84b 100644 --- a/src/core/common/Token.hpp +++ b/src/core/common/Token.hpp @@ -190,6 +190,22 @@ struct Token { static bool isSpecial(TokenId id) {return id > Tokens::MaxTokenId; } /** + * Returns the name of the token -- which is either its content or the name + * of the special token (if it is one). + * + * @return the human readable name of this token instance. + */ + std::string name() const; + + /** + * Returns the name of the special token or an empty string if it is not a + * special token. + * + * @param id + */ + static const char* specialName(TokenId id); + + /** * The getLocation function allows the tokens to be directly passed as * parameter to Logger or LoggableException instances. * |