summaryrefslogtreecommitdiff
path: root/include/m_ctype.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-03-16 10:55:12 +0400
committerAlexander Barkov <bar@mariadb.org>2016-03-16 10:55:12 +0400
commite09299511e83f11f7476f7ea6c81ee12b00d7050 (patch)
treea3544293e29a5d191f2b07ce1810f58e257b1b10 /include/m_ctype.h
parentdc08ccab422098d2466fa342d577f03c941a4ffc (diff)
downloadmariadb-git-e09299511e83f11f7476f7ea6c81ee12b00d7050.tar.gz
MDEV-9665 Remove cs->cset->ismbchar()
Using a more powerfull cs->cset->charlen() instead.
Diffstat (limited to 'include/m_ctype.h')
-rw-r--r--include/m_ctype.h39
1 files changed, 36 insertions, 3 deletions
diff --git a/include/m_ctype.h b/include/m_ctype.h
index ee49e94ef99..b891e89d00d 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -400,7 +400,6 @@ struct my_charset_handler_st
{
my_bool (*init)(struct charset_info_st *, MY_CHARSET_LOADER *loader);
/* Multibyte routines */
- uint (*ismbchar)(CHARSET_INFO *, const char *, const char *);
uint (*mbcharlen)(CHARSET_INFO *, uint c);
size_t (*numchars)(CHARSET_INFO *, const char *b, const char *e);
size_t (*charpos)(CHARSET_INFO *, const char *b, const char *e,
@@ -972,8 +971,42 @@ size_t my_convert_fix(CHARSET_INFO *dstcs, char *dst, size_t dst_length,
#define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b)))
#define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
-#define use_mb(s) ((s)->cset->ismbchar != NULL)
-#define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b)))
+#define use_mb(s) ((s)->mbmaxlen > 1)
+/**
+ Detect if the leftmost character in a string is a valid multi-byte character
+ and return its length, or return 0 otherwise.
+ @param cs - character set
+ @param str - the beginning of the string
+ @param end - the string end (the next byte after the string)
+ @return >0, for a multi-byte character
+ @rerurn 0, for a single byte character, broken sequence, empty string.
+*/
+static inline
+uint my_ismbchar(CHARSET_INFO *cs, const char *str, const char *end)
+{
+ int char_length= (cs->cset->charlen)(cs, (const uchar *) str,
+ (const uchar *) end);
+ return char_length > 1 ? (uint) char_length : 0U;
+}
+
+
+/**
+ Return length of the leftmost character in a string.
+ @param cs - character set
+ @param str - the beginning of the string
+ @param end - the string end (the next byte after the string)
+ @return <=0 on errors (EOL, wrong byte sequence)
+ @return 1 on a single byte character
+ @return >1 on a multi-byte character
+
+ Note, inlike my_ismbchar(), 1 is returned for a single byte character.
+*/
+static inline
+uint my_charlen(CHARSET_INFO *cs, const char *str, const char *end)
+{
+ return (cs->cset->charlen)(cs, (const uchar *) str,
+ (const uchar *) end);
+}
#ifdef USE_MB
#define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a)))
#else