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

Unified Diff: src/plugin/PluginUtil.cpp

Issue 29332775: Issue #1234 - Remove 'CString' From 'ToLowerString()' (Closed)
Patch Set: Created Dec. 15, 2015, 9:10 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/plugin/PluginUtil.cpp
===================================================================
--- a/src/plugin/PluginUtil.cpp
+++ b/src/plugin/PluginUtil.cpp
@@ -53,8 +53,26 @@
return std::wstring(locationUrl, locationUrl.Length());
}
+/**
+ * \par Implementation Note
+ * This function '_wcslwr()' uses the current locale to determine case.
sergei 2015/12/16 10:32:44 I don't think we need this line because it's alrea
Eric 2015/12/16 13:53:26 It's not the same. The header says is it uses the
+ * This is the same function used within 'CStringW::MakeLower()', which this function replaces.
sergei 2015/12/16 10:32:44 The comment on this line is not necessary to be in
Eric 2015/12/16 13:53:26 I wavered on this one. I had decided to leave it i
+ */
std::wstring ToLowerString(const std::wstring& s)
{
- return ToWstring(ToCString(s).MakeLower());
+ std::wstring lower(s); // copy the argument
+ /*
+ * C++11 provides that 'c_str()' returns the internal array in which the string holds its value.
+ * Thus we can modify in-place after casting away the 'const' modifier from 'c_str()'.
+ *
+ * C++11 also provides that 'c_str()' return a null-terminated string.
+ * On the other hand, '_wcslwr_s' throws an assertion failure saying that it's not null-terminated.
+ * So we're using the "insecure" version and suppressing the deprecation warning.
sergei 2015/12/16 10:32:44 Although "insecure" version might work good becaus
Eric 2015/12/16 13:53:26 I had tried it once and it had failed. It turns ou
+ */
+#pragma warning (push)
+#pragma warning(disable : 4996)
+ _wcslwr(const_cast<wchar_t*>(lower.data()));
sergei 2015/12/16 10:32:45 What about returning of an empty string in case of
Eric 2015/12/16 13:53:26 The tests aren't returning an error code, now that
sergei 2015/12/16 15:53:16 Still I would like to check the return value and h
Eric 2015/12/16 16:38:06 Don't need to. According to the documentation, it
+#pragma warning (pop)
+ return lower;
}

Powered by Google App Engine
This is Rietveld