2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Various helper functions
5 * COPYRIGHT: Copyright 2008-2015 Colin Finck <colin@reactos.org>
10 static const char HexCharacters
[] = "0123456789ABCDEF";
13 * Escapes a string according to RFC 1738.
14 * Required for passing parameters to the web service.
17 * Constant pointer to a char array, which contains the input buffer to escape.
20 * The escaped string as std::string.
23 EscapeString(const char* Input
)
25 string ReturnedString
;
29 if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~", *Input
))
31 /* It's a character we don't need to escape, just add it to the output string */
32 ReturnedString
+= *Input
;
36 /* We need to escape this character */
37 ReturnedString
+= '%';
38 ReturnedString
+= HexCharacters
[((UCHAR
)*Input
>> 4) % 16];
39 ReturnedString
+= HexCharacters
[(UCHAR
)*Input
% 16];
44 return ReturnedString
;
48 * Escapes a string according to RFC 1738.
49 * Required for passing parameters to the web service.
52 * Pointer to a std::string, which contains the input buffer to escape.
55 * The escaped string as std::string.
58 EscapeString(const string
& Input
)
60 return EscapeString(Input
.c_str());
64 * Determines whether a string contains entirely numeric values.
67 * Constant pointer to a char array containing the input to check.
70 * true if the string is entirely numeric, false otherwise.
73 IsNumber(const char* Input
)
88 * Outputs a string through the standard output and the debug output.
89 * The input string may have LF or CRLF line endings.
92 * The std::string to output
95 StringOut(const string
& InputString
)
97 const char* pInput
= InputString
.c_str();
98 char* OutputString
= new char[InputString
.size() + 1];
99 char* pOutput
= OutputString
;
101 /* Unify the line endings (the piped output of the tests may use CRLF) */
104 /* If this is a CRLF line-ending, only copy a \n to the new string and skip the next character */
105 if (*pInput
== '\r' && *(pInput
+ 1) == '\n')
120 OutputDebugStringA(OutputString
);
122 if (Configuration
.DoPrint())
123 cout
<< OutputString
<< flush
;
125 delete[] OutputString
;
129 * Gets a value from a specified INI file and returns it converted to ASCII.
132 * Constant pointer to a WCHAR array with the INI section to look in (lpAppName parameter passed to GetPrivateProfileStringW)
135 * Constant pointer to a WCHAR array containing the key to look for in the specified section (lpKeyName parameter passed to GetPrivateProfileStringW)
138 * Constant pointer to a WCHAR array containing the path to the INI file
141 * Returns the data of the value as std::string or an empty string if no data could be retrieved.
144 GetINIValue(PCWCH AppName
, PCWCH KeyName
, PCWCH FileName
)
148 string ReturnedString
;
151 /* Load the value into a temporary Unicode buffer */
152 Length
= GetPrivateProfileStringW(AppName
, KeyName
, NULL
, Buffer
, sizeof(Buffer
) / sizeof(WCHAR
), FileName
);
156 /* Convert the string to ASCII charset */
157 AsciiBuffer
= new char[Length
+ 1];
158 WideCharToMultiByte(CP_ACP
, 0, Buffer
, Length
+ 1, AsciiBuffer
, Length
+ 1, NULL
, NULL
);
160 ReturnedString
= AsciiBuffer
;
161 delete[] AsciiBuffer
;
164 return ReturnedString
;
168 * Converts an ASCII string to a Unicode one.
171 * Constant pointer to a char array containing the ASCII string
174 * The Unicode string as std::wstring
177 AsciiToUnicode(const char* AsciiString
)
181 wstring ReturnString
;
183 Length
= MultiByteToWideChar(CP_ACP
, 0, AsciiString
, -1, NULL
, 0);
185 UnicodeString
= new WCHAR
[Length
];
186 MultiByteToWideChar(CP_ACP
, 0, AsciiString
, -1, UnicodeString
, Length
);
187 ReturnString
= UnicodeString
;
188 delete UnicodeString
;
194 * Converts an ASCII string to a Unicode one.
197 * Pointer to a std::string containing the ASCII string
200 * The Unicode string as std::wstring
203 AsciiToUnicode(const string
& AsciiString
)
205 return AsciiToUnicode(AsciiString
.c_str());
209 * Converts a Unicode string to an ASCII one.
211 * @param UnicodeString
212 * Constant pointer to a WCHAR array containing the Unicode string
215 * The ASCII string as std::string
218 UnicodeToAscii(PCWSTR UnicodeString
)
224 Length
= WideCharToMultiByte(CP_ACP
, 0, UnicodeString
, -1, NULL
, 0, NULL
, NULL
);
226 AsciiString
= new char[Length
];
227 WideCharToMultiByte(CP_ACP
, 0, UnicodeString
, -1, AsciiString
, Length
, NULL
, NULL
);
228 ReturnString
= AsciiString
;
235 * Converts a Unicode string to an ASCII one.
237 * @param UnicodeString
238 * Pointer to a std::wstring containing the Unicode string
241 * The ASCII string as std::string
244 UnicodeToAscii(const wstring
& UnicodeString
)
246 return UnicodeToAscii(UnicodeString
.c_str());