On Feb 20, 2:25 am, Robert Fischer <[email protected]>
wrote:
> If my parser reads through a file and encounters the string sequence 
> backslash, n or the string
> sequence backslash, t, then I (as a parser for a language with Java-style 
> string semantics) would
> like to convert that to newline and tab, respectively.  Similarly, I'd like 
> to convert \u0017 into
> the appropriate unicode character.  What's the easiest way to go about doing 
> that on the JVM?  Any
> handy method out there to accomplish that, either in the standard library or 
> some other library?

As the standard set of control characters is just a handful, I
generally use a simple switch statement. When walking through the
string, and encountering a backslash read the next character. Then
switch on that next character. Depending on the character do the
appropriate thing. For the unicode stuff, after reading the 'u' gobble
up all numbers and convert that into an integer (I believe it is in
hex format, so use the appropriate static method of the Integer
class). That integer can then be assigned to the result char (after
range checking (unicode is 32 bit, just the upper 16 bits are rarely
used, so you choose whether to support multichar characters)).

Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to