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, round two Created Jan. 7, 2016, 2:32 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
« no previous file with comments | « src/plugin/PluginUtil.h ('k') | test/plugin/UtilTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginUtil.cpp
===================================================================
--- a/src/plugin/PluginUtil.cpp
+++ b/src/plugin/PluginUtil.cpp
@@ -55,6 +55,18 @@
std::wstring ToLowerString(const std::wstring& s)
{
- return ToWstring(ToCString(s).MakeLower());
+ std::wstring lower(s); // Copy the argument
+ /*
+ * 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld