From 574884cd7efa0fc8364d107e25e916d61d49e103 Mon Sep 17 00:00:00 2001 From: David Neto Date: Tue, 25 Aug 2015 13:53:19 -0400 Subject: [PATCH] Getting the next word ends at a comment (;) --- source/text.cpp | 1 + source/text.h | 4 +++- test/TextWordGet.cpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/text.cpp b/source/text.cpp index 534e4b117..793bb5827 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -155,6 +155,7 @@ spv_result_t spvTextWordGet(const spv_text text, while (true) { switch (text->str[endPosition->index]) { case ' ': + case ';': case '\t': case '\n': case '\0': { // NOTE: End of word found! diff --git a/source/text.h b/source/text.h index fb9acf72a..768b4e440 100644 --- a/source/text.h +++ b/source/text.h @@ -85,7 +85,9 @@ spv_result_t spvTextAdvanceLine(const spv_text text, spv_position_t *pPosition); /// @return result code spv_result_t spvTextAdvance(const spv_text text, spv_position_t *pPosition); -/// @brief Fetch the next word from the text stream +/// @brief Fetch the next word from the text stream. +/// +/// A word ends at the next comment or whitespace. /// /// @param[in] text stream to read from /// @param[in] startPosition current position in text stream diff --git a/test/TextWordGet.cpp b/test/TextWordGet.cpp index b67b78850..133703a86 100644 --- a/test/TextWordGet.cpp +++ b/test/TextWordGet.cpp @@ -68,6 +68,20 @@ TEST(TextWordGet, SpaceTerminator) { ASSERT_STREQ("Word", word.c_str()); } +TEST(TextWordGet, SemicolonTerminator) { + char textStr[] = "Wo;rd "; + spv_text_t text = {textStr, strlen(textStr)}; + spv_position_t startPosition = {}; + std::string word; + spv_position_t endPosition = {}; + ASSERT_EQ(SPV_SUCCESS, + spvTextWordGet(&text, &startPosition, word, &endPosition)); + ASSERT_EQ(2, endPosition.column); + ASSERT_EQ(0, endPosition.line); + ASSERT_EQ(2, endPosition.index); + ASSERT_STREQ("Wo", word.c_str()); +} + TEST(TextWordGet, MultipleWords) { char textStr[] = "Words in a sentence"; spv_text_t text = {textStr, strlen(textStr)};