summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-03-13 14:03:58 +0000
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-03-13 14:20:54 +0000
commit821b8e50fbfbabe7fe6d0ca0a1778466f07ad1ea (patch)
treed2bd3b7e47f5d1a5b5c1bc65d26840e61fb08f2f /searchlib
parent0edbcb2ffab1f846ba17b5942e8e5043ab51f556 (diff)
Let sub parser be template arg instead of C function pointer
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/util/url.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/util/url.h46
2 files changed, 32 insertions, 32 deletions
diff --git a/searchlib/src/vespa/searchlib/util/url.cpp b/searchlib/src/vespa/searchlib/util/url.cpp
index d60ed222305..a8fb15f2eb1 100644
--- a/searchlib/src/vespa/searchlib/util/url.cpp
+++ b/searchlib/src/vespa/searchlib/util/url.cpp
@@ -144,11 +144,11 @@ URL::IsTokenChar(unsigned char c) // According to FAST URL tokenization
c == '_' || c == '-');
}
+template <bool (*IsPartChar)(unsigned char c)>
unsigned char *
URL::ParseURLPart(unsigned char *src,
unsigned char *dest,
- unsigned int destsize,
- bool (*IsPartChar)(unsigned char c))
+ unsigned int destsize)
{
unsigned char *p = src;
unsigned int len = 0;
@@ -279,7 +279,7 @@ URL::SetURL(const unsigned char *url, size_t length)
if (p[0] == '/' && p[1] == '/')
p += 2;
_startHost = p;
- p = ParseURLPart(p, _host, sizeof(_host), IsHostChar);
+ p = ParseURLPart<IsHostChar>(p, _host, sizeof(_host));
// Locate siteowner. eg. 'www.sony.com' => 'sony'
if (_host[0] != '\0') {
@@ -341,7 +341,7 @@ URL::SetURL(const unsigned char *url, size_t length)
if (*p == ':') {
p++;
_startPort = p;
- p = ParseURLPart(p, _port, sizeof(_port), IsDigitChar);
+ p = ParseURLPart<IsDigitChar>(p, _port, sizeof(_port));
}
}
@@ -351,7 +351,7 @@ URL::SetURL(const unsigned char *url, size_t length)
// Parse path, filename, extension.
_startPath = p;
- p = ParseURLPart(p, _path, sizeof(_path), IsPathChar);
+ p = ParseURLPart<IsPathChar>(p, _path, sizeof(_path));
filename = _path;
if (IsFileNameChar(*filename))
@@ -363,7 +363,7 @@ URL::SetURL(const unsigned char *url, size_t length)
_pathDepth++;
}
_startFileName = _startPath + (filename - _path);
- ParseURLPart(filename, _filename, sizeof(_filename), IsFileNameChar);
+ ParseURLPart<IsFileNameChar>(filename, _filename, sizeof(_filename));
extension = reinterpret_cast<unsigned char *>
(strrchr(reinterpret_cast<char *>(_filename), '.'));
@@ -379,21 +379,21 @@ URL::SetURL(const unsigned char *url, size_t length)
(strchr(reinterpret_cast<char *>(_path), ';'))) != NULL) {
ptmp++;
_startParams = _startPath + (ptmp - _path);
- ParseURLPart(ptmp, _params, sizeof(_params), IsParamsChar);
+ ParseURLPart<IsParamsChar>(ptmp, _params, sizeof(_params));
}
// Parse query part.
if (*p == '?') {
p++;
_startQuery = p;
- p = ParseURLPart(p, _query, sizeof(_query), IsQueryChar);
+ p = ParseURLPart<IsQueryChar>(p, _query, sizeof(_query));
}
// Parse fragment part
if (*p == '#') {
p++;
_startFragment = p;
- p = ParseURLPart(p, _fragment, sizeof(_fragment), IsFragmentChar);
+ p = ParseURLPart<IsFragmentChar>(p, _fragment, sizeof(_fragment));
}
// stuff the rest into address
diff --git a/searchlib/src/vespa/searchlib/util/url.h b/searchlib/src/vespa/searchlib/util/url.h
index f700f0f79f1..e7f50b2e31a 100644
--- a/searchlib/src/vespa/searchlib/util/url.h
+++ b/searchlib/src/vespa/searchlib/util/url.h
@@ -89,32 +89,32 @@ protected:
void Reset(void);
- static inline unsigned char *ParseURLPart(unsigned char *url,
+ template <bool (*IsPartChar)(unsigned char c)>
+ static unsigned char *ParseURLPart(unsigned char *url,
unsigned char *buf,
- unsigned int bufsize,
- bool (*IsPartChar)(unsigned char c));
+ unsigned int bufsize);
public:
- static inline bool IsAlphaChar(unsigned char c);
- static inline bool IsDigitChar(unsigned char c);
- static inline bool IsMarkChar(unsigned char c);
- static inline bool IsUnreservedChar(unsigned char c);
- static inline bool IsEscapedChar(unsigned char c);
- static inline bool IsReservedChar(unsigned char c);
- static inline bool IsUricChar(unsigned char c);
- static inline bool IsPChar(unsigned char c);
-
- static inline bool IsSchemeChar(unsigned char c);
- static inline bool IsHostChar(unsigned char c);
- static inline bool IsPortChar(unsigned char c);
- static inline bool IsPathChar(unsigned char c);
- static inline bool IsFileNameChar(unsigned char c);
- static inline bool IsParamsChar(unsigned char c);
- static inline bool IsParamChar(unsigned char c);
- static inline bool IsQueryChar(unsigned char c);
- static inline bool IsFragmentChar(unsigned char c);
-
- static inline bool IsTokenChar(unsigned char c);
+ static bool IsAlphaChar(unsigned char c);
+ static bool IsDigitChar(unsigned char c);
+ static bool IsMarkChar(unsigned char c);
+ static bool IsUnreservedChar(unsigned char c);
+ static bool IsEscapedChar(unsigned char c);
+ static bool IsReservedChar(unsigned char c);
+ static bool IsUricChar(unsigned char c);
+ static bool IsPChar(unsigned char c);
+
+ static bool IsSchemeChar(unsigned char c);
+ static bool IsHostChar(unsigned char c);
+ static bool IsPortChar(unsigned char c);
+ static bool IsPathChar(unsigned char c);
+ static bool IsFileNameChar(unsigned char c);
+ static bool IsParamsChar(unsigned char c);
+ static bool IsParamChar(unsigned char c);
+ static bool IsQueryChar(unsigned char c);
+ static bool IsFragmentChar(unsigned char c);
+
+ static bool IsTokenChar(unsigned char c);
/**
* Defautl constructor. Optionally, the URL to be parsed may be given