summaryrefslogtreecommitdiff
path: root/tools/common/helpers.h
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-03-18 10:48:26 +0800
committerJohn Hodge <tpg@mutabah.net>2018-03-18 10:48:26 +0800
commit5b0450395af81ceba0d0ac27fc73b16f966bd7d3 (patch)
treee3c753b83a562be78cdbd74b8164dab785bf07a6 /tools/common/helpers.h
parent363e6fa172f787e970c8abc8f631b6d60d571248 (diff)
downloadmrust-5b0450395af81ceba0d0ac27fc73b16f966bd7d3.tar.gz
All - Move toml parser and path header to a common library, start on custom target specs.
Diffstat (limited to 'tools/common/helpers.h')
-rw-r--r--tools/common/helpers.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/common/helpers.h b/tools/common/helpers.h
new file mode 100644
index 00000000..8111483a
--- /dev/null
+++ b/tools/common/helpers.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <string>
+#include <cstring>
+#include <iostream>
+
+namespace helpers {
+
+class string_view
+{
+ const char* m_start;
+ const size_t m_len;
+public:
+ string_view(const char* s, size_t n):
+ m_start(s), m_len(n)
+ {
+ }
+
+ bool operator==(const ::std::string& s) const {
+ return *this == s.c_str();
+ }
+ bool operator==(const char* s) const {
+ if(::std::strncmp(m_start, s, m_len) != 0)
+ return false;
+ return s[m_len] == '\0';
+ }
+
+ char operator[](size_t n) const {
+ return m_start[n];
+ }
+
+ operator ::std::string() const {
+ return ::std::string { m_start, m_start + m_len };
+ }
+ friend ::std::string& operator+=(::std::string& x, const string_view& sv) {
+ x.append(sv.m_start, sv.m_start+sv.m_len);
+ return x;
+ }
+ friend ::std::ostream& operator<<(::std::ostream& os, const string_view& sv) {
+ os.write(sv.m_start, sv.m_len);
+ return os;
+ }
+
+ const char* begin() const {
+ return m_start;
+ }
+ const char* end() const {
+ return m_start+m_len;
+ }
+};
+
+
+} // namespace helpers