Slide 26
Slide 26 text
CSV Character Loop
var textp, laststop, lineEnd: UnsafePointer
while textp < lineEnd {
switch textp[0] {
case ASCII.BackSlash.rawValue:
textp++
case ASCII.quote.rawValue:
quoteCount++
case delimiter where quoteCount % 2 == 0:
// There is a delimiter which is not between an unmatched pair of quotes?
if textp > laststop {
let s = parseStringFrom(laststop, to: textp)
if !s.isEmpty { delegate?.csvParserDidReadField(s, atIndex: fieldNumber) }
}
++fieldNumber
laststop = textp + 1
default: break
}
// Go to the next character
textp++
}
const char *textp, *laststop, *lineEnd;
while (textp < lineEnd) {
switch(textp[0]) {
case '\\':
textp++; break;
case '\"':
quoteCount++; break;
default:
if(textp[0] == delimiter && (quoteCount % 2) == 0) {
// There is a delimiter which is not between an unmachted pair of quotes?
if(textp > laststop) {
NSString *s = parseString(textp, laststop, encoding);
if([s length] > 0 && respondsToDidReadField) {
[delegate parser:self didReadField:s atIndex:fieldNumber];
}
}
++fieldNumber;
laststop = textp + 1;
}
}
// Go to the next character
textp++;
}