source: trunk/src/charsets/ext_ascii_8.c @ 7

Last change on this file since 7 was 7, checked in by cameron, 11 years ago

Reference extraction; checking ]]> in text; < in atts.

File size: 1.7 KB
Line 
1/*  ext_ascii_8.c - Lexer object for 8-bit ASCII-based character sets.
2    Copyright (c) 2007, Robert D. Cameron.
3    Licensed to the public under the Open Software License 3.0.
4    Licensed to International Characters, Inc., under the Academic
5    Free License 3.0.
6
7*/
8#include "ext_ascii_8.h"
9
10Ext_ASCII_8_Lexer::Ext_ASCII_8_Lexer(XML_Buffer *b, ParallelStreamSet *p) : Lexer(b, p) {
11}
12
13
14#define min(a,b) ((a) < (b) ? (a) : (b))
15
16const int CODE_UNIT_BYTES = 1;  /* 8-bit code units in this file. */
17const int BYTE_STREAM_SIZE = (BUFFER_BLOCKS * BLOCKSIZE + LOOKAHEAD_POSITIONS) * CODE_UNIT_BYTES;
18
19int Ext_ASCII_8_Lexer::AdvanceBuffer(int newpos) {
20  int new_blocks, new_packs;
21  unsigned char * buf_ptr = xml_buf->GetBytePtr(newpos * CODE_UNIT_BYTES);
22  BytePack * src_data = (BytePack *) buf_ptr;
23  int avail_bytes = xml_buf->PrepareBytes(BYTE_STREAM_SIZE);
24#ifdef BUFFER_PROFILING
25  start_BOM_interval(bitstream_timer);
26#endif
27  if (avail_bytes >= BYTE_STREAM_SIZE) {
28    new_blocks = BUFFER_BLOCKS;
29    new_packs = new_blocks * 8 + 1;
30    for (int pk = 0; pk < new_packs; pk++) {
31      parsing_engine_data->x8data[pk] = sisd_load_unaligned(&src_data[pk]);
32    }
33  }
34  else {
35    new_blocks = min(BUFFER_BLOCKS, (avail_bytes + BLOCKSIZE - 1)/BLOCKSIZE);
36    new_packs = new_blocks * 8 + 1;
37    for (int pk = 0; pk < new_packs; pk++) {
38      parsing_engine_data->x8data[pk] = sisd_load_unaligned(&src_data[pk]);
39    }
40    ((unsigned char *) parsing_engine_data->x8data)[avail_bytes] = ']';
41  }
42  ComputeLexicalItemStreams(new_blocks);
43  return avail_bytes/CODE_UNIT_BYTES;
44}
45
46int Ext_ASCII_8_Lexer::BOM_size(int rel_pos) {
47  if (s3int32((unsigned char *) &parsing_engine_data->x8data) == c3int32(0xEF, 0xBB, 0xBF))
48    return 3;
49  else return 0;
50}
Note: See TracBrowser for help on using the repository browser.