/src/uWebSockets/src/Utilities.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Authored by Alex Hultman, 2018-2020. |
3 | | * Intellectual property of third-party. |
4 | | |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at |
8 | | |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #ifndef UWS_UTILITIES_H |
19 | | #define UWS_UTILITIES_H |
20 | | |
21 | | /* Various common utilities */ |
22 | | |
23 | | #include <cstdint> |
24 | | |
25 | | namespace uWS { |
26 | | namespace utils { |
27 | | |
28 | 0 | inline int u32toaHex(uint32_t value, char *dst) { |
29 | 0 | char palette[] = "0123456789abcdef"; |
30 | 0 | char temp[10]; |
31 | 0 | char *p = temp; |
32 | 0 | do { |
33 | 0 | *p++ = palette[value & 15]; |
34 | 0 | value >>= 4; |
35 | 0 | } while (value > 0); |
36 | |
|
37 | 0 | int ret = (int) (p - temp); |
38 | |
|
39 | 0 | do { |
40 | 0 | *dst++ = *--p; |
41 | 0 | } while (p != temp); |
42 | |
|
43 | 0 | return ret; |
44 | 0 | } |
45 | | |
46 | 0 | inline int u64toa(uint64_t value, char *dst) { |
47 | 0 | char temp[20]; |
48 | 0 | char *p = temp; |
49 | 0 | do { |
50 | 0 | *p++ = (char) ((value % 10) + '0'); |
51 | 0 | value /= 10; |
52 | 0 | } while (value > 0); |
53 | |
|
54 | 0 | int ret = (int) (p - temp); |
55 | |
|
56 | 0 | do { |
57 | 0 | *dst++ = *--p; |
58 | 0 | } while (p != temp); |
59 | |
|
60 | 0 | return ret; |
61 | 0 | } |
62 | | |
63 | | } |
64 | | } |
65 | | |
66 | | #endif // UWS_UTILITIES_H |