Esempio n. 1
0
bool VWebUtils::replaceHeadingWithSpan(QString &p_html)
{
    bool altered = false;
    int pos = 0;
    QString spanTag("span");

    while (pos < p_html.size()) {
        int tagIdx = p_html.indexOf(m_tagReg, pos);
        if (tagIdx == -1) {
            break;
        }

        QString tagName = m_tagReg.cap(1);
        if (!isHeadingTag(tagName)) {
            pos = tagIdx + m_tagReg.matchedLength();
            continue;
        }

        p_html.replace(tagIdx + 1, 2, spanTag);

        pos = tagIdx + m_tagReg.matchedLength() + spanTag.size() - 2;

        pos = skipToTagEnd(p_html, pos, tagName);

        Q_ASSERT(pos != -1);

        Q_ASSERT(p_html.mid(pos - 3, 2) == tagName);

        p_html.replace(pos - 3, 2, spanTag);

        pos = pos + spanTag.size() - 2;

        altered = true;
    }

    return altered;
}
Esempio n. 2
0
void HTMLParser	::	pTag( TElementShared aParent )	{

	cout << "p tag found\n";

	// Add to parent
	TElementShared element = mDocument->createElement( "p" );
	aParent->appendChild( element );
	
	bool insideP = true;
	string attribute;
	
	while ( insideP )	{
		
		string data = getString();

		switch ( mStringType )	{
			case ATTR :	{
				attribute = data;
				if ( mAttrNoValue )	{
					element->setAttribute( attribute, "" );
					attribute = "";
				}
				break;
			}
			case ATTRVALUE :	{
				if ( attribute.compare( "" ) )	{
					// Attribute has a name
					// I'll declare it legal
					element->setAttribute( attribute, data );
					attribute = "";
				}
				break;
			}
			case TAG :	{
				if ( !isStartTag() )	{
					if ( isPTag() )	{
						cout << "p closing tag found\n";
						insideP = false;
						continue;
					}
					if ( isAdressTag() ||
						 isBodyStyleTag() ||
						 isFormTag() ||
						 isListTag() )	{
						cout << "p closed implicitly\n";
						insideP = false;
						backPedal();
						continue;
					}
		
					cout << "p: Unexpected closing tag found: " << mTag << ". Skipping...\n";
		
				}
				else	{
					if ( isBlockLevelTag() ||
						 isHeadingTag() ||
						 isLITag() )	{
						cout << "p closed implicitly\n";
						insideP = false;
						backPedal();
						continue;
					}
					if ( isTextLevelTag() )	{
						textLevelTag( element );
						continue;
					}
					if ( isCommentTag() )	{
						commentTag( element );
						continue;
					}

					// Not a known tag
					cout << "p: Unexpected tag found: " << mTag << ". Skipping...\n";
					skipTag();

				}
				break;
			}
			case TEXT :	{
				if ( data.compare( " " ) && data.compare( "" ) )	{
					cout << "Text is:" << endl << data << endl;
					TTextShared text = mDocument->createText( data );
					element->appendChild( text );
				}
				break;
			}
		}
	}

}
Esempio n. 3
0
void HTMLParser	::	bodyStyleTag( TElementShared aParent, bool aInsideForm )	{
	
	cout << mTag << " tag found\n";

	// Save the tag name
	string tag = mTag;

	// Add to parent
	TElementShared element = mDocument->createElement( mTag );
	aParent->appendChild( element );

	bool insideBodyStyle = true;
	string attribute;
	
	while ( insideBodyStyle )	{
		// Warning: more possible than a tag only
		string data = getString();

		switch ( mStringType )	{
			case ATTR :	{
				attribute = data;
				if ( mAttrNoValue )	{
					element->setAttribute( attribute, "" );
					attribute = "";
				}
				break;
			}
			case ATTRVALUE :	{
				if ( attribute.compare( "" ) )	{
					// Attribute has a name
					// I'll declare it legal
					element->setAttribute( attribute, data );
					attribute = "";
				}
				break;
			}
			case TAG :	{
				if ( isStartTag() )	{
					if ( isHeadingTag() )	{
						normalTextTag( element );
						continue;
					}
					if ( isAdressTag() )	{
						adressTag( element );
						continue;
					}
					if ( isBlockLevelTag() )	{
						blockLevelTag( element, aInsideForm );
						continue;
					}
					if ( isTextLevelTag() )	{
						textLevelTag( element );
						continue;
					}
					if ( isCommentTag() )	{
						commentTag( element );
						continue;
					}
		
					// Not a known tag
					cout << "bodyStyle: Unexpected tag found: " << mTag << ". Skipping...\n";
					skipTag();
					
				}
				else	{			
					if ( !mTag.compare( tag ) )	{
						cout << mTag << " closing tag found\n";
		
						// End the while loop
						insideBodyStyle = false;
					}
					else	{
						cout << "bodyStyle: Unexpected closing tag found: " << mTag << ". Skipping...\n";
					}
				}
				break;
			}
			case TEXT :	{
				if ( data.compare( " " ) && data.compare( "" ) )	{
					cout << "Text is:" << endl << data << endl;
					TTextShared text = mDocument->createText( data );
					element->appendChild( text );
				}
				break;
			}
		}
	}
	
}