1
2
3
4
5
6
7
8
9
10
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
* Jonathan Schleifer <js@webkeks.org>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
|
1
2
3
4
5
6
7
8
9
10
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
* @"" literal.
*/
if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
([self UTF8StringLength] * 3) + 1];
for (i = 0; *string != '\0'; string++) {
/*
* '+' is also listed in RFC 1738, however, '+' is sometimes
* interpreted as space in HTTP. Therefore always escape it to
* make sure it's always interpreted correctly.
*/
if (!(*string & 0x80) && (isalnum((int)*string) ||
*string == '$' || *string == '-' || *string == '_' ||
*string == '.' || *string == '!' || *string == '*' ||
*string == '(' || *string == ')' || *string == ',' ||
strchr(ignored, *string) != NULL))
retCString[i++] = *string;
else {
uint8_t high, low;
high = *string >> 4;
low = *string & 0x0F;
retCString[i++] = '%';
retCString[i++] =
(high > 9 ? high - 10 + 'A' : high + '0');
retCString[i++] =
(low > 9 ? low - 10 + 'A' : low + '0');
}
|
>
>
|
|
<
<
|
|
|
|
|
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
* @"" literal.
*/
if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
([self UTF8StringLength] * 3) + 1];
for (i = 0; *string != '\0'; string++) {
unsigned char c = *string;
/*
* '+' is also listed in RFC 1738, however, '+' is sometimes
* interpreted as space in HTTP. Therefore always escape it to
* make sure it's always interpreted correctly.
*/
if (!(c & 0x80) && (isalnum(c) || c == '$' || c == '-' ||
c == '_' || c == '.' || c == '!' || c == '*' || c == '(' ||
c == ')' || c == ',' || strchr(ignored, c) != NULL))
retCString[i++] = c;
else {
unsigned char high, low;
high = c >> 4;
low = c & 0x0F;
retCString[i++] = '%';
retCString[i++] =
(high > 9 ? high - 10 + 'A' : high + '0');
retCString[i++] =
(low > 9 ? low - 10 + 'A' : low + '0');
}
|