Skip to content

Conversation

@sri-adarsh-kumar
Copy link

@sri-adarsh-kumar sri-adarsh-kumar commented Nov 2, 2025

Summary

Implements locale-aware currency symbol parsing to fix issue #423. Previously, symbols like $ were rejected as ambiguous even when the locale made the currency unambiguous. The new implementation uses precedence-based resolution (explicit currency → locale default → global scan) with proper error messages for genuinely ambiguous cases.

Changes

  • Add extractLeadingSymbol() to separate currency symbols from numeric content (handles $100, US$1,234)
  • Implement resolveSymbol() with locale-aware precedence and ambiguity detection
  • Add comprehensive test coverage for USD/CAD/JPY/CNY symbol parsing across different locales

This change is Reviewable

sri-adarsh-kumar and others added 2 commits November 2, 2025 13:08
Support round-trip format/parse for currency symbols with locale-aware precedence resolution:
- Extract leading symbol before digits/separators to handle attached amounts (e.g., $100)
- Resolve symbols using explicit currency → locale default → global scan precedence
- Preserve currency symbols during normalization to prevent spurious matches
- Handle both prefix ($US) and suffix (US$) symbol forms with bidirectional substring matching
- Raise ambiguity errors with candidate lists when symbols match multiple currencies
- Add comprehensive tests for locale-specific resolution and edge cases

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ling

Enforce spec requirement that empty/missing symbols fail when explicit currency is set. Replace broad Exception catches with specific IllegalArgumentException, and remove unnecessary defensive try-catch that cannot occur given non-null locale validation. Remove unused Collectors import.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@sri-adarsh-kumar sri-adarsh-kumar changed the title Fix issue 423 locale aware symbol parsing [WIP] Fix issue 423 locale aware symbol parsing Nov 2, 2025
Enhanced JavaDoc comments for all new helper methods with concrete examples showing:
- Symbol extraction behavior across different formats
- Precedence-based resolution scenarios (locale default, explicit currency, unique/ambiguous matches)
- Matching rules and normalization logic with bidirectional examples
- Edge cases and error conditions

Removed unused 'providers' parameter from resolveSymbol() method since it only returns an ISO code string - the actual provider-aware currency lookup happens in the caller.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sri-adarsh-kumar sri-adarsh-kumar changed the title [WIP] Fix issue 423 locale aware symbol parsing Fix issue 423 locale aware symbol parsing Nov 3, 2025
@sri-adarsh-kumar sri-adarsh-kumar marked this pull request as ready for review November 3, 2025 15:15
@sri-adarsh-kumar
Copy link
Author

@keilw Please review the PR when you get time.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant