From 82e8c6e3075102b857bc2af3f3de9897435ad6e6 Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 8 Feb 2012 01:52:54 +0000 Subject: [PATCH] Added workaround for bang with trailing backspace. http://rainmeter.net/forum/viewtopic.php?t=11229&p=64075 --- Library/Rainmeter.cpp | 67 +++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 88ab5375..81e22e53 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -111,10 +111,25 @@ std::vector CRainmeter::ParseString(LPCTSTR str) // Split the argument between first space. // Or if string is in quotes, the after the second quote. + auto stripQuotes = [&](std::wstring& string) + { + size_t pos = 0; + do + { + pos = string.find(L'"', pos); + if (pos != std::wstring::npos) + { + string.erase(pos, 1); + } + } + while (pos != std::wstring::npos); + }; + size_t pos; std::wstring newStr; while ((pos = arg.find_first_not_of(L' ')) != std::wstring::npos) { + size_t extra = 1; if (arg[pos] == L'"') { if (arg.size() > (pos + 2) && @@ -123,23 +138,12 @@ std::vector CRainmeter::ParseString(LPCTSTR str) // Eat found quotes and finding ending """ arg.erase(0, pos + 3); - size_t extra = 4; + extra = 4; if ((pos = arg.find(L"\"\"\" ")) == std::wstring::npos) { extra = 3; - pos = arg.find(L"\"\"\""); + pos = arg.rfind(L"\"\"\""); // search backward } - - if (pos != std::wstring::npos) - { - newStr.assign(arg, 0, pos); - arg.erase(0, pos + extra); - - result.push_back(newStr); - } - - // Skip stripping quotes - continue; } else { @@ -163,44 +167,25 @@ std::vector CRainmeter::ParseString(LPCTSTR str) if (pos != std::wstring::npos) { newStr.assign(arg, 0, pos); - arg.erase(0, pos + 1); - - // Strip quotes - size_t start = 0; - do - { - pos = newStr.find(L'"', start); - if (pos != std::wstring::npos) - { - newStr.erase(pos, 1); - start = pos; - } - } - while (pos != std::wstring::npos); + arg.erase(0, pos + extra); + if (extra == 1) stripQuotes(newStr); result.push_back(newStr); } else // quote or space not found { + newStr = arg; + arg.clear(); + + if (extra == 1) stripQuotes(newStr); + result.push_back(newStr); break; } } - if (!arg.empty()) + if (!arg.empty() && result.empty()) { - // Strip quotes - size_t start = 0; - do - { - pos = arg.find(L'"', start); - if (pos != std::wstring::npos) - { - arg.erase(pos, 1); - start = pos; - } - } - while (pos != std::wstring::npos); - + stripQuotes(arg); result.push_back(arg); } }