~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/util/tablename_to_filename.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <config.h>
22
22
#include <string>
23
23
 
 
24
#include <boost/foreach.hpp>
24
25
#include <drizzled/util/tablename_to_filename.h>
25
 
 
26
26
#include <drizzled/internal/my_sys.h>
27
27
 
28
 
namespace drizzled
29
 
{
30
 
namespace util
31
 
{
 
28
namespace drizzled {
 
29
namespace util {
32
30
 
33
 
static const char hexchars[]= "0123456789abcdef";
 
31
static const char* hexchars= "0123456789abcdef";
34
32
 
35
33
 
36
34
/*
44
42
  RETURN
45
43
    true if errors happen. false on success.
46
44
*/
47
 
bool tablename_to_filename(const std::string &from, std::string &to)
 
45
std::string tablename_to_filename(const std::string &from)
48
46
{
49
 
  
50
 
  std::string::const_iterator iter= from.begin();
51
 
  for (; iter != from.end(); ++iter)
 
47
  std::string to;
 
48
  BOOST_FOREACH(char it, from)
52
49
  {
53
 
    if (isascii(*iter))
 
50
    if (isascii(it))
54
51
    {
55
 
      if ((isdigit(*iter)) ||
56
 
          (islower(*iter)) ||
57
 
          (*iter == '_') ||
58
 
          (*iter == ' ') ||
59
 
          (*iter == '-'))
 
52
      if (isdigit(it) || islower(it) || it == '_' || it == ' ' || it == '-')
60
53
      {
61
 
        to.push_back(*iter);
 
54
        to.push_back(it);
62
55
        continue;
63
56
      }
64
57
 
65
 
      if (isupper(*iter))
 
58
      if (isupper(it))
66
59
      {
67
 
        to.push_back(tolower(*iter));
 
60
        to.push_back(tolower(it));
68
61
        continue;
69
62
      }
70
63
    }
71
64
   
72
65
    /* We need to escape this char in a way that can be reversed */
73
66
    to.push_back('@');
74
 
    to.push_back(hexchars[(*iter >> 4) & 15]);
75
 
    to.push_back(hexchars[(*iter) & 15]);
 
67
    to.push_back(hexchars[(it >> 4) & 15]);
 
68
    to.push_back(hexchars[it & 15]);
76
69
  }
77
70
 
78
71
  if (drizzled::internal::check_if_legal_tablename(to.c_str()))
79
72
  {
80
 
    to.append("@@@");
 
73
    to += "@@@";
81
74
  }
82
 
  return false;
 
75
  return to;
83
76
}
84
77
 
85
78
} /* namespace util */