Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20334

Re: Unicode escapes and String literals?

Received by 10.66.89.135 with SMTP id bo7mr2036254pab.16.1355526998746; Fri, 14 Dec 2012 15:16:38 -0800 (PST)
Received by 10.50.7.198 with SMTP id l6mr1289273iga.3.1355526998695; Fri, 14 Dec 2012 15:16:38 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!kr7no2378321pbb.0!news-out.google.com!6ni44385pbd.1!nntp.google.com!kt20no3660045pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Fri, 14 Dec 2012 15:16:38 -0800 (PST)
In-Reply-To <0camc85sbkqmmgic2r05toov7p65c0hoi1@4ax.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
NNTP-Posting-Host 69.28.149.29
References <kad3d6$eoo$1@dont-email.me> <kad4io$see$1@news2.informatik.uni-stuttgart.de> <kad7rb$btq$1@dont-email.me> <8d054b85-a6ed-4bab-a8a9-81e967a84fda@googlegroups.com> <0camc85sbkqmmgic2r05toov7p65c0hoi1@4ax.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <7db64abf-3fdd-412b-8af6-11b6e0a7231c@googlegroups.com> (permalink)
Subject Re: Unicode escapes and String literals?
From Lew <lewbloch@gmail.com>
Injection-Date Fri, 14 Dec 2012 23:16:38 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.java.programmer:20334

Show key headers only | View raw


rossum wrote:
> Lew wrote:
>>>>>  if you create a String with \u0066\u0065\u0064 in it
>>
>>Exactly how?
> 
> StringBuilder sb = new StringBuilder(18);
>   sb.append('\\');
>   sb.append("u0066");
>   sb.append('\\');
>   sb.append("u0065");
>   sb.append('\\');
>   sb.append("u0064");
>         
>   String ss = sb.toString();
>   System.out.println(ss);
> 
> Produces: \u0066\u0065\u0064
> 
> Which still leaves the question why?

This has been explained to death upthread already.

Those are not Unicode escapes, that's why.

You have created the String literal that comprises backslashes, the letter "u" and 
various digits. That happens at runtime.

There is no way for the pre-compiler to see those and convert them.

That code sequence is exactly equivalent to this one:

  StringBuilder sb = new StringBuilder(\u0031\u0038); 
  sb.append('\u005c\u005c\u0027)\u003b 
  sb.append("\u0075\u0030\u0030\u0036\u0036"); 
  sb.append('\u005c\u005c\u0027)\u003b 
  sb.append("u006\u0035\u0022); 
  sb.append('\u005c\u005c\u0027)\u003b 
  sb.append(\u0022\u00750064"); 

Unicode escape sequence processing is a pre-compiler operation, not a compiler 
operation and not a run-time operation. 

To do what you want you have to parse the string and convert it yourself.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unicode escapes and String literals? Knute Johnson <nospam@knutejohnson.com> - 2012-12-13 09:31 -0800
  Re: Unicode escapes and String literals? Thomas Richter <thor@math.tu-berlin.de> - 2012-12-13 18:51 +0100
    Re: Unicode escapes and String literals? Knute Johnson <nospam@knutejohnson.com> - 2012-12-13 10:47 -0800
      Re: Unicode escapes and String literals? Lew <lewbloch@gmail.com> - 2012-12-13 11:41 -0800
        Re: Unicode escapes and String literals? rossum <rossum48@coldmail.com> - 2012-12-14 13:32 +0000
          Re: Unicode escapes and String literals? Lew <lewbloch@gmail.com> - 2012-12-14 15:16 -0800
      Re: Unicode escapes and String literals? markspace <-@.> - 2012-12-13 12:58 -0800
        Re: Unicode escapes and String literals? David Lamb <dalamb@cs.queensu.ca> - 2012-12-13 16:21 -0500
          Re: Unicode escapes and String literals? markspace <-@.> - 2012-12-13 14:00 -0800
            Re: Unicode escapes and String literals? David Lamb <dalamb@cs.queensu.ca> - 2012-12-13 17:17 -0500
            Re: Unicode escapes and String literals? David Lamb <dalamb@cs.queensu.ca> - 2012-12-13 17:19 -0500
            Re: Unicode escapes and String literals? Lew <lewbloch@gmail.com> - 2012-12-13 17:11 -0800
          Re: Unicode escapes and String literals? Arne Vajhøj <arne@vajhoej.dk> - 2012-12-13 19:38 -0500
  Re: Unicode escapes and String literals? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-13 11:46 -0800
    Re: Unicode escapes and String literals? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-13 11:49 -0800
    Re: Unicode escapes and String literals? Knute Johnson <nospam@knutejohnson.com> - 2012-12-13 14:55 -0800
      Re: Unicode escapes and String literals? markspace <-@.> - 2012-12-13 15:32 -0800
  Re: Unicode escapes and String literals? Arne Vajhøj <arne@vajhoej.dk> - 2012-12-13 18:09 -0500
    Re: Unicode escapes and String literals? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-13 15:52 -0800
      Re: Unicode escapes and String literals? Arne Vajhøj <arne@vajhoej.dk> - 2012-12-13 19:40 -0500
    Re: Unicode escapes and String literals? Knute Johnson <nospam@knutejohnson.com> - 2012-12-13 16:11 -0800
      Re: Unicode escapes and String literals? Arne Vajhøj <arne@vajhoej.dk> - 2012-12-13 19:43 -0500
        Re: Unicode escapes and String literals? Knute Johnson <nospam@knutejohnson.com> - 2012-12-13 17:08 -0800
  Re: Unicode escapes and String literals? Roedy Green <see_website@mindprod.com.invalid> - 2012-12-14 02:28 -0800
    Re: Unicode escapes and String literals? Arne Vajhøj <arne@vajhoej.dk> - 2012-12-14 21:05 -0500
  Re: Unicode escapes and String literals? Roedy Green <see_website@mindprod.com.invalid> - 2012-12-17 02:42 -0800

csiph-web