2014-09-07 15:08:27 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
2017-05-07 11:24:17 +00:00
|
|
|
* Copyright(C) 2007 Randy Rizun <rrizun@gmail.com>
|
2014-09-07 15:08:27 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
#ifndef S3FS_STRING_UTIL_H_
|
|
|
|
#define S3FS_STRING_UTIL_H_
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//
|
|
|
|
// A collection of string utilities for manipulating URLs and HTTP responses.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Gloval variables
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
extern const std::string SPACES;
|
2017-11-18 03:50:36 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Inline functions
|
|
|
|
//-------------------------------------------------------------------
|
2017-11-18 03:50:36 +00:00
|
|
|
static inline int STR2NCMP(const char *str1, const char *str2) { return strncmp(str1, str2, strlen(str2)); }
|
2020-08-22 12:40:53 +00:00
|
|
|
static inline const char* SAFESTRPTR(const char *strptr) { return strptr ? strptr : ""; }
|
2010-11-13 23:59:23 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Templates
|
|
|
|
//-------------------------------------------------------------------
|
2017-11-18 18:10:29 +00:00
|
|
|
template <class T> std::string str(T value);
|
2010-11-13 23:59:23 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Macros(WTF8)
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
#define WTF8_ENCODE(ARG) \
|
|
|
|
std::string ARG##_buf; \
|
|
|
|
const char * ARG = _##ARG; \
|
|
|
|
if (use_wtf8 && s3fs_wtf8_encode( _##ARG, 0 )) { \
|
|
|
|
s3fs_wtf8_encode( _##ARG, &ARG##_buf); \
|
|
|
|
ARG = ARG##_buf.c_str(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Utilities
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
//
|
2019-07-13 01:52:35 +00:00
|
|
|
// Convert string to off_t. Throws std::invalid_argument and std::out_of_range on bad input.
|
2020-08-22 12:40:53 +00:00
|
|
|
//
|
2019-09-05 03:36:42 +00:00
|
|
|
off_t s3fs_strtoofft(const char* str, int base = 0);
|
2020-05-03 08:08:28 +00:00
|
|
|
bool try_strtoofft(const char* str, off_t& value, int base = 0);
|
|
|
|
off_t cvt_strtoofft(const char* str, int base = 0);
|
2013-11-17 08:50:41 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//
|
|
|
|
// String Manipulation
|
|
|
|
//
|
2011-06-26 00:37:52 +00:00
|
|
|
std::string trim_left(const std::string &s, const std::string &t = SPACES);
|
|
|
|
std::string trim_right(const std::string &s, const std::string &t = SPACES);
|
|
|
|
std::string trim(const std::string &s, const std::string &t = SPACES);
|
|
|
|
std::string lower(std::string s);
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Date string
|
|
|
|
//
|
2015-01-28 17:13:11 +00:00
|
|
|
std::string get_date_rfc850(void);
|
|
|
|
void get_date_sigv3(std::string& date, std::string& date8601);
|
|
|
|
std::string get_date_string(time_t tm);
|
|
|
|
std::string get_date_iso8601(time_t tm);
|
2019-02-03 14:22:16 +00:00
|
|
|
bool get_unixtime_from_iso8601(const char* pdate, time_t& unixtime);
|
|
|
|
bool convert_unixtime_from_option_arg(const char* argv, time_t& unixtime);
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// For encoding
|
|
|
|
//
|
2011-06-26 00:37:52 +00:00
|
|
|
std::string urlEncode(const std::string &s);
|
2015-01-20 16:31:36 +00:00
|
|
|
std::string urlEncode2(const std::string &s);
|
2015-04-20 17:24:57 +00:00
|
|
|
std::string urlDecode(const std::string& s);
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2015-04-20 17:24:57 +00:00
|
|
|
bool takeout_str_dquart(std::string& str);
|
2013-07-10 06:24:06 +00:00
|
|
|
bool get_keyword_value(std::string& target, const char* keyword, std::string& value);
|
2010-12-21 15:24:46 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//
|
|
|
|
// For binary string
|
|
|
|
//
|
2015-08-19 18:22:30 +00:00
|
|
|
std::string s3fs_hex(const unsigned char* input, size_t length);
|
|
|
|
char* s3fs_base64(const unsigned char* input, size_t length);
|
|
|
|
unsigned char* s3fs_decode64(const char* input, size_t* plength);
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
//
|
|
|
|
// WTF8
|
|
|
|
//
|
2019-02-18 12:27:44 +00:00
|
|
|
bool s3fs_wtf8_encode(const char *s, std::string *result);
|
|
|
|
std::string s3fs_wtf8_encode(const std::string &s);
|
|
|
|
bool s3fs_wtf8_decode(const char *s, std::string *result);
|
|
|
|
std::string s3fs_wtf8_decode(const std::string &s);
|
2019-02-15 15:57:03 +00:00
|
|
|
|
2010-11-13 23:59:23 +00:00
|
|
|
#endif // S3FS_STRING_UTIL_H_
|
2014-09-07 15:08:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
2020-08-22 12:40:53 +00:00
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2014-09-07 15:08:27 +00:00
|
|
|
* End:
|
2020-08-22 12:40:53 +00:00
|
|
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: expandtab sw=4 ts=4
|
2014-09-07 15:08:27 +00:00
|
|
|
*/
|