Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/WebKit/Source/wtf/HexNumber.h

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #ifndef HexNumber_h 20 #ifndef HexNumber_h
21 #define HexNumber_h 21 #define HexNumber_h
22 22
23 #include "wtf/text/StringConcatenate.h" 23 #include "wtf/text/StringConcatenate.h"
24 24
25 namespace WTF { 25 namespace WTF {
26 26
27 enum HexConversionMode { 27 enum HexConversionMode {
28 Lowercase, 28 Lowercase,
29 Uppercase 29 Uppercase
30 }; 30 };
31 31
32 namespace Internal { 32 namespace Internal {
33 33
34 const LChar lowerHexDigits[17] = "0123456789abcdef"; 34 const LChar lowerHexDigits[17] = "0123456789abcdef";
35 const LChar upperHexDigits[17] = "0123456789ABCDEF"; 35 const LChar upperHexDigits[17] = "0123456789ABCDEF";
36 inline const LChar* hexDigitsForMode(HexConversionMode mode) 36 inline const LChar* hexDigitsForMode(HexConversionMode mode) {
37 { 37 return mode == Lowercase ? lowerHexDigits : upperHexDigits;
38 return mode == Lowercase ? lowerHexDigits : upperHexDigits;
39 } 38 }
40 39
41 } // namespace Internal 40 } // namespace Internal
42 41
43 template<typename T> 42 template <typename T>
44 inline void appendByteAsHex(unsigned char byte, T& destination, HexConversionMod e mode = Uppercase) 43 inline void appendByteAsHex(unsigned char byte, T& destination, HexConversionMod e mode = Uppercase) {
45 { 44 const LChar* hexDigits = Internal::hexDigitsForMode(mode);
46 const LChar* hexDigits = Internal::hexDigitsForMode(mode); 45 destination.append(hexDigits[byte >> 4]);
47 destination.append(hexDigits[byte >> 4]); 46 destination.append(hexDigits[byte & 0xF]);
48 destination.append(hexDigits[byte & 0xF]);
49 } 47 }
50 48
51 template<typename T> 49 template <typename T>
52 inline void placeByteAsHexCompressIfPossible(unsigned char byte, T& destination, unsigned& index, HexConversionMode mode = Uppercase) 50 inline void placeByteAsHexCompressIfPossible(unsigned char byte, T& destination, unsigned& index, HexConversionMode mode = Uppercase) {
53 { 51 const LChar* hexDigits = Internal::hexDigitsForMode(mode);
54 const LChar* hexDigits = Internal::hexDigitsForMode(mode); 52 if (byte >= 0x10)
55 if (byte >= 0x10) 53 destination[index++] = hexDigits[byte >> 4];
56 destination[index++] = hexDigits[byte >> 4]; 54 destination[index++] = hexDigits[byte & 0xF];
57 destination[index++] = hexDigits[byte & 0xF];
58 } 55 }
59 56
60 template<typename T> 57 template <typename T>
61 inline void placeByteAsHex(unsigned char byte, T& destination, HexConversionMode mode = Uppercase) 58 inline void placeByteAsHex(unsigned char byte, T& destination, HexConversionMode mode = Uppercase) {
62 { 59 const LChar* hexDigits = Internal::hexDigitsForMode(mode);
63 const LChar* hexDigits = Internal::hexDigitsForMode(mode); 60 *destination++ = hexDigits[byte >> 4];
64 *destination++ = hexDigits[byte >> 4]; 61 *destination++ = hexDigits[byte & 0xF];
65 *destination++ = hexDigits[byte & 0xF];
66 } 62 }
67 63
68 template<typename T> 64 template <typename T>
69 inline void appendUnsignedAsHex(unsigned number, T& destination, HexConversionMo de mode = Uppercase) 65 inline void appendUnsignedAsHex(unsigned number, T& destination, HexConversionMo de mode = Uppercase) {
70 { 66 const LChar* hexDigits = Internal::hexDigitsForMode(mode);
71 const LChar* hexDigits = Internal::hexDigitsForMode(mode); 67 Vector<LChar, 8> result;
72 Vector<LChar, 8> result; 68 do {
73 do { 69 result.prepend(hexDigits[number % 16]);
74 result.prepend(hexDigits[number % 16]); 70 number >>= 4;
75 number >>= 4; 71 } while (number > 0);
76 } while (number > 0);
77 72
78 destination.append(result.data(), result.size()); 73 destination.append(result.data(), result.size());
79 } 74 }
80 75
81 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the conver sion. 76 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the conver sion.
82 template<typename T> 77 template <typename T>
83 inline void appendUnsignedAsHexFixedSize(unsigned number, T& destination, unsign ed desiredDigits, HexConversionMode mode = Uppercase) 78 inline void appendUnsignedAsHexFixedSize(unsigned number, T& destination, unsign ed desiredDigits, HexConversionMode mode = Uppercase) {
84 { 79 ASSERT(desiredDigits);
85 ASSERT(desiredDigits);
86 80
87 const LChar* hexDigits = Internal::hexDigitsForMode(mode); 81 const LChar* hexDigits = Internal::hexDigitsForMode(mode);
88 Vector<LChar, 8> result; 82 Vector<LChar, 8> result;
89 do { 83 do {
90 result.prepend(hexDigits[number % 16]); 84 result.prepend(hexDigits[number % 16]);
91 number >>= 4; 85 number >>= 4;
92 } while (result.size() < desiredDigits); 86 } while (result.size() < desiredDigits);
93 87
94 ASSERT(result.size() == desiredDigits); 88 ASSERT(result.size() == desiredDigits);
95 destination.append(result.data(), result.size()); 89 destination.append(result.data(), result.size());
96 } 90 }
97 91
98 } // namespace WTF 92 } // namespace WTF
99 93
100 using WTF::appendByteAsHex; 94 using WTF::appendByteAsHex;
101 using WTF::appendUnsignedAsHex; 95 using WTF::appendUnsignedAsHex;
102 using WTF::appendUnsignedAsHexFixedSize; 96 using WTF::appendUnsignedAsHexFixedSize;
103 using WTF::placeByteAsHex; 97 using WTF::placeByteAsHex;
104 using WTF::placeByteAsHexCompressIfPossible; 98 using WTF::placeByteAsHexCompressIfPossible;
105 using WTF::Lowercase; 99 using WTF::Lowercase;
106 100
107 #endif // HexNumber_h 101 #endif // HexNumber_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTraits.h ('k') | third_party/WebKit/Source/wtf/InstanceCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698