1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
1 |
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Brian Aker
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
22 |
#include <string> |
23 |
||
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
24 |
#include <boost/foreach.hpp> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
25 |
#include <drizzled/util/tablename_to_filename.h> |
26 |
#include <drizzled/internal/my_sys.h> |
|
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
27 |
|
2269.1.7
by Olaf van der Spek
Use util::string::ptr |
28 |
namespace drizzled { |
29 |
namespace util { |
|
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
30 |
|
2318.9.8
by Olaf van der Spek
Refactor tablename_to_filename() |
31 |
static const char* hexchars= "0123456789abcdef"; |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
32 |
|
33 |
||
34 |
/*
|
|
35 |
Translate a table name to a cursor name (WL #1324).
|
|
36 |
||
37 |
SYNOPSIS
|
|
38 |
tablename_to_filename()
|
|
39 |
from The table name
|
|
40 |
to OUT The cursor name
|
|
41 |
||
42 |
RETURN
|
|
43 |
true if errors happen. false on success.
|
|
44 |
*/
|
|
2318.9.8
by Olaf van der Spek
Refactor tablename_to_filename() |
45 |
std::string tablename_to_filename(const std::string &from) |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
46 |
{
|
2318.9.8
by Olaf van der Spek
Refactor tablename_to_filename() |
47 |
std::string to; |
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
48 |
BOOST_FOREACH(char it, from) |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
49 |
{
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
50 |
if (isascii(it)) |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
51 |
{
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
52 |
if (isdigit(it) || islower(it) || it == '_' || it == ' ' || it == '-') |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
53 |
{
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
54 |
to.push_back(it); |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
55 |
continue; |
56 |
}
|
|
57 |
||
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
58 |
if (isupper(it)) |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
59 |
{
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
60 |
to.push_back(tolower(it)); |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
61 |
continue; |
62 |
}
|
|
63 |
}
|
|
64 |
||
65 |
/* We need to escape this char in a way that can be reversed */
|
|
66 |
to.push_back('@'); |
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
67 |
to.push_back(hexchars[(it >> 4) & 15]); |
68 |
to.push_back(hexchars[it & 15]); |
|
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
69 |
}
|
70 |
||
71 |
if (drizzled::internal::check_if_legal_tablename(to.c_str())) |
|
72 |
{
|
|
2318.9.4
by Olaf van der Spek
Refactor tablename_to_filename |
73 |
to += "@@@"; |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
74 |
}
|
2318.9.8
by Olaf van der Spek
Refactor tablename_to_filename() |
75 |
return to; |
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
76 |
}
|
77 |
||
78 |
} /* namespace util */ |
|
79 |
} /* namespace drizzled */ |