Skip to content

refactor split_str_once#7483

Open
Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:refactor_split_str_once
Open

refactor split_str_once#7483
Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:refactor_split_str_once

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

Rewrite split_str_once to be more robust, to handle Unicode, and to return length and position information rather than modifying the source string, taking the approach also used by str_wrap_to_width. In combination with the new length variants of common string utility functions, this allows strings to be split without copying them. In many cases, using the old design, strings were copied multiple times per frame in numerous places.

Includes unit tests to handle numerous usual and unusual cases. All of the historical string splitting anomalies should now be fixed, including a bug in the retail algorithm where an exactly matching string followed by whitespace wasn't split properly.

A followup PR will refactor split_str.

@Goober5000 Goober5000 added enhancement A new feature or upgrade of an existing feature to add additional functionality. cleanup A modification or rewrite of code to make it more understandable or easier to maintain. refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability labels May 28, 2026
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch from 5b68a0e to f901889 Compare May 28, 2026 02:36
@Goober5000 Goober5000 marked this pull request as draft May 28, 2026 03:17
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch 2 times, most recently from 63128d3 to 761a111 Compare May 28, 2026 03:22
@Goober5000 Goober5000 marked this pull request as ready for review May 28, 2026 03:23
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch from 761a111 to ec31049 Compare May 28, 2026 06:13
@BMagnu BMagnu added the Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle label May 31, 2026
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch from ec31049 to f3de2f8 Compare June 2, 2026 05:33
@Goober5000 Goober5000 marked this pull request as draft June 2, 2026 05:47
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch from f3de2f8 to 56db112 Compare June 2, 2026 06:20
Rewrite `split_str_once` to be more robust, to handle Unicode, and to return length and position information rather than modifying the source string, taking the approach also used by `str_wrap_to_width`.  In combination with the new length variants of common string utility functions, this allows strings to be split without copying them.  In many cases, using the old design, strings were copied multiple times per frame in numerous places.

Includes unit tests to handle numerous usual and unusual cases.  All of the historical string splitting anomalies should now be fixed, including a bug in the retail algorithm where an exactly matching string followed by whitespace wasn't split properly.

A followup PR will refactor `split_str`.
@Goober5000 Goober5000 force-pushed the refactor_split_str_once branch from 56db112 to 7412e0b Compare June 2, 2026 07:01
@Goober5000 Goober5000 marked this pull request as ready for review June 2, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup A modification or rewrite of code to make it more understandable or easier to maintain. enhancement A new feature or upgrade of an existing feature to add additional functionality. refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants