Yes, you're right, we can simply ignore the unpaired quotes.
I'll incorporate your suggestion, thanks!
Sincerely yours,
Ivan
On 06.01.2015 0:12, Xueming Shen wrote:
On 01/05/2015 12:41 PM, Ivan Gerasimov wrote:
Thanks Sherman!
On 05.01.2015 22:10, Xueming Shen wrote:
Just wonder if we really need that "inQuotes" logic here? A
straightforward approach might
be "every time you have a quote, skip everything until you hit
another one, when counting,
or copy everything into the buffer until hit another one, when
copying" ?
I agree it would work, but, in my opinion, it would be a bit more
complicated.
The counting loop would look something like this:
------------------------------------
outerLoop: for (int i = 0; i < ldLen; ++i) {
char ch = ldPath.charAt(i);
if (mayBeQuoted && ch == '\"') {
thereAreQuotes = true;
for (++i; i < ldLen; ++i) {
if (ldPath.charAt(i) == '\"') {
continue outerLoop;
}
}
break; // unpaired quote
} else if (ch == ps) {
psCount++;
}
}
------------------------------------
which is 3 lines longer, comparing to the loop with inQuotes flag.
It does not seem like we are doing anything special for "unpaired
quote" (just ignore it?),
if that is the case, you probably don't need to do anything for it,
the code could be
something like
for (int i = 0; i < ldLen; ++i) {
char ch = ldPath.charAt(i);
if (mayBeQuoted && ch == '\"') {
thereAreQuotes = true;
while (++i < ldLen && ldPath.charAt(i) != '\"') {}
} else if (ch == ps) {
psCount++;
}
}
I have not tried to debug the code though :-) Just an opinion here.
-Sherman