Add more raw string literals missed previously
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 4 Jun 2020 12:09:06 +0000 (14:09 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 12 Aug 2020 07:48:29 +0000 (09:48 +0200)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
.clang-tidy
shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp
shell_integration/windows/OCUtil/CommunicationSocket.cpp
src/common/filesystembase.h
src/common/utility.cpp
src/common/utility_win.cpp
src/gui/navigationpanehelper.cpp
test/csync/csync_tests/check_csync_exclude.cpp
test/csync/encoding_tests/check_encoding.cpp

index 311e66d9e7aec6a81cda92e4fbef09a5c6908f12..4c03e129deebd4d0153fae4689578e237169c9e0 100644 (file)
@@ -1,6 +1,7 @@
 Checks: '-*,
     cppcoreguidelines-init-variables,
     modernize-make-*,
+    modernize-raw-string-literal,
     modernize-redundant-void-arg,
     modernize-replace-*,
     modernize-return-braced-init-list,
index e855ff43f5cb14938bfe6d62ad09631dc006e192..38e1d5e06890342994bd6464890b0661b6381667 100644 (file)
@@ -85,7 +85,7 @@ HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL
     wchar_t szSubkey[MAX_PATH];
 
     // Create the HKCR\CLSID\{<CLSID>} key.
-    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
+    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), LR"(CLSID\%s)", szCLSID);
     if (SUCCEEDED(hr))
     {
         hr = SetHKCRRegistryKeyAndValue(szSubkey, nullptr, pszFriendlyName);
@@ -94,7 +94,7 @@ HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL
         if (SUCCEEDED(hr))
         {
             hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
-                L"CLSID\\%s\\InprocServer32", szCLSID);
+                LR"(CLSID\%s\InprocServer32)", szCLSID);
             if (SUCCEEDED(hr))
             {
                 // Set the default value of the InprocServer32 key to the 
@@ -123,7 +123,7 @@ HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
     wchar_t szSubkey[MAX_PATH];
 
     // Delete the HKCR\CLSID\{<CLSID>} key.
-    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
+    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), LR"(CLSID\%s)", szCLSID);
     if (SUCCEEDED(hr))
     {
         hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
@@ -167,7 +167,7 @@ HRESULT OCContextMenuRegHandler::RegisterShellExtContextMenuHandler(
 
     // Create the key HKCR\<File Type>\shellex\ContextMenuHandlers\{friendlyName>}
     hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
-        L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName);
+        LR"(%s\shellex\ContextMenuHandlers\%s)", pszFileType, pszFriendlyName);
     if (SUCCEEDED(hr))
     {
         // Set the default value of the key.
@@ -208,7 +208,7 @@ HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
 
     // Remove the HKCR\<File Type>\shellex\ContextMenuHandlers\{friendlyName} key.
     hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
-        L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName);
+        LR"(%s\shellex\ContextMenuHandlers\%s)", pszFileType, pszFriendlyName);
     if (SUCCEEDED(hr))
     {
         hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
index f24b30ba60bd4cd5803d1c3c5debc37dd52f721b..649a9a145f19baa1c2d0b2d41af61762b53092b4 100644 (file)
@@ -44,7 +44,7 @@ std::wstring getUserName() {
 
 std::wstring CommunicationSocket::DefaultPipePath()
 {
-    auto pipename = std::wstring(L"\\\\.\\pipe\\");
+    auto pipename = std::wstring(LR"(\\.\pipe\)");
     pipename += L"ownCloud-";
     pipename += getUserName();
     return pipename;
index c5bed655884d847e9d8aa37a7d9604f8cffec25e..08abdfcb139a854807d8fb5076e931e7150d256f 100644 (file)
@@ -175,10 +175,10 @@ namespace FileSystem {
         if( str[0] == '/' || str[0] == '\\' ) {
             // Don't prepend if already UNC
             if( !(len > 1 && (str[1] == '/' || str[1] == '\\')) ) {
-                longStr.append("\\\\?");
+                longStr.append(R"(\\?)");
             }
         } else {
-            longStr.append("\\\\?\\"); // prepend string by this four magic chars.
+            longStr.append(R"(\\?\)"); // prepend string by this four magic chars.
         }
         longStr += str;
 
index 28f507696e3538ced2ddbb1ee2d9e951acc4ddf0..519bfc022cb1bb0f6c6352c310559b63e2397f33 100644 (file)
@@ -666,7 +666,7 @@ QByteArray Utility::conflictFileBaseName(const QByteArray &conflictName)
 
 QString Utility::sanitizeForFileName(const QString &name)
 {
-    const auto invalid = QStringLiteral("/?<>\\:*|\"");
+    const auto invalid = QStringLiteral(R"(/?<>\:*|")");
     QString result;
     result.reserve(name.size());
     for (const auto c : name) {
index 9df84e0c5c866bc94b6ba0fba8aabf1c15dbe920..13badf59967b10eef01b6a3f99800be45b04d3cc 100644 (file)
@@ -25,7 +25,7 @@
 #include <string>
 #include <QLibrary>
 
-static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
+static const char runPathC[] = R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)";
 
 namespace OCC {
 
@@ -91,7 +91,7 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,
 static inline bool hasDarkSystray_private()
 {
     if(Utility::registryGetKeyValue(    HKEY_CURRENT_USER,
-                                        "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
+                                        R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)",
                                         "SystemUsesLightTheme" ) == 1) {
         return false;
     }
index f738799d435b79d771ad1ea2cd16a6ad4d1768b2..a95830eee22118ce89bca28fd6c250a9b599ebef 100644 (file)
@@ -68,7 +68,7 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
 #ifdef Q_OS_WIN
     Utility::registryWalkSubKeys(
         HKEY_CURRENT_USER,
-        QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace"),
+        QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)"),
         [&entriesToRemove](HKEY key, const QString &subKey) {
             QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName"));
             if (appName.toString() == QLatin1String(APPLICATION_NAME)) {
@@ -138,7 +138,7 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
                 // Step 11: Register your extension in the namespace root
                 Utility::registrySetKeyValue(HKEY_CURRENT_USER, namespacePath, QString(), REG_SZ, title);
                 // Step 12: Hide your extension from the Desktop
-                Utility::registrySetKeyValue(HKEY_CURRENT_USER, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel"), clsidStr, REG_DWORD, 0x1);
+                Utility::registrySetKeyValue(HKEY_CURRENT_USER, QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel)"), clsidStr, REG_DWORD, 0x1);
 
                 // For us, to later be able to iterate and find our own namespace entries and associated CLSID.
                 // Use the macro instead of the theme to make sure it matches with the uninstaller.
index 85efea3686cd25184478fb4102b2d3ad3b680509..c052f242498119946f95c2a83edda51c6cbf23ac 100644 (file)
@@ -681,7 +681,7 @@ static void check_csync_exclude_expand_escapes(void **state)
 {
     (void)state;
 
-    QByteArray line = "keep \\' \\\" \\? \\\\ \\a \\b \\f \\n \\r \\t \\v \\z \\#";
+    QByteArray line = R"(keep \' \" \? \\ \a \b \f \n \r \t \v \z \#)";
     csync_exclude_expand_escapes(line);
     assert_true(0 == strcmp(line.constData(), "keep ' \" ? \\\\ \a \b \f \n \r \t \v \\z #"));
 
index 22dc20e1ec35beaaf2bda71382b4174309326f48..7d3733bc62a6a0ed04b6d21f738e436a013bc188 100644 (file)
@@ -116,35 +116,35 @@ static void check_long_win_path(void **state)
 
     {
         const char *path = "C://DATA/FILES/MUSIC/MY_MUSIC.mp3"; // check a short path
-        const char *exp_path = "\\\\?\\C:\\\\DATA\\FILES\\MUSIC\\MY_MUSIC.mp3";
+        const char *exp_path = R"(\\?\C:\\DATA\FILES\MUSIC\MY_MUSIC.mp3)";
         QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path)));
         assert_string_equal(new_short, exp_path);
     }
 
     {
-        const char *path = "\\\\foo\\bar/MY_MUSIC.mp3";
-        const char *exp_path = "\\\\foo\\bar\\MY_MUSIC.mp3";
+        const char *path = R"(\\foo\bar/MY_MUSIC.mp3)";
+        const char *exp_path = R"(\\foo\bar\MY_MUSIC.mp3)";
         QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path)));
         assert_string_equal(new_short, exp_path);
     }
 
     {
-        const char *path = "//foo\\bar/MY_MUSIC.mp3";
-        const char *exp_path = "\\\\foo\\bar\\MY_MUSIC.mp3";
+        const char *path = R"(//foo\bar/MY_MUSIC.mp3)";
+        const char *exp_path = R"(\\foo\bar\MY_MUSIC.mp3)";
         QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path)));
         assert_string_equal(new_short, exp_path);
     }
 
     {
         const char *path = "\\foo\\bar";
-        const char *exp_path = "\\\\?\\foo\\bar";
+        const char *exp_path = R"(\\?\foo\bar)";
         QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path)));
         assert_string_equal(new_short, exp_path);
     }
 
     {
         const char *path = "/foo/bar";
-        const char *exp_path = "\\\\?\\foo\\bar";
+        const char *exp_path = R"(\\?\foo\bar)";
         QByteArray new_short = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(path, strlen(path)));
         assert_string_equal(new_short, exp_path);
     }
