ReactOS  0.4.12-dev-18-gf469aca
stringutils.c File Reference
#include "precomp.h"
#include "utils.h"
#include "stringutils.h"
Include dependency graph for stringutils.c:

Go to the source code of this file.

Functions

LPTSTR FormatStringV (LPCTSTR str, va_list args)
 
LPTSTR FormatString (LPCTSTR str,...)
 
LPSTR UnicodeToAnsi (LPCWSTR strW)
 
LPWSTR AnsiToUnicode (LPCSTR strA)
 
LPSTR DuplicateStringA (LPCSTR str)
 
LPWSTR DuplicateStringW (LPCWSTR str)
 
LPSTR DuplicateStringAEx (LPCSTR str, size_t numOfChars)
 
LPWSTR DuplicateStringWEx (LPCWSTR str, size_t numOfChars)
 
LPTSTR FindSubStrI (LPCTSTR str, LPCTSTR strSearch)
 
LPTSTR AppendPathSeparator (LPTSTR lpszPath)
 

Function Documentation

◆ AnsiToUnicode()

LPWSTR AnsiToUnicode ( LPCSTR  strA)

Definition at line 69 of file stringutils.c.

70 {
71  LPWSTR strW;
72  int iNeededChars;
73 
74  if (!strA) return NULL;
75 
76  iNeededChars = MultiByteToWideChar(CP_ACP,
78  strA, -1, NULL, 0);
79 
80  strW = (LPWSTR)MemAlloc(0, iNeededChars * sizeof(WCHAR));
81  if (!strW) return NULL;
82 
85  strA, -1, strW, iNeededChars);
86 
87  return strW;
88 }
char strA[12]
Definition: clipboard.c:2028
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define MB_PRECOMPOSED
Definition: winnls.h:269
WCHAR strW[12]
Definition: clipboard.c:2029
smooth NULL
Definition: ftsmooth.c:416
#define MultiByteToWideChar
Definition: compat.h:100
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ AppendPathSeparator()

LPTSTR AppendPathSeparator ( LPTSTR  lpszPath)

Definition at line 220 of file stringutils.c.

221 {
222  size_t iLen = 0;
223 
224  if (!lpszPath || (iLen = _tcslen(lpszPath)) >= MAX_PATH)
225  return NULL;
226 
227  if (iLen >= 1)
228  {
229  lpszPath += iLen - 1;
230  if (*lpszPath++ != _T('\\'))
231  {
232  *lpszPath++ = _T('\\');
233  *lpszPath = _T('\0');
234  }
235  }
236 
237  return lpszPath;
238 }
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:26

◆ DuplicateStringA()

LPSTR DuplicateStringA ( LPCSTR  str)

Definition at line 90 of file stringutils.c.

