summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-03-01 00:02:29 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-03-01 00:02:29 +0900
commite73c3c53ffb9ce681fe712142143777eaf50da47 (patch)
treec16d879d1011f80be97a7e2471476e17fe0b0a86 /src/util.h
parent037f1512dbcdf19237d6064660d5c75b4121f0bf (diff)
Fixed clang warning and errors.
Test for the zero-length array with A2_ARRAY_LEN was commented out since it is only used in unit test code and clang and old gcc 3.4.3 emit error.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/util.h b/src/util.h
index 80de4d29..243a2eeb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -71,7 +71,7 @@ class BinaryStream;
class FileEntry;
class RequestGroup;
class Option;
-class Pref;
+struct Pref;
#define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10)
#define STRTOULL(X) strtoull(X, reinterpret_cast<char**>(0), 10)
@@ -111,6 +111,52 @@ std::string nativeToUtf8(const std::string& src);
namespace util {
+extern const std::string DEFAULT_STRIP_CHARSET;
+
+template<typename InputIterator>
+std::pair<InputIterator, InputIterator> stripIter
+(InputIterator first, InputIterator last,
+ const std::string& chars = DEFAULT_STRIP_CHARSET)
+{
+ for(; first != last &&
+ std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
+ if(first == last) {
+ return std::make_pair(first, last);
+ }
+ InputIterator left = last-1;
+ for(; left != first &&
+ std::find(chars.begin(), chars.end(), *left) != chars.end(); --left);
+ return std::make_pair(first, left+1);
+}
+
+template<typename InputIterator>
+InputIterator lstripIter
+(InputIterator first, InputIterator last, char ch)
+{
+ for(; first != last && *first == ch; ++first);
+ return first;
+}
+
+template<typename InputIterator, typename InputIterator2>
+InputIterator lstripIter
+(InputIterator first, InputIterator last,
+ InputIterator2 cfirst, InputIterator2 clast)
+{
+ for(; first != last && std::find(cfirst, clast, *first) != clast; ++first);
+ return first;
+}
+
+template<typename InputIterator>
+InputIterator lstripIter
+(InputIterator first, InputIterator last)
+{
+ return lstripIter(first, last,
+ DEFAULT_STRIP_CHARSET.begin(), DEFAULT_STRIP_CHARSET.end());
+}
+
+std::string strip
+(const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
+
template<typename InputIterator>
void divide
(std::pair<std::pair<InputIterator, InputIterator>,
@@ -161,52 +207,6 @@ std::string itos(int64_t value, bool comma = false);
int64_t difftv(struct timeval tv1, struct timeval tv2);
int32_t difftvsec(struct timeval tv1, struct timeval tv2);
-extern const std::string DEFAULT_STRIP_CHARSET;
-
-template<typename InputIterator>
-std::pair<InputIterator, InputIterator> stripIter
-(InputIterator first, InputIterator last,
- const std::string& chars = DEFAULT_STRIP_CHARSET)
-{
- for(; first != last &&
- std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
- if(first == last) {
- return std::make_pair(first, last);
- }
- InputIterator left = last-1;
- for(; left != first &&
- std::find(chars.begin(), chars.end(), *left) != chars.end(); --left);
- return std::make_pair(first, left+1);
-}
-
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last, char ch)
-{
- for(; first != last && *first == ch; ++first);
- return first;
-}
-
-template<typename InputIterator, typename InputIterator2>
-InputIterator lstripIter
-(InputIterator first, InputIterator last,
- InputIterator2 cfirst, InputIterator2 clast)
-{
- for(; first != last && std::find(cfirst, clast, *first) != clast; ++first);
- return first;
-}
-
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last)
-{
- return lstripIter(first, last,
- DEFAULT_STRIP_CHARSET.begin(), DEFAULT_STRIP_CHARSET.end());
-}
-
-std::string strip
-(const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
-
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
std::string percentEncode(const unsigned char* target, size_t len);