Provide a version of parseStringArray() that intern()s the array elements.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@951 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: StringUtil.java,v 1.46 2002/11/24 04:50:10 mdb Exp $
|
// $Id: StringUtil.java,v 1.47 2002/11/26 09:16:53 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -668,6 +668,16 @@ public class StringUtil
|
|||||||
* array will result in the function returning null.
|
* array will result in the function returning null.
|
||||||
*/
|
*/
|
||||||
public static String[] parseStringArray (String source)
|
public static String[] parseStringArray (String source)
|
||||||
|
{
|
||||||
|
return parseStringArray(source, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like {@link #parseStringArray(String)} but can be instructed to
|
||||||
|
* invoke {@link String#intern} on the strings being parsed into the
|
||||||
|
* array.
|
||||||
|
*/
|
||||||
|
public static String[] parseStringArray (String source, boolean intern)
|
||||||
{
|
{
|
||||||
int tcount = 0, tpos = -1, tstart = 0;
|
int tcount = 0, tpos = -1, tstart = 0;
|
||||||
|
|
||||||
@@ -691,6 +701,9 @@ public class StringUtil
|
|||||||
while ((tpos = source.indexOf(",", tpos+1)) != -1) {
|
while ((tpos = source.indexOf(",", tpos+1)) != -1) {
|
||||||
tokens[tcount] = source.substring(tstart, tpos);
|
tokens[tcount] = source.substring(tstart, tpos);
|
||||||
tokens[tcount] = replace(tokens[tcount].trim(), "%COMMA%", ",");
|
tokens[tcount] = replace(tokens[tcount].trim(), "%COMMA%", ",");
|
||||||
|
if (intern) {
|
||||||
|
tokens[tcount] = tokens[tcount].intern();
|
||||||
|
}
|
||||||
tstart = tpos+1;
|
tstart = tpos+1;
|
||||||
tcount++;
|
tcount++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user