Code Comments
Programming Forum and web based access to our favorite programming groups.In connection with writing some unit tests, I need a utility to convert text output to a String constant expression. http://www.snible.org/java2/uni2java.html is almost exactly what I want, but I would prefer the literals broken at newlines and concatenated. That is: aaa\bbb kkk gets converted to "aaa\\bbb\nkkk\n". I would prefer: "aaa\\bbb\n" + "kkk\n" This seems like a wheel that should already exist, so I would rather not invent it myself. Patricia
Post Follow-up to this messagePatricia Shanahan wrote: > In connection with writing some unit tests, I need a utility to convert > text output to a String constant expression. > > http://www.snible.org/java2/uni2java.html is almost exactly what I want, > but I would prefer the literals broken at newlines and concatenated. > That is: > > aaa\bbb > kkk > > > gets converted to "aaa\\bbb\nkkk\n". I would prefer: > > "aaa\\bbb\n" + > "kkk\n" > > This seems like a wheel that should already exist, so I would rather not > invent it myself. freemarker.template.utility.StringUtil Should get you as close as the above mentioned. <http://freemarker.org/> > Patricia
Post Follow-up to this messageloop through char by char and if the char gets any special treatment
replace it with something
String s = "hi\n\\kkk"; //hi
//\kkk
StringBuilder b = new StringBuilder();
for(char c : s.toCharArray())
{
switch(c)
{
case '\n':b.append("\\n");break;
case '\r':b.append("\\r");break;
case '\':b.append("\\\\")break;
case '\"':b.append("\\\"");break;
case ''':b.append("\\'");break;
//Add in whatever else
default:b.append(c);
}
}
http://groups.google.com/group/java...eloupment?hl=en
Post Follow-up to this messageOn Sun, 30 Mar 2008 13:14:00 -0700, Patricia Shanahan <pats@acm.org> wrote, quoted or indirectly quoted someone who said : >In connection with writing some unit tests, I need a utility to convert >text output to a String constant expression. see the code in http://mindprod.com/applet/quoter.html you can change it to suit yourself. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this messageIn article <ov63v352r8amfd5jvltpc9hdfdlcrsbbc9@4ax.com>, Roedy Green <see_website@mindprod.com.invalid> wrote: > On Sun, 30 Mar 2008 13:14:00 -0700, Patricia Shanahan <pats@acm.org> > wrote, quoted or indirectly quoted someone who said : > > > see the code in http://mindprod.com/applet/quoter.html > you can change it to suit yourself. Roedy: This utility is quite comprehensive, but it may be a challenge to modify: the common13, csv, ledatastream and hunkio directories appear to be missing:-) Any pointers? John -- John B. Matthews trashgod at gmail dot com home dot woh dot rr dot com slash jbmatthews
Post Follow-up to this messageOn Tue, 01 Apr 2008 12:46:39 -0400, "John B. Matthews" <nospam@nospam.com> wrote, quoted or indirectly quoted someone who said : >Roedy: This utility is quite comprehensive, but it may be a challenge to >modify: the common13, csv, ledatastream and hunkio directories appear to >be missing:-) Any pointers? all those packages are available to download. see http://mindprod.com/products.html But if you want to just cannibalise the code to create string literals, you need only one class in the bundle, namely ToJavaStringLiteral.java I have corrected the zip to include common13. It did not used to need it. I converted it from AWT to Swing recently, which now uses it. Quoter does not use csv, ledatastream or hunkio. It does not even mention them in comments. Have youQuoter with some other program? Maybe fileio? -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this messageIn article <bpv4v3tit34795k4dv2burkmlu2jmlodv3@4ax.com>, Roedy Green <see_website@mindprod.com.invalid> wrote: > On Tue, 01 Apr 2008 12:46:39 -0400, "John B. Matthews" > <nospam@nospam.com> wrote, quoted or indirectly quoted someone who > said : > > > all those packages are available to download. see > http://mindprod.com/products.html > > But if you want to just cannibalise the code to create string > literals, you need only one class in the bundle, namely > ToJavaStringLiteral.java > > I have corrected the zip to include common13. It did not used to need > it. I converted it from AWT to Swing recently, which now uses it. > > Quoter does not use csv, ledatastream or hunkio. It does not even > mention them in comments. Have youQuoter with some other > program? Maybe fileio? Thanks! The new source <http://mindprod.com/zips/quoter41.zip> builds correctly; it contains the common13 directory, as imported in lines 83-85 of Quoter.java: import com.mindprod.common13.CMPAboutJBox; import com.mindprod.common13.HybridJ; import com.mindprod.common13.JEButton; I was confounding common11.CMPAboutBox & common13.CMPAboutJBox. The others (csv, ledatastream or hunkio) are imported by unused classes. For example, the class ImageInfo imports LEDataInputStream. Here are the dependencies I found: ./com/mindprod/common11/ImageInfo.java: import com.mindprod.ledatastream.LEDataInputStream; ./com/mindprod/entities/GenCheat.java: import com.mindprod.csv.CSVReader; ./com/mindprod/entities/InsertFileEntities.java: import com.mindprod.hunkio.HunkIO; ./com/mindprod/entities/StripFileEntities.java: import com.mindprod.hunkio.HunkIO; I was tracking down a problem with the applet occasionally losing clipboard access in Safari; the application works fine. John -- John B. Matthews trashgod at gmail dot com home dot woh dot rr dot com slash jbmatthews
Post Follow-up to this messageOn Tue, 01 Apr 2008 20:30:21 -0400, "John B. Matthews" <nospam@nospam.com> wrote, quoted or indirectly quoted someone who said : >./com/mindprod/common11/ImageInfo.java: > import com.mindprod.ledatastream.LEDataInputStream; >./com/mindprod/entities/GenCheat.java: > import com.mindprod.csv.CSVReader; >./com/mindprod/entities/InsertFileEntities.java: > import com.mindprod.hunkio.HunkIO; >./com/mindprod/entities/StripFileEntities.java: > import com.mindprod.hunkio.HunkIO; arrgh. This means you need those packages just to do the build, even though you never use those classes. I have updated the ANT scripts to include ledatastream all the time and csv and hunkio whenever entities is used. I will post within the hour. I wonder what sort of tool I could concoct to make sure my zips are complete. I found GenJar to make sure the jar is complete without excess fat. I was thinking of writing a tool to make sure everything in the jar was in the zip, but that is nowhere near sufficient. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this messageIn article <fdn7v398fis3re1kceepbb3ppnes1rh59b@4ax.com>, Roedy Green <see_website@mindprod.com.invalid> wrote: > On Tue, 01 Apr 2008 20:30:21 -0400, "John B. Matthews" > <nospam@nospam.com> wrote, quoted or indirectly quoted someone who > said : > > > arrgh. This means you need those packages just to do the build, even > though you never use those classes. This was not my experience using javac; after deleting all the class files, the sources compiled with a few warnings and main executed correctly. (Absent an E: drive, I can't use your build.xml file:-) > I have updated the ANT scripts to include ledatastream all the time > and csv and hunkio whenever entities is used. I will post within the > hour. The new zip compiles correctly. Although the web site still shows the last update as "2008-02-09", the zip is indeed new. > I wonder what sort of tool I could concoct to make sure my zips are > complete. Would ant's depend task be of use? With some restrictions, it appears to determine dependencies based on references in the class files themselves: <http://ant.apache.org/manual/OptionalTasks/depend.html> [...] John -- John B. Matthews trashgod at gmail dot com home dot woh dot rr dot com slash jbmatthews
Post Follow-up to this messageOn Wed, 02 Apr 2008 20:54:50 -0400, "John B. Matthews" <nospam@nospam.com> wrote, quoted or indirectly quoted someone who said : > >This was not my experience using javac; after deleting all the class >files, the sources compiled with a few warnings and main executed >correctly. (Absent an E: drive, I can't use your build.xml file:-) use the simpler rebuild.xml file. All you need do is modify this one line. <project name="common13" basedir="E:/" default="jar"> to change that E: More detailed instructions willl appear on the website within the hour. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.