summaryrefslogtreecommitdiff
path: root/src/base/str.hh
diff options
context:
space:
mode:
authorSteve Reinhardt <steve.reinhardt@amd.com>2012-08-06 16:52:49 -0700
committerSteve Reinhardt <steve.reinhardt@amd.com>2012-08-06 16:52:49 -0700
commitb647b48bf4d980e26b4626e94f1207ad66fc324e (patch)
tree552ff31c06305500cde480a456a152d94f9e1293 /src/base/str.hh
parentd55115936e0711422c6d708572b391e15432bec1 (diff)
downloadgem5-b647b48bf4d980e26b4626e94f1207ad66fc324e.tar.xz
str: add an overloaded startswith() utility method
for various string types and use it in a few places.
Diffstat (limited to 'src/base/str.hh')
-rw-r--r--src/base/str.hh32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/base/str.hh b/src/base/str.hh
index 6d617df72..b3f3153ec 100644
--- a/src/base/str.hh
+++ b/src/base/str.hh
@@ -33,6 +33,7 @@
#define __STR_HH__
#include <cctype>
+#include <cstring>
#include <sstream>
#include <string>
#include <vector>
@@ -140,4 +141,35 @@ quote(const std::string &s)
return ret;
}
+
+/**
+ * Return true if 's' starts with the prefix string 'prefix'.
+ */
+inline bool
+startswith(const char *s, const char *prefix)
+{
+ return (strncmp(s, prefix, strlen(prefix)) == 0);
+}
+
+
+/**
+ * Return true if 's' starts with the prefix string 'prefix'.
+ */
+inline bool
+startswith(const std::string &s, const char *prefix)
+{
+ return (s.compare(0, strlen(prefix), prefix) == 0);
+}
+
+
+/**
+ * Return true if 's' starts with the prefix string 'prefix'.
+ */
+inline bool
+startswith(const std::string &s, const std::string &prefix)
+{
+ return (s.compare(0, prefix.size(), prefix) == 0);
+}
+
+
#endif //__STR_HH__