| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code by Matt McCutchen, see the LICENSE file |
| 6 |
| 1 #include "BigIntegerUtils.hh" | 7 #include "BigIntegerUtils.hh" |
| 2 #include "BigUnsignedInABase.hh" | 8 #include "BigUnsignedInABase.hh" |
| 3 | 9 |
| 4 std::string bigUnsignedToString(const BigUnsigned &x) { | 10 std::string bigUnsignedToString(const BigUnsigned &x) { |
| 5 return std::string(BigUnsignedInABase(x, 10)); | 11 return std::string(BigUnsignedInABase(x, 10)); |
| 6 } | 12 } |
| 7 | 13 |
| 8 std::string bigIntegerToString(const BigInteger &x) { | 14 std::string bigIntegerToString(const BigInteger &x) { |
| 9 return (x.getSign() == BigInteger::negative) | 15 return (x.getSign() == BigInteger::negative) |
| 10 ? (std::string("-") + bigUnsignedToString(x.getMagnitude())) | 16 ? (std::string("-") + bigUnsignedToString(x.getMagnitude())) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 base = 10; | 35 base = 10; |
| 30 else if (osFlags & os.hex) { | 36 else if (osFlags & os.hex) { |
| 31 base = 16; | 37 base = 16; |
| 32 if (osFlags & os.showbase) | 38 if (osFlags & os.showbase) |
| 33 os << "0x"; | 39 os << "0x"; |
| 34 } else if (osFlags & os.oct) { | 40 } else if (osFlags & os.oct) { |
| 35 base = 8; | 41 base = 8; |
| 36 if (osFlags & os.showbase) | 42 if (osFlags & os.showbase) |
| 37 os << '0'; | 43 os << '0'; |
| 38 } else | 44 } else |
| 45 #ifdef FOXIT_CHROME_BUILD |
| 46 abort(); |
| 47 #else |
| 39 throw "std::ostream << BigUnsigned: Could not determine the desi
red base from output-stream flags"; | 48 throw "std::ostream << BigUnsigned: Could not determine the desi
red base from output-stream flags"; |
| 49 #endif |
| 40 std::string s = std::string(BigUnsignedInABase(x, base)); | 50 std::string s = std::string(BigUnsignedInABase(x, base)); |
| 41 os << s; | 51 os << s; |
| 42 return os; | 52 return os; |
| 43 } | 53 } |
| 44 | 54 |
| 45 std::ostream &operator <<(std::ostream &os, const BigInteger &x) { | 55 std::ostream &operator <<(std::ostream &os, const BigInteger &x) { |
| 46 if (x.getSign() == BigInteger::negative) | 56 if (x.getSign() == BigInteger::negative) |
| 47 os << '-'; | 57 os << '-'; |
| 48 os << x.getMagnitude(); | 58 os << x.getMagnitude(); |
| 49 return os; | 59 return os; |
| 50 } | 60 } |
| OLD | NEW |