From 9cfe89f551413dcf49e5de07137379c90ffce887 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 30 May 2016 16:05:49 +0100 Subject: [PATCH] Added the OutputText function along with unit tests for it. --- source/common/text.cpp | 34 +++++++++ source/common/text.h | 1 + source/tests/xestiacalendar_commonfunctions.h | 75 +++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/source/common/text.cpp b/source/common/text.cpp index fff4c83..1768488 100644 --- a/source/common/text.cpp +++ b/source/common/text.cpp @@ -304,4 +304,38 @@ void SplitPathFilename(string *CalendarEntryHREF, string *EntryURIPath, (*EntryFilename) = CalendarEntryHREF->substr((LastForwardSlash + 1)); +} + +string OutputText(string *TextInput){ + + string OutputTextData; + string OutputLine; + int CharSeek = 0; + int LineSeek = 0; + int MaxLineSeek = 77; + + for (CharSeek = 0; CharSeek < TextInput->size(); CharSeek++){ + + LineSeek++; + + if (LineSeek == MaxLineSeek){ + + OutputLine += TextInput->substr(CharSeek, 1); + OutputLine += "\n"; + OutputTextData += OutputLine; + OutputLine = " "; + LineSeek = 0; + MaxLineSeek = 76; + continue; + + } + + OutputLine += TextInput->substr(CharSeek, 1); + + } + + OutputTextData += OutputLine; + + return OutputTextData; + } \ No newline at end of file diff --git a/source/common/text.h b/source/common/text.h index 993547a..1c1c008 100644 --- a/source/common/text.h +++ b/source/common/text.h @@ -24,5 +24,6 @@ bool HexToInt(std::string *HexString, int *Number); bool IntToHex(int *Number, std::string *HexString, int HexFill); void SplitPathFilename(std::string *CalendarEntryHREF, std::string *EntryURIPath, std::string *EntryFilename); +std::string OutputText(std::string *TextInput); #endif \ No newline at end of file diff --git a/source/tests/xestiacalendar_commonfunctions.h b/source/tests/xestiacalendar_commonfunctions.h index 1b8af0b..8da4adc 100644 --- a/source/tests/xestiacalendar_commonfunctions.h +++ b/source/tests/xestiacalendar_commonfunctions.h @@ -326,4 +326,79 @@ TEST(CommonFunctions, ColourStruct){ ASSERT_EQ("#10101010", (string)Colour3); ASSERT_EQ("#50505050", (string)Colour4); +} + +TEST(CommonFunctions, OutputText){ + + string InputText1 = "This is an example text."; + string OutputText1 = "This is an example text."; + string ResultText1 = ""; + + string InputText2 = "This is the first sentence. This is the second sentence" + ". This is the third sentence. This is the fourth sentence. This " + "is the fifth sentence."; + string OutputText2 = "This is the first sentence. This is the second sentence" + ". This is the third se\n ntence. This is the fourth sentence. This " + "is the fifth sentence."; + string ResultText2 = ""; + + string InputText3 = "This is the first sentence. This is the second sentence" + ". This is the third sentence. This is the fourth sentence. This " + "is the fifth sentence. This is the sixth sentence. This is the s" + "eventh sentence. This is the eighth sentence. This is the ninth " + "sentence. This is the tenth sentence."; + string OutputText3 = "This is the first sentence. This is the second sentence. This is the third se\n" + " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n" + " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n" + " This is the ninth sentence. This is the tenth sentence."; + string ResultText3 = ""; + + string InputText4 = "This is the first sentence. This is the second sentence" + ". This is the third sentence. This is the fourth sentence. This " + "is the fifth sentence. This is the sixth sentence. This is the s" + "eventh sentence. This is the eighth sentence. This is the ninth " + "sentence. This is the tenth sentence. This is the eleventh sente" + "nce. This is the twelfth sentence. This is the thirteenth senten" + "ce. This is the fourteenth sentence. This is the fifteenth sente" + "nce."; + string OutputText4 = "This is the first sentence. This is the second sentence. This is the third se\n" + " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n" + " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n" + " This is the ninth sentence. This is the tenth sentence. This is the eleventh\n" + " sentence. This is the twelfth sentence. This is the thirteenth sentence. Th\n" + " is is the fourteenth sentence. This is the fifteenth sentence."; + string ResultText4 = ""; + + string InputText5 = "This is the first sentence. This is the second sentence" + ". This is the third sentence. This is the fourth sentence. This " + "is the fifth sentence. This is the sixth sentence. This is the s" + "eventh sentence. This is the eighth sentence. This is the ninth " + "sentence. This is the tenth sentence. This is the eleventh sente" + "nce. This is the twelfth sentence. This is the thirteenth senten" + "ce. This is the fourteenth sentence. This is the fifteenth sente" + "nce. This is the sixteenth sentence. This is the seventeenth sen" + "tence. This is the eighteenth sentence. This is the ninteenth se" + "ntence. This is the twentieth sentence."; + string OutputText5 = "This is the first sentence. This is the second sentence. This is the third se\n" + " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n" + " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n" + " This is the ninth sentence. This is the tenth sentence. This is the eleventh\n" + " sentence. This is the twelfth sentence. This is the thirteenth sentence. Th\n" + " is is the fourteenth sentence. This is the fifteenth sentence. This is the s\n" + " ixteenth sentence. This is the seventeenth sentence. This is the eighteenth \n" + " sentence. This is the ninteenth sentence. This is the twentieth sentence."; + string ResultText5; + + ResultText1 = OutputText(&InputText1); + ResultText2 = OutputText(&InputText2); + ResultText3 = OutputText(&InputText3); + ResultText4 = OutputText(&InputText4); + ResultText5 = OutputText(&InputText5); + + ASSERT_EQ(ResultText1, OutputText1); + ASSERT_EQ(ResultText2, OutputText2); + ASSERT_EQ(ResultText3, OutputText3); + ASSERT_EQ(ResultText4, OutputText4); + ASSERT_EQ(ResultText5, OutputText5); + } \ No newline at end of file -- 2.39.5