[jdom-interest] Legal values of line separator

Alex Chaffee guru at edamame.stinky.com
Sun Jul 9 12:21:23 PDT 2000


My two cents:

* null string should throw NullPointer or IllegalArgument, no preference 

* standard strings should be constants

* any other string should be accepted silently; who are we to restrict
unanticipated uses of the code that may come up in the future?  If
someone wants to use "<br>" then let them; maybe they're making some
weird XSL template or other odd file format.  The fact that they're
taking the time to call the function means they've thought about it
and hopefully read the Javadoc which warns against this and spells out
recommended behavior.

The use of constants can make use of this clever trick:

	final public static String SEPARATOR_MAC = "\r";
	final public static String SEPARATOR_UNIX = "\n";
	final public static String SEPARATOR_DOS = "\r\n";
	final public static String SEPARATOR_WINDOWS = "\r\n";
	final public static String SEPARATOR_DEFAULT = "\r\n";
	final public static String SEPARATOR_LOCAL = System.getProperty("line.separator");

(JDK 1.2 allows us to do dynamic finals; if you want to be
back-compatible, then take "final" off the last one and it'll work on
any JDK.)

So all possibilities are taken into account, and there's only one
method signature.


-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



More information about the jdom-interest mailing list