~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset_info.h

  • Committer: Gustaf Thorslund
  • Date: 2010-11-02 09:28:14 UTC
  • mto: (1911.1.1 build) (1900.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1901.
  • Revision ID: gustaf@thorslund.org-20101102092814-aih84whrkf6925kc
Replaced macros with functions/templates. Part of blueprint:
  https://blueprints.edge.launchpad.net/drizzle/+spec/replace-macro-functions/

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
659
664
#define _MY_X   0200    /* heXadecimal digit */
660
665
 
661
666
 
662
 
#define my_isascii(c)   (!((c) & ~0177))
663
 
#define my_toascii(c)   ((c) & 0177)
664
 
#define my_tocntrl(c)   ((c) & 31)
665
 
#define my_toprint(c)   ((c) | 64)
666
 
#define my_toupper(s,c) (char) ((s)->to_upper[(unsigned char) (c)])
667
 
#define my_tolower(s,c) (char) ((s)->to_lower[(unsigned char) (c)])
668
 
#define my_isalpha(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_U | _MY_L))
669
 
#define my_isupper(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_U)
670
 
#define my_islower(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_L)
671
 
#define my_isdigit(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_NMR)
672
 
#define my_isxdigit(s, c) (((s)->ctype+1)[(unsigned char) (c)] & _MY_X)
673
 
#define my_isalnum(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_U | _MY_L | _MY_NMR))
674
 
#define my_isspace(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_SPC)
675
 
#define my_ispunct(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & _MY_PNT)
676
 
#define my_isprint(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B))
677
 
#define my_isgraph(s, c)  (((s)->ctype+1)[(unsigned char) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR))
678
 
#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
}
679
751
 
680
752
/* Some macros that should be cleaned up a little */
681
 
#define my_isvar(s,c)                 (my_isalnum(s,c) || (c) == '_')
682
 
#define my_isvar_start(s,c)           (my_isalpha(s,c) || (c) == '_')
683
 
 
684
 
#define my_binary_compare(s)          ((s)->state  & MY_CS_BINSORT)
685
 
#define use_strnxfrm(s)               ((s)->state  & MY_CS_STRNXFRM)
686
 
#define my_strnxfrm(cs, d, dl, s, sl) \
687
 
   ((cs)->coll->strnxfrm((cs), (d), (dl), (dl), (s), (sl), MY_STRXFRM_PAD_WITH_SPACE))
688
 
#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
689
 
#define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
690
 
   ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
691
 
#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m)))
692
 
#define my_strcasecmp(s, a, b)        ((s)->coll->strcasecmp((s), (a), (b)))
693
 
#define my_charpos(cs, b, e, num)     (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
694
 
 
695
 
 
696
 
#define use_mb(s)                     ((s)->cset->ismbchar != NULL)
697
 
#define my_ismbchar(s, a, b)          ((s)->cset->ismbchar((s), (a), (b)))
698
 
#define my_mbcharlen(s, a)            ((s)->cset->mbcharlen((s),(a)))
699
 
 
700
 
#define my_caseup_str(s, a)           ((s)->cset->caseup_str((s), (a)))
701
 
#define my_casedn_str(s, a)           ((s)->cset->casedn_str((s), (a)))
702
 
#define my_strntol(s, a, b, c, d, e)  ((s)->cset->strntol((s),(a),(b),(c),(d),(e)))
703
 
#define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e)))
704
 
#define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e)))
705
 
#define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e)))
706
 
#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
} // fixme!!!
 
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
}
707
883
 
708
884
int make_escape_code(const CHARSET_INFO * const cs, const char *escape);
709
885