summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/address.h13
-rw-r--r--src/include/convert.h17
2 files changed, 24 insertions, 6 deletions
diff --git a/src/include/address.h b/src/include/address.h
index 2cb4aef..2e354be 100644
--- a/src/include/address.h
+++ b/src/include/address.h
@@ -1,14 +1,15 @@
/**
- * @file address.h
- * @brief Declaration of the Address class.
- * @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @file address.h
+ * @brief Declaration of the Address class.
+ * @author Andreas Aardal Hanssen
+ * @date 2002-2005
*/
#ifndef address_h_included
#define address_h_included
#include <string>
+#include <string_view>
namespace Binc {
@@ -19,8 +20,8 @@ namespace Binc {
std::string toParenList() const;
- Address(const std::string &name, const std::string &addr);
- Address(const std::string &wholeaddr);
+ static Address from(std::string name, std::string_view addr);
+ static Address from(std::string_view wholeaddr);
};
}
diff --git a/src/include/convert.h b/src/include/convert.h
index 0c7e703..030c1b5 100644
--- a/src/include/convert.h
+++ b/src/include/convert.h
@@ -15,6 +15,7 @@
#include <iomanip>
#include <iostream>
#include <string>
+#include <string_view>
#include <vector>
#include <stdio.h>
@@ -130,6 +131,22 @@ namespace Binc {
chomp(s_in, chars);
}
+ inline void trim(std::string_view &s_in, std::string_view chars = " \t\r\n")
+ {
+ size_t n = 0;
+ while (n < s_in.length() && chars.find(s_in[n]) != std::string_view::npos) {
+ n++;
+ }
+ s_in = s_in.substr(n);
+
+ if (s_in.empty()) return;
+
+ n = s_in.length();
+ while (n > 0 && chars.find(s_in[--n]) != std::string_view::npos) {
+ }
+ s_in = s_in.substr(0, n + 1);
+ }
+
inline const std::string unfold(const std::string &a, bool removecomment = true)
{
std::string tmp;