[PATCH 2/4] regedit: Simplify parseKeyName()

Hugh McMaster hugh.mcmaster at outlook.com
Mon Apr 24 08:48:49 CDT 2017


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/regedit/regproc.c | 40 +++++++++-------------------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 96c4564..37431ff 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -303,48 +303,26 @@ static int REGPROC_unescape_string(WCHAR* str)
 
 static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
 {
-    WCHAR* lpSlash = NULL;
-    unsigned int i, len;
+    unsigned int i, num_class_keys;
 
     if (lpKeyName == NULL)
         return FALSE;
 
-    for(i = 0; *(lpKeyName+i) != 0; i++)
-    {
-        if(*(lpKeyName+i) == '\\')
-        {
-            lpSlash = lpKeyName+i;
-            break;
-        }
-    }
+    *lpKeyPath = strchrW(lpKeyName, '\\');
+    if (*lpKeyPath) (*lpKeyPath)++;
 
-    if (lpSlash)
-    {
-        len = lpSlash-lpKeyName;
-    }
-    else
-    {
-        len = lstrlenW(lpKeyName);
-        lpSlash = lpKeyName+len;
-    }
     *hKey = NULL;
-
-    for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++) {
-        if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], -1) == CSTR_EQUAL &&
-            len == lstrlenW(reg_class_namesW[i])) {
+    num_class_keys = ARRAY_SIZE(reg_class_keys);
+    for (i = 0; i < num_class_keys; i++)
+    {
+        if (!strncmpW(lpKeyName, reg_class_namesW[i], lstrlenW(reg_class_namesW[i])))
+        {
             *hKey = reg_class_keys[i];
             break;
         }
     }
 
-    if (*hKey == NULL)
-        return FALSE;
-
-
-    if (*lpSlash != '\0')
-        lpSlash++;
-    *lpKeyPath = lpSlash;
-    return TRUE;
+    return (*hKey != NULL);
 }
 
 /* Globals used by the setValue() & co */
-- 
2.7.4




More information about the wine-patches mailing list