/src/php-src/ext/uri/uriparser/src/UriParseBase.c
Line | Count | Source |
1 | | /* |
2 | | * uriparser - RFC 3986 URI parsing library |
3 | | * |
4 | | * Copyright (C) 2007, Weijia Song <songweijia@gmail.com> |
5 | | * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org> |
6 | | * All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above |
13 | | * copyright notice, this list of conditions and the following |
14 | | * disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above |
17 | | * copyright notice, this list of conditions and the following |
18 | | * disclaimer in the documentation and/or other materials |
19 | | * provided with the distribution. |
20 | | * |
21 | | * 3. Neither the name of the copyright holder nor the names of |
22 | | * its contributors may be used to endorse or promote products |
23 | | * derived from this software without specific prior written |
24 | | * permission. |
25 | | * |
26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
30 | | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
31 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
32 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
33 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
35 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
37 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | */ |
39 | | |
40 | | #ifndef URI_DOXYGEN |
41 | | # include "UriParseBase.h" |
42 | | #endif |
43 | | |
44 | | void uriWriteQuadToDoubleByte(const unsigned char * hexDigits, int digitCount, |
45 | 0 | unsigned char * output) { |
46 | 0 | switch (digitCount) { |
47 | 0 | case 1: |
48 | | /* 0x___? -> \x00 \x0? */ |
49 | 0 | output[0] = 0; |
50 | 0 | output[1] = hexDigits[0]; |
51 | 0 | break; |
52 | | |
53 | 0 | case 2: |
54 | | /* 0x__?? -> \0xx \x?? */ |
55 | 0 | output[0] = 0; |
56 | 0 | output[1] = 16 * hexDigits[0] + hexDigits[1]; |
57 | 0 | break; |
58 | | |
59 | 0 | case 3: |
60 | | /* 0x_??? -> \0x? \x?? */ |
61 | 0 | output[0] = hexDigits[0]; |
62 | 0 | output[1] = 16 * hexDigits[1] + hexDigits[2]; |
63 | 0 | break; |
64 | | |
65 | 0 | case 4: |
66 | | /* 0x???? -> \0?? \x?? */ |
67 | 0 | output[0] = 16 * hexDigits[0] + hexDigits[1]; |
68 | 0 | output[1] = 16 * hexDigits[2] + hexDigits[3]; |
69 | 0 | break; |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | 0 | unsigned char uriGetOctetValue(const unsigned char * digits, int digitCount) { |
74 | 0 | switch (digitCount) { |
75 | 0 | case 1: |
76 | 0 | return digits[0]; |
77 | | |
78 | 0 | case 2: |
79 | 0 | return 10 * digits[0] + digits[1]; |
80 | | |
81 | 0 | case 3: |
82 | 0 | default: |
83 | 0 | return 100 * digits[0] + 10 * digits[1] + digits[2]; |
84 | 0 | } |
85 | 0 | } |