@@ -153,10 +153,10 @@ static void check_long_win_path(void **state)
             "elonglonglonglong/flonglonglonglong/glonglonglonglong/hlonglonglonglong/ilonglonglonglong/"
             "jlonglonglonglong/klonglonglonglong/llonglonglonglong/mlonglonglonglong/nlonglonglonglong/"
             "olonglonglonglong/file.txt";
-    const char *longPathConv = "\\\\?\\D:\\\\alonglonglonglong\\blonglonglonglong\\clonglonglonglong\\dlonglonglonglong\\"
-            "elonglonglonglong\\flonglonglonglong\\glonglonglonglong\\hlonglonglonglong\\ilonglonglonglong\\"
-            "jlonglonglonglong\\klonglonglonglong\\llonglonglonglong\\mlonglonglonglong\\nlonglonglonglong\\"
-            "olonglonglonglong\\file.txt";
+    const char *longPathConv = R"(\\?\D:\\alonglonglonglong\blonglonglonglong\clonglonglonglong\dlonglonglonglong\)"
+            R"(elonglonglonglong\flonglonglonglong\glonglonglonglong\hlonglonglonglong\ilonglonglonglong\)"
+            R"(jlonglonglonglong\klonglonglonglong\llonglonglonglong\mlonglonglonglong\nlonglonglonglong\)"
+            R"(olonglonglonglong\file.txt)";
 
     QByteArray new_long = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(longPath, strlen(longPath)));
     // printf("XXXXXXXXXXXX %s %d\n", new_long, mem_reserved);