Commit 6ee6daed authored by Ken Martin's avatar Ken Martin
Browse files

BUG: some bug fixes, better docs, and more coverage

parent cecf31a7
......@@ -886,6 +886,7 @@ kwsys_stl::string SystemTools::UnCapitalizedWords(const kwsys_stl::string& s)
return n;
}
// only works for words with at least two letters
kwsys_stl::string SystemTools::AddSpaceBetweenCapitalizedWords(
const kwsys_stl::string& s)
{
......@@ -1035,7 +1036,7 @@ char* SystemTools::RemoveCharsButUpperHex(const char* str)
char *ptr = clean_str;
while (*str)
{
if ((*str >= '0' && *str <= '9') || (*str >= 'A' && *str <= 'H'))
if ((*str >= '0' && *str <= '9') || (*str >= 'A' && *str <= 'F'))
{
*ptr++ = *str;
}
......
......@@ -206,6 +206,7 @@ public:
/**
* Return string with space added between capitalized words
* (i.e. EatMyShorts becomes Eat My Shorts )
* (note that IEatShorts becomes IEat Shorts)
*/
static kwsys_stl::string AddSpaceBetweenCapitalizedWords(
const kwsys_stl::string&);
......
......@@ -118,6 +118,151 @@ bool CheckDetectFileType()
return res;
}
//----------------------------------------------------------------------------
bool CheckStringOperations()
{
bool res = true;
kwsys_stl::string test = "mary had a little lamb.";
if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.")
{
kwsys_ios::cerr
<< "Problem with CapitalizedWords "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
test = "Mary Had A Little Lamb.";
if (kwsys::SystemTools::UnCapitalizedWords(test) !=
"mary had a little lamb.")
{
kwsys_ios::cerr
<< "Problem with UnCapitalizedWords "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
test = "MaryHadTheLittleLamb.";
if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
"Mary Had The Little Lamb.")
{
kwsys_ios::cerr
<< "Problem with AddSpaceBetweenCapitalizedWords "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
const char * cres =
kwsys::SystemTools::AppendStrings("Mary Had A"," Little Lamb.");
if (strcmp(cres,"Mary Had A Little Lamb."))
{
delete [] cres;
kwsys_ios::cerr
<< "Problem with AppendStrings "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres;
cres =
kwsys::SystemTools::AppendStrings("Mary Had"," A ","Little Lamb.");
if (strcmp(cres,"Mary Had A Little Lamb."))
{
delete [] cres;
kwsys_ios::cerr
<< "Problem with AppendStrings "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres;
if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.",'a') != 3)
{
kwsys_ios::cerr
<< "Problem with CountChar "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
cres =
kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.","aeiou");
if (strcmp(cres,"Mry Hd A Lttl Lmb."))
{
delete [] cres;
kwsys_ios::cerr
<< "Problem with RemoveChars "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres;
cres =
kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
if (strcmp(cres,"A"))
{
delete [] cres;
kwsys_ios::cerr
<< "Problem with RemoveCharsButUpperHex "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres;
char *cres2 = new char [strlen("Mary Had A Little Lamb.")+1];
strcpy(cres2,"Mary Had A Little Lamb.");
kwsys::SystemTools::ReplaceChars(cres2,"aeiou",'X');
if (strcmp(cres2,"MXry HXd A LXttlX LXmb."))
{
delete [] cres2;
kwsys_ios::cerr
<< "Problem with ReplaceChars "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres2;
if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
"Mary "))
{
kwsys_ios::cerr
<< "Problem with StringStartsWith "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
" Lamb."))
{
kwsys_ios::cerr
<< "Problem with StringEndsWith "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
if (strcmp(cres,"Mary Had A Little Lamb."))
{
delete [] cres;
kwsys_ios::cerr
<< "Problem with DuplicateString "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
delete [] cres;
test = "Mary Had A Little Lamb.";
if (kwsys::SystemTools::CropString(test,13) !=
"Mary ...Lamb.")
{
kwsys_ios::cerr
<< "Problem with CropString "
<< TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
res = false;
}
return res;
}
//----------------------------------------------------------------------------
int main(/*int argc, char* argv*/)
{
......@@ -145,5 +290,7 @@ int main(/*int argc, char* argv*/)
res &= CheckDetectFileType();
res &= CheckStringOperations();
return res ? 0 : 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment