Merge branch 'upstream-kwsys' into update-kwsys

This commit is contained in:
Brad King 2014-05-13 14:55:35 -04:00
commit 7fa16df4d7
10 changed files with 185 additions and 156 deletions

View File

@ -178,7 +178,7 @@ bool CommandLineArguments::GetMatchedArguments(
matches->push_back(parg);
}
}
return matches->size() > 0;
return !matches->empty();
}
//----------------------------------------------------------------------------
@ -235,7 +235,7 @@ int CommandLineArguments::Parse()
return 0;
}
CommandLineArguments_DEBUG("This is a space argument: " << arg
<< " value: " << this->Internals->Argv[cc+1].c_str());
<< " value: " << this->Internals->Argv[cc+1]);
// Value is the next argument
if ( !this->PopulateVariable(cs, this->Internals->Argv[cc+1].c_str()) )
{
@ -244,7 +244,7 @@ int CommandLineArguments::Parse()
cc ++;
break;
case EQUAL_ARGUMENT:
if ( arg.size() == sarg.size() || *(arg.c_str() + sarg.size()) != '=' )
if ( arg.size() == sarg.size() || arg.at(sarg.size()) != '=' )
{
this->Internals->LastArgument --;
return 0;
@ -309,11 +309,11 @@ int CommandLineArguments::Parse()
else if ( this->StoreUnusedArgumentsFlag )
{
CommandLineArguments_DEBUG("Store unused argument " << arg);
this->Internals->UnusedArguments.push_back(arg.c_str());
this->Internals->UnusedArguments.push_back(arg);
}
else
{
kwsys_ios::cerr << "Got unknown argument: \"" << arg.c_str() << "\"" << kwsys_ios::endl;
kwsys_ios::cerr << "Got unknown argument: \"" << arg << "\"" << kwsys_ios::endl;
this->Internals->LastArgument --;
return 0;
}

View File

@ -229,8 +229,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
{
fname = d.GetFile(cc);
if ( strcmp(fname.c_str(), ".") == 0 ||
strcmp(fname.c_str(), "..") == 0 )
if ( fname == "." || fname == ".." )
{
continue;
}
@ -271,11 +270,10 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
}
else
{
if ( (this->Internals->Expressions.size() > 0) &&
this->Internals->Expressions[
this->Internals->Expressions.size()-1].find(fname.c_str()) )
if ( !this->Internals->Expressions.empty() &&
this->Internals->Expressions.rbegin()->find(fname) )
{
this->AddFile(this->Internals->Files, realname.c_str());
this->AddFile(this->Internals->Files, realname);
}
}
}
@ -310,8 +308,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
{
fname = d.GetFile(cc);
if ( strcmp(fname.c_str(), ".") == 0 ||
strcmp(fname.c_str(), "..") == 0 )
if ( fname == "." || fname == ".." )
{
continue;
}
@ -354,7 +351,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
{
if ( last )
{
this->AddFile(this->Internals->Files, realname.c_str());
this->AddFile(this->Internals->Files, realname);
}
else
{
@ -442,9 +439,9 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
int ch = expr[cc];
if ( ch == '/' )
{
if ( cexpr.size() > 0 )
if ( !cexpr.empty() )
{
this->AddExpression(cexpr.c_str());
this->AddExpression(cexpr);
}
cexpr = "";
}
@ -453,9 +450,9 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
cexpr.append(1, static_cast<char>(ch));
}
}
if ( cexpr.size() > 0 )
if ( !cexpr.empty() )
{
this->AddExpression(cexpr.c_str());
this->AddExpression(cexpr);
}
// Handle network paths
@ -471,11 +468,11 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
}
//----------------------------------------------------------------------------
void Glob::AddExpression(const char* expr)
void Glob::AddExpression(const kwsys_stl::string& expr)
{
this->Internals->Expressions.push_back(
kwsys::RegularExpression(
this->PatternToRegex(expr).c_str()));
this->PatternToRegex(expr)));
}
//----------------------------------------------------------------------------
@ -500,11 +497,11 @@ const char* Glob::GetRelative()
}
//----------------------------------------------------------------------------
void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file)
void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file)
{
if ( !this->Relative.empty() )
{
files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file));
files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file.c_str()));
}
else
{

View File

@ -91,10 +91,10 @@ protected:
const kwsys_stl::string& dir);
//! Add regular expression
void AddExpression(const char* expr);
void AddExpression(const kwsys_stl::string& expr);
//! Add a file to the list
void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file);
void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file);
GlobInternals* Internals;
bool Recurse;

