~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset_info.h

  • Committer: Brian Aker
  • Date: 2010-12-18 02:06:13 UTC
  • Revision ID: brian@tangent.org-20101218020613-8lxhcvsy812bu960
Formatting + remove default from switch/case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
/*
17
17
  A better inplementation of the UNIX ctype(3) library.
21
21
#define DRIZZLED_CHARSET_INFO_H
22
22
 
23
23
#include <sys/types.h>
 
24
#include <cstddef>
24
25
 
25
26
namespace drizzled
26
27
{
65
66
#define MY_CS_TOOSMALL4 -104  /* Need at least 4 bytes: wc_mb and mb_wc */
66
67
#define MY_CS_TOOSMALL5 -105  /* Need at least 5 bytes: wc_mb and mb_wc */
67
68
#define MY_CS_TOOSMALL6 -106  /* Need at least 6 bytes: wc_mb and mb_wc */
68
 
/* A helper macros for "need at least n bytes" */
69
 
#define MY_CS_TOOSMALLN(n)    (-100-(n))
 
69
 
 
70
/* A helper function for "need at least n bytes" */
 
71
inline static int my_cs_toosmalln(int n)
 
72
{
 
73
  return -100-n;
 
74
}
70
75
 
71
76
#define MY_SEQ_INTTAIL  1
72
77
#define MY_SEQ_SPACES   2
238
243
  /* Charset dependant snprintf() */
239
244
  size_t (*snprintf)(const struct charset_info_st * const, char *to, size_t n,
240
245
                     const char *fmt,
241
 
                     ...) __attribute__((format(printf, 4, 5)));
 
246
                     ...)
 
247
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
 
248
                         __attribute__((format(printf, 4, 5)))
 
249
#endif
 
250
                         ;
242
251
  size_t (*long10_to_str)(const struct charset_info_st * const, char *to, size_t n,
243
252
                          int radix, long int val);
