00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <drizzled/sql_string.h>
00024 #include <drizzled/type/boolean.h>
00025 #include <drizzled/charset.h>
00026
00027 namespace drizzled {
00028 namespace type {
00029
00030 const char* convert(bool source, bool ansi_display)
00031 {
00032 if (source)
00033 return ansi_display ? "YES" : "TRUE";
00034 return ansi_display ? "NO" : "FALSE";
00035 }
00036
00037 void convert(String& destination, bool source, bool ansi_display)
00038 {
00039 const char* v= convert(source, ansi_display);
00040 destination.alloc(strlen(v));
00041 strcpy(destination.c_ptr(), v);
00042 destination.length(strlen(v));
00043 }
00044
00045 bool convert(bool &destination, const char *source, const size_t source_length)
00046 {
00047 switch (source_length)
00048 {
00049 case 1:
00050 {
00051 switch (source[0])
00052 {
00053 case 'y': case 'Y':
00054 case 't': case 'T':
00055 destination= true;
00056 return true;
00057
00058 case 'n': case 'N':
00059 case 'f': case 'F':
00060 destination= false;
00061 return true;
00062 }
00063 }
00064 break;
00065
00066 case 5:
00067 if (not (system_charset_info->strcasecmp(source, "FALSE")))
00068 {
00069 destination= false;
00070 return true;
00071 }
00072 break;
00073
00074 case 4:
00075 if (not (system_charset_info->strcasecmp(source, "TRUE")))
00076 {
00077 destination= true;
00078 return true;
00079 }
00080 break;
00081
00082 case 3:
00083 if (not (system_charset_info->strcasecmp(source, "YES")))
00084 {
00085 destination= true;
00086 return true;
00087 }
00088 break;
00089
00090 case 2:
00091 if (not (system_charset_info->strcasecmp(source, "NO")))
00092 {
00093 destination= false;
00094 return true;
00095 }
00096 break;
00097 }
00098
00099
00100 destination= false;
00101 return false;
00102 }
00103
00104 bool convert(bool &destination, String &source)
00105 {
00106 return convert(destination, source.c_ptr(), source.length());
00107 }
00108
00109 }
00110 }