0

I am reading the 3.3 Unicode Escapes section in the lang spec. (https://docs.oracle.com/javase/specs/jls/se19/html/jls-3.html#jls-3.3)

There is this particular piece of text I am having difficulty understanding:

consider how many backslashes appeared contiguously as raw input characters in the result, back to a non-backslash character or the start of the result. (It is immaterial whether any such backslash arose from an ASCII \ character in the compiler's raw input or from a Unicode escape \u005c in the compiler's raw input.) If this number is even, then the ASCII \ character is eligible to begin a Unicode escape; if the number is odd, then the ASCII \ character is not eligible to begin a Unicode escape.

For example, the raw input "\\u2122=\u2122" results in the eleven characters " \ \ u 2 1 2 2 = ™ " because while the second ASCII \ character in the raw input is not eligible to begin a Unicode escape, the third ASCII \ character is eligible, and \u2122 is the Unicode encoding of the character ™.

but in \\u2122=\u2122, in the left side of =, there are 2 backslashes making it eligible to begin a unicode escape, but the right side of =, there's only 1 backslash. I understand that this is wrong interpretation because it makes sense that \\u2122 is wrong. And I can count it as being odd number of backslashes if I am ignoring the backslash associated with the unicode escape. But there is this following mention in parentheses:

It is immaterial whether any such backslash arose from an ASCII \ character in the compiler's raw input or from a Unicode escape \u005c in the compiler's raw input.

I want to understand how and where my understanding of this went wrong.

bt01
  • 1

1 Answers1

0

It looks like the text in the first paragraph you quote just swapped "even" and "odd" in the text. Because, just as the example in the same paragraph shows, it is quite the opposite: an odd sequence will imply that at the end there is one non-escaped \ , which then can start a unicode escape sequence.

jsbueno
  • 99,910
  • 10
  • 151
  • 209