Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,24 @@
public final class BigDecimalParser {

private final char[] chars;
private final int off;
private final int len;

BigDecimalParser(char[] chars, int off, int len) {
BigDecimalParser(char[] chars) {
this.chars = chars;
this.off = off;
this.len = len;
len = chars.length;
}

BigDecimal parse() throws NumberFormatException {
try {
if (len < 500) {
return new BigDecimal(chars, off, len);
if (chars.length < 500) {
return new BigDecimal(chars);
}

int splitLen = len / 10;
int splitLen = chars.length / 10;
return parseBigDecimal(splitLen);

} catch (NumberFormatException e) {
String val = new String(chars, off, len);

throw new NumberFormatException("Value \"" + val + "\" can not be represented as BigDecimal."
throw new NumberFormatException("Value \"" + new String(chars) + "\" can not be represented as BigDecimal."
+ " Reason: " + e.getMessage());
}
}
Expand All @@ -43,7 +39,7 @@ private BigDecimal parseBigDecimal(int splitLen) {
int dotIdx = -1;
int scale = 0;

for (int i = off; i < len; i++) {
for (int i = 0; i < len; i++) {
char c = chars[i];
switch (c) {
case '+':
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,15 @@ public static BigDecimal parseBigDecimal(String s) throws NumberFormatException
return parseBigDecimal(ch);
}

public static BigDecimal parseBigDecimal(char[] ch) throws NumberFormatException {
return parseBigDecimal(ch, 0, ch.length);
public static BigDecimal parseBigDecimal(char[] ch, int off, int len) throws NumberFormatException {
char[] copy = new char[len];
System.arraycopy(ch, off, copy, 0, len);

return parseBigDecimal(copy);
}

public static BigDecimal parseBigDecimal(char[] ch, int off, int len) throws NumberFormatException {
BigDecimalParser parser = new BigDecimalParser(ch, off, len);
public static BigDecimal parseBigDecimal(char[] ch) throws NumberFormatException {
BigDecimalParser parser = new BigDecimalParser(ch);

return parser.parse();
}
Expand Down