summaryrefslogtreecommitdiff
path: root/third_party/bigint/BigUnsignedInABase.cc
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-12-02 16:34:20 -0800
committerBo Xu <bo_xu@foxitsoftware.com>2014-12-02 16:34:20 -0800
commit91dd8c77ae849c22a8e4c9275e3f728b474b5be5 (patch)
tree79c1805c6a18ab234053f79fc4e10edabad5eef1 /third_party/bigint/BigUnsignedInABase.cc
parent44047c3300d07192a67b1714084cc2d43b1e9bd9 (diff)
downloadpdfium-91dd8c77ae849c22a8e4c9275e3f728b474b5be5.tar.xz
Modify big integer library
This patch follows https://pdfium.googlesource.com/pdfium/+/44047c3300d07192a67b1714084cc2d43b1e9bd9 Modify the library to resolve compile error, add copyright notice and change pdfium.gyp and BUILD.gn R=tsepez@chromium.org Review URL: https://codereview.chromium.org/754743003
Diffstat (limited to 'third_party/bigint/BigUnsignedInABase.cc')
-rw-r--r--third_party/bigint/BigUnsignedInABase.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/third_party/bigint/BigUnsignedInABase.cc b/third_party/bigint/BigUnsignedInABase.cc
index 999faaf2db..a24042d538 100644
--- a/third_party/bigint/BigUnsignedInABase.cc
+++ b/third_party/bigint/BigUnsignedInABase.cc
@@ -1,15 +1,29 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code by Matt McCutchen, see the LICENSE file.
+
#include "BigUnsignedInABase.hh"
BigUnsignedInABase::BigUnsignedInABase(const Digit *d, Index l, Base base)
: NumberlikeArray<Digit>(d, l), base(base) {
// Check the base
if (base < 2)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): The base must be at least 2";
+#endif
// Validate the digits.
for (Index i = 0; i < l; i++)
if (blk[i] >= base)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): A digit is too large for the specified base";
+#endif
// Eliminate any leading zeros we may have been passed.
zapLeadingZeros();
@@ -32,7 +46,11 @@ namespace {
BigUnsignedInABase::BigUnsignedInABase(const BigUnsigned &x, Base base) {
// Check the base
if (base < 2)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase(BigUnsigned, Base): The base must be at least 2";
+#endif
this->base = base;
// Get an upper bound on how much space we need
@@ -73,7 +91,11 @@ BigUnsignedInABase::operator BigUnsigned() const {
BigUnsignedInABase::BigUnsignedInABase(const std::string &s, Base base) {
// Check the base.
if (base > 36)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase(std::string, Base): The default string conversion routines use the symbol set 0-9, A-Z and therefore support only up to base 36. You tried a conversion with a base over 36; write your own string conversion routine.";
+#endif
// Save the base.
// This pattern is seldom seen in C++, but the analogous ``this.'' is common in Java.
this->base = base;
@@ -94,17 +116,29 @@ BigUnsignedInABase::BigUnsignedInABase(const std::string &s, Base base) {
else if (theSymbol >= 'a' && theSymbol <= 'z')
blk[digitNum] = theSymbol - 'a' + 10;
else
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase(std::string, Base): Bad symbol in input. Only 0-9, A-Z, a-z are accepted.";
+#endif
if (blk[digitNum] >= base)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): A digit is too large for the specified base";
+#endif
}
zapLeadingZeros();
}
BigUnsignedInABase::operator std::string() const {
if (base > 36)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsignedInABase ==> std::string: The default string conversion routines use the symbol set 0-9, A-Z and therefore support only up to base 36. You tried a conversion with a base over 36; write your own string conversion routine.";
+#endif
if (len == 0)
return std::string("0");
// Some compilers don't have push_back, so use a char * buffer instead.