ReactOS 0.4.15-dev-8102-g108db8f
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{
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}
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
WCHAR strW[12]
Definition: clipboard.c:2029
char strA[12]
Definition: clipboard.c:2028
#define MB_PRECOMPOSED
Definition: winnls.h:281
__wchar_t WCHAR
Definition: xmlstorage.h:180
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}
#define MAX_PATH
Definition: compat.h:34
#define _T(x)
Definition: vfdio.h:22
#define _tcslen
Definition: xmlstorage.h:198

◆ 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
const WCHAR * str
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175

◆ 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}
#define CHAR(Char)
#define min(a, b)
Definition: monoChain.cc:55
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230

◆ 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}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149

◆ 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}
#define L(x)
Definition: ntvdm.h:50
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236

◆ FindSubStrI()

LPTSTR FindSubStrI ( LPCTSTR  str,
LPCTSTR  strSearch 
)

Definition at line 183 of file stringutils.c.

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}
#define _totupper
Definition: tchar.h:1509
POINT cp
Definition: magnifier.c:59
struct S1 s1
struct S2 s2
CHAR * LPTSTR
Definition: xmlstorage.h:192

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

◆ FormatString()

LPTSTR FormatString ( LPCTSTR  str,
  ... 
)

Definition at line 33 of file stringutils.c.

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

◆ FormatStringV()

LPTSTR FormatStringV ( LPCTSTR  str,
va_list  args 
)

Definition at line 16 of file stringutils.c.

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}
#define _vsctprintf
Definition: tchar.h:544
#define StringCchVPrintf
Definition: strsafe.h:482
char TCHAR
Definition: xmlstorage.h:189

Referenced by FormatString().

◆ 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}
#define WideCharToMultiByte
Definition: compat.h:111
#define WC_COMPOSITECHECK
Definition: unicode.h:43