OLD | NEW |
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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 const LChar* hexDigits = Internal::hexDigitsForMode(mode); | 52 const LChar* hexDigits = Internal::hexDigitsForMode(mode); |
53 Vector<LChar, 8> result; | 53 Vector<LChar, 8> result; |
54 do { | 54 do { |
55 result.prepend(hexDigits[number % 16]); | 55 result.prepend(hexDigits[number % 16]); |
56 number >>= 4; | 56 number >>= 4; |
57 } while (number > 0); | 57 } while (number > 0); |
58 | 58 |
59 destination.append(result.data(), result.size()); | 59 destination.append(result.data(), result.size()); |
60 } | 60 } |
61 | 61 |
62 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the conver
sion. | 62 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the |
| 63 // conversion. |
63 template <typename T> | 64 template <typename T> |
64 inline void appendUnsignedAsHexFixedSize(unsigned number, | 65 inline void appendUnsignedAsHexFixedSize(unsigned number, |
65 T& destination, | 66 T& destination, |
66 unsigned desiredDigits, | 67 unsigned desiredDigits, |
67 HexConversionMode mode = Uppercase) { | 68 HexConversionMode mode = Uppercase) { |
68 ASSERT(desiredDigits); | 69 ASSERT(desiredDigits); |
69 | 70 |
70 const LChar* hexDigits = Internal::hexDigitsForMode(mode); | 71 const LChar* hexDigits = Internal::hexDigitsForMode(mode); |
71 Vector<LChar, 8> result; | 72 Vector<LChar, 8> result; |
72 do { | 73 do { |
73 result.prepend(hexDigits[number % 16]); | 74 result.prepend(hexDigits[number % 16]); |
74 number >>= 4; | 75 number >>= 4; |
75 } while (result.size() < desiredDigits); | 76 } while (result.size() < desiredDigits); |
76 | 77 |
77 ASSERT(result.size() == desiredDigits); | 78 ASSERT(result.size() == desiredDigits); |
78 destination.append(result.data(), result.size()); | 79 destination.append(result.data(), result.size()); |
79 } | 80 } |
80 | 81 |
81 } // namespace WTF | 82 } // namespace WTF |
82 | 83 |
83 using WTF::appendByteAsHex; | 84 using WTF::appendByteAsHex; |
84 using WTF::appendUnsignedAsHex; | 85 using WTF::appendUnsignedAsHex; |
85 using WTF::appendUnsignedAsHexFixedSize; | 86 using WTF::appendUnsignedAsHexFixedSize; |
86 using WTF::Lowercase; | 87 using WTF::Lowercase; |
87 | 88 |
88 #endif // HexNumber_h | 89 #endif // HexNumber_h |
OLD | NEW |