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 #include <string>
00023
00024 #include <drizzled/util/tablename_to_filename.h>
00025
00026 #include <drizzled/internal/my_sys.h>
00027
00028 namespace drizzled
00029 {
00030 namespace util
00031 {
00032
00033 static const char hexchars[]= "0123456789abcdef";
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 bool tablename_to_filename(const std::string &from, std::string &to)
00048 {
00049
00050 std::string::const_iterator iter= from.begin();
00051 for (; iter != from.end(); ++iter)
00052 {
00053 if (isascii(*iter))
00054 {
00055 if ((isdigit(*iter)) ||
00056 (islower(*iter)) ||
00057 (*iter == '_') ||
00058 (*iter == ' ') ||
00059 (*iter == '-'))
00060 {
00061 to.push_back(*iter);
00062 continue;
00063 }
00064
00065 if (isupper(*iter))
00066 {
00067 to.push_back(tolower(*iter));
00068 continue;
00069 }
00070 }
00071
00072
00073 to.push_back('@');
00074 to.push_back(hexchars[(*iter >> 4) & 15]);
00075 to.push_back(hexchars[(*iter) & 15]);
00076 }
00077
00078 if (drizzled::internal::check_if_legal_tablename(to.c_str()))
00079 {
00080 to.append("@@@");
00081 }
00082 return false;
00083 }
00084
00085 }
00086 }