static bool ConvertBSTRAttributesToArray(const nsAString& aStr, nsTArray<Attribute>* aAttrs) { if (!aAttrs) { return false; } enum { eName = 0, eValue = 1, eNumStates } state; nsAutoString tokens[eNumStates]; auto itr = aStr.BeginReading(), end = aStr.EndReading(); state = eName; while (itr != end) { switch (*itr) { case L'\\': // Skip the backslash so that we're looking at the escaped char ++itr; if (itr == end || !IsEscapedChar(*itr)) { // Invalid state return false; } break; case L':': if (state != eName) { // Bad, should be looking at name return false; } state = eValue; ++itr; continue; case L';': if (state != eValue) { // Bad, should be looking at value return false; } state = eName; aAttrs->AppendElement( Attribute(NS_ConvertUTF16toUTF8(tokens[eName]), tokens[eValue])); tokens[eName].Truncate(); tokens[eValue].Truncate(); ++itr; continue; default: break; } tokens[state] += *itr; ++itr; } return true; }
// For example: X"ABCDEFG\"HIJKLMN"Y // We are now at A, and would skip to Y // The double quote before H is a "C-escaped-character", We shouldn't quite from that bool Tokenizer::SkipToStringEnd(const wxChar& ch) { while (true) { while (CurrentChar() != ch && MoveToNextChar()) // don't check EOF when MoveToNextChar already does ; if (IsEOF()) return false; if (IsEscapedChar()) break; MoveToNextChar(); } return true; }