added: Patter::delete_all_white flag

if true all text-items which have only white characters (with new lines as well)
       will be deleted
       this not actually delete the whole item but only the string
       the item will be present with an empty string
       default: false



git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@260 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-12-09 00:34:17 +00:00
parent 9b4586d7be
commit dbe91a6d91
2 changed files with 46 additions and 4 deletions

View File

@ -121,7 +121,8 @@ void SplitUnixDirectory(const std::string & name, std::string & dir, std::string
Pattern::Pattern() Pattern::Pattern()
{ {
allow_include = true; allow_include = true;
delete_all_white = false;
} }
@ -237,13 +238,40 @@ return *(itext++);
} }
bool Pattern::IsWhite(int c )
{
if( c==' ' || c=='\t' || c==13 )
return true;
return false;
}
void Pattern::SkipWhiteCharacters() void Pattern::SkipWhiteCharacters()
{ {
while( *itext==' ' || *itext=='\t' ) while( IsWhite(*itext) )
++itext; ++itext;
} }
void Pattern::CheckWhiteAndDelete(std::string & s)
{
std::string::size_type i;
if( s.empty() )
return;
for(i=0 ; i<s.size() && (s[i]==10 || IsWhite(s[i])) ; ++i);
if( i<s.size() )
// there are other characters in the string
return;
s.clear();
}
std::string Pattern::ReadDirective() std::string Pattern::ReadDirective()
{ {
std::string directive; std::string directive;
@ -518,6 +546,9 @@ int c;
while( (c = ReadCharInText()) != -1 ) while( (c = ReadCharInText()) != -1 )
item.text += c; item.text += c;
if( delete_all_white )
CheckWhiteAndDelete(item.text);
item.type = Item::item_text; item.type = Item::item_text;
} }
@ -1198,7 +1229,7 @@ void Generator::MakeTextDefine(Pattern::Item & item)
void Generator::MakeText(Pattern::Item & item) void Generator::MakeText(Pattern::Item & item)
{ {
const int max_loop = 10000; const int max_loop = 30000;
if( loop == -1 ) if( loop == -1 )
return; return;

View File

@ -111,8 +111,17 @@ public:
Item item_root; Item item_root;
// allowing include tag
// default: true
bool allow_include; bool allow_include;
// if true all text-items which have only white characters (with new lines as well)
// will be deleted - useful in *.txt templates
// this not actually delete the whole item but only the string
// the item will be present with an empty string
// default: false
bool delete_all_white;
private: private:
const char * itext; const char * itext;
std::string directory; std::string directory;
@ -122,8 +131,10 @@ private:
std::string ReadFile(const char * name); std::string ReadFile(const char * name);
int ReadCharInText(); int ReadCharInText();
bool IsWhite(int c);
void SkipWhiteCharacters(); void SkipWhiteCharacters();
void CheckWhiteAndDelete(std::string & s);
std::string ReadDirective(); std::string ReadDirective();
std::string ReadString(bool skip_first_quote = false); std::string ReadString(bool skip_first_quote = false);
std::string ReadDirectiveOrString(); std::string ReadDirectiveOrString();