src/Generic/reader/SGMLTag.cpp
// This is a helper method to computeTagAttributes and should not otherwise
// be called.
// Given an attribute name and the position of the attribute's equals sign,
// will attempt to find the attribute value. If it does, it will store
// the name-->value mapping in _tagAttributes.  In any case, it will
// return the position the next attribute search should begin from

This is a helper method to computeTagAttributes and should not otherwise
be called.
Given an attribute name and the position of the attribute's equals sign,
will attempt to find the attribute value. If it does, it will store
the name-->value mapping in _tagAttributes.  In any case, it will
return the position the next attribute search should begin from
This is a helper method to computeTagAttributes and should not otherwise be called . Given an attribute name and the position of the attribute ' s equals sign will attempt to find the attribute value . If it does it will store the name -- > value mapping in _tagAttributes . In any case it will return the position the next attribute search should begin from
int SGMLTag::locateAndSetAttributeValue( std::wstring& attributeName, int eqLoc) {
    wchar_t delimiter = L' ';
    int valueStartPos = -1;
    for (int pos = eqLoc +1; pos < _end; ++pos) {
        wchar_t charAtPos = _source->charAt(pos);
        if (charAtPos == L'\"') {
            delimiter = L'"';
            valueStartPos = pos+1;
            break;
        } else if (charAtPos == L'\'') {
            delimiter = L'\'';
            valueStartPos = pos+1;
            break;
        } else if (isSGMLTagWhiteSpace(charAtPos)) {
        } else {
            if (pos == eqLoc + 1) {
                delimiter = L' ';
                valueStartPos = pos;
                break;
            } else {
                break;
            }
        }
    }
    if (foundWithinBounds(valueStartPos)) {
        int closingDelimiterPos;
        if (L' ' == delimiter) {
            closingDelimiterPos = findNextSGMLWhiteSpace(valueStartPos+1);
         } else {
			std::wstring str(1, delimiter);
			closingDelimiterPos = _source->indexOf( str.c_str(),valueStartPos+1);
        }
        if (!foundWithinBounds(closingDelimiterPos)) {
            closingDelimiterPos = _end-1;
        }
		LSPtr attributeValue;
		attributeValue.reset(_source->substring(valueStartPos, closingDelimiterPos));
        _tagAttributes.insert(std::make_pair(attributeName, attributeValue));
        return closingDelimiterPos + 1;
    } else {
        return eqLoc + 1;
    }
}
int SGMLTag :: locateAndSetAttributeValue ( std :: wstring & attributeName , int eqLoc ) { wchar_t delimiter = L' ' ; int valueStartPos = -1 ; for ( int pos = eqLoc + 1 ; pos < _end ; ++ pos ) { wchar_t charAtPos = _source -> charAt ( pos ) ; if ( charAtPos == L' \" ' ) { delimiter = L' ' ; valueStartPos = pos + 1 ; break ; } else if ( charAtPos == L' \' ' ) { delimiter = L' \' ' ; valueStartPos = pos + 1 ; break ; } else if ( isSGMLTagWhiteSpace ( charAtPos ) ) { } else { if ( pos == eqLoc + 1 ) { delimiter = L' ' ; valueStartPos = pos ; break ; } else { break ; } } } if ( foundWithinBounds ( valueStartPos ) ) { int closingDelimiterPos ; if ( L' ' == delimiter ) { closingDelimiterPos = findNextSGMLWhiteSpace ( valueStartPos + 1 ) ; } else { std :: wstring str ( 1 , delimiter ) ; closingDelimiterPos = _source -> indexOf ( str . c_str ( ) , valueStartPos + 1 ) ; } if ( ! foundWithinBounds ( closingDelimiterPos ) ) { closingDelimiterPos = _end - 1 ; } LSPtr attributeValue ; attributeValue . reset ( _source -> substring ( valueStartPos , closingDelimiterPos ) ) ; _tagAttributes . insert ( std :: make_pair ( attributeName , attributeValue ) ) ; return closingDelimiterPos + 1 ; } else { return eqLoc + 1 ; } }
This is a helper method to computeTagAttributes and should not otherwise
be called.
This is a helper method to computeTagAttributes and should not otherwise be called .
// we handle several situations when trying to find the attribute value
 // (a) standard SGML attributes are surrounded by " or ' and may be
 //        separated from the attribute name by any number of spaces
 //       <foo attr="bar" attr2='meep' />
 // (b) if there is a span of non-whitespace immediately following
 //        the attribute name but without quotes, we will use explicit
 //        as the value.
 //        <foo attr=bar attr2=meep />
 // (c) if there is a space following = and the first non-whitespace
 //      character after = is not a quote (or not present at all),
 //      we return en empty string
 // continue - we can have any number of spaces
 // before the attribute value
 // we encountered a non-space character before
 // encountering any quote
 // are we immediately adjacent to the =?
 // if so, use the attribute value
 // not pos + 1 because we want to include
 // the character we just found
 // we do not parse an attribute value in this case
 // so we break leaving valueStartPos at -1
 // if we don't find a closing delimiter, we use
 // the rest of the tag contents as the value
 // RMG: there is a small bug here - if we have a tag like
 // <foo attr="meep />.
 // We probably don't want to include the closing /.
 // But we are already handling malformed input here, so
 // we won't complicate things to deal with it at the moment.