244
253
  size_t (*int64_t10_to_str)(const struct charset_info_st * const, char *to, size_t n,
655
664
#define _MY_X   0200    /* heXadecimal digit */
656
665
 
657
666
 
658
 
#define my_isascii(c)   (!((c) & ~0177))
659
 
#define my_toascii(c)   ((c) & 0177)
660
 
#define my_tocntrl(c)   ((c) & 31)
661
 
#define my_toprint(c)   ((c) | 64)
662
 
#define my_toupper(s,c) (char) ((s)->to_upper[(unsigned char) (c)])
663
 
#define my_tolower(s,c) (char) ((s)->to_lower[(unsigned char) (c)])
664
 
#define my_isalpha(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_U | _MY_L))
665
 
#define my_isupper(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_U)
666
 
#define my_islower(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_L)
667
 
#define my_isdigit(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_NMR)
668
 
#define my_isxdigit(s, c) (((s)->ctype+1)[(unsigned char) (c)] & _MY_X)
669
 
#define my_isalnum(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_U | _MY_L | _MY_NMR))
670
 
#define my_isspace(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_SPC)
671
 
#define my_ispunct(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_PNT)
672
 
#define my_isprint(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B))
673
 
#define my_isgraph(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR))
674
 
#define my_iscntrl(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_CTR)
 
667
inline static bool my_isascii(char c)      
 
668
{
 
669
  return (!(c & ~0177));
 
670
}
 
671
 
 
672
inline static char my_toascii(char c)
 
673
{
 
674
  return (c & 0177);
 
675
}
 
676
 
 
677
inline static char my_tocntrl(char c) 
 
678
{
 
679
  return (c & 31);
 
680
}
 
681
 
 
682
inline static char my_toprint(char c)
 
683
{
 
684
  return (c | 64);
 
685
}
 
686
 
 
687
inline static char my_toupper(const charset_info_st *s, char c)
 
688
{
 
689
  return (char)(s->to_upper[(unsigned char)c]);
 
690
}
 
691
 
 
692
inline static char my_tolower(const charset_info_st *s, char c)
 
693
{
 
694
  return (char)(s->to_lower[(unsigned char)c]);
 
695
}
 
696
 
 
697
inline static bool my_isalpha(const charset_info_st *s, char c)
 
698
{
 
699
  return ((s->ctype+1)[(unsigned char)c] & (_MY_U | _MY_L));
 
700
}
 
701
 
 
702
inline static bool my_isupper(const charset_info_st *s, char c)
 
703
{
 
704
  return ((s->ctype+1)[(unsigned char)c] & _MY_U);
 
705
}
 
706
 
 
707
inline static bool my_islower(const charset_info_st *s, char c)
 
708
{
 
709
  return ((s->ctype+1)[(unsigned char)c] & _MY_L);
 
710
}
 
711
 
 
712
inline static bool my_isdigit(const charset_info_st *s, char c)
 
713
{
 
714
  return ((s->ctype+1)[(unsigned char)c] & _MY_NMR);
 
715
}
 
716
 
 
717
inline static bool my_isxdigit(const charset_info_st *s, char c)
 
718
{
 
719
  return ((s->ctype+1)[(unsigned char)c] & _MY_X);
 
720
}
 
721
 
 
722
inline static bool my_isalnum(const charset_info_st *s, char c) 
 
723
{
 
724
  return ((s->ctype+1)[(unsigned char)c] & (_MY_U | _MY_L | _MY_NMR));
 
725
}
 
726
 
 
727
inline static bool my_isspace(const charset_info_st *s, char c)
 
728
{
 
729
  return ((s->ctype+1)[(unsigned char)c] & _MY_SPC);
 
730
}
 
731
 
 
732
inline static bool my_ispunct(const charset_info_st *s, char c)  
 
733
{
 
734
  return ((s->ctype+1)[(unsigned char)c] & _MY_PNT);
 
735
}
 
736
 
 
737
inline static bool my_isprint(const charset_info_st *s, char c)  
 
738
{
 
739
  return ((s->ctype+1)[(unsigned char)c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B));
 
740
}
 
741
 
 
742
inline static bool my_isgraph(const charset_info_st *s, char c)
 
743
{
 
744
  return ((s->ctype+1)[(unsigned char)c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR));
 
745
}
 
746
 
 
747
inline static bool my_iscntrl(const charset_info_st *s, char c)  
 
748
{
 
749
  return ((s->ctype+1)[(unsigned char)c] & _MY_CTR);
 
750
}
675
751
 
676
752
/* Some macros that should be cleaned up a little */
677
 
#define my_isvar(s,c)                 (my_isalnum(s,c) || (c) == '_')
678
 
#define my_isvar_start(s,c)           (my_isalpha(s,c) || (c) == '_')
679
 
 
680
 
#define my_binary_compare(s)          ((s)->state  & MY_CS_BINSORT)
681
 
#define use_strnxfrm(s)               ((s)->state  & MY_CS_STRNXFRM)
682
 
#define my_strnxfrm(cs, d, dl, s, sl) \
683
 
   ((cs)->coll->strnxfrm((cs), (d), (dl), (dl), (s), (sl), MY_STRXFRM_PAD_WITH_SPACE))
684
 
#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
685
 
#define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
686
 
   ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
687
 
#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m)))
688
 
#define my_strcasecmp(s, a, b)        ((s)->coll->strcasecmp((s), (a), (b)))
689
 
#define my_charpos(cs, b, e, num)     (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
690
 
 
691
 
 
692
 
#define use_mb(s)                     ((s)->cset->ismbchar != NULL)
693
 
#define my_ismbchar(s, a, b)          ((s)->cset->ismbchar((s), (a), (b)))
694
 
#define my_mbcharlen(s, a)            ((s)->cset->mbcharlen((s),(a)))
695
 
 
696
 
#define my_caseup_str(s, a)           ((s)->cset->caseup_str((s), (a)))
697
 
#define my_casedn_str(s, a)           ((s)->cset->casedn_str((s), (a)))
698
 
#define my_strntol(s, a, b, c, d, e)  ((s)->cset->strntol((s),(a),(b),(c),(d),(e)))
699
 
#define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e)))
700
 
#define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e)))
701
 
#define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e)))
702
 
#define my_strntod(s, a, b, c, d)     ((s)->cset->strntod((s),(a),(b),(c),(d)))
 
753
inline static bool my_isvar(const charset_info_st *s, char c)
 
754
{
 
755
  return (my_isalnum(s,c) || (c) == '_');
 
756
}
 
757
 
 
758
inline static bool my_isvar_start(const charset_info_st *s, char c)
 
759
{
 
760
  return (my_isalpha(s,c) || (c) == '_');
 
761
}
 
762
 
 
763
inline static bool my_binary_compare(const charset_info_st *s)
 
764
{
 
765
  return (s->state  & MY_CS_BINSORT);
 
766
}
 
767
 
 
768
inline static bool use_strnxfrm(const charset_info_st *s)
 
769
{
 
770
  return (s->state & MY_CS_STRNXFRM);
 
771
}
 
772
 
 
773
inline static size_t my_strnxfrm(const charset_info_st *cs, 
 
774
                                 unsigned char *dst, 
 
775
                                 const size_t dstlen, 
 
776
                                 const unsigned char *src, 
 
777
                                 const uint32_t srclen)
 
778
{
 
779
  return (cs->coll->strnxfrm(cs, dst, dstlen, dstlen, src, srclen, MY_STRXFRM_PAD_WITH_SPACE));
 
780
}
 
781
 
 
782
inline static int my_strnncoll(const charset_info_st *cs, 
 
783
                               const unsigned char *s, 
 
784
                               const size_t slen, 
 
785
                               const unsigned char *t,
 
786
                               const size_t tlen) 
 
787
{
 
788
  return (cs->coll->strnncoll(cs, s, slen, t, tlen, 0));
 
789
}
 
790
 
 
791
inline static bool my_like_range(const charset_info_st *cs,
 
792
                                 const char *ptr, const size_t ptrlen,
 
793
                                 const char escape, 
 
794
                                 const char w_one,
 
795
                                 const char w_many, 
 
796
                                 const size_t reslen, 
 
797
                                 char *minstr, char *maxstr, 
 
798
                                 size_t *minlen, size_t *maxlen)
 
799
{
 
800
  return (cs->coll->like_range(cs, ptr, ptrlen, escape, w_one, w_many, reslen, 
 
801
                               minstr, maxstr, minlen, maxlen));
 
802
}
 
803
 
 
804
inline static int my_wildcmp(const charset_info_st *cs,
 
805
                             const char *str, const char *strend,
 
806
                             const char *w_str, const char *w_strend,
 
807
                             const int escape,
 
808
                             const int w_one, const int w_many) 
 
809
{
 
810
  return (cs->coll->wildcmp(cs, str, strend, w_str, w_strend, escape, w_one, w_many));
 
811
}
 
812
 
 
813
inline static int my_strcasecmp(const charset_info_st *cs, const char *s, const char *t)
 
814
{
 
815
  return (cs->coll->strcasecmp(cs, s, t));
 
816
}
 
817
 
 
818
template <typename CHAR_T>
 
819
inline static size_t my_charpos(const charset_info_st *cs, 
 
820
                                const CHAR_T *b, const CHAR_T* e, size_t num)
 
821
{
 
822
  return (cs->cset->charpos(cs, (const char*) b, (const char *)e, num));
 
823
}
 
824
 
 
825
inline static bool use_mb(const charset_info_st *cs)
 
826
{
 
827
  return (cs->cset->ismbchar != NULL);
 
828
}
 
829
 
 
830
inline static unsigned int  my_ismbchar(const charset_info_st *cs, const char *a, const char *b)
 
831
{
 
832
  return (cs->cset->ismbchar(cs, a, b));
 
833
}
 
834
 
 
835
inline static unsigned int my_mbcharlen(const charset_info_st *cs, uint32_t c)
 
836
{
 
837
  return (cs->cset->mbcharlen(cs, c));
 
838
}
 
839
 
 
840
 
 
841
inline static size_t my_caseup_str(const charset_info_st *cs, char *src)
 
842
{
 
843
  return (cs->cset->caseup_str(cs, src));
 
844
}
 
845
 
 
846
inline static size_t my_casedn_str(const charset_info_st *cs, char *src)
 
847
{
 
848
  return (cs->cset->casedn_str(cs, src));
 
849
}
 
850
 
 
851
inline static long my_strntol(const charset_info_st *cs, 
 
852
                              const char* s, const size_t l, const int base, char **e, int *err)
 
853
{
 
854
  return (cs->cset->strntol(cs, s, l, base, e, err));
 
855
}
 
856
 
 
857
inline static unsigned long my_strntoul(const charset_info_st *cs, 
 
858
                                        const char* s, const size_t l, const int base, 
 
859
                                        char **e, int *err)
 
860
{
 
861
  return (cs->cset->strntoul(cs, s, l, base, e, err));
 
862
}
 
863
 
 
864
inline static int64_t my_strntoll(const charset_info_st *cs, 
 
865
                                 const char* s, const size_t l, const int base, char **e, int *err)
 
866
{
 
867
  return (cs->cset->strntoll(cs, s, l, base, e, err));
 
868
}
 
869
 
 
870
inline static int64_t my_strntoull(const charset_info_st *cs, 
 
871
                                   const char* s, const size_t l, const int base, 
 
872
                                   char **e, int *err)
 
873
{
 
874
  return (cs->cset->strntoull(cs, s, l, base, e, err));
 
875
}
 
876
 
 
877
 
 
878
inline static double my_strntod(const charset_info_st *cs, 
 
879
                                char* s, const size_t l, char **e, int *err)
 
880
{
 
881
  return (cs->cset->strntod(cs, s, l, e, err));
 
882
}
703
883
 
704
884
int make_escape_code(const CHARSET_INFO * const cs, const char *escape);
705
885