aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/http_util/http_util.cpp27
-rw-r--r--src/lib/utils/mem_pool/mem_pool.cpp2
-rw-r--r--src/lib/utils/scan_name.cpp8
-rw-r--r--src/lib/utils/scan_name.h2
4 files changed, 25 insertions, 14 deletions
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp
index 8ce3b1b94..5527f5041 100644
--- a/src/lib/utils/http_util/http_util.cpp
+++ b/src/lib/utils/http_util/http_util.cpp
@@ -23,7 +23,7 @@ namespace {
* closes the socket.
*/
std::string http_transact(const std::string& hostname,
- const std::string& service,
+ const std::string& service,
const std::string& message,
std::chrono::milliseconds timeout)
{
@@ -67,6 +67,19 @@ std::string http_transact(const std::string& hostname,
return oss.str();
}
+bool needs_url_encoding(char c)
+ {
+ if(c >= 'A' && c <= 'Z')
+ return false;
+ if(c >= 'a' && c <= 'z')
+ return false;
+ if(c >= '0' && c <= '9')
+ return false;
+ if(c == '-' || c == '_' || c == '.' || c == '~')
+ return false;
+ return true;
+ }
+
}
std::string url_encode(const std::string& in)
@@ -75,16 +88,10 @@ std::string url_encode(const std::string& in)
for(auto c : in)
{
- if(c >= 'A' && c <= 'Z')
- out << c;
- else if(c >= 'a' && c <= 'z')
- out << c;
- else if(c >= '0' && c <= '9')
- out << c;
- else if(c == '-' || c == '_' || c == '.' || c == '~')
- out << c;
- else
+ if(needs_url_encoding(c))
out << '%' << hex_encode(cast_char_ptr_to_uint8(&c), 1);
+ else
+ out << c;
}
return out.str();
diff --git a/src/lib/utils/mem_pool/mem_pool.cpp b/src/lib/utils/mem_pool/mem_pool.cpp
index 872196c86..bc6d97f73 100644
--- a/src/lib/utils/mem_pool/mem_pool.cpp
+++ b/src/lib/utils/mem_pool/mem_pool.cpp
@@ -149,7 +149,7 @@ class BitMap final
BitMap(size_t bits) : m_len(bits)
{
m_bits.resize((bits + BITMASK_BITS - 1) / BITMASK_BITS);
- m_main_mask = static_cast<bitmask_type>(~0);
+ m_main_mask = ~static_cast<bitmask_type>(0);
m_last_mask = m_main_mask;
if(bits % BITMASK_BITS != 0)
diff --git a/src/lib/utils/scan_name.cpp b/src/lib/utils/scan_name.cpp
index e2a8112c8..5b1390923 100644
--- a/src/lib/utils/scan_name.cpp
+++ b/src/lib/utils/scan_name.cpp
@@ -60,8 +60,12 @@ SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec))
{
}
-SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info()
- {
+SCAN_Name::SCAN_Name(const std::string& algo_spec) :
+ m_orig_algo_spec(algo_spec),
+ m_alg_name(),
+ m_args(),
+ m_mode_info()
+ {
if(algo_spec.empty())
throw Invalid_Argument("Expected algorithm name, got empty string");
diff --git a/src/lib/utils/scan_name.h b/src/lib/utils/scan_name.h
index 7135a0eb3..65e02f7ac 100644
--- a/src/lib/utils/scan_name.h
+++ b/src/lib/utils/scan_name.h
@@ -31,7 +31,7 @@ class SCAN_Name final
* Create a SCAN_Name
* @param algo_spec A SCAN-format name
*/
- explicit SCAN_Name(std::string algo_spec);
+ explicit SCAN_Name(const std::string& algo_spec);
/**
* @return original input string