src: Rewrite util::stripIter
This commit is contained in:
parent
baf2dc3ddf
commit
8f62441112
|
@ -33,7 +33,7 @@ namespace spdylay {
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
const std::string DEFAULT_STRIP_CHARSET("\r\n\t ");
|
const char DEFAULT_STRIP_CHARSET[] = "\r\n\t ";
|
||||||
|
|
||||||
bool isAlpha(const char c)
|
bool isAlpha(const char c)
|
||||||
{
|
{
|
||||||
|
|
11
src/util.h
11
src/util.h
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "spdylay_config.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -77,21 +78,19 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const std::string DEFAULT_STRIP_CHARSET;
|
extern const char DEFAULT_STRIP_CHARSET[];
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
std::pair<InputIterator, InputIterator> stripIter
|
std::pair<InputIterator, InputIterator> stripIter
|
||||||
(InputIterator first, InputIterator last,
|
(InputIterator first, InputIterator last,
|
||||||
const std::string& chars = DEFAULT_STRIP_CHARSET)
|
const char* chars = DEFAULT_STRIP_CHARSET)
|
||||||
{
|
{
|
||||||
for(; first != last &&
|
for(; first != last && strchr(chars, *first) != 0; ++first);
|
||||||
std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
|
|
||||||
if(first == last) {
|
if(first == last) {
|
||||||
return std::make_pair(first, last);
|
return std::make_pair(first, last);
|
||||||
}
|
}
|
||||||
InputIterator left = last-1;
|
InputIterator left = last-1;
|
||||||
for(; left != first &&
|
for(; left != first && strchr(chars, *left) != 0; --left);
|
||||||
std::find(chars.begin(), chars.end(), *left) != chars.end(); --left);
|
|
||||||
return std::make_pair(first, left+1);
|
return std::make_pair(first, left+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue