diff --git a/s3fs/src/Makefile.am b/s3fs/src/Makefile.am index dcf872e..9417577 100644 --- a/s3fs/src/Makefile.am +++ b/s3fs/src/Makefile.am @@ -1,6 +1,7 @@ bin_PROGRAMS=s3fs -s3fs_SOURCES=s3fs.cpp + AM_CPPFLAGS = $(DEPS_CFLAGS) + +s3fs_SOURCES = s3fs.cpp string_util.cpp s3fs_LDADD = $(DEPS_LIBS) - diff --git a/s3fs/src/s3fs.cpp b/s3fs/src/s3fs.cpp index acb6aba..6b1543b 100644 --- a/s3fs/src/s3fs.cpp +++ b/s3fs/src/s3fs.cpp @@ -37,11 +37,12 @@ #include #include -#include #include #include #include +#include "string_util.h" + using namespace std; class auto_fd { @@ -59,31 +60,6 @@ class auto_fd { int fd; }; -template string str(T value) { - stringstream tmp; - tmp << value; - return tmp.str(); -} - -inline string trim_left(const string& s, const string& t = SPACES) { - string d(s); - return d.erase(0, s.find_first_not_of(t)) ; -} // end of trim_left - -inline string trim_right(const string &s, const string &t = SPACES) { - string d(s); - string::size_type i(d.find_last_not_of(t)); - if (i == string::npos) - return ""; - else - return d.erase(d.find_last_not_of(t) + 1); -} // end of trim_right - -inline string trim(const string& s, const string& t = SPACES) { - string d(s); - return trim_left(trim_right(d, t), t); -} // end of trim - class auto_lock { public: auto_lock(pthread_mutex_t& lock) : lock(lock) { @@ -1644,14 +1620,6 @@ static int my_fuse_opt_proc(void *data, const char *arg, int key, struct fuse_ar return 1; } -string StringToLower(string strToConvert) { - //change each element of the string to lower case - for(unsigned int i = 0; i< strToConvert.length(); i++) { - strToConvert[i] = tolower(strToConvert[i]); - } - return strToConvert; -} - int main(int argc, char *argv[]) { for (int i = 1; i < argc; ++i) { @@ -1675,7 +1643,7 @@ int main(int argc, char *argv[]) { exit(1); } - if ( StringToLower(bucket) != bucket ) { + if (lower(bucket) != bucket) { cout << argv[0] << ": bucket \"" << bucket.c_str() << "\" - buckets with upper case characters in their names are not supported" << endl; exit(1); diff --git a/s3fs/src/s3fs.h b/s3fs/src/s3fs.h index 1d77c5d..c070145 100644 --- a/s3fs/src/s3fs.h +++ b/s3fs/src/s3fs.h @@ -31,8 +31,6 @@ using namespace std; return result; \ } -#define SPACES " \t\r\n" - typedef pair progress_t; static long connect_timeout = 2; diff --git a/s3fs/src/string_util.cpp b/s3fs/src/string_util.cpp new file mode 100644 index 0000000..b47fdd7 --- /dev/null +++ b/s3fs/src/string_util.cpp @@ -0,0 +1,30 @@ +/* + * s3fs - FUSE-based file system backed by Amazon S3 + * + * Copyright 2007-2008 Randy Rizun + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "string_util.h" + +string lower(string s) { + // change each character of the string to lower case + for (unsigned int i = 0; i < s.length(); i++) { + s[i] = tolower(s[i]); + } + return s; +} + diff --git a/s3fs/src/string_util.h b/s3fs/src/string_util.h new file mode 100644 index 0000000..a8731a3 --- /dev/null +++ b/s3fs/src/string_util.h @@ -0,0 +1,41 @@ +#ifndef S3FS_STRING_UTIL_H_ +#define S3FS_STRING_UTIL_H_ + +/* + * A collection of string utilities for manipulating URLs and HTTP responses. + */ +#include +#include + +#define SPACES " \t\r\n" + +using namespace std; + +template string str(T value) { + stringstream tmp; + tmp << value; + return tmp.str(); +} + +inline string trim_left(const string &s, const string &t = SPACES) { + string d(s); + return d.erase(0, s.find_first_not_of(t)); +} + +inline string trim_right(const string &s, const string &t = SPACES) { + string d(s); + string::size_type i(d.find_last_not_of(t)); + if (i == string::npos) + return ""; + else + return d.erase(d.find_last_not_of(t) + 1); +} + +inline string trim(const string &s, const string &t = SPACES) { + string d(s); + return trim_left(trim_right(d, t), t); +} + +string lower(string s); + +#endif // S3FS_STRING_UTIL_H_