Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 std::wstring GetLocationUrl(IWebBrowser2& browser) | 46 std::wstring GetLocationUrl(IWebBrowser2& browser) |
47 { | 47 { |
48 ATL::CComBSTR locationUrl; | 48 ATL::CComBSTR locationUrl; |
49 if (FAILED(browser.get_LocationURL(&locationUrl)) || !locationUrl) | 49 if (FAILED(browser.get_LocationURL(&locationUrl)) || !locationUrl) |
50 { | 50 { |
51 return std::wstring(); | 51 return std::wstring(); |
52 } | 52 } |
53 return std::wstring(locationUrl, locationUrl.Length()); | 53 return std::wstring(locationUrl, locationUrl.Length()); |
54 } | 54 } |
55 | 55 |
56 /** | |
57 * \par Implementation Note | |
58 * 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
| |
59 * This is the same function used within 'CStringW::MakeLower()', which this f unction 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
| |
60 */ | |
61 std::wstring ToLowerString(const std::wstring& s) | 56 std::wstring ToLowerString(const std::wstring& s) |
62 { | 57 { |
63 std::wstring lower(s); // copy the argument | 58 std::wstring lower(s); // Copy the argument |
64 /* | 59 /* |
65 * C++11 provides that 'c_str()' returns the internal array in which the strin g holds its value. | 60 * Documentation for '_wcslwr_s' https://msdn.microsoft.com/en-us/library/y889 wzfw.aspx |
66 * Thus we can modify in-place after casting away the 'const' modifier from 'c _str()'. | 61 * This documentation is incorrect on an important point. |
67 * | 62 * Regarding parameter validation, it says "length of string" where it should say "length of buffer". |
68 * C++11 also provides that 'c_str()' return a null-terminated string. | 63 * The call below has argument "length + 1" to include the terminating null ch aracter in the buffer. |
69 * On the other hand, '_wcslwr_s' throws an assertion failure saying that it's not null-terminated. | |
70 * So we're using the "insecure" version and suppressing the deprecation warni ng. | |
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
| |
71 */ | 64 */ |
72 #pragma warning (push) | 65 auto e = _wcslwr_s(const_cast<wchar_t*>(lower.c_str()), lower.length() + 1); / / uses the current locale |
73 #pragma warning(disable : 4996) | 66 if (e != 0) |
74 _wcslwr(const_cast<wchar_t*>(lower.data())); | 67 { |
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
| |
75 #pragma warning (pop) | 68 throw std::logic_error("Error code returned from _wcslwr_s()"); |
69 } | |
76 return lower; | 70 return lower; |
77 } | 71 } |
78 | 72 |
LEFT | RIGHT |