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-2009 Colin Finck <colin@reactos.org>
11 * Escapes a string according to RFC 1738.
12 * Required for passing parameters to the web service.
15 * Pointer to a CHAR array, which will receive the escaped string.
16 * The output buffer must be large enough to hold the full escaped string. You're on the safe side
17 * if you make the output buffer three times as large as the input buffer.
20 * Pointer to a CHAR array, which contains the input buffer to escape.
23 EscapeString(PCHAR Output
, PCHAR Input
)
25 const CHAR HexCharacters
[] = "0123456789ABCDEF";
29 if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~", *Input
) )
31 /* It's a character we don't need to escape, just add it to the output string */
36 /* We need to escape this character */
38 *Output
++ = HexCharacters
[((UCHAR
)*Input
>> 4) % 16];
39 *Output
++ = HexCharacters
[(UCHAR
)*Input
% 16];
48 * Outputs a string through the standard output and the debug output.
49 * The string may have LF or CRLF line endings.
52 * The string to output
55 StringOut(PCHAR String
)
61 /* The piped output of the tests may use CRLF line endings, so convert them to LF.
62 As both printf and OutputDebugStringA operate in text mode, the line-endings will be properly converted again later. */
63 Length
= strlen(String
);
64 NewString
= HeapAlloc(hProcessHeap
, 0, Length
+ 1);
65 pNewString
= NewString
;
69 /* If this is a CRLF line-ending, only copy a \n to the new string and skip the next character */
70 if(*String
== '\r' && *(String
+ 1) == '\n')
77 /* Otherwise copy the string */
78 *pNewString
= *String
;
85 /* Null-terminate it */
90 OutputDebugStringA(NewString
);
93 HeapFree(hProcessHeap
, 0, NewString
);