View File

@ -882,13 +882,6 @@ void regdump ();
static char* regprop ();
#endif
bool RegularExpression::find (kwsys_stl::string const& s)
{
return find(s.c_str());
}
// find -- Matches the regular expression to the given string.
// Returns true if found, and sets start and end indexes accordingly.

View File

@ -198,12 +198,17 @@ public:
* Instantiate RegularExpression with compiled char*.
*/
inline RegularExpression (char const*);
/**
* Instantiate RegularExpression as a copy of another regular expression.
*/
RegularExpression (RegularExpression const&);
/**
* Instantiate RegularExpression with compiled string.
*/
inline RegularExpression (kwsys_stl::string const&);
/**
* Destructor.
*/
@ -215,6 +220,12 @@ public:
*/
bool compile (char const*);
/**
* Compile a regular expression into internal code
* for later pattern matching.
*/
inline bool compile (kwsys_stl::string const&);
/**
* Matches the regular expression to the given string.
* Returns true if found, and sets start and end indexes accordingly.
@ -225,7 +236,7 @@ public:
* Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly.
*/
bool find (kwsys_stl::string const&);
inline bool find (kwsys_stl::string const&);
/**
* Index to start of first find.
@ -312,6 +323,16 @@ inline RegularExpression::RegularExpression (const char* s)
}
}
/**
* Creates a regular expression from string s, and
* compiles s.
*/
inline RegularExpression::RegularExpression (const kwsys_stl::string& s)
{
this->program = 0;
this->compile(s);
}
/**
* Destroys and frees space allocated for the regular expression.
*/
@ -322,6 +343,24 @@ inline RegularExpression::~RegularExpression ()
//#endif
}
/**
* Compile a regular expression into internal code
* for later pattern matching.
*/
inline bool RegularExpression::compile (kwsys_stl::string const& s)
{
return this->compile(s.c_str());
}
/**
* Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly.
*/
inline bool RegularExpression::find (kwsys_stl::string const& s)
{
return this->find(s.c_str());
}
/**
* Set the start position for the regular expression.
*/

View File

