~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/util/tablename_to_filename.cc

  • Committer: Mark Atwood
  • Date: 2011-08-01 05:22:14 UTC
  • mfrom: (1919.3.53 drizzle_pbms)
  • Revision ID: me@mark.atwood.name-20110801052214-3wdsx3xgld6b5v4f
merge lp:~barry-leslie/drizzle/drizzle_pbms

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