4
* Copyright (c) Chris Putnam 2007-2010
6
* Source code released under the GPL
13
#include "newstr_conv.h"
15
#include "xml_encoding.h"
18
xml_getencodingr( xml *node )
21
int n = CHARSET_UNKNOWN, m;
22
if ( xml_tagexact( node, "xml" ) ) {
23
s = xml_getattrib( node, "encoding" );
25
if ( !strcasecmp( s->data, "UTF-8" ) )
27
else n = get_charset( s->data );
28
if ( n==CHARSET_UNKNOWN ) {
29
fprintf( stderr, "Warning: did not recognize "
30
"encoding '%s'\n", s->data );
35
m = xml_getencodingr( node->down );
36
if ( m!=CHARSET_UNKNOWN ) n = m;
39
m = xml_getencodingr( node->next );
40
if ( m!=CHARSET_UNKNOWN ) n = m;
46
xml_getencoding( newstr *s )
50
int file_charset = CHARSET_UNKNOWN;
52
p = strstr( s->data, "<?xml" );
53
if ( !p ) p = strstr( s->data, "<?XML" );
55
q = strstr( p, "?>" );
57
newstr_init( &descriptor );
58
newstr_segcpy( &descriptor, p, q+2 );
59
xml_init( &descriptxml );
60
xml_tree( descriptor.data, &descriptxml );
61
file_charset = xml_getencodingr( &descriptxml );
62
xml_free( &descriptxml );
63
newstr_free( &descriptor );
64
newstr_segdel( s, p, q+2 );