Skip to content

Commit

Permalink
improvement: Don't use format since it seems to break at some chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Dec 4, 2024
1 parent 4aa1e0f commit ddd08aa
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,22 @@ class LegacyScanner(input: Input, dialect: Dialect) {
}
}

/**
* The algorithm for calculating unicode is as follows:
* - `ch | 0x10000` gets us a new binary number: 1 at 17 position, then zeroes and then the
* actual char number.
* - `Integer.toHexString(ch \| 0x10000)` gets us the hexagonal unicode plus the one from 17
* position
* - `Integer.toHexString(ch | 0x10000).substring(1)` drops that added one
*
* This way we don't have to prefix with 0s since they will be included in the hex number
* string.
*/
@inline
def reportIllegalCharacter(): Unit = curr
.setInvalidToken(s"illegal character '\\u${"%04x".format(ch)}'")
def reportIllegalCharacter(): Unit = {
val output = "\\u" + Integer.toHexString(ch | 0x10000).substring(1);
curr.setInvalidToken("illegal character '" + output + "'")
}

(ch: @switch) match {
case ' ' =>
Expand Down

0 comments on commit ddd08aa

Please sign in to comment.