void SourceEdit::TokenizeLine(const CStringW& line, CArray<CStringW>& tokens) { int i = 0; while (true) { // We are either at the start of the line, or the end of the previous token, // so scan forward to find the start of the next token. while (true) { if (i == line.GetLength()) return; WCHAR c = line.GetAt(i); if ((c != L' ') && (c != L'\t')) break; i++; } // Find the end of this token int j = line.Find(L" ",i); if (j == -1) { // No final delimiter, so this must be the last token if (i < line.GetLength()) tokens.Add(line.Mid(i)); return; } else { // Store this token and move to the end of it tokens.Add(line.Mid(i,j-i)); i = j; } } }
bool SourceEdit::GetNextLine(const CStringW& text, CStringW& line, int& i) { if (i == text.GetLength()) { // If at the very end, the final line must be blank line = ""; i++; return true; } else if (i > text.GetLength()) { // Past the end of the text, so stop reading lines return false; } line.Empty(); while (i < text.GetLength()) { WCHAR c = text.GetAt(i); i++; switch (c) { case L'\r': // Check for a "\r\n" sequence if (i < text.GetLength()) { if (text.GetAt(i) == L'\n') i++; } return true; case L'\n': return true; default: line.AppendChar(c); break; } } // Having got here a line must have ended without a trailing carriage return, // so move beyond the end of text to make sure this is the last line. i++; return true; }
void Skein::Node::OverwriteBanner(CStringW& inStr) { // Does this text contain an Inform 7 banner? int i = inStr.Find(L"\nRelease "); if (i >= 0) { int release, serial, build; if (swscanf((LPCWSTR)inStr+i,L"\nRelease %d / Serial number %d / Inform 7 build %d",&release,&serial,&build) == 3) { // Replace the banner line with asterisks for (int j = i+1; j < inStr.GetLength(); j++) { if (inStr.GetAt(j) == '\n') break; inStr.SetAt(j,'*'); } } } }
CStringW Skein::Node::StripWhite(const CStringW& inStr) { CStringW outStr; outStr.Preallocate(inStr.GetLength()+1); for (int i = 0; i < inStr.GetLength(); i++) { WCHAR c = inStr.GetAt(i); switch (c) { case L'\n': case L'\r': case L' ': case L'\t': break; case '>': if (i < inStr.GetLength()-1) outStr.AppendChar(c); default: outStr.AppendChar(c); break; } } return outStr; }