mirror of https://github.com/apache/lucene.git
try to distinguish between quote as a string delimiter or something else: SOLR-140
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@508805 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b7e7ea6afe
commit
3e80baf529
|
@ -36,14 +36,21 @@ public class StrUtils {
|
||||||
ArrayList<String> lst = new ArrayList<String>(4);
|
ArrayList<String> lst = new ArrayList<String>(4);
|
||||||
int pos=0, start=0, end=s.length();
|
int pos=0, start=0, end=s.length();
|
||||||
char inString=0;
|
char inString=0;
|
||||||
|
char ch=0;
|
||||||
while (pos < end) {
|
while (pos < end) {
|
||||||
char ch = s.charAt(pos++);
|
char prevChar=ch;
|
||||||
|
ch = s.charAt(pos++);
|
||||||
if (ch=='\\') { // skip escaped chars
|
if (ch=='\\') { // skip escaped chars
|
||||||
pos++;
|
pos++;
|
||||||
} else if (inString != 0 && ch==inString) {
|
} else if (inString != 0 && ch==inString) {
|
||||||
inString=0;
|
inString=0;
|
||||||
} else if (ch=='\'' || ch=='"') {
|
} else if (ch=='\'' || ch=='"') {
|
||||||
inString=ch;
|
// If char is directly preceeded by a number or letter
|
||||||
|
// then don't treat it as the start of a string.
|
||||||
|
// Examples: 50" TV, or can't
|
||||||
|
if (!Character.isLetterOrDigit(prevChar)) {
|
||||||
|
inString=ch;
|
||||||
|
}
|
||||||
} else if (ch==separator && inString==0) {
|
} else if (ch==separator && inString==0) {
|
||||||
lst.add(s.substring(start,pos-1));
|
lst.add(s.substring(start,pos-1));
|
||||||
start=pos;
|
start=pos;
|
||||||
|
|
Loading…
Reference in New Issue