improve transcode error printing

This commit is contained in:
dockes
2007-05-30 12:31:19 +00:00
parent 441820d1ef
commit c5ebe00247
6 changed files with 35 additions and 16 deletions
+20 -4
View File
@@ -49,6 +49,7 @@ bool MimeHandlerHtml::set_document_file(const string &fn)
LOGINFO(("textHtmlToDoc: cant read: %s\n", fn.c_str()));
return false;
}
m_filename = fn;
return set_document_string(otext);
}
@@ -64,8 +65,13 @@ bool MimeHandlerHtml::next_document()
if (m_havedoc == false)
return false;
m_havedoc = false;
// If set_doc(fn), take note of file name.
string fn = m_filename;
m_filename.erase();
string charset = m_defcharset;
LOGDEB(("textHtmlToDoc: next_document. defcharset: %s\n",charset.c_str()));
LOGDEB(("textHtmlToDoc: next_document. defcharset: %s\n",
charset.c_str()));
// - We first try to convert from the default configured charset
// (which may depend of the current directory) to utf-8. If this
@@ -82,13 +88,23 @@ bool MimeHandlerHtml::next_document()
LOGDEB(("Html::mkDoc: pass %d\n", pass));
MyHtmlParser p;
// Try transcoding. If it fails, use original text.
if (!transcode(m_html, transcoded, charset, "UTF-8")) {
LOGERR(("textHtmlToDoc: transcode failed from cs '%s' to UTF-8\n",
charset.c_str()));
int ecnt;
if (!transcode(m_html, transcoded, charset, "UTF-8", &ecnt)) {
LOGDEB(("textHtmlToDoc: transcode failed from cs '%s' to UTF-8 for"
"[%s]", charset.c_str(), fn.empty()?"unknown":fn.c_str()));
transcoded = m_html;
// We don't know the charset, at all
p.ocharset = p.charset = charset = "";
} else {
if (ecnt) {
if (pass == 0) {
LOGDEB(("textHtmlToDoc: init transcode had %d errors for "
"[%s]", ecnt, fn.empty()?"unknown":fn.c_str()));
} else {
LOGERR(("textHtmlToDoc: final transcode had %d errors for "
"[%s]", ecnt, fn.empty()?"unknown":fn.c_str()));
}
}
// ocharset has the putative source charset, transcoded is now
// in utf-8
p.ocharset = charset;
+2 -1
View File
@@ -16,7 +16,7 @@
*/
#ifndef _HTML_H_INCLUDED_
#define _HTML_H_INCLUDED_
/* @(#$Id: mh_html.h,v 1.9 2006-12-16 15:39:54 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: mh_html.h,v 1.10 2007-05-30 12:31:19 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
@@ -38,6 +38,7 @@ class MimeHandlerHtml : public RecollFilter {
}
virtual bool next_document();
private:
string m_filename;
string m_html;
};