• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Illegal characters in Java code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Illegal characters in Java code?


  • Subject: Re: Illegal characters in Java code?
  • From: Greg Guerin <email@hidden>
  • Date: Mon, 25 Jun 2007 12:17:26 -0700

James Closs wrote:

>switch( next_char )
>{
>        case '¿':
>                next_char = '?';
>                break;
>..snip..
>This method is compiling and running fine in one class file, yet when I
>copy and paste it into another class file it won't compile. I keep getting
>'unclosed character literal' and 'illegal character errors'.

I suspect that the pasted-into source file isn't actually being saved as
MacRoman (Western - Mac), but as something else.  One way to test this
hypothesis is to hex-dump both source files (read 'man hexdump'), then use
diff or FileMerge to compare the hex output.

One way to fix the source-encoding problem is to use Unicode escapes in
your source, instead of relying on a particular source-encoding:
  case '\u00bf':  // inverted question-mark
  case '\u00f1':  // tilde n

You can find the Unicode tables at www.unicode.org.


You may also want to use table-lookup instead of a large 'switch'
statement.  The compiled class-files should be dramatically smaller.

Start with a String literal which you initialize with the mappings for a
series of chars.  Then index into it using String.charAt() to retrieve the
replacement char.

Here's a table from some code of mine, for mapping the accented letters in
the range U+00C0 thru U+00FF to unaccented replacements (with * and /
thrown in for multiply and divide).
  private static final String DEACCENTS =
      "AAAAAAACEEEEIIII" +  // C0-CF
      "DNOOOOO*OUUUUYTs" +  // D0-DF
      "aaaaaaaceeeeiiii" +  // E0-EF
      "dnooooo/ouuuuyty";  // F0-FF

In the code that uses the table, I have this fragment, after suitable
range-checking of the input char:
   build.append( DEACCENTS.charAt( ch - 0x00C0 ) );

where 'build' is a StringBuffer, and 'ch' is the input char being translated.

Figuring out suitable mappings and lookup-table Strings for other
characters is left as an exercise for the interested reader.

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Illegal characters in Java code?
      • From: James Closs <email@hidden>
  • Prev by Date: Re: libstdc++ and 10.3.9
  • Next by Date: Using NASM in Xcode 2.4
  • Previous by thread: Illegal characters in Java code?
  • Next by thread: Re: Illegal characters in Java code?
  • Index(es):
    • Date
    • Thread