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: rewrite to use _wcslwr_s() Created Dec. 16, 2015, 1:51 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,23 @@
return std::wstring(locationUrl, locationUrl.Length());
}
+/**
+ * \par Implementation Note
+ * We call '_wcslwr_s()', which take C-style strings and uses the current locale to determine case.
sergei 2015/12/16 15:53:16 It still can be just a one line comment "uses the
Eric 2015/12/16 16:38:07 That's reasonable.
+ */
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()'.
sergei 2015/12/16 15:53:16 These two lines are completely redundant.
Eric 2015/12/16 16:38:07 Just because you understand it already doesn't mea
Oleksandr 2016/01/05 22:59:00 From what I remember the consensus on comments is
Eric 2016/01/07 14:34:04 Done.
+ *
+ * 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.
sergei 2015/12/16 15:53:16 It does say "Size of the buffer.", so these three
Eric 2015/12/16 16:38:07 It also says "size of string", and it does that (l
Oleksandr 2016/01/05 22:59:00 How about just a comment like: //NOTE: second para
Eric 2016/01/07 14:34:04 It's not typical for documentation to be incorrect
+ */
+ _wcslwr_s(const_cast<wchar_t*>(lower.c_str()), lower.length() + 1);
+ 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