mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-05 12:27:53 +00:00
Factored out purely string-based operations into string_util
git-svn-id: http://s3fs.googlecode.com/svn/trunk@216 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
parent
22f260e582
commit
184a31d676
@ -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)
|
||||
|
||||
|
||||
|
@ -37,11 +37,12 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <strings.h>
|
||||
|
||||
#include "string_util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class auto_fd {
|
||||
@ -59,31 +60,6 @@ class auto_fd {
|
||||
int fd;
|
||||
};
|
||||
|
||||
template<typename T> 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);
|
||||
|
@ -31,8 +31,6 @@ using namespace std;
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define SPACES " \t\r\n"
|
||||
|
||||
typedef pair<double, double> progress_t;
|
||||
|
||||
static long connect_timeout = 2;
|
||||
|
30
s3fs/src/string_util.cpp
Normal file
30
s3fs/src/string_util.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* s3fs - FUSE-based file system backed by Amazon S3
|
||||
*
|
||||
* Copyright 2007-2008 Randy Rizun <rrizun@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
41
s3fs/src/string_util.h
Normal file
41
s3fs/src/string_util.h
Normal file
@ -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 <sstream>
|
||||
#include <string>
|
||||
|
||||
#define SPACES " \t\r\n"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<typename T> 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_
|
Loading…
Reference in New Issue
Block a user