Fix carrage return purging, broke in pre-release only

This commit is contained in:
Wilson Snyder 2010-04-10 09:11:52 -04:00
parent 29b0ea0af9
commit 10689ffaba
1 changed files with 15 additions and 10 deletions

View File

@ -636,20 +636,25 @@ void V3PreProcImp::openFile(FileLine* fl, V3InFilter* filterp, const string& fil
// Filter all DOS CR's en-mass. This avoids bugs with lexing CRs in the wrong places. // Filter all DOS CR's en-mass. This avoids bugs with lexing CRs in the wrong places.
// This will also strip them from strings, but strings aren't supposed to be multi-line without a "\" // This will also strip them from strings, but strings aren't supposed to be multi-line without a "\"
for (StrList::iterator it=wholefile.begin(); it!=wholefile.end(); ++it) { for (StrList::iterator it=wholefile.begin(); it!=wholefile.end(); ++it) {
// We don't test for \0 as we allow and strip mid-string '\0's (for now). // We don't end-loop at \0 as we allow and strip mid-string '\0's (for now).
// We also edit in place. This is nasty to other users of the string, but bool strip = false;
// there aren't any, and it avoids needing 2x the memory on very large files.
const char* sp = it->data(); const char* sp = it->data();
const char* ep = sp + it->length(); const char* ep = sp + it->length();
char* cp = (char*) sp; // Only process if needed, as saves extra string allocations
for (; sp<ep; sp++) { for (const char* cp=sp; cp<ep; cp++) {
if (*sp != '\r' && *sp != '\0') { if (VL_UNLIKELY(*cp == '\r' || *cp == '\0')) {
*cp++ = *sp; strip = true; break;
} }
} }
size_t len = cp - it->data(); if (strip) {
// Truncate old string string out; out.reserve(it->length());
it->erase(len); for (const char* cp=sp; cp<ep; cp++) {
if (!(*cp == '\r' || *cp == '\0')) {
out += *cp;
}
}
*it = out;
}
// Push the data to an internal buffer. // Push the data to an internal buffer.
m_lexp->scanBytesBack(*it); m_lexp->scanBytesBack(*it);