On Sun, 2009-04-05 at 19:03 +0200, Mark wrote:

> For now, I suppose HTML content is the most relevant, unless XML content
> is parsed differently? I could try calling detect_encoding() in
> render/libxml_binding.c

No. XML content isn't (yet) parsed differently. Additionally, the parser
will have been destroyed, so you can't call binding_get_encoding.
detect_encoding() is private to the libxml2 parser binding (this parser
binding will be disappearing imminently, as hubbub is far superior) so
cannot be called from anywhere else.

In nsgtk_source_dialog_init, you have the following:

> //may need to g_utf_validate() then strcpy the url              
> thiswindow->url = bw->current_content->url;

All strings in the core are UTF-8 encoded.

> char * closing = strstr(bw->current_content->source_data, "</html>");
> if (!closing) {
>         closing = strstr(bw->current_content->source_data, "</HTML>");
> }
> if (closing)
>         *(closing + 7) = 0;
> 
> int len = strlen(bw->current_content->source_data);
> *(bw->current_content->source_data + len) = 0;

Ugh! If you want the length (in bytes) of the source data, use
content->source_size. The above needlessly corrupts the source data, and
will fail for all pages with source after the </html>. It also doesn't
handle </Html>, for example. All-in-all, not very nice.

> char ** data = (char **)malloc(sizeof(char *));
> utf8_from_enc(bw->current_content->source_data,
>                 bw->current_content->data.html.encoding,
>                 strlen(bw->current_content->source_data), data);
> thiswindow->data = *data;

The following is far cleaner:

utf8_from_enc(bw->current_content->source_data,
                bw->current_content->data.html.encoding,
                bw->current_content->source_size,
                &thiswindow->data);

You must check the return value from utf8_from_enc, too.

> char *title = malloc(strlen(bw->current_content->url) + 10);

It's clearer to use "+ SLEN("Source of ") + 1" than "+ 10".

> strcpy(title, "Source of ");
> strcat(title, bw->current_content->url);

Consider using memcpy here -- it's faster. Alternatively, sprintf(title,
"Source of %s", bw->current_content->url); is clearer.
         
> gtk_window_set_title(wndSource, title);

Where is title freed?

I'll leave the rest for someone else, as it's GTK specific.


J.


Reply via email to