• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

unicode escapes

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


JLS 3.3
The character produced by a Unicode escape does not participate in further
Unicode escapes. For example, the raw input \u005cu005a results in the six char-acters
\ u 0 0 5 a, because 005c is the Unicode value for \.


I tried to test the following code snippet, but fails with "illegal escape character".

What am I missing? Would appreciate any clarifications. Thanks.
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to many characters in the sequence. That's whay it has an error.
 
Abu Yoosuf
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
Are you disagreeing with what is in jls 3.3?
I tried few few other variations.
1. String s = "\u005c\u005a"; //doesn't compile
2. String ss = "\\u005c\u005a"; //output is \u005cZ
3. String sss = "\u005c\\u005a"; //output is \Z
I can understand the output for 2 & 3 but not for 1. If \u005c translates to \, I expected s to be assigned to "\\u005a" by the end of the translation.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from JLS 3.10.6
(within an string literal..)


...It is a compile-time error if the character following a backslash in an escape is not
an ASCII b, t, n, f, r, ", ', \, 0, 1, 2, 3, 4, 5, 6, or 7. The Unicode escape \u is processed earlier


The following string is ok:
"\u005ctThis would be printed at a tab distance"
this string is equivalent to "\tThis would be..."
because \u005c has been translated to a backslash
However being \u0009 the Unicode for \t ,
"\u005cu0009Error"
will cause a compiler error, because \u005c has been translated to "\" and you cannot have "\u" within a string literal.
 
Abu Yoosuf
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic