Skip to content

Move Text(format:) to Swift Regex - #20

Merged
Jeehut merged 1 commit into
mainfrom
wip/text-format-swift-regex
Oct 15, 2026
Merged

Jeehut merged 1 commit into
mainfrom
wip/text-format-swift-regex

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 14, 2026

Copy link
Copy Markdown
Member

Overview

Text(format:partialStyling:) used HandyRegex, which HandySwift deprecated, so every build of the package showed two deprecation warnings. It now uses a Swift Regex literal, which also removes the fatalError for an unexpected capture count. Rendering is unchanged.

The parts are still joined with Text's +. Interpolating them into one LocalizedStringKey instead was considered, as + is deprecated once the deployment target reaches iOS 26, but under Xcode's "Double-Length Pseudolanguage" that version renders @@@@@ placeholders in front of the text. + does not warn at the package's current minimum, so it stays until the minimum reaches 26.

Split out of #7.

How this was verified

TextFormatTests compares Text(format:) pixel by pixel with texts concatenated by hand: plain text, paired tags, symbol tags, unknown and mismatched tags, and percent signs.

  • With main's TextExt.swift all 5 tests pass too, which shows the rendering did not change.
  • They can fail: with the styling of paired tags dropped, pairedTags, unknownAndMismatchedTagsStayLiteral and textWithPercentSigns fail.
  • Warnings: main builds with 'init(_:options:)' is deprecated and 'matches(in:)' is deprecated in TextExt.swift; this branch builds TextExt.swift without warnings.
✔ Test run with 5 tests in 1 suite passed.

The initializer used HandyRegex, which HandySwift deprecated, so every
build showed two deprecation warnings. It now uses a Swift Regex
literal, which also removes the fatalError for an unexpected capture
count. The parts are still joined with Text's + operator: it is only
deprecated once the deployment target reaches iOS 26, and interpolating
the parts into a LocalizedStringKey instead shows placeholder characters
under Xcode's pseudolanguages. Tests compare the rendering pixel by pixel
against texts concatenated by hand.
@Jeehut
Jeehut merged commit e8b3bec into main Oct 15, 2026
5 checks passed
@Jeehut
Jeehut deleted the wip/text-format-swift-regex branch October 15, 2026 10:05
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