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: address comments Created Dec. 16, 2015, 4:35 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
@@ -55,6 +55,21 @@
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()'.
+ *
+ * Documentation for '_wcslwr_s' https://msdn.microsoft.com/en-us/library/y889wzfw.aspx
+ * This documentation is incorrect on an important point.
+ * Regarding parameter validation, it says "length of string" where it should say "length of buffer".
+ * The call below has argument "length + 1" to include the terminating null character in the buffer.
+ */
+ auto e = _wcslwr_s(const_cast<wchar_t*>(lower.c_str()), lower.length() + 1); // uses the current locale
+ if (e != 0)
+ {
+ throw std::logic_error("Error code returned from _wcslwr_s()");
+ }
+ return lower;
}
« no previous file with comments | « src/plugin/PluginUtil.h ('k') | test/plugin/UtilTest.cpp » ('j') | test/plugin/UtilTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld