Left: | ||
Right: |
OLD | NEW |
---|---|
1 #ifndef UTILS_H | 1 #ifndef UTILS_H |
2 #define UTILS_H | 2 #define UTILS_H |
3 | 3 |
4 #include <algorithm> | 4 #include <algorithm> |
5 #include <locale> | 5 #include <locale> |
6 #include <functional> | 6 #include <functional> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #define WM_ALREADY_UP_TO_DATE WM_APP+1 | 9 #define WM_ALREADY_UP_TO_DATE WM_APP+1 |
10 #define WM_UPDATE_CHECK_ERROR WM_APP+2 | 10 #define WM_UPDATE_CHECK_ERROR WM_APP+2 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 T TrimString(T text) | 43 T TrimString(T text) |
44 { | 44 { |
45 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring | 45 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring |
46 T trimmed(text); | 46 T trimmed(text); |
47 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); | 47 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); |
48 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace))); | 48 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace))); |
49 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end()); | 49 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end()); |
50 return trimmed; | 50 return trimmed; |
51 } | 51 } |
52 | 52 |
53 template <class T> | |
54 T ExtractHTTPHeader(const T& allHeaders, const T& targetHeaderName, const T& del imiter) | |
Felix Dahlke
2014/11/03 04:58:16
1. I think we generally capitalise it like this: E
Oleksandr
2014/11/03 11:37:37
2. Http headers can be seperated by '\0' as well.
sergei
2014/11/03 14:17:46
If we really want to have it in utils then tests a
Oleksandr
2014/11/04 12:02:42
Yes, I can see how the changes to make this more g
Felix Dahlke
2014/11/04 16:13:25
Fully agree, good points Sergei.
| |
55 { | |
56 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderName); | |
57 if (targetHeaderBeginsAt == T::npos) | |
58 { | |
59 return T(); | |
60 } | |
61 targetHeaderBeginsAt += targetHeaderName.length(); | |
62 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | |
63 if (targetHeaderEndsAt == T::npos) | |
64 { | |
65 return T(); | |
66 } | |
67 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHead erBeginsAt); | |
68 } | |
69 | |
53 #endif // UTILS_H | 70 #endif // UTILS_H |
OLD | NEW |