src/Generic/reader/SGMLTag.cpp
// method called by constructor to compute the mappping of SGML attributes to their values
// should not be called elsewhere

method called by constructor to compute the mappping of SGML attributes to their values
should not be called elsewhere
method called by constructor to compute the mappping of SGML attributes to their values should not be called elsewhere
void SGMLTag::computeTagAttributes() {
    int start=_start+1;
	while (start < _end) {
		const int eqLoc = _source->indexOf(L"=", start);
		if (!foundWithinBounds(eqLoc)) {
		    return;
		}
		int searchForAttrPos = eqLoc - 1;
		bool foundAttribute=false;
		for (; searchForAttrPos > start; --searchForAttrPos) {
		    wchar_t probeChar = _source->charAt(searchForAttrPos);
			if(!isSGMLTagWhiteSpace(probeChar)){
				foundAttribute=true;
			} else if (foundAttribute) {
			    break;
		    }
		}
	    if (foundAttribute) {
    	    const int attributeStart = searchForAttrPos + 1;
            LocatedString* attributeNameLS = _source->substring(attributeStart,eqLoc);
            attributeNameLS->trim();
            std::wstring attributeName = attributeNameLS->toWString();
            delete attributeNameLS;
	        start = locateAndSetAttributeValue(attributeName, eqLoc);
        } else {
            SessionLogger::warn_user("sgml_tag_problem") << "Invalid attribute while parsing SGML tag "
				<< _source->substring(_start, _end)->toString() << "\n";
            start = eqLoc + 1;
        }
	}
}
void SGMLTag :: computeTagAttributes ( ) { int start = _start + 1 ; while ( start < _end ) { const int eqLoc = _source -> indexOf ( L" " , start ) ; if ( ! foundWithinBounds ( eqLoc ) ) { return ; } int searchForAttrPos = eqLoc - 1 ; bool foundAttribute = false ; for ( ; searchForAttrPos > start ; -- searchForAttrPos ) { wchar_t probeChar = _source -> charAt ( searchForAttrPos ) ; if ( ! isSGMLTagWhiteSpace ( probeChar ) ) { foundAttribute = true ; } else if ( foundAttribute ) { break ; } } if ( foundAttribute ) { const int attributeStart = searchForAttrPos + 1 ; LocatedString * attributeNameLS = _source -> substring ( attributeStart , eqLoc ) ; attributeNameLS -> trim ( ) ; std :: wstring attributeName = attributeNameLS -> toWString ( ) ; delete attributeNameLS ; start = locateAndSetAttributeValue ( attributeName , eqLoc ) ; } else { SessionLogger :: warn_user ( " " ) << " " << _source -> substring ( _start , _end ) -> toString ( ) << " \n " ; start = eqLoc + 1 ; } } }
method called by constructor to compute the mappping of SGML attributes to their values
should not be called elsewhere
method called by constructor to compute the mappping of SGML attributes to their values should not be called elsewhere
// recall that start is the position of the opening <
 // and end is the position of the closing >
 // locate attributes by searching for equals signs
 // no more equals signs means no more attributes
 // search backwards from the equals sign to find the attribute name
 // there can be any amount of whitespace between the attribute
 // name and the equals sign. When we've found non-whitespace
 // when going backwards, then we have found the end of the attribute
 // name
 // if we are within the attribute name going backwards and we
 // encounter another space, then we are at the beginning of the
 // attribute name
 // end of substring is exclusive, beginning is inclusive
 //BUG:: should it be eqLoc-1??
 // if we didn't find an attribute name for an equals sign, then
 // our tag is somehow corrupted
 // SessionLogger TODO: I can't seem to get this one to fire