91 {
92  LPSTR dupStr;
93  size_t strSizePlusNull;
94 
95  if (!str) return NULL;
96 
97  strSizePlusNull = strlen(str) + 1;
98 
99  dupStr = (LPSTR)MemAlloc(0, strSizePlusNull * sizeof(CHAR));
100  if (!dupStr) return NULL;
101 
102  StringCchCopyA(dupStr, strSizePlusNull, str);
103 
104  return dupStr;
105 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
char CHAR
Definition: xmlstorage.h:175
char * LPSTR
Definition: xmlstorage.h:182
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145

◆ DuplicateStringAEx()

LPSTR DuplicateStringAEx ( LPCSTR  str,
size_t  numOfChars 
)

Definition at line 124 of file stringutils.c.

125 {
126  LPSTR dupStr;
127  size_t strSize;
128 
129  if (!str) return NULL;
130 
131  strSize = min(strlen(str), numOfChars);
132 
133  dupStr = (LPSTR)MemAlloc(0, (strSize + 1) * sizeof(CHAR));
134  if (!dupStr) return NULL;
135 
136  StringCchCopyNA(dupStr, strSize + 1, str, strSize);
137  dupStr[strSize] = '\0';
138 
139  return dupStr;
140 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
char * LPSTR
Definition: xmlstorage.h:182
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define min(a, b)
Definition: monoChain.cc:55
#define CHAR(Char)

◆ DuplicateStringW()

LPWSTR DuplicateStringW ( LPCWSTR  str)

Definition at line 107 of file stringutils.c.

108 {
109  LPWSTR dupStr;
110  size_t strSizePlusNull;
111 
112  if (!str) return NULL;
113 
114  strSizePlusNull = wcslen(str) + 1;
115 
116  dupStr = (LPWSTR)MemAlloc(0, strSizePlusNull * sizeof(WCHAR));
117  if (!dupStr) return NULL;
118 
119  StringCchCopyW(dupStr, strSizePlusNull, str);
120 
121  return dupStr;
122 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ DuplicateStringWEx()

LPWSTR DuplicateStringWEx ( LPCWSTR  str,
size_t  numOfChars 
)

Definition at line 142 of file stringutils.c.

143 {
144  LPWSTR dupStr;
145  size_t strSize;
146 
147  if (!str) return NULL;
148 
149  strSize = min(wcslen(str), numOfChars);
150 
151  dupStr = (LPWSTR)MemAlloc(0, (strSize + 1) * sizeof(WCHAR));
152  if (!dupStr) return NULL;
153 
154  StringCchCopyNW(dupStr, strSize + 1, str, strSize);
155  dupStr[strSize] = L'\0';
156 
157  return dupStr;
158 }
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define WCHAR
Definition: msvc.h:43
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1087
#define min(a, b)
Definition: monoChain.cc:55
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ FindSubStrI()

LPTSTR FindSubStrI ( LPCTSTR  str,
LPCTSTR  strSearch 
)

Definition at line 183 of file stringutils.c.

Referenced by AddNTOSInstallationItem(), AddService(), and IsWindowsOS().

184 {
185  LPTSTR cp = (LPTSTR)str;
186  LPTSTR s1, s2;
187 
188  if (!*strSearch)
189  return (LPTSTR)str;
190 
191  while (*cp)
192  {
193  s1 = cp;
194  s2 = (LPTSTR)strSearch;
195 
196  while (*s1 && *s2 && (_totupper(*s1) == _totupper(*s2)))
197  ++s1, ++s2;
198 
199  if (!*s2)
200  return cp;
201 
202  ++cp;
203  }
204 
205  return NULL;
206 }
struct S2 s2
#define _totupper
Definition: tchar.h:1509
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
struct S1 s1
POINT cp
Definition: magnifier.c:60

◆ FormatString()

LPTSTR FormatString ( LPCTSTR  str,
  ... 
)

Definition at line 33 of file stringutils.c.

34 {
35  LPTSTR lpszString;
36  va_list args;
37 
38  va_start(args, str);
39  lpszString = FormatStringV(str, args);
40  va_end(args);
41 
42  return lpszString;
43 }
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define va_end(ap)
Definition: acmsvcex.h:90
const WCHAR * str
char * va_list
Definition: acmsvcex.h:78
LPTSTR FormatStringV(LPCTSTR str, va_list args)
Definition: stringutils.c:16
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66

◆ FormatStringV()

LPTSTR FormatStringV ( LPCTSTR  str,
va_list  args 
)

Definition at line 16 of file stringutils.c.

Referenced by FormatString().

17 {
18  LPTSTR lpszString;
19  size_t strLenPlusNull;
20 
21  if (!str) return NULL;
22 
23  strLenPlusNull = _vsctprintf(str, args) + 1;
24 
25  lpszString = (LPTSTR)MemAlloc(0, strLenPlusNull * sizeof(TCHAR));
26  if (!lpszString) return NULL;
27 
28  StringCchVPrintf(lpszString, strLenPlusNull, str, args);
29 
30  return lpszString;
31 }
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
Definition: match.c:390
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _vsctprintf
Definition: tchar.h:544
#define StringCchVPrintf
Definition: strsafe.h:482

◆ UnicodeToAnsi()

LPSTR UnicodeToAnsi ( LPCWSTR  strW)

Definition at line 48 of file stringutils.c.

49 {
50  LPSTR strA;
51  int iNeededChars;
52 
53  if (!strW) return NULL;
54 
55  iNeededChars = WideCharToMultiByte(CP_ACP,
56  WC_COMPOSITECHECK /* | WC_NO_BEST_FIT_CHARS */,
57  strW, -1, NULL, 0, NULL, NULL);
58 
59  strA = (LPSTR)MemAlloc(0, iNeededChars * sizeof(CHAR));
60  if (!strA) return NULL;
61 
63  WC_COMPOSITECHECK /* | WC_NO_BEST_FIT_CHARS */,
64  strW, -1, strA, iNeededChars, NULL, NULL);
65 
66  return strA;
67 }
char strA[12]
Definition: clipboard.c:2028
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
char CHAR
Definition: xmlstorage.h:175
char * LPSTR
Definition: xmlstorage.h:182
WCHAR strW[12]
Definition: clipboard.c:2029
smooth NULL
Definition: ftsmooth.c:416
#define WC_COMPOSITECHECK
Definition: unicode.h:43