[
https://issues.apache.org/jira/browse/LUCENE-5952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14137295#comment-14137295
]
Uwe Schindler commented on LUCENE-5952:
---------------------------------------
I found this one I implemented long time ago (its more than 10 years old and
still in use, because faster than String.split):
{code:java}
public final class StrictStringTokenizer {
public StrictStringTokenizer(String s, char delimiter) {
this.s=s;
this.delimiter=delimiter;
}
public final String nextToken() {
if (pos<0) return "";
int pos1=s.indexOf(delimiter,pos);
String s1;
if (pos1>=0) {
s1=s.substring(pos,pos1);
pos=pos1+1;
} else {
s1=s.substring(pos);pos=-1;
}
return s1;
}
public final boolean hasMoreTokens() {
return (pos>=0);
}
// add your data members here
private final String s;
private final char delimiter;
private int pos=0;
}
{code}
Its a drop-in replacement for StringTokenizer. Maybe remove the "return empty
token if after last" and throw NoSuchElement.
> Give Version parsing exceptions more descriptive error messages
> ---------------------------------------------------------------
>
> Key: LUCENE-5952
> URL: https://issues.apache.org/jira/browse/LUCENE-5952
> Project: Lucene - Core
> Issue Type: Bug
> Affects Versions: 4.10
> Reporter: Michael McCandless
> Priority: Blocker
> Fix For: 4.10.1, 4.11, 5.0
>
> Attachments: LUCENE-5952.patch, LUCENE-5952.patch, LUCENE-5952.patch,
> LUCENE-5952.patch
>
>
> As discussed on the dev list, it's spooky how Version.java tries to fully
> parse the incoming version string ... and then throw exceptions that lack
> details about what invalid value it received, which file contained the
> invalid value, etc.
> It also seems too low level to be checking versions (e.g. is not future proof
> for when 4.10 is passed a 5.x index by accident), and seems redundant with
> the codec headers we already have for checking versions?
> Should we just go back to lenient parsing?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]