Commit 8f624411 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

src: Rewrite util::stripIter

parent baf2dc3d
......@@ -33,7 +33,7 @@ namespace spdylay {
namespace util {
const std::string DEFAULT_STRIP_CHARSET("\r\n\t ");
const char DEFAULT_STRIP_CHARSET[] = "\r\n\t ";
bool isAlpha(const char c)
{
......
......@@ -27,6 +27,7 @@
#include "spdylay_config.h"
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
......@@ -77,21 +78,19 @@ public:
}
};
extern const std::string DEFAULT_STRIP_CHARSET;
extern const char DEFAULT_STRIP_CHARSET[];
template<typename InputIterator>
std::pair<InputIterator, InputIterator> stripIter
(InputIterator first, InputIterator last,
const std::string& chars = DEFAULT_STRIP_CHARSET)
const char* chars = DEFAULT_STRIP_CHARSET)
{
for(; first != last &&
std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
for(; first != last && strchr(chars, *first) != 0; ++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);
for(; left != first && strchr(chars, *left) != 0; --left);
return std::make_pair(first, left+1);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment