Read literal escape character from a file

E

Eddy C

Hi,

Does a class exist which will read escape character from a file and
convert them, as I have file which contains escape characters escaped.
e.g

....Objectives\n\t1.draw\n\t2.final\n

I then want to parse the file and produce the real characters.

Objectives
1.draw
2.final

TIA
 
R

Roedy Green

Does a class exist which will read escape character from a file and
convert them, as I have file which contains escape characters escaped.

That is pretty easy. I will write you one for $20.

I take it you want these sequences to turn into a single char:
\n
\t
\uxxxx
\\
\r
 
E

Eddy C

Yes it easy but I don't like to re-invent the wheel if a class already
exists. I have a class that does it already to a certain extent but I
stopped in the event that it existed already in the SDK
 
T

Thomas Fritsch

Eddy C said:
Yes it easy but I don't like to re-invent the wheel if a class already
exists. I have a class that does it already to a certain extent but I
stopped in the event that it existed already in the SDK
Look into the source of java.util.Properties, especially at the 50 lines of
its private method loadConvert(String). You see that even the Sun people
(re)invented the wheel for unescaping the \... syntax of characters. Hence
I'm pretty sure that the class you look for doesn't exist anywhere in the
java.* and sun.* packages.
 
D

David N. Welton

Eddy said:
Hi,

Does a class exist which will read escape character from a file and
convert them, as I have file which contains escape characters escaped.
e.g

...Objectives\n\t1.draw\n\t2.final\n

I then want to parse the file and produce the real characters.

I just committed some code(*) to the Hecl (www.hecl.org) parser to do
this yesterday. It's kind of specific to Hecl, but it might give you an
idea of what needs to be done. The only really tricky one is \u.

At the very end of the file:

http://cvs.sourceforge.net/viewcvs.py/hecl/hecl/core/org/hecl/Parse.java?rev=1.6&view=auto

(*) So it might have some errors in it:)

--
David N. Welton
- http://www.dedasys.com/davidw/

Linux, Open Source Consulting
- http://www.dedasys.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top