Skip to content

Optimize UnescapeText method using StringBuilder#2389

Open
y114git wants to merge 1 commit into
UnderminersTeam:masterfrom
y114git:patch-1
Open

Optimize UnescapeText method using StringBuilder#2389
y114git wants to merge 1 commit into
UnderminersTeam:masterfrom
y114git:patch-1

Conversation

@y114git

@y114git y114git commented Jun 5, 2026

Copy link
Copy Markdown

Refactor UnescapeText method to use StringBuilder for optimization.

Description

This refactors UndertaleString.UnescapeText to parse escape sequences in a single pass with StringBuilder instead of applying multiple chained string.Replace calls.

The previous implementation could re-process characters produced by an earlier replacement. For example, an escaped literal backslash followed by n ("\\n" in assembler text) could be transformed into a real newline because Replace("\\n", "\n") ran before Replace("\\\\", "\\").

The new implementation handles only the escape sequences emitted by UndertaleString.ToString(true):

  • \r -> carriage return
  • \n -> newline
  • \" -> double quote
  • \\ -> literal backslash

Unknown escape-like sequences are preserved as-is instead of dropping the backslash. This keeps strings such as Windows paths (C:\Users\Name) or unsupported escape-like text (\t, \x, \0, \U) from being silently changed.

Caveats

This intentionally does not add support for additional GML/C-style escape sequences such as \t, \xNN, octal escapes, or Unicode escapes. The method is used by the VM assembler text path and is kept as the inverse of UndertaleString.ToString(true), rather than a full GML string literal parser.

Notes

Needs tests ig

Refactor UnescapeText method to use StringBuilder for optimization.
@colinator27 colinator27 added this to the Possible for 0.9.x milestone Jun 13, 2026
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.

2 participants