Skip to content

Commit

Permalink
* Modified shortref and CRLF handling to assume the new canonised input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker committed May 24, 2001
1 parent a8634ca commit 470fbe4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
11 changes: 11 additions & 0 deletions Test/crlf.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE text [
<!ENTITY new.p STARTTAG "p">
<!SHORTREF for.text
"&#RS;&#RE;" new.p>
<!ELEMENT text O O (p+)>
<!USEMAP for.text text>
<!ELEMENT p O O (#PCDATA)>
]>
par 1

par 2
2 changes: 2 additions & 0 deletions Test/ok/crlf.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[element(text, [], [element(p, [], ['par 1']), element(p, [], ['par 2'])])].
[].
103 changes: 47 additions & 56 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,11 +1712,6 @@ match_map(dtd *dtd, dtd_map *map, int len, ichar *data)
e--;
continue;
}
if ( *m == '\r' && *e == '\n' ) /* dubious */
{ m--;
e--;
continue;
}
if ( *m == CHR_DBLANK )
{ if ( e>data && HasClass(dtd, *e, CH_WHITE) )
e--;
Expand All @@ -1740,50 +1735,46 @@ match_map(dtd *dtd, dtd_map *map, int len, ichar *data)

static void
match_shortref(dtd_parser *p)
{
/* condition in caller */
if ( p->map /*&& p->map->ends[p->cdata->data[p->cdata->size-1]]*/ )
{ dtd_map *map;

for(map = p->map->map; map; map = map->next)
{ int len;

if ( (len=match_map(p->dtd, map,
p->cdata->size, (ichar *)p->cdata->data)) )
{ p->cdata->size -= len;

if ( p->cdata_must_be_empty )
{ int blank = TRUE;
const ichar *s;
int i;

for(s = p->cdata->data, i=0; i++ < p->cdata->size; s++)
{ if ( !HasClass(p->dtd, *s, CH_BLANK) )
{ blank = FALSE;
break;
}
}
{ dtd_map *map;

p->blank_cdata = blank;
for(map = p->map->map; map; map = map->next)
{ int len;

if ( (len=match_map(p->dtd, map,
p->cdata->size, (ichar *)p->cdata->data)) )
{ p->cdata->size -= len;

if ( p->cdata_must_be_empty )
{ int blank = TRUE;
const ichar *s;
int i;

for(s = p->cdata->data, i=0; i++ < p->cdata->size; s++)
{ if ( !HasClass(p->dtd, *s, CH_BLANK) )
{ blank = FALSE;
break;
}
}

WITH_CLASS(p, EV_SHORTREF,
{ sgml_cplocation(&p->startloc, &p->location);
p->startloc.charpos -= len;
p->startloc.linepos -= len;
if ( p->startloc.linepos < 0 )
{ p->startloc.line--;
p->startloc.linepos = 0; /* not correct! */
}
DEBUG(printf("%d-%d: Matched map '%s' --> %s, len = %d\n",
p->startloc.charpos,
p->location.charpos,
map->from, map->to->name, len));

process_entity(p, map->to->name);
}) /* TBD: optimise */
break;
p->blank_cdata = blank;
}

WITH_CLASS(p, EV_SHORTREF,
{ sgml_cplocation(&p->startloc, &p->location);
p->startloc.charpos -= len;
p->startloc.linepos -= len;
if ( p->startloc.linepos < 0 )
{ p->startloc.line--;
p->startloc.linepos = 0; /* not correct! */
}
DEBUG(printf("%d-%d: Matched map '%s' --> %s, len = %d\n",
p->startloc.charpos,
p->location.charpos,
map->from, map->to->name, len));

process_entity(p, map->to->name);
}) /* TBD: optimise */
break;
}
}
}
Expand Down Expand Up @@ -4201,21 +4192,21 @@ add_cdata(dtd_parser *p, int chr)
p->blank_cdata = FALSE;
}

if ( chr == '\n' )
{ if ( p->map && p->map->ends['\r'] &&
(buf->size == 0 || buf->data[buf->size-1] != '\r') )
{ add_ocharbuf(buf, '\r');
match_shortref(p);
}

if ( buf->size > 0 && buf->data[buf->size-1] == '\r' )
buf->size--;
}

add_ocharbuf(buf, chr);

if ( p->map && p->map->ends[chr] )
match_shortref(p);

if ( chr == '\n' ) /* dubious. Whould we do that */
{ int sz; /* here or in the space-handling? */

if ( (sz=buf->size) > 1 &&
buf->data[sz-1] == LF &&
buf->data[sz-2] == CR )
{ buf->data[sz-2] = LF;
buf->size--;
}
}
}
}

Expand Down

0 comments on commit 470fbe4

Please sign in to comment.