Code: Select all
wxString::Trim
wxString& Trim(bool fromRight = true)
Removes white-space (space, tabs, form feed, newline and carriage return) from the left or from the right end of the string (right is default).If one is not concerned with Preferences creep one would probably add a preference to turn this automatic behavior on and off. Personally, I do not bother with this preference because I always want it on!
Here is the code:
at or near line number 32 in Export.h add two new function declarations:
Code: Select all
class TimeTrack;
class Mixer;
wxString Trim(const wxString & pString, const wxString & pWhitespace = wxT(" t"));
wxString Reduce(const wxString & pString, const wxString & pFiller = wxT(" "), const wxString & pWhitespace = wxT(" t"));
class FormatInfo
{Code: Select all
wxString Trim(const wxString & pString, const wxString & pWhitespace) {
const auto stringBeginning = pString.find_first_not_of(pWhitespace);
//if (stringBeginning == std::string::npos)
if (stringBeginning == wxString::npos)
return wxString(wxEmptyString); // no content
const auto stringEnding = pString.find_last_not_of(pWhitespace);
const auto stringRange = stringEnding - stringBeginning + 1;
return pString.substr(stringBeginning, stringRange);
}
wxString Reduce(const wxString & pString, const wxString & pFiller, const wxString & pWhitespace)
{
// trim first
wxString result = Trim(pString, pWhitespace);
// replace sub ranges
auto beginSpace = result.find_first_of(pWhitespace);
//while (beginSpace != std::string::npos)
while (beginSpace != wxString::npos)
{
const auto endSpace = result.find_first_not_of(pWhitespace, beginSpace);
const auto range = endSpace - beginSpace;
result.replace(beginSpace, range, pFiller);
const auto newStart = beginSpace + pFiller.length();
beginSpace = result.find_first_of(pWhitespace, newStart);
}
return result;
}Code: Select all
bool Exporter::CheckFilename()
{
//[…]
// Strip leading and trailing spaces & remove redundant spaces
wxString fileName(mFilename.GetName());
fileName = Reduce (fileName);
mFilename.SetName(fileName);
if (!mProject->GetDirManager()->EnsureSafeFilename(mFilename))
return false;