|
Jaroslav Škarvada |
573565 |
--- a/src/search.c 2007-10-01 14:47:55.000000000 +0200
|
|
Jaroslav Škarvada |
573565 |
+++ b/src/search.c 2007-09-30 23:38:45.000000000 +0200
|
|
Jaroslav Škarvada |
573565 |
@@ -282,6 +282,7 @@
|
|
Jaroslav Škarvada |
573565 |
static int use_dfa_checked = 0;
|
|
Jaroslav Škarvada |
573565 |
size_t i, ret_val;
|
|
Jaroslav Škarvada |
573565 |
#ifdef MBS_SUPPORT
|
|
Jaroslav Škarvada |
573565 |
+ const char *last_char = NULL;
|
|
Jaroslav Škarvada |
573565 |
int mb_cur_max = MB_CUR_MAX;
|
|
Jaroslav Škarvada |
573565 |
mbstate_t mbs;
|
|
Jaroslav Škarvada |
573565 |
memset (&mbs, '\0', sizeof (mbstate_t));
|
|
Jaroslav Škarvada |
573565 |
@@ -338,6 +341,8 @@
|
|
Jaroslav Škarvada |
573565 |
while (bytes_left)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
size_t mlen = mbrlen (beg, bytes_left, &mbs);
|
|
Jaroslav Škarvada |
573565 |
+
|
|
Jaroslav Škarvada |
573565 |
+ last_char = beg;
|
|
Jaroslav Škarvada |
573565 |
if (mlen == (size_t) -1 || mlen == 0)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
/* Incomplete character: treat as single-byte. */
|
|
Jaroslav Škarvada |
573565 |
@@ -398,6 +403,8 @@
|
|
Jaroslav Škarvada |
573565 |
while (bytes_left)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
size_t mlen = mbrlen (beg, bytes_left, &mbs);
|
|
Jaroslav Škarvada |
573565 |
+
|
|
Jaroslav Škarvada |
573565 |
+ last_char = beg;
|
|
Jaroslav Škarvada |
573565 |
if (mlen == (size_t) -1 || mlen == 0)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
/* Incomplete character: treat as single-byte. */
|
|
Jaroslav Škarvada |
573565 |
@@ -475,10 +483,84 @@
|
|
Jaroslav Škarvada |
573565 |
if (match_words)
|
|
Jaroslav Škarvada |
573565 |
while (match <= best_match)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
+ int lword_match = 0;
|
|
Jaroslav Škarvada |
573565 |
+ if (match == buf)
|
|
Jaroslav Škarvada |
573565 |
+ lword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ assert (start > 0);
|
|
Jaroslav Škarvada |
573565 |
+#ifdef MBS_SUPPORT
|
|
Jaroslav Škarvada |
573565 |
+ if (mb_cur_max > 1)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ const char *s;
|
|
Jaroslav Škarvada |
573565 |
+ int mr;
|
|
Jaroslav Škarvada |
573565 |
+ wchar_t pwc;
|
|
Jaroslav Škarvada |
573565 |
+ if (using_utf8)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ s = match - 1;
|
|
Jaroslav Škarvada |
573565 |
+ while (s > buf
|
|
Jaroslav Škarvada |
573565 |
+ && (unsigned char) *s >= 0x80
|
|
Jaroslav Škarvada |
573565 |
+ && (unsigned char) *s <= 0xbf)
|
|
Jaroslav Škarvada |
573565 |
+ --s;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+ s = last_char;
|
|
Jaroslav Škarvada |
573565 |
+ mr = mbtowc (&pwc, s, match - s);
|
|
Jaroslav Škarvada |
573565 |
+ if (mr <= 0)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ memset (&mbs, '\0', sizeof (mbstate_t));
|
|
Jaroslav Škarvada |
573565 |
+ lword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ else if (!(iswalnum (pwc) || pwc == L'_')
|
|
Jaroslav Škarvada |
573565 |
+ && mr == (int) (match - s))
|
|
Jaroslav Škarvada |
573565 |
+ lword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+#endif /* MBS_SUPPORT */
|
|
Jaroslav Škarvada |
573565 |
+ if (!WCHAR ((unsigned char) match[-1]))
|
|
Jaroslav Škarvada |
573565 |
+ lword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+
|
|
Jaroslav Škarvada |
573565 |
+ if (lword_match)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ int rword_match = 0;
|
|
Jaroslav Škarvada |
573565 |
+ if (start + len == end - beg - 1)
|
|
Jaroslav Škarvada |
573565 |
+ rword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+#ifdef MBS_SUPPORT
|
|
Jaroslav Škarvada |
573565 |
+ if (mb_cur_max > 1)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ wchar_t nwc;
|
|
Jaroslav Škarvada |
573565 |
+ int mr;
|
|
Jaroslav Škarvada |
573565 |
+
|
|
Jaroslav Škarvada |
573565 |
+ mr = mbtowc (&nwc, buf + start + len,
|
|
Jaroslav Škarvada |
573565 |
+ end - buf - start - len - 1);
|
|
Jaroslav Škarvada |
573565 |
+ if (mr <= 0)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ memset (&mbs, '\0', sizeof (mbstate_t));
|
|
Jaroslav Škarvada |
573565 |
+ rword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ else if (!iswalnum (nwc) && nwc != L'_')
|
|
Jaroslav Škarvada |
573565 |
+ rword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+#endif /* MBS_SUPPORT */
|
|
Jaroslav Škarvada |
573565 |
+ if (!WCHAR ((unsigned char) match[len]))
|
|
Jaroslav Škarvada |
573565 |
+ rword_match = 1;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+
|
|
Jaroslav Škarvada |
573565 |
+ if (rword_match)
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ if (!start_ptr)
|
|
Jaroslav Škarvada |
573565 |
+ /* Returns the whole line. */
|
|
Jaroslav Škarvada |
573565 |
+ goto success;
|
|
Jaroslav Škarvada |
573565 |
+ else
|
|
Jaroslav Škarvada |
573565 |
+ {
|
|
Jaroslav Škarvada |
573565 |
+ goto assess_pattern_match;
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
+ }
|
|
Jaroslav Škarvada |
573565 |
- if ((match == buf || !WCHAR ((unsigned char) match[-1]))
|
|
Jaroslav Škarvada |
573565 |
- && (len == end - beg - 1
|
|
Jaroslav Škarvada |
573565 |
- || !WCHAR ((unsigned char) match[len])))
|
|
Jaroslav Škarvada |
573565 |
- goto assess_pattern_match;
|
|
Jaroslav Škarvada |
573565 |
if (len > 0)
|
|
Jaroslav Škarvada |
573565 |
{
|
|
Jaroslav Škarvada |
573565 |
/* Try a shorter length anchored at the same place. */
|