summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorunknown <bar@bar.mysql.r18.ru>2003-09-25 13:35:21 +0500
committerunknown <bar@bar.mysql.r18.ru>2003-09-25 13:35:21 +0500
commit10bb09e4983adb664ba325dbc44efb19055844fd (patch)
tree74e7bba010ea5bd7a3112d49ae100d65a839136d /strings
parente81d45c182971be3a29e042794f0922112f11479 (diff)
downloadmariadb-git-10bb09e4983adb664ba325dbc44efb19055844fd.tar.gz
CHARSET_INFO::instr was extended to return more substring match results:
- offset of substr begining - offset of substr end - number of characters (MB compatible)
Diffstat (limited to 'strings')
-rw-r--r--strings/ctype-bin.c32
-rw-r--r--strings/ctype-mb.c39
-rw-r--r--strings/ctype-simple.c32
3 files changed, 85 insertions, 18 deletions
diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
index 75070203239..340084ad848 100644
--- a/strings/ctype-bin.c
+++ b/strings/ctype-bin.c
@@ -263,16 +263,25 @@ static int my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)),
}
static
-int my_instr_bin(CHARSET_INFO *cs __attribute__((unused)),
+uint my_instr_bin(CHARSET_INFO *cs __attribute__((unused)),
const char *big, uint b_length,
- const char *small, uint s_length)
+ const char *small, uint s_length,
+ my_match_t *match, uint nmatch)
{
register const uchar *str, *search, *end, *search_end;
if (s_length <= b_length)
{
if (!s_length)
- return 0; /* Empty string is always found */
+ {
+ if (nmatch)
+ {
+ match->beg= 0;
+ match->end= 0;
+ match->mblen= 0;
+ }
+ return 1; /* Empty string is always found */
+ }
str= (const uchar*) big;
search= (const uchar*) small;
@@ -293,11 +302,24 @@ skipp:
if ((*i++) != (*j++))
goto skipp;
- return (int) (str- (const uchar*)big) -1;
+ if (nmatch > 0)
+ {
+ match[0].beg= 0;
+ match[0].end= str- (const uchar*)big-1;
+ match[0].mblen= match[0].end;
+
+ if (nmatch > 1)
+ {
+ match[1].beg= match[0].end;
+ match[1].end= match[0].end+s_length;
+ match[1].mblen= match[1].end-match[1].beg;
+ }
+ }
+ return 2;
}
}
}
- return -1;
+ return 0;
}
diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c
index 03323b3d3a1..ba53ebfb64c 100644
--- a/strings/ctype-mb.c
+++ b/strings/ctype-mb.c
@@ -274,18 +274,28 @@ uint my_charpos_mb(CHARSET_INFO *cs __attribute__((unused)),
return b-b0;
}
-int my_instr_mb(CHARSET_INFO *cs,
- const char *big, uint b_length,
- const char *small, uint s_length)
+uint my_instr_mb(CHARSET_INFO *cs,
+ const char *big, uint b_length,
+ const char *small, uint s_length,
+ my_match_t *match, uint nmatch)
{
- register const char *end;
+ register const char *end, *big0;
int res= 0;
if (s_length <= b_length)
{
if (!s_length)
- return 0; // Empty string is always found
+ {
+ if (nmatch)
+ {
+ match->beg= 0;
+ match->end= 0;
+ match->mblen= 0;
+ }
+ return 1; // Empty string is always found
+ }
+ big0= big;
end= big+b_length-s_length+1;
while (big < end)
@@ -294,15 +304,28 @@ int my_instr_mb(CHARSET_INFO *cs,
if (!cs->coll->strnncoll(cs, (unsigned char*) big, s_length,
(unsigned char*) small, s_length))
- return res;
-
+ {
+ if (nmatch)
+ {
+ match[0].beg= big0;
+ match[0].end= big-big0;
+ match[0].mblen= res;
+ if (nmatch > 1)
+ {
+ match[1].beg= match[0].end;
+ match[1].end= match[0].end+s_length;
+ match[1].mblen= 0; /* Not computed */
+ }
+ }
+ return 2;
+ }
mblen= (mblen= my_ismbchar(cs, big, end)) ? mblen : 1;
big+= mblen;
b_length-= mblen;
res++;
}
}
- return -1;
+ return 0;
}
/* BINARY collations handlers for MB charsets */
diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c
index 152980dd305..f85ce5e7a2b 100644
--- a/strings/ctype-simple.c
+++ b/strings/ctype-simple.c
@@ -1030,16 +1030,25 @@ uint my_lengthsp_8bit(CHARSET_INFO *cs __attribute__((unused)),
}
-int my_instr_simple(CHARSET_INFO *cs,
+uint my_instr_simple(CHARSET_INFO *cs,
const char *big, uint b_length,
- const char *small, uint s_length)
+ const char *small, uint s_length,
+ my_match_t *match, uint nmatch)
{
register const uchar *str, *search, *end, *search_end;
if (s_length <= b_length)
{
if (!s_length)
- return 0; // Empty string is always found
+ {
+ if (nmatch)
+ {
+ match->beg= 0;
+ match->end= 0;
+ match->mblen= 0;
+ }
+ return 1; /* Empty string is always found */
+ }
str= (const uchar*) big;
search= (const uchar*) small;
@@ -1060,11 +1069,24 @@ skipp:
if (cs->sort_order[*i++] != cs->sort_order[*j++])
goto skipp;
- return (int) (str- (const uchar*)big) -1;
+ if (nmatch > 0)
+ {
+ match[0].beg= 0;
+ match[0].end= str- (const uchar*)big-1;
+ match[0].mblen= match[0].end;
+
+ if (nmatch > 1)
+ {
+ match[1].beg= match[0].end;
+ match[1].end= match[0].end+s_length;
+ match[1].mblen= match[1].end-match[1].beg;
+ }
+ }
+ return 2;
}
}
}
- return -1;
+ return 0;
}