BOOL CSimpleSAH::SetAttribute(LPCSTR lpAttriName, LPCSTR lpNewVal) { CString tmp; CString tag(strCurTagBuf); tag.MakeLower(); CString attri(lpAttriName); attri.MakeLower(); BOOL found = FALSE; try{ CString s; int i=0, j=0; while(!found) { i = tag.Find(attri, i); if(i<0) break; j = tag.Find('=', i); s = tag.Mid(i+attri.GetLength(), j-i-attri.GetLength()); s.TrimLeft(); if(s.IsEmpty()) { found=TRUE; tmp = strCurTagBuf.Mid(j+1); tmp.TrimLeft(); tag = strCurTagBuf.Left(j+1); //XXX= tag += "\""; tag += lpNewVal; tag += "\""; //XXX="VVV" if(tmp.GetAt(0) == '\"' || tmp.GetAt(0) == '\'') //quated string { tmp = tmp.Right(tmp.GetLength()-1); i = tmp.FindOneOf("\'\"\r\n>"); if(tmp.GetAt(i) == '\"' || tmp.GetAt(i) == '\'') i++; } else i = tmp.FindOneOf(" \r\n>\'\""); tag += strCurTagBuf.Right(tmp.GetLength() - i); strCurTagBuf = tag; } i += attri.GetLength(); } } catch(...) { } return found; }
CString CSimpleSAH::GetAttribute(LPCSTR lpAttriName) { CString tmp; CString tag(strCurTagBuf); tag.MakeLower(); CString attri(lpAttriName); attri.MakeLower(); try{ CString s; int i=0, j=0; BOOL found = FALSE; while(!found) { i = tag.Find(attri, i); if(i<0) break; j = tag.Find('=', i); s = tag.Mid(i+attri.GetLength(), j-i-attri.GetLength()); s.TrimLeft(); if(s.IsEmpty()) { found=TRUE; tmp = strCurTagBuf.Mid(j+1); if(tmp.GetAt(0) == '\"' || tmp.GetAt(0) == '\'') //quoted string { tmp = tmp.Right(tmp.GetLength()-1); i = tmp.FindOneOf("\'\"\r\n>"); } else i = tmp.FindOneOf(" \r\n>\'\""); tmp = tmp.Left(i); tmp.TrimLeft(); tmp.TrimRight(); } i += attri.GetLength(); } } catch(...) { } return tmp; }
void attris(AttriMap& m) { std::string k, v; while (attri(k, v)) m.push_back(std::make_pair(k, v)); }