Skip to content

Conversation

@Brock-Gibson
Copy link

Fixes: #62

This pull request introduces improved support for Android string format specifiers, adds comprehensive test cases for format flags and width/precision handling, and refactors the codebase to better distinguish between iOS and Android parsing logic.

Noticed we had a bunch of missing format specifiers that weren't handled properly when i started using this in my own project. Filed that issue and figured i should just improve it to make the format specifiers a bit more robust.

When i ran swiftformat per the contribution guidelines I got a bunch of unrelated changes, not sure how those made it into the base.

Android format specifier support and parsing:

  • Added parsing logic for Android-specific format specifiers, including support for flags, width, and precision, by introducing androidArgumentRegex and related expressions in Expressions.swift. Parsing now distinguishes between iOS and Android strings using a new platform property in FormatString.
  • Updated AndroidStringsFile to construct FormatString objects with platform: .android, ensuring correct parsing of Android format strings.

Test case and example improvements:

  • Added new string resources to strings-base.xml and strings-translation.xml to cover format specifier flags, width, and precision, including both correct and intentionally incorrect translations for validation.

"%((?<position>\\d+)\\$)?(?<specifier>(\(lengthExpression))?(\(specifierExpression)))"
static let nativeArgumentRegex = try! NSRegularExpression(
pattern: Expressions.nativeArgumentExpression,
private static let iosArgumentExpression =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core changes are here to keep iOS backwards compatible and properly handle android separately going forward

@Brock-Gibson Brock-Gibson marked this pull request as ready for review December 16, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Fix comparing locale strings and strings with more complex format args

1 participant