OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_COMMON_CGI_H__ | |
17 #define OMAHA_COMMON_CGI_H__ | |
18 | |
19 #include <tchar.h> | |
20 | |
21 namespace omaha { | |
22 | |
23 class CGI { | |
24 public: | |
25 // Maximum factor by which EscapeString() can increase the string length | |
26 static const int kEscapeFactor = 3; | |
27 | |
28 // EscapeString() converts funky characters found in "src[0,srcn-1]" into | |
29 // escape sequences. The escaped string is placed back in "dst". At most | |
30 // "dstn" characters are written into "dst", including the | |
31 // null-termination byte. Returns true if | |
32 // successful, false if the escaped string will not fit entirely in "dstn" | |
33 // characters. Since escaping can increase the length, "dst" should not | |
34 // be the same as "src". | |
35 | |
36 // These functions always return a null-terminated string, even if they | |
37 // fail (e.g. if a bad escape sequence is found). As a consequence, you | |
38 // must pass in a dstn > 0. | |
39 // If you want to guarantee that the result will fit, you need | |
40 // dstn >= kEscapeFactor * srcn + 1 | |
41 // for EscapeString and | |
42 // dstn >= srcn + 1 | |
43 // for UnescapeString. | |
44 | |
45 static bool EscapeString(const TCHAR* src, int srcn, TCHAR* dst, int dstn); | |
46 static bool UnescapeString(const TCHAR* src, int srcn, TCHAR* dst, int dstn); | |
47 }; | |
48 | |
49 } // namespace omaha | |
50 | |
51 #endif // OMAHA_COMMON_CGI_H__ | |
OLD | NEW |