Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Utils.h

Issue 5081266177179648: Issue 1104 - Cannot uncheck Disable on website option in tool bar (Closed)
Patch Set: Created Feb. 23, 2015, 12:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/shared/Utils.h
diff --git a/src/shared/Utils.h b/src/shared/Utils.h
index befdf237aafeef59f39becbb1daa86fdbb64af9a..26d8581d91e41ff32fe13121d5983fbc4e4b729a 100644
--- a/src/shared/Utils.h
+++ b/src/shared/Utils.h
@@ -56,7 +56,35 @@ std::wstring ToUtf16String(const std::string& str);
std::vector<std::wstring> ToUtf16Strings(const std::vector<std::string>& value);
std::wstring GetDllDir();
std::wstring GetAppDataPath();
-void ReplaceString(std::wstring& input, const std::wstring placeholder, const std::wstring replacement);
+
+template<typename T>
+void ReplaceString(T& input, const T& placeholder, const T& replacement)
Eric 2015/02/26 16:14:10 We want to be able to use type inference for this
+{
+ auto replaceStart = input.find(placeholder);
+ if (replaceStart != T::npos)
+ {
+ input.replace(replaceStart, placeholder.length(), replacement);
+ }
+}
+
+template <typename T>
+T ASCIIStringToLower(const T& text)
Eric 2015/02/26 16:14:10 We could take the opportunity to rename this "Asci
+{
+ T textlower;
+ std::transform(text.begin(), text.end(), std::back_inserter(textlower),
+ [](T::value_type ch)
+ {
+ return std::tolower(ch, std::locale());
+ }
+ );
+ return textlower;
+}
+
+template<typename T>
+bool BeginsWith(const T& value, const T& prefix)
+{
+ return value.compare(0, prefix.length(), prefix) == 0;
+}
Eric 2015/02/26 16:14:10 Here are the unit tests I had previously, adapted
Eric 2015/02/26 16:14:10 I wrote a version of this last summer in the giant
template<class T>
T TrimString(T text)

Powered by Google App Engine
This is Rietveld