| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 destination.push_back(hexDigits[byte & 0xF]); | 62 destination.push_back(hexDigits[byte & 0xF]); |
| 63 } | 63 } |
| 64 | 64 |
| 65 template <typename T> | 65 template <typename T> |
| 66 static inline void appendUnsignedAsHex(unsigned number, | 66 static inline void appendUnsignedAsHex(unsigned number, |
| 67 T& destination, | 67 T& destination, |
| 68 HexConversionMode mode = Uppercase) { | 68 HexConversionMode mode = Uppercase) { |
| 69 const LChar* hexDigits = hexDigitsForMode(mode); | 69 const LChar* hexDigits = hexDigitsForMode(mode); |
| 70 Vector<LChar, 8> result; | 70 Vector<LChar, 8> result; |
| 71 do { | 71 do { |
| 72 result.prepend(hexDigits[number % 16]); | 72 result.push_front(hexDigits[number % 16]); |
| 73 number >>= 4; | 73 number >>= 4; |
| 74 } while (number > 0); | 74 } while (number > 0); |
| 75 | 75 |
| 76 destination.append(result.data(), result.size()); | 76 destination.append(result.data(), result.size()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the | 79 // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the |
| 80 // conversion. | 80 // conversion. |
| 81 template <typename T> | 81 template <typename T> |
| 82 static inline void appendUnsignedAsHexFixedSize( | 82 static inline void appendUnsignedAsHexFixedSize( |
| 83 unsigned number, | 83 unsigned number, |
| 84 T& destination, | 84 T& destination, |
| 85 unsigned desiredDigits, | 85 unsigned desiredDigits, |
| 86 HexConversionMode mode = Uppercase) { | 86 HexConversionMode mode = Uppercase) { |
| 87 DCHECK(desiredDigits); | 87 DCHECK(desiredDigits); |
| 88 | 88 |
| 89 const LChar* hexDigits = hexDigitsForMode(mode); | 89 const LChar* hexDigits = hexDigitsForMode(mode); |
| 90 Vector<LChar, 8> result; | 90 Vector<LChar, 8> result; |
| 91 do { | 91 do { |
| 92 result.prepend(hexDigits[number % 16]); | 92 result.push_front(hexDigits[number % 16]); |
| 93 number >>= 4; | 93 number >>= 4; |
| 94 } while (result.size() < desiredDigits); | 94 } while (result.size() < desiredDigits); |
| 95 | 95 |
| 96 DCHECK_EQ(result.size(), desiredDigits); | 96 DCHECK_EQ(result.size(), desiredDigits); |
| 97 destination.append(result.data(), result.size()); | 97 destination.append(result.data(), result.size()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 static inline const LChar* hexDigitsForMode(HexConversionMode mode) { | 101 static inline const LChar* hexDigitsForMode(HexConversionMode mode) { |
| 102 return mode == Lowercase ? Internal::lowerHexDigits | 102 return mode == Lowercase ? Internal::lowerHexDigits |
| 103 : Internal::upperHexDigits; | 103 : Internal::upperHexDigits; |
| 104 } | 104 } |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 } // namespace WTF | 107 } // namespace WTF |
| 108 | 108 |
| 109 using WTF::HexNumber; | 109 using WTF::HexNumber; |
| 110 | 110 |
| 111 #endif // HexNumber_h | 111 #endif // HexNumber_h |
| OLD | NEW |