TidyNetworkReply::~TidyNetworkReply() { delete nam; if (!this->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) { tidyBufFree( &output ); tidyBufFree( &errbuf ); tidyRelease( tdoc ); } }
QString tidyHtml(QString str, bool& ok) { #ifdef NO_TIDY ok = true; return str; #else QString res = str; ok = false; static bool isTidyWithIntBodyOnly = isTidyWithIntBodyOnlyCheck(); TidyDoc tdoc = tidyCreate(); TidyBuffer output; TidyBuffer errbuf; tidyBufInit(&output); tidyBufInit(&errbuf); bool configOk = tidyOptSetBool(tdoc, TidyXhtmlOut, yes) && tidyOptSetBool(tdoc, TidyForceOutput, yes) && tidyOptSetBool(tdoc, TidyMark, no) && (isTidyWithIntBodyOnly ? tidyOptSetInt(tdoc, TidyBodyOnly, 1) : tidyOptSetBool(tdoc, TidyBodyOnly, yes)) && tidyOptSetInt(tdoc, TidyWrapLen, 0) && tidyOptSetInt(tdoc, TidyDoctypeMode, TidyDoctypeOmit); if (configOk && (tidySetCharEncoding(tdoc, "utf8") >= 0) && (tidySetErrorBuffer(tdoc, &errbuf) >= 0) && (tidyParseString(tdoc, str.toUtf8().data()) >= 0) && (tidyCleanAndRepair(tdoc) >= 0) && (tidyRunDiagnostics(tdoc) >= 0) && (tidySaveBuffer(tdoc, &output) >= 0) && (output.bp != 0 && output.size > 0)) { res = QString::fromUtf8((char*)output.bp, output.size); ok = true; } #ifdef DEBUG_MARKUP if (errbuf.size > 0) { QString errStr = QString::fromUtf8((char*)errbuf.bp, errbuf.size); qDebug() << "\n[DEBUG] MARKUP, libtidy errors and warnings:\n" << errStr; } #endif if (output.bp != 0) tidyBufFree(&output); if (errbuf.bp != 0) tidyBufFree(&errbuf); tidyRelease(tdoc); return res.trimmed(); #endif }
int main(int argc, char **argv ) { CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; TidyDoc tdoc; TidyBuffer docbuf = {0}; TidyBuffer tidy_errbuf = {0}; int err; if ( argc == 2) { curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); tdoc = tidyCreate(); tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */ tidyOptSetInt(tdoc, TidyWrapLen, 4096); tidySetErrorBuffer( tdoc, &tidy_errbuf ); tidyBufInit(&docbuf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf); err=curl_easy_perform(curl); if ( !err ) { err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */ if ( err >= 0 ) { err = tidyCleanAndRepair(tdoc); /* fix any problems */ if ( err >= 0 ) { err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */ if ( err >= 0 ) { dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */ fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */ } } } } else fprintf(stderr, "%s\n", curl_errbuf); /* clean-up */ curl_easy_cleanup(curl); tidyBufFree(&docbuf); tidyBufFree(&tidy_errbuf); tidyRelease(tdoc); return(err); } else printf( "usage: %s <url>\n", argv[0] ); return(0); }
static html_valid_status_t html_valid_run (html_valid_t * htv, SV * html, SV ** output_ptr, SV ** errors_ptr) { const char * html_string; STRLEN html_length; SV * output; SV * errors; TidyBuffer tidy_output = {0}; TidyBuffer tidy_errbuf = {0}; /* First set these up sanely in case the stuff hits the fan. */ * output_ptr = & PL_sv_undef; * errors_ptr = & PL_sv_undef; /* Work around bug where allocator sometimes does not get set. */ CopyAllocator (htv->tdoc, & tidy_output); CopyAllocator (htv->tdoc, & tidy_errbuf); html_string = SvPV (html, html_length); CALL_TIDY (tidySetErrorBuffer (htv->tdoc, & tidy_errbuf)); htv->n_mallocs++; CALL_TIDY (tidyParseString (htv->tdoc, html_string)); CALL_TIDY (tidyCleanAndRepair (htv->tdoc)); CALL_TIDY (tidyRunDiagnostics (htv->tdoc)); CALL_TIDY (tidySaveBuffer (htv->tdoc, & tidy_output)); htv->n_mallocs++; /* Copy the contents of the buffers into the Perl scalars. */ output = newSVpv ((char *) tidy_output.bp, tidy_output.size); errors = newSVpv ((char *) tidy_errbuf.bp, tidy_errbuf.size); /* HTML Tidy randomly segfaults here due to "allocator" not being set in some cases, hence the above CopyAllocator fix. */ tidyBufFree (& tidy_output); htv->n_mallocs--; tidyBufFree (& tidy_errbuf); htv->n_mallocs--; /* These are not our mallocs, they are Perl's mallocs, so we don't increase htv->n_mallocs for these. After we return them, we no longer take care of these. */ * output_ptr = output; * errors_ptr = errors; return html_valid_ok; }
void TidyReader::closeFile (void) { if (m_tidy) { tidyBufFree (&m_outbuf); #ifndef DEBUG tidyBufFree (&m_errbuf); #endif tidyRelease (m_tidy); m_tidy = 0; } memset (&m_outbuf, 0 , sizeof (TidyBuffer)); memset (&m_errbuf, 0 , sizeof (TidyBuffer)); }
QVector<QString> UCHome_Main_SiteConst::find_sys_notice(TidyDoc doc) { QVector<QString> sys_notes; QString note; char *notes_ids[] = { "mtag_invite", "f_request", NULL }; char *nid = NULL; TidyNode node = NULL; TidyNode node2 = NULL; TidyBuffer tbuf; for(int i = 0; i < 16 ; i++) { nid = notes_ids[i]; if(nid == NULL) { break; } node = this->searchNode(doc, NULL, nid, TidyTag_DIV); if(node != NULL) { tidyBufInit(&tbuf); tidyNodeGetText(doc, node, &tbuf); note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp)); sys_notes.append(note); tidyBufFree(&tbuf); q_debug()<<note; }else{ q_debug()<<"Warning: "<<nid<<" not found"; } } return sys_notes; }
void CCaHtmlParse::__GetPriceAndRamainTicket(UINT *pPrice, UINT *pRemainTicket, const TidyDoc & tdoc, const TidyNode & tdNode) { CStringA straRet; *pPrice = 0; *pRemainTicket = 0; TidyBuffer text = {0}; tidyBufInit(&text); TidyNodeType type = tidyNodeGetType(tdNode); tidyNodeGetText(tdoc, tdNode, &text); straRet.Format("%s",text.bp); straRet.TrimLeft(); CStringA straKey("</font>"); int iPos = straRet.Find(straKey); int iEndPos = straRet.Find("</strong>"); int iStartPos = iPos+straKey.GetLength(); CStringA straPrice = straRet.Mid(iStartPos, iEndPos-iStartPos); straPrice.Remove(0x0d);//去掉回车 straPrice.Remove(0x0a);//去掉换行 *pPrice = atoi(straPrice.GetBuffer(0)); straPrice.ReleaseBuffer(); //剩余座位 straKey = ":"; iPos = straRet.Find(straKey); iEndPos = straRet.Find("</td>"); iStartPos = iPos+straKey.GetLength(); CStringA straRemainSeat = straRet.Mid(iStartPos, iEndPos-iStartPos); *pRemainTicket = atoi(straRemainSeat.GetBuffer(0)); straRemainSeat.ReleaseBuffer(); tidyBufFree(&text); }
QString UCHome_Main_SiteConst::find_sys_notice_by_type(TidyDoc doc, char *type_class) { QString note; char *nid = type_class; TidyNode node = NULL; TidyNode node2 = NULL; TidyBuffer tbuf; if(nid == NULL) { q_debug()<<""; return note; } node = this->searchNode(doc, NULL, nid, TidyTag_DIV); if(node != NULL) { tidyBufInit(&tbuf); tidyNodeGetText(doc, node, &tbuf); note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp)); tidyBufFree(&tbuf); q_debug()<<note; }else{ q_debug()<<"Warning: "<<nid<<" not found"; } return note; }
static int tidy_doc_cast_handler(zval *in, zval *out, int type) { TidyBuffer output; PHPTidyObj *obj; switch (type) { case IS_LONG: ZVAL_LONG(out, 0); break; case IS_DOUBLE: ZVAL_DOUBLE(out, 0); break; case _IS_BOOL: ZVAL_TRUE(out); break; case IS_STRING: obj = Z_TIDY_P(in); tidyBufInit(&output); tidySaveBuffer (obj->ptdoc->doc, &output); ZVAL_STRINGL(out, (char *) output.bp, output.size ? output.size-1 : 0); tidyBufFree(&output); break; default: return FAILURE; } return SUCCESS; }
static void tidy_doc_update_properties(PHPTidyObj *obj) { TidyBuffer output; zval temp; tidyBufInit(&output); tidySaveBuffer (obj->ptdoc->doc, &output); if (output.size) { if (!obj->std.properties) { rebuild_object_properties(&obj->std); } ZVAL_STRINGL(&temp, (char*)output.bp, output.size-1); zend_hash_str_update(obj->std.properties, "value", sizeof("value") - 1, &temp); } tidyBufFree(&output); if (obj->ptdoc->errbuf->size) { if (!obj->std.properties) { rebuild_object_properties(&obj->std); } ZVAL_STRINGL(&temp, (char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1); zend_hash_str_update(obj->std.properties, "errorBuffer", sizeof("errorBuffer") - 1, &temp); } }
/* Traverse the document tree */ void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) { TidyNode child; for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { ctmbstr name = tidyNodeGetName( child ); if ( name ) { /* if it has a name, then it's an HTML tag ... */ TidyAttr attr; printf( "%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { printf(tidyAttrName(attr)); tidyAttrValue(attr)?printf("=\"%s\" ", tidyAttrValue(attr)):printf(" "); } printf( ">\n"); } else { /* if it doesn't have a name, then it's probably text, cdata, etc... */ TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetText(doc, child, &buf); printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:""); tidyBufFree(&buf); } dumpNode( doc, child, indent + 4 ); /* recursive */ } }
void HTMLTidy::run() throw( std::runtime_error ) { TidyBuffer outputBuffer = { 0 }; TidyBuffer errorBuffer = { 0 }; // try to create valid XHTML document for XML parser: int tidyResult = -1; if( tidyOptSetBool( handle, TidyXhtmlOut, yes ) ) { tidyResult = tidySetErrorBuffer( handle, &errorBuffer ); } if( tidyResult >= 0 ) { tidyResult = tidyParseString( handle, document.c_str() ); } if( tidyResult >= 0 ) { tidyResult = tidyCleanAndRepair( handle ); } if( tidyResult >= 0 ) { tidyResult = tidyRunDiagnostics( handle ); } if( tidyResult > 1 ) { if( !tidyOptSetBool( handle, TidyForceOutput, yes ) ) { tidyResult = -1; } } if( tidyResult >= 0 ) { tidyResult = tidySaveBuffer( handle, &outputBuffer ); } if( tidyResult > 0 ) { std::clog << "*********************************" << std::endl; std::clog << "HTMLTidy: Diagnostics of libtidy:" << std::endl; std::clog << errorBuffer.bp; std::clog << "*********************************" << std::endl; } else if( tidyResult < 0 ) { std::stringstream sstrTidyResult; sstrTidyResult << tidyResult; throw std::runtime_error( "HTMLTidy: A severe error occured while tidying up the received document (" + sstrTidyResult.str() + ")." ); } resultDocument.reserve( outputBuffer.size ); // avoid frequent (re-)allocations for( unsigned int i = 0; i < outputBuffer.size; i++ ) { resultDocument.insert( resultDocument.end(), static_cast< char >( *(outputBuffer.bp + i) ) ); } tidyBufFree( &outputBuffer ); tidyBufFree( &errorBuffer ); }
void TIDY_CALL freeFileSource( TidyInputSource* inp, Bool closeIt ) { FileSource* fin = (FileSource*) inp->sourceData; if ( closeIt && fin && fin->fp ) fclose( fin->fp ); tidyBufFree( &fin->unget ); MemFree( fin ); }
bool CCFHtmlTidy::TidyMain(const char* pSourceIn, const char* pOptions, std::string &strOut, std::string &strErr) { TidyBuffer output; TidyBuffer errbuf; int rc = -1; Bool ok = yes; TidyDoc tdoc = tidyCreate(); // Initialize "document" tidyBufInit(&output); tidyBufInit(&errbuf); TidyOptionsSet(tidyDocToImpl(tdoc), pOptions); if (ok) rc = tidySetErrorBuffer(tdoc, &errbuf); // Capture diagnostics if (rc >= 0) rc = tidyParseString(tdoc, pSourceIn); // Parse the input if (rc >= 0) rc = tidyCleanAndRepair(tdoc); // Tidy it up! if (rc >= 0) rc = tidyRunDiagnostics(tdoc); // Kvetch //if ( rc > 1 ) // If error, force output. // rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); if (rc >= 0) rc = tidySaveBuffer(tdoc, &output); // Pretty Print if (rc >= 0) { if (output.bp) { strOut = reinterpret_cast<char const*>(output.bp); } } strErr = reinterpret_cast<char const*>(errbuf.bp); std::string strEmpty = "No warnings or errors were found.\n\n"; if (0 == strEmpty.compare(strErr)) { strErr.clear(); } tidyBufFree(&output); tidyBufFree(&errbuf); tidyRelease(tdoc); return true; }
QString tidy(QString input) // take html code and return it converted to xhtml code { // the following code is (c) Charles Reitzel and Dave Raggett, see the package tidy TidyBuffer output = {0}; TidyBuffer errbuf = {0}; QString result; int rc = -1; Bool ok; TidyDoc tdoc = tidyCreate(); // Initialize "document" ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); // Convert to XHTML if ( ok ) rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics tidySetCharEncoding( tdoc, "utf8" ); if ( rc >= 0 ) rc = tidyParseString( tdoc, input.toUtf8().constData() ); // Parse the input if ( rc >= 0 ) rc = tidyCleanAndRepair( tdoc ); // Tidy it up! if ( rc >= 0 ) rc = tidyRunDiagnostics( tdoc ); // Kvetch if ( rc > 1 ) // If error, force output. rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); if ( rc >= 0 ) rc = tidySaveBuffer( tdoc, &output ); // Pretty Print if ( rc >= 0 ) { char* outputstring; // content of the outputfile // find out length of outputstring int length=0; // length of outputstring byte* string=output.bp; while (*string) { string++; length++; } outputstring=(char*)malloc(length); snprintf(outputstring,length,"%s",output.bp); result=QString::fromUtf8(outputstring,length); } else printf( "A severe error (\%d) occurred.\\n", rc ); tidyBufFree( &output ); tidyBufFree( &errbuf ); tidyRelease( tdoc ); result=result.replace("ö","ö"); return result; }
void tidy(std::string &input) { TidyBuffer output = {0}; TidyBuffer errbuf = {0}; TidyDoc tdoc = tidyCreate(); tidyOptSetBool(tdoc, TidyXhtmlOut, yes); tidySetErrorBuffer(tdoc, &errbuf); // Capture diagnostics tidyParseString(tdoc, input.c_str()); tidyCleanAndRepair(tdoc); tidySaveBuffer(tdoc, &output); input = std::string((const char*)output.bp); tidyBufFree(&output); tidyBufFree(&errbuf); tidyRelease(tdoc); }
bool HTidyInterface::formatSource( const char* textIn, CString &strTidy, CString &strMsg ) { TidyBuffer output; TidyBuffer errbuf; int rc = -1; Bool ok = yes; TidyDoc tdoc = tidyCreate(); // Initialize "document" tidyBufInit(&output); tidyBufInit(&errbuf); InitTidyDefault(tdoc); SetTidyConfig(tdoc); if ( ok ) rc = tidySetErrorBuffer(tdoc, &errbuf); // Capture diagnostics if ( rc >= 0 ) rc = tidyParseString(tdoc, textIn); // Parse the input if ( rc >= 0 ) rc = tidyCleanAndRepair(tdoc); // Tidy it up! if ( rc >= 0 ) rc = tidyRunDiagnostics(tdoc); // Kvetch //if ( rc > 1 ) // If error, force output. // rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); if ( rc >= 0 ) rc = tidySaveBuffer(tdoc, &output); // Pretty Print if ( rc >= 0 ) { strTidy = reinterpret_cast< char const* >(output.bp); } strMsg = reinterpret_cast< char const* >(errbuf.bp); CString strEmpty = _T("No warnings or errors were found.\r\n\r\n"); if (0 == strEmpty.Compare(strMsg)) { strMsg.Empty(); } tidyBufFree(&output); tidyBufFree(&errbuf); tidyRelease(tdoc); return true; }
// formats the 'dom' tree into HTML output. int lua_tidy_saveString(lua_State *L) { pTidy t = toTidy(L,1); TidyBuffer output; tidyBufInit(&output); lua_pushnumber(L, tidySaveBuffer(t->tdoc, &output)); lua_pushlstring(L, (char*)output.bp, output.size); tidyBufFree( &output ); return 1; }
void CCaHtmlParse::__GetAirPortCode(CStringA & straDCode, CStringA & straACode, const TidyDoc & tdoc, const TidyNode & tdNode) { CStringA straRet; CStringA straSha("上海虹桥"); CStringA straPvg("上海浦东"); CStringA straPek("北京首都"); CStringA straNay("北京南苑"); straDCode = ""; straACode = ""; TidyBuffer text = {0}; tidyBufInit(&text); TidyNodeType type = tidyNodeGetType(tdNode); tidyNodeGetText(tdoc, tdNode, &text); straRet.Format("%s",text.bp); straRet.TrimLeft(); CStringA straKey("<br />");//<br />后有回车换行符 int iPos = straRet.Find(straKey); CStringA straDCity = straRet.Mid(4, iPos-4); if (-1 != straDCity.Find(straSha)) straDCode = "SHA"; else if (-1 != straDCity.Find(straPvg)) straDCode = "PVG"; else if (-1 != straDCity.Find(straPek)) straDCode = "PEK"; else if(-1 != straDCity.Find(straNay)) straDCode = "NAY"; else { } //取到达机场,<br />后有回车换行符 straRet = straRet.Mid(iPos+straKey.GetLength()); straRet.Remove(0x0d);//去掉回车 straRet.Remove(0x0a);//去掉换行 int iEndPos = straRet.Find("</td>"); CStringA straACity = straRet.Left(iEndPos); if (-1 != straACity.Find(straSha)) straACode = "SHA"; else if (-1 != straACity.Find(straPvg)) straACode = "PVG"; else if (-1 != straACity.Find(straPek)) straACode = "PEK"; else if(-1 != straACity.Find(straNay)) straACode = "NAY"; else { } tidyBufFree(&text); }
/* {{{ proto string tidy_get_output() Return a string representing the parsed tidy markup */ static PHP_FUNCTION(tidy_get_output) { TidyBuffer output; TIDY_FETCH_OBJECT; tidyBufInit(&output); tidySaveBuffer(obj->ptdoc->doc, &output); FIX_BUFFER(&output); RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0); tidyBufFree(&output); }
int main(int argc, char **argv ) { const char* input = "<title>Hello</title><p>World!"; TidyBuffer output = {0}; TidyBuffer errbuf = {0}; int rc = -1; Bool ok; // Initialize "document" TidyDoc tdoc = tidyCreate(); printf( "Tidying:\t%s\n", input ); // Convert to XHTML ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); if ( ok ) rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics if ( rc >= 0 ) rc = tidyParseString( tdoc, input ); // Parse the input if ( rc >= 0 ) rc = tidyCleanAndRepair( tdoc ); // Tidy it up! if ( rc >= 0 ) rc = tidyRunDiagnostics( tdoc ); // Kvetch if ( rc > 1 ) // If error, force output. rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); if ( rc >= 0 ) rc = tidySaveBuffer( tdoc, &output ); // Pretty Print if ( rc >= 0 ) { if ( rc > 0 ) printf( "\nDiagnostics:\n\n%s", errbuf.bp ); printf( "\nAnd here is the result:\n\n%s", output.bp ); } else printf( "A severe error (%d) occurred.\n", rc ); tidyBufFree( &output ); tidyBufFree( &errbuf ); tidyRelease( tdoc ); return rc; }
// garbage collection, make sure we mark all opened nodes as expired. int lua_tidy_gc ( lua_State *L ) { pTidy t = toTidy(L,1); doc_clear_all_nodes(t); // all nodes are marked as expired. tidyRelease( t->tdoc ); tidyBufFree( &t->errbuf ); t->tdoc = NULL; return 0; }
// quick and dirty shortcut function. int lua_tidy_easyClean ( lua_State *L ) { TidyBuffer output; TidyBuffer errbuf; int rc; pTidy t; const char * input; tidyBufInit(&output); tidyBufInit(&errbuf); rc = -1; t = toTidy(L,1); input = lua_tostring(L,2); rc = tidySetErrorBuffer( t->tdoc, &errbuf ); if ( rc >= 0 ) rc = tidyParseString( t->tdoc, input ); if ( rc >= 0 ) rc = tidyCleanAndRepair( t->tdoc ); if ( rc >= 0 ) rc = tidyRunDiagnostics( t->tdoc ); if ( rc >= 0 ) rc = tidySaveBuffer( t->tdoc, &output ); lua_pushlstring(L, (char*)output.bp,output.size); if ( rc != 0 ) lua_pushlstring(L, (char*)errbuf.bp,errbuf.size); else lua_pushnil(L); lua_pushnumber(L, rc); tidyBufFree( &output ); tidyBufFree( &errbuf ); return 3; }
char *copyTidyNodeValue(TidyNode tnode, TidyDoc tdoc) { TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetValue(tdoc,tnode,&buf); char *str = (char *)xmalloc(buf.size+1); memcpy(str,buf.bp,buf.size); str[buf.size] = '\0'; tidyBufFree(&buf); return str; }
std::string cleanHTML (std::string html) { TidyDoc tidyDoc = tidyCreate(); TidyBuffer tidyOutputBuffer = {0}; // Configure Tidy // The flags tell Tidy to output XML and disable showing warnings bool configSuccess = tidyOptSetBool(tidyDoc, TidyXmlOut, yes) && tidyOptSetBool(tidyDoc, TidyQuiet, yes) && tidyOptSetBool(tidyDoc, TidyNumEntities, yes) && tidyOptSetBool(tidyDoc, TidyShowWarnings, no); tidyOptSetValue(tidyDoc,TidyForceOutput,"true"); int tidyResponseCode = -1; // Parse input if (configSuccess) tidyResponseCode = tidyParseString(tidyDoc, html.c_str()); // Process HTML if (tidyResponseCode >= 0) tidyResponseCode = tidyCleanAndRepair(tidyDoc); // Output the HTML to our buffer if (tidyResponseCode >= 0) tidyResponseCode = tidySaveBuffer(tidyDoc, &tidyOutputBuffer); // Any errors from Tidy? if (tidyResponseCode < 0) throw ("Tidy encountered an error while parsing an HTML response. Tidy response code: " + tidyResponseCode); // Grab the result from the buffer and then free Tidy's memory std::string tidyResult = (char*)tidyOutputBuffer.bp; tidyBufFree(&tidyOutputBuffer); tidyRelease(tidyDoc); return tidyResult; }
static void tidy_object_free_storage(zend_object *object) { PHPTidyObj *intern = php_tidy_fetch_object(object); zend_object_std_dtor(&intern->std); if (intern->ptdoc) { intern->ptdoc->ref_count--; if (intern->ptdoc->ref_count <= 0) { tidyBufFree(intern->ptdoc->errbuf); efree(intern->ptdoc->errbuf); tidyRelease(intern->ptdoc->doc); efree(intern->ptdoc); } } }
FeedRecord* UCHome_Main_SiteConst::parse_note(void *state_data, TidyDoc doc, TidyNode node) { FeedRecord * rec = NULL; QString note; TidyBuffer tbuf; tidyBufInit(&tbuf); tidyNodeGetText(doc, node, &tbuf); note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp)); rec = new FeedRecord(); rec->content = this->rewrite_relative_link(note); md5CheckSum((char*)tbuf.bp, tbuf.size, rec->md5sum); tidyBufFree(&tbuf); //q_debug()<<"Orig:"<<note; return rec; }
int tidyDocSaveString( TidyDocImpl* doc, tmbstr buffer, uint* buflen ) { uint outenc = cfg( doc, TidyOutCharEncoding ); uint nl = cfg( doc, TidyNewline ); TidyBuffer outbuf = {0}; StreamOut* out = TY_(BufferOutput)( &outbuf, outenc, nl ); int status = tidyDocSaveStream( doc, out ); if ( outbuf.size > *buflen ) status = -ENOMEM; else memcpy( buffer, outbuf.bp, outbuf.size ); *buflen = outbuf.size; tidyBufFree( &outbuf ); MemFree( out ); return status; }
void CCaHtmlParse::__GetFlightStartTime(CStringA & strFlightStartTime, const TidyDoc & tdoc, const TidyNode & tdNode) { CStringA straRet; strFlightStartTime = ""; TidyBuffer text = {0}; tidyBufInit(&text); TidyNodeType type = tidyNodeGetType(tdNode); tidyNodeGetText(tdoc, tdNode, &text); straRet.Format("%s",text.bp); CStringA straKey("\">"); int iStartPos = straRet.Find(straKey); int iEndPos = straRet.Find("</strong>"); iStartPos = iStartPos+straKey.GetLength(); strFlightStartTime = straRet.Mid(iStartPos, iEndPos-iStartPos); tidyBufFree(&text); }
static zend_object *tidy_object_new(zend_class_entry *class_type, zend_object_handlers *handlers, tidy_obj_type objtype) { PHPTidyObj *intern; intern = ecalloc(1, sizeof(PHPTidyObj) + zend_object_properties_size(class_type)); zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); switch(objtype) { case is_node: break; case is_doc: intern->ptdoc = emalloc(sizeof(PHPTidyDoc)); intern->ptdoc->doc = tidyCreate(); intern->ptdoc->ref_count = 1; intern->ptdoc->initialized = 0; intern->ptdoc->errbuf = emalloc(sizeof(TidyBuffer)); tidyBufInit(intern->ptdoc->errbuf); if (tidySetErrorBuffer(intern->ptdoc->doc, intern->ptdoc->errbuf) != 0) { tidyBufFree(intern->ptdoc->errbuf); efree(intern->ptdoc->errbuf); tidyRelease(intern->ptdoc->doc); efree(intern->ptdoc); efree(intern); php_error_docref(NULL, E_ERROR, "Could not set Tidy error buffer"); } tidyOptSetBool(intern->ptdoc->doc, TidyForceOutput, yes); tidyOptSetBool(intern->ptdoc->doc, TidyMark, no); TIDY_SET_DEFAULT_CONFIG(intern->ptdoc->doc); tidy_add_default_properties(intern, is_doc); break; } intern->std.handlers = handlers; return &intern->std; }