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:
parent
9b4586d7be
commit
dbe91a6d91
35
src/ezc.cpp
35
src/ezc.cpp
|
@ -122,6 +122,7 @@ void SplitUnixDirectory(const std::string & name, std::string & dir, std::string
|
|||
Pattern::Pattern()
|
||||
{
|
||||
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()
|
||||
{
|
||||
while( *itext==' ' || *itext=='\t' )
|
||||
while( IsWhite(*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 directive;
|
||||
|
@ -518,6 +546,9 @@ int c;
|
|||
while( (c = ReadCharInText()) != -1 )
|
||||
item.text += c;
|
||||
|
||||
if( delete_all_white )
|
||||
CheckWhiteAndDelete(item.text);
|
||||
|
||||
item.type = Item::item_text;
|
||||
}
|
||||
|
||||
|
@ -1198,7 +1229,7 @@ void Generator::MakeTextDefine(Pattern::Item & item)
|
|||
|
||||
void Generator::MakeText(Pattern::Item & item)
|
||||
{
|
||||
const int max_loop = 10000;
|
||||
const int max_loop = 30000;
|
||||
|
||||
if( loop == -1 )
|
||||
return;
|
||||
|
|
11
src/ezc.h
11
src/ezc.h
|
@ -111,8 +111,17 @@ public:
|
|||
|
||||
Item item_root;
|
||||
|
||||
// allowing include tag
|
||||
// default: true
|
||||
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:
|
||||
const char * itext;
|
||||
std::string directory;
|
||||
|
@ -122,7 +131,9 @@ private:
|
|||
std::string ReadFile(const char * name);
|
||||
|
||||
int ReadCharInText();
|
||||
bool IsWhite(int c);
|
||||
void SkipWhiteCharacters();
|
||||
void CheckWhiteAndDelete(std::string & s);
|
||||
|
||||
std::string ReadDirective();
|
||||
std::string ReadString(bool skip_first_quote = false);
|
||||
|
|
Loading…
Reference in New Issue