@ -627,7 +627,7 @@ bool SystemTools::MakeDirectory(const char* path)
return SystemTools::FileIsDirectory(path);
}
kwsys_stl::string dir = path;
if(dir.size() == 0)
if(dir.empty())
{
return false;
}
@ -1262,7 +1262,7 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2,
kwsys_stl::string SystemTools::Capitalized(const kwsys_stl::string& s)
{
kwsys_stl::string n;
if(s.size() == 0)
if(s.empty())
{
return n;
}
@ -1322,7 +1322,7 @@ kwsys_stl::string SystemTools::AddSpaceBetweenCapitalizedWords(
const kwsys_stl::string& s)
{
kwsys_stl::string n;
if (s.size())
if (!s.empty())
{
n.reserve(s.size());
n += s[0];
@ -1815,12 +1815,13 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
// remove trailing slash if the path is more than
// a single /
pathCString = path.c_str();
if(path.size() > 1 && *(pathCString+(path.size()-1)) == '/')
size_t size = path.size();
if(size > 1 && *path.rbegin() == '/')
{
// if it is c:/ then do not remove the trailing slash
if(!((path.size() == 3 && pathCString[1] == ':')))
if(!((size == 3 && pathCString[1] == ':')))
{
path = path.substr(0, path.size()-1);
path.resize(size - 1);
}
}
}
@ -2500,7 +2501,7 @@ kwsys_stl::string SystemTools
i != path.end(); ++i)
{
kwsys_stl::string& p = *i;
if(p.empty() || p[p.size()-1] != '/')
if(p.empty() || *p.rbegin() != '/')
{
p += "/";
}
@ -2535,7 +2536,7 @@ kwsys_stl::string SystemTools
kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
if(tryPath != "" && !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
// Couldn't find the file.
return "";
@ -2554,7 +2555,7 @@ kwsys_stl::string SystemTools
kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
if(tryPath != "" && SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
// Couldn't find the file.
return "";
@ -2594,18 +2595,15 @@ kwsys_stl::string SystemTools::FindProgram(
kwsys_stl::string tryPath;
// first try with extensions if the os supports them
if(extensions.size())
for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
extensions.begin(); i != extensions.end(); ++i)
{
for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
extensions.begin(); i != extensions.end(); ++i)
tryPath = name;
tryPath += *i;
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
tryPath = name;
tryPath += *i;
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
}
return SystemTools::CollapseFullPath(tryPath);
}
}
// now try just the name
@ -2613,7 +2611,7 @@ kwsys_stl::string SystemTools::FindProgram(
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
// now construct the path
kwsys_stl::vector<kwsys_stl::string> path;
@ -2636,7 +2634,7 @@ kwsys_stl::string SystemTools::FindProgram(
i != path.end(); ++i)
{
kwsys_stl::string& p = *i;
if(p.empty() || p[p.size()-1] != '/')
if(p.empty() || *p.rbegin() != '/')
{
p += "/";
}
@ -2651,19 +2649,16 @@ kwsys_stl::string SystemTools::FindProgram(
SystemTools::ReplaceString(*p, "\"", "");
#endif
// first try with extensions
if(extensions.size())
for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
= extensions.begin(); ext != extensions.end(); ++ext)
{
for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
= extensions.begin(); ext != extensions.end(); ++ext)
tryPath = *p;
tryPath += name;
tryPath += *ext;
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
tryPath = *p;
tryPath += name;
tryPath += *ext;
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
}
return SystemTools::CollapseFullPath(tryPath);
}
}
// now try it without them
@ -2672,7 +2667,7 @@ kwsys_stl::string SystemTools::FindProgram(
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
}
// Couldn't find the program.
@ -2732,7 +2727,7 @@ kwsys_stl::string SystemTools
i != path.end(); ++i)
{
kwsys_stl::string& p = *i;
if(p.empty() || p[p.size()-1] != '/')
if(p.empty() || *p.rbegin() != '/')
{
p += "/";
}
@ -2749,7 +2744,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
#endif
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
@ -2759,7 +2754,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
#else
tryPath = *p;
@ -2769,7 +2764,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
tryPath = *p;
tryPath += "lib";
@ -2778,7 +2773,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
tryPath = *p;
tryPath += "lib";
@ -2787,7 +2782,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
tryPath = *p;
tryPath += "lib";
@ -2796,7 +2791,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
tryPath = *p;
tryPath += "lib";
@ -2805,7 +2800,7 @@ kwsys_stl::string SystemTools
if(SystemTools::FileExists(tryPath.c_str())
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
return SystemTools::CollapseFullPath(tryPath);
}
#endif
}
@ -2823,11 +2818,11 @@ kwsys_stl::string SystemTools::GetRealPath(const char* path)
bool SystemTools::FileIsDirectory(const char* name)
{
size_t length = strlen(name);
if (length == 0)
if (!*name)
{
return false;
}
size_t length = strlen(name);
// Remove any trailing slash from the name except in a root component.
char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
@ -2940,7 +2935,7 @@ kwsys_stl::string SystemTools::GetCurrentWorkingDirectory(bool collapse)
}
if(collapse)
{
return SystemTools::CollapseFullPath(path.c_str());
return SystemTools::CollapseFullPath(path);
}
return path;
}
@ -3041,7 +3036,7 @@ bool SystemTools::FindProgramPath(const char* argv0,
kwsys_stl::vector<kwsys_stl::string>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
msg << " \"" << *i << "\"\n";
}
errorMsg = msg.str();
return false;
@ -3051,12 +3046,12 @@ bool SystemTools::FindProgramPath(const char* argv0,
}
kwsys_stl::string SystemTools::CollapseFullPath(const char* in_relative)
kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_relative)
{
return SystemTools::CollapseFullPath(in_relative, 0);
}
void SystemTools::AddTranslationPath(const char * a, const char * b)
void SystemTools::AddTranslationPath(const kwsys_stl::string& a, const kwsys_stl::string& b)
{
kwsys_stl::string path_a = a;
kwsys_stl::string path_b = b;
@ -3073,11 +3068,11 @@ void SystemTools::AddTranslationPath(const char * a, const char * b)
== kwsys_stl::string::npos )
{
// Before inserting make sure path ends with '/'
if(path_a.size() && path_a[path_a.size() -1] != '/')
if(!path_a.empty() && *path_a.rbegin() != '/')
{
path_a += '/';
}
if(path_b.size() && path_b[path_b.size() -1] != '/')
if(!path_b.empty() && *path_b.rbegin() != '/')
{
path_b += '/';
}
@ -3090,11 +3085,11 @@ void SystemTools::AddTranslationPath(const char * a, const char * b)
}
}
void SystemTools::AddKeepPath(const char* dir)
void SystemTools::AddKeepPath(const kwsys_stl::string& dir)
{
kwsys_stl::string cdir;
Realpath(SystemTools::CollapseFullPath(dir).c_str(), cdir);
SystemTools::AddTranslationPath(cdir.c_str(), dir);
SystemTools::AddTranslationPath(cdir, dir);
}
void SystemTools::CheckTranslationPath(kwsys_stl::string & path)
@ -3135,24 +3130,26 @@ SystemToolsAppendComponents(
kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
kwsys_stl::vector<kwsys_stl::string>::const_iterator last)
{
static const kwsys_stl::string up = "..";
static const kwsys_stl::string cur = ".";
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = first;
i != last; ++i)
{
if(*i == "..")
if(*i == up)
{
if(out_components.size() > 1)
{
out_components.erase(out_components.end()-1, out_components.end());
out_components.resize(out_components.size()-1);
}
}
else if(!(*i == ".") && !(*i == ""))
else if(!i->empty() && *i != cur)
{
out_components.push_back(*i);
}
}
}
kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path,
const char* in_base)
{
// Collect the output path components.
@ -3212,7 +3209,7 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
// collapsed, so I am going to try to comment it out, and see what hits the
// fan, hopefully quickly.
// Commented out line below:
//SystemTools::AddTranslationPath(newPath.c_str(), in_path);
//SystemTools::AddTranslationPath(newPath, in_path);
SystemTools::CheckTranslationPath(newPath);
#ifdef _WIN32
@ -3277,7 +3274,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot
// path into the remote dir
for(unsigned int i = 0; i < localSplit.size(); ++i)
{
if(localSplit[i].size())
if(!localSplit[i].empty())
{
finalPath.push_back("../");
}
@ -3287,7 +3284,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot
for(kwsys_stl::vector<String>::iterator vit = remoteSplit.begin();
vit != remoteSplit.end(); ++vit)
{
if(vit->size())
if(!vit->empty())
{
finalPath.push_back(*vit);
}
@ -3298,7 +3295,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot
for(kwsys_stl::vector<String>::iterator vit1 = finalPath.begin();
vit1 != finalPath.end(); ++vit1)
{
if(relativePath.size() && relativePath[relativePath.size()-1] != '/')
if(!relativePath.empty() && *relativePath.rbegin() != '/')
{
relativePath += "/";
}
@ -3312,7 +3309,7 @@ static int GetCasePathName(const kwsys_stl::string & pathIn,
kwsys_stl::string & casePath)
{
kwsys_stl::vector<kwsys_stl::string> path_components;
SystemTools::SplitPath(pathIn.c_str(), path_components);
SystemTools::SplitPath(pathIn, path_components);
if(path_components[0].empty()) // First component always exists.
{
// Relative paths cannot be converted.
@ -3394,11 +3391,11 @@ kwsys_stl::string SystemTools::GetActualCaseForPath(const char* p)
}
//----------------------------------------------------------------------------
const char* SystemTools::SplitPathRootComponent(const char* p,
const char* SystemTools::SplitPathRootComponent(const std::string& p,
kwsys_stl::string* root)
{
// Identify the root component.
const char* c = p;
const char* c = p.c_str();
if((c[0] == '/' && c[1] == '/') || (c[0] == '\\' && c[1] == '\\'))
{
// Network path.
@ -3480,17 +3477,17 @@ const char* SystemTools::SplitPathRootComponent(const char* p,
}
//----------------------------------------------------------------------------
void SystemTools::SplitPath(const char* p,
void SystemTools::SplitPath(const std::string& p,
kwsys_stl::vector<kwsys_stl::string>& components,
bool expand_home_dir)
{
const char* c = p;
const char* c;
components.clear();
// Identify the root component.
{
kwsys_stl::string root;
c = SystemTools::SplitPathRootComponent(c, &root);
c = SystemTools::SplitPathRootComponent(p, &root);
// Expand home directory references if requested.
if(expand_home_dir && !root.empty() && root[0] == '~')
@ -3520,12 +3517,12 @@ void SystemTools::SplitPath(const char* p,
}
}
#endif
if(!homedir.empty() && (homedir[homedir.size()-1] == '/' ||
homedir[homedir.size()-1] == '\\'))
if(!homedir.empty() && (*homedir.rbegin() == '/' ||
*homedir.rbegin() == '\\'))
{
homedir = homedir.substr(0, homedir.size()-1);
homedir.resize(homedir.size() - 1);
}
SystemTools::SplitPath(homedir.c_str(), components);
SystemTools::SplitPath(homedir, components);
}
else
{
@ -3541,9 +3538,7 @@ void SystemTools::SplitPath(const char* p,
if(*last == '/' || *last == '\\')
{
// End of a component. Save it.
components.push_back(
kwsys_stl::string(first,static_cast<kwsys_stl::string::size_type>(
last-first)));
components.push_back(kwsys_stl::string(first, last));
first = last+1;
}
}
@ -3551,9 +3546,7 @@ void SystemTools::SplitPath(const char* p,
// Save the last component unless there were no components.
if(last != c)
{
components.push_back(
kwsys_stl::string(first,static_cast<kwsys_stl::string::size_type>(
last-first)));
components.push_back(kwsys_stl::string(first, last));
}
}
@ -3572,6 +3565,13 @@ SystemTools
{
// Construct result in a single string.
kwsys_stl::string result;
size_t len = 0;
kwsys_stl::vector<kwsys_stl::string>::const_iterator i;
for(i = first; i != last; ++i)
{
len += 1 + i->size();
}
result.reserve(len);
// The first two components do not add a slash.
if(first != last)
@ -3595,18 +3595,18 @@ SystemTools
}
//----------------------------------------------------------------------------
bool SystemTools::ComparePath(const char* c1, const char* c2)
bool SystemTools::ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2)
{
#if defined(_WIN32) || defined(__APPLE__)
# ifdef _MSC_VER
return _stricmp(c1, c2) == 0;
return _stricmp(c1.c_str(), c2.c_str()) == 0;
# elif defined(__APPLE__) || defined(__GNUC__)
return strcasecmp(c1, c2) == 0;
return strcasecmp(c1.c_str(), c2.c_str()) == 0;
#else
return SystemTools::Strucmp(c1, c2) == 0;
return SystemTools::Strucmp(c1.c_str(), c2.c_str()) == 0;
# endif
#else
return strcmp(c1, c2) == 0;
return c1 == c2;
#endif
}
@ -3680,7 +3680,7 @@ kwsys_stl::string SystemTools::GetFilenamePath(const kwsys_stl::string& filename
{
return ret + '/';
}
if(ret.size() == 0)
if(ret.empty())
{
return "/";
}
@ -3701,7 +3701,7 @@ kwsys_stl::string SystemTools::GetFilenameName(const kwsys_stl::string& filename
#if defined(_WIN32)
kwsys_stl::string::size_type slash_pos = filename.find_last_of("/\\");
#else
kwsys_stl::string::size_type slash_pos = filename.find_last_of("/");
kwsys_stl::string::size_type slash_pos = filename.rfind('/');
#endif
if(slash_pos != kwsys_stl::string::npos)
{
@ -3915,7 +3915,7 @@ bool SystemTools::LocateFileInDir(const char *filename,
// Try to find the file in 'dir'
bool res = false;
if (filename_base.size() && dir)
if (!filename_base.empty() && dir)
{
size_t dir_len = strlen(dir);
int need_slash =
@ -3949,10 +3949,10 @@ bool SystemTools::LocateFileInDir(const char *filename,
filename_dir = SystemTools::GetFilenamePath(filename_dir);
filename_dir_base = SystemTools::GetFilenameName(filename_dir);
#if defined( _WIN32 )
if (!filename_dir_base.size() ||
filename_dir_base[filename_dir_base.size() - 1] == ':')
if (filename_dir_base.empty() ||
*filename_dir_base.rbegin() == ':')
#else
if (!filename_dir_base.size())
if (filename_dir_base.empty())
#endif
{
break;
@ -3970,7 +3970,7 @@ bool SystemTools::LocateFileInDir(const char *filename,
res = SystemTools::LocateFileInDir(
filename_base.c_str(), temp.c_str(), filename_found, 0);
} while (!res && filename_dir_base.size());
} while (!res && !filename_dir_base.empty());
}
}
@ -3979,30 +3979,30 @@ bool SystemTools::LocateFileInDir(const char *filename,
bool SystemTools::FileIsFullPath(const char* in_name)
{
kwsys_stl::string name = in_name;
size_t len = strlen(in_name);
#if defined(_WIN32) || defined(__CYGWIN__)
// On Windows, the name must be at least two characters long.
if(name.length() < 2)
if(len < 2)
{
return false;
}
if(name[1] == ':')
if(in_name[1] == ':')
{
return true;
}
if(name[0] == '\\')
if(in_name[0] == '\\')
{
return true;
}
#else
// On UNIX, the name must be at least one character long.
if(name.length() < 1)
if(len < 1)
{
return false;
}
#endif
#if !defined(_WIN32)
if(name[0] == '~')
if(in_name[0] == '~')
{
return true;
}
@ -4010,29 +4010,29 @@ bool SystemTools::FileIsFullPath(const char* in_name)
// On UNIX, the name must begin in a '/'.
// On Windows, if the name begins in a '/', then it is a full
// network path.
if(name[0] == '/')
if(in_name[0] == '/')
{
return true;
}
return false;
}
bool SystemTools::GetShortPath(const char* path, kwsys_stl::string& shortPath)
bool SystemTools::GetShortPath(const kwsys_stl::string& path, kwsys_stl::string& shortPath)
{
#if defined(WIN32) && !defined(__CYGWIN__)
const int size = int(strlen(path)) +1; // size of return
const int size = int(path.size()) +1; // size of return
char *tempPath = new char[size]; // create a buffer
DWORD ret;
// if the path passed in has quotes around it, first remove the quotes
if (path[0] == '"' && path[strlen(path)-1] == '"')
if (!path.empty() && path[0] == '"' && *path.rbegin() == '"')
{
strcpy(tempPath,path+1);
tempPath[strlen(tempPath)-1] = '\0';
strcpy(tempPath,path.c_str()+1);
tempPath[size-2] = '\0';
}
else
{
strcpy(tempPath,path);
strcpy(tempPath,path.c_str());
}
kwsys_stl::wstring wtempPath = Encoding::ToWide(tempPath);
@ -4073,7 +4073,7 @@ void SystemTools::SplitProgramFromArgs(const char* path,
// may have spaces in its name so we have to look for it
kwsys_stl::vector<kwsys_stl::string> e;
kwsys_stl::string findProg = SystemTools::FindProgram(path, e);
if(findProg.size())
if(!findProg.empty())
{
program = findProg;
args = "";
@ -4103,7 +4103,7 @@ void SystemTools::SplitProgramFromArgs(const char* path,
}
// Now try and find the program in the path
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
if(findProg.size())
if(!findProg.empty())
{
program = findProg;
// remove trailing spaces from program
@ -4344,9 +4344,9 @@ kwsys_stl::string SystemTools::GetParentDirectory(const char* fileOrDir)
return SystemTools::GetFilenamePath(fileOrDir);
}
bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
bool SystemTools::IsSubDirectory(const kwsys_stl::string& cSubdir, const kwsys_stl::string& cDir)
{
if(!*cDir)
if(cDir.empty())
{
return false;
}
@ -4357,7 +4357,7 @@ bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
if(subdir.size() > dir.size() && subdir[dir.size()] == '/')
{
std::string s = subdir.substr(0, dir.size());
return SystemTools::ComparePath(s.c_str(), dir.c_str());
return SystemTools::ComparePath(s, dir);
}
return false;
}
@ -4926,8 +4926,8 @@ void SystemTools::ClassInitialize()
// Add the translation to keep the logical path name.
if(!cwd_changed.empty() && !pwd_changed.empty())
{
SystemTools::AddTranslationPath(cwd_changed.c_str(),
pwd_changed.c_str());
SystemTools::AddTranslationPath(cwd_changed,
pwd_changed);
}
}
}

View File

@ -357,8 +357,8 @@ public:
* (which defaults to the current working directory). The full path
* is returned.
*/
static kwsys_stl::string CollapseFullPath(const char* in_relative);
static kwsys_stl::string CollapseFullPath(const char* in_relative,
static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative);
static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative,
const char* in_base);
/**
@ -383,7 +383,7 @@ public:
* returned. The root component is stored in the "root" string if
* given.
*/
static const char* SplitPathRootComponent(const char* p,
static const char* SplitPathRootComponent(const std::string& p,
kwsys_stl::string* root=0);
/**
@ -396,7 +396,7 @@ public:
* automatically expanded if expand_home_dir is true and this
* platform supports them.
*/
static void SplitPath(const char* p,
static void SplitPath(const std::string& p,
kwsys_stl::vector<kwsys_stl::string>& components,
bool expand_home_dir = true);
@ -413,7 +413,7 @@ public:
/**
* Compare a path or components of a path.
*/
static bool ComparePath(const char* c1, const char* c2);
static bool ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2);
/**
@ -465,7 +465,7 @@ public:
* For windows return the short path for the given path,
* Unix just a pass through
*/
static bool GetShortPath(const char* path, kwsys_stl::string& result);
static bool GetShortPath(const kwsys_stl::string& path, kwsys_stl::string& result);
/**
* Read line from file. Make sure to get everything. Due to a buggy stream
@ -487,7 +487,7 @@ public:
/**
* Check if the given file or directory is in subdirectory of dir
*/
static bool IsSubDirectory(const char* fileOrDir, const char* dir);
static bool IsSubDirectory(const kwsys_stl::string& fileOrDir, const kwsys_stl::string& dir);
/** -----------------------------------------------------------------
* File Manipulation Routines
@ -806,13 +806,13 @@ public:
/**
* Add an entry in the path translation table.
*/
static void AddTranslationPath(const char * dir, const char * refdir);
static void AddTranslationPath(const kwsys_stl::string& dir, const kwsys_stl::string& refdir);
/**
* If dir is different after CollapseFullPath is called,
* Then insert it into the path translation table
*/
static void AddKeepPath(const char* dir);
static void AddKeepPath(const kwsys_stl::string& dir);
/**
* Update path by going through the Path Translation table;

View File

@ -171,7 +171,7 @@ int testCommandLineArguments(int argc, char* argv[])
CompareTwoLists(strings_argument, valid_strings, 4);
CompareTwoLists(stl_strings_argument, valid_stl_strings, 4);
kwsys_ios::cout << "Some STL String variable was set to: " << some_stl_string_variable.c_str() << kwsys_ios::endl;
kwsys_ios::cout << "Some STL String variable was set to: " << some_stl_string_variable << kwsys_ios::endl;
kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable << kwsys_ios::endl;
kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable1 << kwsys_ios::endl;
kwsys_ios::cout << "bool_arg1 variable was set to: " << bool_arg1 << kwsys_ios::endl;

View File

@ -57,12 +57,12 @@ int testCommandLineArguments1(int argc, char* argv[])
}
if ( p != "1" )
{
kwsys_ios::cout << "Problem setting P. Value of P: " << p.c_str() << kwsys_ios::endl;
kwsys_ios::cout << "Problem setting P. Value of P: " << p << kwsys_ios::endl;
res = 1;
}
kwsys_ios::cout << "Value of N: " << n << kwsys_ios::endl;
kwsys_ios::cout << "Value of M: " << m << kwsys_ios::endl;
kwsys_ios::cout << "Value of P: " << p.c_str() << kwsys_ios::endl;
kwsys_ios::cout << "Value of P: " << p << kwsys_ios::endl;
if ( m )
{
delete [] m;

View File

@ -60,8 +60,8 @@ static bool CheckConvertToUnixSlashes(kwsys_stl::string input,
if ( result != output )
{
kwsys_ios::cerr
<< "Problem with ConvertToUnixSlashes - input: " << input.c_str()
<< " output: " << result.c_str() << " expected: " << output.c_str()
<< "Problem with ConvertToUnixSlashes - input: " << input
<< " output: " << result << " expected: " << output
<< kwsys_ios::endl;
return false;
}
@ -86,8 +86,8 @@ static bool CheckEscapeChars(kwsys_stl::string input,
if (result != output)
{
kwsys_ios::cerr
<< "Problem with CheckEscapeChars - input: " << input.c_str()
<< " output: " << result.c_str() << " expected: " << output.c_str()
<< "Problem with CheckEscapeChars - input: " << input
<< " output: " << result << " expected: " << output
<< kwsys_ios::endl;
return false;
}