Minor tweaks.

This commit is contained in:
spx 2011-07-14 00:26:53 +00:00
parent 6ceacb0d98
commit fdad6fb036
8 changed files with 35 additions and 45 deletions

View File

@ -600,17 +600,13 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
{ {
if ((*iter).size() > 0) if ((*iter).size() > 0)
{ {
std::wstring strSection = (*iter); std::wstring::size_type pos = (*iter).find_first_not_of(L" \t\r\n");
std::wstring::size_type pos = strSection.find_first_not_of(L" \t\r\n");
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
std::wstring::size_type lastPos = strSection.find_last_not_of(L" \t\r\n"); std::wstring::size_type lastPos = (*iter).find_last_not_of(L" \t\r\n");
if (pos != 0 || lastPos != (strSection.length() - 1))
{ // Trim white-space
// Trim white-space std::wstring strSection((*iter), pos, lastPos - pos + 1);
strSection.swap(std::wstring(strSection, pos, lastPos - pos + 1));
}
const std::wstring& strStyle = GetValue(strSection, key, strDefault); const std::wstring& strStyle = GetValue(strSection, key, strDefault);
@ -1147,7 +1143,7 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
if (sep != std::wstring::npos && sep != 0) if (sep != std::wstring::npos && sep != 0)
{ {
std::wstring value = key.substr(sep + 1, len - sep); std::wstring value = key.substr(sep + 1, len - sep);
key.resize(sep); key.erase(sep);
std::wstring lowerKey = StrToLower(key); std::wstring lowerKey = StrToLower(key);
if (foundKeys.insert(lowerKey).second) if (foundKeys.insert(lowerKey).second)
@ -1159,7 +1155,7 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
(value[0] == L'\'' && value[valueLen - 1] == L'\''))) (value[0] == L'\'' && value[valueLen - 1] == L'\'')))
{ {
valueLen -= 2; valueLen -= 2;
value.swap(value.substr(1, valueLen)); value.assign(value, 1, valueLen);
} }
if (wcsncmp(lowerKey.c_str(), L"@include", 8) == 0) if (wcsncmp(lowerKey.c_str(), L"@include", 8) == 0)

View File

@ -67,15 +67,9 @@ std::wstring CGroup::CreateGroup(const std::wstring& str)
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
std::wstring::size_type lastPos = str.find_last_not_of(L" \t\r\n"); std::wstring::size_type lastPos = str.find_last_not_of(L" \t\r\n");
if (pos != 0 || lastPos != (str.length() - 1))
{ // Trim white-space
// Trim white-space strTmp.assign(str, pos, lastPos - pos + 1);
strTmp.swap(std::wstring(str, pos, lastPos - pos + 1));
}
else
{
strTmp = str;
}
// Convert to lower // Convert to lower
std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower); std::transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::towlower);

View File

@ -344,12 +344,12 @@ HINSTANCE ExecuteCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, LPCTSTR sz
size_t quotePos2 = command.find(L"\"", quotePos + 1); size_t quotePos2 = command.find(L"\"", quotePos + 1);
if (quotePos2 != std::wstring::npos) if (quotePos2 != std::wstring::npos)
{ {
args = command.substr(quotePos2 + 1); args.assign(command, quotePos2 + 1, command.length() - (quotePos2 + 1));
command = command.substr(quotePos + 1, quotePos2 - quotePos - 1); command.assign(command, quotePos + 1, quotePos2 - quotePos - 1);
} }
else else
{ {
command.erase(0, quotePos + 1); command.erase(0, 1);
} }
} }
else else
@ -357,8 +357,8 @@ HINSTANCE ExecuteCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, LPCTSTR sz
size_t spacePos = command.find(L" "); size_t spacePos = command.find(L" ");
if (spacePos != std::wstring::npos) if (spacePos != std::wstring::npos)
{ {
args = command.substr(spacePos + 1); args.assign(command, spacePos + 1, command.length() - (spacePos + 1));
command = command.substr(0, spacePos); command.erase(spacePos);
} }
} }

View File

@ -298,7 +298,7 @@ std::wstring CMeasure::ExtractWord(std::wstring& buffer)
if (end != std::wstring::npos) if (end != std::wstring::npos)
{ {
ret = buffer.substr(1, end - 1); ret.assign(buffer, 1, end - 1);
++end; ++end;
} }
else else
@ -319,7 +319,7 @@ std::wstring CMeasure::ExtractWord(std::wstring& buffer)
} }
else else
{ {
ret = buffer.substr(0, ++end); // The separator is also returned! ret.assign(buffer, 0, ++end); // The separator is also returned!
} }
} }
} }

View File

@ -933,7 +933,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
pos3 = args.find(L' '); pos3 = args.find(L' ');
if (pos3 != std::wstring::npos) if (pos3 != std::wstring::npos)
{ {
measure = args.substr(0, pos3); measure.assign(args, 0, pos3);
args.erase(0, ++pos3); args.erase(0, ++pos3);
CMeasure* m = GetMeasure(measure); CMeasure* m = GetMeasure(measure);
@ -970,7 +970,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
pos3 = args.find(L' '); pos3 = args.find(L' ');
if (pos3 != std::wstring::npos) if (pos3 != std::wstring::npos)
{ {
measure = args.substr(0, pos3); measure.assign(args, 0, pos3);
++pos3; ++pos3;
} }
else else
@ -4992,7 +4992,7 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
std::wstring::size_type pos = str.find(' '); std::wstring::size_type pos = str.find(' ');
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
bang = str.substr(0, pos); bang.assign(str, 0, pos);
str.erase(0, pos + 1); str.erase(0, pos + 1);
arg = str; arg = str;
} }

