~ubuntu-branches/ubuntu/hardy/totem-pl-parser/hardy-proposed

« back to all changes in this revision

Viewing changes to plparse/xmllexer.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-01-07 21:49:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080107214925-r0oz12jw3rk9gvcx
Tags: 2.21.90-0ubuntu1
* New upstream release
  - Depend on Camel and newer glibs to parse dates from Atom and RSS feeds
  - Handle Byte-Order-Marks in Podcasts
  - Fix for redirections on Apple's trailer pages
  - Fix relative links when two paths have the same prefix
  - Don't copy buffers when checking for file types
* debian/control{.in};
  - Build depend on libcamel
  - Bump Standards-Version to 3.7.3
* Updated shlibs
* Added watch file
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 * You should have received a copy of the GNU Library General Public
17
17
 * License along with the Gnome Library; see the file COPYING.LIB.  If not,
18
 
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 
 * Boston, MA 02111-1307, USA.
20
 
 *
21
 
 *  $Id: xmllexer.c,v 1.13 2007/03/04 16:19:12 hadess Exp $
22
 
 *
 
18
 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 
19
 * Floor, Boston, MA 02110, USA
23
20
 */
24
21
 
25
22
#define LOG_MODULE "xmllexer"
43
40
#include <iconv.h>
44
41
#endif
45
42
 
 
43
#include "bswap.h"
 
44
 
46
45
/* private constants*/
47
46
 
48
47
/* private global variables */
50
49
static int lexbuf_size = 0;
51
50
static int lexbuf_pos  = 0;
52
51
static int in_comment  = 0;
 
52
static char *lex_malloc = NULL;
 
53
 
 
54
enum utf { UTF32BE, UTF32LE, UTF16BE, UTF16LE };
 
55
 
 
56
static void lex_convert (const char * buf, int size, enum utf utf)
 
57
{
 
58
  char *utf8 = malloc (size * (utf >= UTF16BE ? 3 : 6) + 1);
 
59
  char *bp = utf8;
 
60
  while (size > 0)
 
61
  {
 
62
    uint32_t c = 0;
 
63
    switch (utf)
 
64
    {
 
65
    case UTF32BE: c = _X_BE_32 (buf); buf += 4; break;
 
66
    case UTF32LE: c = _X_LE_32 (buf); buf += 4; break;
 
67
    case UTF16BE: c = _X_BE_16 (buf); buf += 2; break;
 
68
    case UTF16LE: c = _X_LE_16 (buf); buf += 2; break;
 
69
    }
 
70
    if (!c)
 
71
      break; /* embed a NUL, get a truncated string */
 
72
    if (c < 128)
 
73
      *bp++ = c;
 
74
    else
 
75
    {
 
76
      int count = (c >= 0x04000000) ? 5 :
 
77
                  (c >= 0x00200000) ? 4 :
 
78
                  (c >= 0x00010000) ? 3 :
 
79
                  (c >= 0x00000800) ? 2 : 1;
 
80
      *bp = (char)(0x1F80 >> count);
 
81
      count *= 6;
 
82
      *bp++ |= c >> count;
 
83
      while ((count -= 6) >= 0)
 
84
        *bp++ = 128 | ((c >> count) & 0x3F);
 
85
    }
 
86
  }
 
87
  *bp = 0;
 
88
  lexbuf_size = bp - utf8;
 
89
  lexbuf = lex_malloc = realloc (utf8, lexbuf_size + 1);
 
90
}
53
91
 
54
92
static enum {
55
93
  NORMAL,
58
96
} lex_mode = NORMAL;
59
97
 
60
98
void lexer_init(const char * buf, int size) {
 
99
  static const char boms[] = { 0xFF, 0xFE, 0, 0, 0xFE, 0xFF },
 
100
                    bom_utf8[] = { 0xEF, 0xBB, 0xBF };
 
101
 
 
102
  free (lex_malloc);
 
103
  lex_malloc = NULL;
 
104
 
61
105
  lexbuf      = buf;
62
106
  lexbuf_size = size;
 
107
 
 
108
  if (size >= 4 && !memcmp (buf, boms + 2, 4))
 
109
    lex_convert (buf + 4, size - 4, UTF32BE);
 
110
  else if (size >= 4 && !memcmp (buf, boms, 4))
 
111
    lex_convert (buf + 4, size - 4, UTF32LE);
 
112
  else if (size >= 3 && !memcmp (buf, bom_utf8, 3))
 
113
  {
 
114
    lexbuf += 3;
 
115
    lexbuf_size -= 3;
 
116
  }
 
117
  else if (size >= 2 && !memcmp (buf, boms + 4, 2))
 
118
    lex_convert (buf + 2, size - 2, UTF16BE);
 
119
  else if (size >= 2 && !memcmp (buf, boms, 2))
 
120
    lex_convert (buf + 2, size - 2, UTF16LE);
 
121
 
63
122
  lexbuf_pos  = 0;
64
123
  lex_mode    = NORMAL;
65
124
  in_comment  = 0;