From b5ea2514e296237ebf0f2b3a1347cf51cb97b650 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 7 Sep 2010 23:52:41 +0000 Subject: [PATCH] added to Generator: void RecognizeSpecialChars(bool spec); recognizing some special characters in text patterns (item_text in Patterns) \r will be a carriage return (13) \n will be a new line (10) \t will be a tabulator (9) \s will be a space \\ will be one '\' default: false void TrimWhite(bool trim); trimming white characters (at the beginning and at the end of an item_text) (special char \s if enabled is not treated as a white character here) default: false void SkipNewLine(bool skip); skipping new line characters (from the whole string in an item_text) but you can use a new line character written as "\n" (if special chars are turn on) default: false git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@305 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/ezc.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/ezc.h | 33 ++++++++++++++- 2 files changed, 146 insertions(+), 4 deletions(-) diff --git a/src/ezc.cpp b/src/ezc.cpp index 3157936..60cc355 100644 --- a/src/ezc.cpp +++ b/src/ezc.cpp @@ -298,7 +298,7 @@ return *(itext++); } -bool Pattern::IsWhite(int c ) +bool Pattern::IsWhite(int c) { // 13 (\r) is from a dos file at the end of a line (\r\n) // 160 is an unbreakable space @@ -324,7 +324,6 @@ size_t i; if( s.empty() ) return; - //for(i=0 ; iwrite(start, end-start); + } +} + + +void Generator::TrimWhite(const char *& start, const char *& end) +{ + while( start != end && pattern->IsWhite(*start) ) + ++start; + + while( start != end && pattern->IsWhite(*(end-1)) ) + --end; +} + + +void Generator::MakeItemText(Pattern::Item & item) +{ +const char * start = item.text.c_str(); +const char * end = item.text.c_str() + item.text.size(); + + if( trim_white ) + TrimWhite(start, end); + + if( special_chars ) + PrintSpecialText(start, end); + else + PrintNormalText(start, end); +} void Generator::MakeTextContainer(Pattern::Item & item) @@ -1535,7 +1646,7 @@ void Generator::MakeText(Pattern::Item & item) return; } - if ( item.type == Pattern::Item::item_text ) *output_stream << item.text; + if ( item.type == Pattern::Item::item_text ) MakeItemText(item); else if( item.type == Pattern::Item::item_container ) MakeTextContainer(item); else if( item.type == Pattern::Item::item_normal ) MakeTextNormal(item); else if( item.type == Pattern::Item::item_if ) MakeTextIf(item); diff --git a/src/ezc.h b/src/ezc.h index 192367e..578998e 100644 --- a/src/ezc.h +++ b/src/ezc.h @@ -84,6 +84,9 @@ public: void CreateMsg(std::ostringstream & o, const char * type, const char * arg = 0); std::string CreateMsg(const char * type, const char * arg = 0); + bool IsWhite(int c); + + struct Item { @@ -158,7 +161,6 @@ private: bool ReadFileFromDir(const std::string & dir, const char * name, std::string & result); int ReadCharInText(); - bool IsWhite(int c); void SkipWhite(); void CheckWhiteAndDelete(std::string & s); @@ -287,6 +289,26 @@ public: void Set(Functions & f); void SetMax(int max_items_, int max_for_items_); + // recognizing some special characters in text patterns (item_text in Patterns) + // \r will be a carriage return (13) + // \n will be a new line (10) + // \t will be a tabulator (9) + // \s will be a space + // \\ will be one '\' + // default: false + void RecognizeSpecialChars(bool spec); + + // trimming white characters (at the beginning and at the end of an item_text) + // (special char \s if enabled is not treated as a white character here) + // default: false + void TrimWhite(bool trim); + + // skipping new line characters (from the whole string in an item_text) + // but you can use a new line character written as "\n" (if special chars are turn on) + // default: false + void SkipNewLine(bool skip); + + void Generate(); private: @@ -299,6 +321,9 @@ private: int current_item; int max_items; int max_for_items; + bool special_chars; + bool trim_white; + bool skip_new_line; // an empty string for info objects const std::string empty; @@ -312,6 +337,11 @@ private: void CallUserFunction(Functions::Function * function, Info & info); void CallVariable(Functions::Function * function, Info & info); + char CreateSpecialChar(char c); + void PrintSpecialText(const char * start, const char * end); + void PrintNormalText(const char * start, const char * end); + void TrimWhite(const char *& start, const char *& end); + void MakeTextIf_go(Pattern::Item & item, bool result); bool MakeTextIfindexnumber(Pattern::Item & item, Functions::Function * function, bool & result); void MakeTextIf(Pattern::Item & item); @@ -323,6 +353,7 @@ private: void MakeTextIfindex(Pattern::Item & item); void MakeTextForLoop(Pattern::Item & item, Functions::Function * function); void MakeTextFor(Pattern::Item & item); + void MakeItemText(Pattern::Item & item); void MakeTextContainer(Pattern::Item & item); void MakeTextNormal(Pattern::Item & item); void MakeTextIs(Pattern::Item & item);