Skip to content

Read a currency symbol outside the parentheses in Parse [patch] - #207

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/currency-outside-parentheses
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/currency-outside-parentheses

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #204

What changed

StripAffixes recognised parentheses only when they wrapped the whole trimmed string, and it checked for them before stripping the currency symbol. A symbol outside the parentheses therefore left ( as the first character: "$(45)", "$(1,234.50)", "(45)$" and "$ (45)" under Currency, and "¤(45)" under Any, all threw. decimal, double, long and BigInteger give -45 for each of them.

The new StripCurrencySymbolOutsideParentheses runs before the parenthesis check under AllowParentheses. It removes one leading or trailing currency symbol, along with the spaces SpacesBesideCurrencySymbol allows beside it, but only when the rest is wholly enclosed in parentheses. It marks the symbol as read, so the inner pass can't accept a second one, and "$($45)" and "$(45)$" still fail. A leading outer symbol counts as hasLeadingCurrencySymbol, so the separator choice for "$(1,234.50)" matches the inside-the-parentheses case.

Tests

Every row is checked against decimal with the same text, style and format.

  • TestParseAcceptsWhatDecimalAccepts gains the issue's table: the five outside-symbol inputs, plus "(¤45)" and "(45¤)" for comparison. The five outside-symbol rows fail without the fix.
  • TestParseRejectsWhatDecimalRejects gains "$($45)", "$(45)$" and "$(45".
  • Full suite: 692 passed.

Generated by Claude Code

The parenthesis check ran before the currency symbol was stripped, so
"$(45)", "(45)$" and "$ (45)" under Currency threw where decimal,
double, long and BigInteger give -45. A currency symbol, with the spaces
it may have beside it, is now removed first when what remains is wholly
enclosed in parentheses. It counts as the number's one symbol, so
"$($45)" and "$(45)$" still fail.

Fixes #204

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4B4xxTAPzAHBD4zKk
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants