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