]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes to common source files not applicable to open-vm-tools.
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 27 Jul 2021 17:37:24 +0000 (10:37 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 27 Jul 2021 17:37:24 +0000 (10:37 -0700)
open-vm-tools/lib/include/strutil.h
open-vm-tools/lib/misc/strutil.c

index 5022a6d74a8d18e98caa043a15b2a33336a917a2..43ee5519becfc261658d3808d4b4f1a7c23fbdc0 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2018, 2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -37,6 +37,10 @@ struct DynBuf;
 
 char *StrUtil_GetNextToken(unsigned int *index, const char *str,
                            const char *delimiters);
+#if defined(_WIN32)
+wchar_t *StrUtil_GetNextTokenW(unsigned int *index, const wchar_t *str,
+                               const wchar_t *delimiters);
+#endif
 Bool StrUtil_GetNextIntToken(int32 *out, unsigned int *index, const char *str,
                              const char *delimiters);
 Bool StrUtil_GetNextUintToken(uint32 *out, unsigned int *index, const char *str,
index 5eb659a80bcaa0da04f776297fbcff7d421a843f..6152b811c465d35f8e14ac886ec36baa8e6b811a 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2019, 2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -26,7 +26,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#if !defined(_WIN32)
+#if defined(_WIN32)
+#include <wchar.h>
+#else
 #include <strings.h> /* For strncasecmp */
 #include <stdint.h>
 #endif
@@ -133,6 +135,75 @@ StrUtil_GetNextToken(unsigned int *index,    // IN/OUT: Index to start at
 }
 
 
+#if defined(_WIN32)
+/*
+ ******************************************************************************
+ * StrUtil_GetNextTokenW --
+ *
+ *      Get the next token from a UTF-16 string after a given index w/o
+ *      modifying the original string. This routine is based on the
+ *      StrUtil_GetNextToken() function but convert it from ASCII to Unicode
+ *      version.
+ *
+ * Results:
+ *      An allocated, NULL-terminated string containing the token. 'index'
+ *      is updated to point after the returned token
+ *      NULL if no tokens are left
+ *
+ * Side effects:
+ *      None
+ *
+ ******************************************************************************
+ */
+
+wchar_t *
+StrUtil_GetNextTokenW(unsigned int  *index,      // IN/OUT: Index to start at
+                      const wchar_t *str,        // IN    : String to parse
+                      const wchar_t *delimiters) // IN    : Separating tokens
+{
+   unsigned int startIndex;
+   unsigned int length;
+   wchar_t *token;
+
+   ASSERT(index != NULL);
+   ASSERT(str != NULL);
+   ASSERT(delimiters != NULL);
+   ASSERT(*index <= wcslen(str));
+
+#define NOT_DELIMITER (wcschr(delimiters, str[*index]) == NULL)
+
+   /* Skip leading delimiters. */
+   for (;; (*index)++) {
+      if (str[*index] == L'\0') {
+         return NULL;
+      }
+
+      if (NOT_DELIMITER) {
+         break;
+      }
+   }
+   startIndex = *index;
+
+   /*
+    * Walk the string until we reach the end of it, or we find a
+    * delimiter.
+    */
+   for ((*index)++; str[*index] != L'\0' && NOT_DELIMITER; (*index)++) {
+   }
+
+#undef NOT_DELIMITER
+
+   length = *index - startIndex;
+   ASSERT(length);
+   token = Util_SafeMalloc(sizeof *token * (length + 1));
+   wmemcpy(token, str + startIndex, length);
+   token[length] = L'\0';
+
+   return token;
+}
+#endif
+
+
 /*
  *-----------------------------------------------------------------------------
  *