version 1.14, 2010/06/26 17:56:43 |
version 1.15, 2010/07/16 00:34:33 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
|
|
|
|
int |
int |
mandoc_eos(const char *p, size_t sz) |
mandoc_eos(const char *p, size_t sz, int enclosed) |
{ |
{ |
|
const char *q; |
|
int found = 0; |
|
|
if (0 == sz) |
if (0 == sz) |
return(0); |
return(0); |
|
|
* propogate outward. |
* propogate outward. |
*/ |
*/ |
|
|
for ( ; sz; sz--) { |
for (q = p + sz - 1; q >= p; q--) { |
switch (p[(int)sz - 1]) { |
switch (*q) { |
case ('\"'): |
case ('\"'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('\''): |
case ('\''): |
|
|
case (']'): |
case (']'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (')'): |
case (')'): |
|
if (0 == found) |
|
enclosed = 1; |
break; |
break; |
case ('.'): |
case ('.'): |
/* Escaped periods. */ |
|
if (sz > 1 && '\\' == p[(int)sz - 2]) |
|
return(0); |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('!'): |
case ('!'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('?'): |
case ('?'): |
return(1); |
found = 1; |
|
break; |
default: |
default: |
return(0); |
return(found && (!enclosed || isalnum(*q))); |
} |
} |
} |
} |
|
|
return(0); |
return(found && !enclosed); |
} |
} |
|
|
|
|