All pastes #56938 Raw Edit

Someone

public text v1 · immutable
#56938 ·published 2006-05-18 20:42 UTC
rendered paste body
static bool stripTextDecl( QString& str )
{
    QString textDeclStart( "<?xml" );
    if ( str.startsWith( textDeclStart ) ) {
	QRegExp textDecl(QString::fromLatin1(
	    "^<\\?xml\\s+"
	    "(version\\s*=\\s*((['\"])[-a-zA-Z0-9_.:]+\\3))?"
	    "\\s*"
	    "(encoding\\s*=\\s*((['\"])[A-Za-z][-a-zA-Z0-9_.]*\\6))?"
	    "\\s*\\?>"
	));
	QString strTmp = str.replace( textDecl, "" );
	if ( strTmp.length() != str.length() )
	    return FALSE; // external entity has wrong TextDecl
	str = strTmp;
    }
    return TRUE;
}