summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/kwsys/SystemTools.cxx3
-rw-r--r--Source/kwsys/SystemTools.hxx.in1
-rw-r--r--Source/kwsys/testSystemTools.cxx147
3 files changed, 150 insertions, 1 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 172ce49..291024e 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -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;
}
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index dada510..4649a0a 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -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&);
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 2106f7a..f5550ae 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -119,6 +119,151 @@ bool CheckDetectFileType()
}
//----------------------------------------------------------------------------
+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*/)
{
bool res = true;
@@ -145,5 +290,7 @@ int main(/*int argc, char* argv*/)
res &= CheckDetectFileType();
+ res &= CheckStringOperations();
+
return res ? 0 : 1;
}