View File

@ -1746,7 +1746,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
} }
else if (iniFile[iniFile.length() - 1] == L'\"') else if (iniFile[iniFile.length() - 1] == L'\"')
{ {
iniFile = iniFile.substr(1, iniFile.length() - 2); iniFile.assign(iniFile, 1, iniFile.length() - 2);
} }
} }
@ -1777,14 +1777,13 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
bDefaultIniLocation = true; bDefaultIniLocation = true;
} }
// Set the log file location // Set the log file and stats file location
m_LogFile = m_StatsFile = m_IniFile; m_LogFile = m_StatsFile = m_IniFile;
size_t logFileLen = m_LogFile.length(); size_t logFileLen = m_LogFile.length();
if (logFileLen > 4 && _wcsicmp(m_LogFile.substr(logFileLen - 4).c_str(), L".ini") == 0) if (logFileLen > 4 && _wcsicmp(m_LogFile.substr(logFileLen - 4).c_str(), L".ini") == 0)
{ {
m_LogFile.replace(logFileLen - 4, 4, L".log"); m_LogFile.replace(logFileLen - 4, 4, L".log");
m_StatsFile.replace(logFileLen - 4, 4, L".sta"); m_StatsFile.replace(logFileLen - 4, 4, L".stats");
m_StatsFile += L"ts";
} }
else else
{ {
@ -1910,7 +1909,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
std::wstring::size_type loc; std::wstring::size_type loc;
if ((loc = m_Path.find_first_of(L':')) != std::wstring::npos) if ((loc = m_Path.find_first_of(L':')) != std::wstring::npos)
{ {
m_Drive = m_Path.substr(0, loc + 1); m_Drive.assign(m_Path, 0, loc + 1);
} }
else if (m_Path.length() >= 2 && (m_Path[0] == L'\\' || m_Path[0] == L'/') && (m_Path[1] == L'\\' || m_Path[1] == L'/')) else if (m_Path.length() >= 2 && (m_Path[0] == L'\\' || m_Path[0] == L'/') && (m_Path[1] == L'\\' || m_Path[1] == L'/'))
{ {
@ -1922,7 +1921,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
loc = loc2; loc = loc2;
} }
} }
m_Drive = m_Path.substr(0, loc); m_Drive.assign(m_Path, 0, loc);
} }
// Test that the Rainmeter.ini file is writable // Test that the Rainmeter.ini file is writable
@ -3224,7 +3223,8 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
std::wstring::size_type len = strCommand.length(); std::wstring::size_type len = strCommand.length();
if (len >= 2 && strCommand[0] == L'\"' && strCommand[len - 1] == L'\"') if (len >= 2 && strCommand[0] == L'\"' && strCommand[len - 1] == L'\"')
{ {
strCommand.swap(strCommand.substr(1, len - 2)); len -= 2;
strCommand.assign(strCommand, 1, len);
} }
PlaySound(strCommand.c_str(), NULL, flags); PlaySound(strCommand.c_str(), NULL, flags);
@ -3255,7 +3255,7 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
size_t pos = strCommand.find(L' '); size_t pos = strCommand.find(L' ');
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
bang = strCommand.substr(0, pos); bang.assign(strCommand, 0, pos);
strCommand.erase(0, pos + 1); strCommand.erase(0, pos + 1);
arg = strCommand; arg = strCommand;
} }
@ -3753,7 +3753,7 @@ void CRainmeter::ResetStats()
time(&long_time); time(&long_time);
newtime = localtime(&long_time); newtime = localtime(&long_time);
m_StatsDate = _wasctime(newtime); m_StatsDate = _wasctime(newtime);
m_StatsDate.resize(m_StatsDate.size() - 1); m_StatsDate.erase(m_StatsDate.size() - 1);
// Only Net measure has stats at the moment // Only Net measure has stats at the moment
CMeasureNet::ResetStats(); CMeasureNet::ResetStats();

View File

@ -1168,7 +1168,7 @@ std::wstring CSystem::GetTemporaryFile(const std::vector<std::wstring>& iniFileM
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
filename = iniFile.substr(pos + 1); filename.assign(iniFile, pos + 1, iniFile.length() - (pos + 1));
} }
else else
{ {

View File

@ -1206,7 +1206,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
std::wstring::size_type pos = path.find_first_not_of(L'\\'); std::wstring::size_type pos = path.find_first_not_of(L'\\');
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
path = path.substr(pos); path.erase(0, pos);
} }
PathCanonicalize(buffer, urlData->iniFile.substr(0, urlData->iniFile.find_last_of(L'\\') + 1).c_str()); // "#CURRENTPATH#" PathCanonicalize(buffer, urlData->iniFile.substr(0, urlData->iniFile.find_last_of(L'\\') + 1).c_str()); // "#CURRENTPATH#"
@ -1241,11 +1241,11 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
std::wstring name; std::wstring name;
if (pos2 != std::wstring::npos) if (pos2 != std::wstring::npos)
{ {
name = url.substr(pos1, pos2 - pos1); name.assign(url, pos1, pos2 - pos1);
} }
else else
{ {
name = url.substr(pos1); name.assign(url, pos1, url.length() - pos1);
} }
if (!name.empty()) if (!name.empty())
@ -1319,8 +1319,8 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
std::wstring path, ext; std::wstring path, ext;
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
path = fullpath.substr(0, pos); path.assign(fullpath, 0, pos);
ext = fullpath.substr(pos); ext.assign(fullpath, pos, fullpath.length() - pos);
} }
else else
{ {