Sync with trunk (r48414)
[reactos.git] / dll / win32 / shlwapi / string.c
index a0269b6..6102f3c 100644 (file)
@@ -584,7 +584,9 @@ LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
  */
 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
 {
-    if (!lpszStr || !lpszSearch) return NULL;
+    TRACE("(%s, %s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
+
+    if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL;
     return strstrW( lpszStr, lpszSearch );
 }
 
@@ -707,6 +709,75 @@ LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
   return NULL;
 }
 
+/*************************************************************************
+ * StrStrNW    [SHLWAPI.@]
+ *
+ * Find a substring within a string up to a given number of initial characters.
+ *
+ * PARAMS
+ *  lpFirst    [I] String to search in
+ *  lpSrch     [I] String to look for
+ *  cchMax     [I] Maximum number of initial search characters
+ *
+ * RETURNS
+ *  The start of lpFirst within lpSrch, or NULL if not found.
+ */
+LPWSTR WINAPI StrStrNW(LPCWSTR lpFirst, LPCWSTR lpSrch, UINT cchMax)
+{
+    UINT i;
+    int len;
+
+    TRACE("(%s, %s, %u)\n", debugstr_w(lpFirst), debugstr_w(lpSrch), cchMax);
+
+    if (!lpFirst || !lpSrch || !*lpSrch || !cchMax)
+        return NULL;
+
+    len = strlenW(lpSrch);
+
+    for (i = cchMax; *lpFirst && (i > 0); i--, lpFirst++)
+    {
+        if (!strncmpW(lpFirst, lpSrch, len))
+            return (LPWSTR)lpFirst;
+    }
+
+    return NULL;
+}
+
+/*************************************************************************
+ * StrStrNIW   [SHLWAPI.@]
+ *
+ * Find a substring within a string up to a given number of initial characters,
+ * ignoring case.
+ *
+ * PARAMS
+ *  lpFirst    [I] String to search in
+ *  lpSrch     [I] String to look for
+ *  cchMax     [I] Maximum number of initial search characters
+ *
+ * RETURNS
+ *  The start of lpFirst within lpSrch, or NULL if not found.
+ */
+LPWSTR WINAPI StrStrNIW(LPCWSTR lpFirst, LPCWSTR lpSrch, UINT cchMax)
+{
+    UINT i;
+    int len;
+
+    TRACE("(%s, %s, %u)\n", debugstr_w(lpFirst), debugstr_w(lpSrch), cchMax);
+
+    if (!lpFirst || !lpSrch || !*lpSrch || !cchMax)
+        return NULL;
+
+    len = strlenW(lpSrch);
+
+    for (i = cchMax; *lpFirst && (i > 0); i--, lpFirst++)
+    {
+        if (!strncmpiW(lpFirst, lpSrch, len))
+            return (LPWSTR)lpFirst;
+    }
+
+    return NULL;
+}
+
 /*************************************************************************
  * StrToIntA   [SHLWAPI.@]
  *