summaryrefslogtreecommitdiff
path: root/libartbase/base/utils.h
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2021-02-08 17:46:15 -0800
committer Alex Light <allight@google.com> 2021-02-10 01:39:40 +0000
commit60117aeeffda3d01a5314984694ae3d6d4588fc1 (patch)
tree12f5062c456de8b50418a8fb74c801c8ccc5b690 /libartbase/base/utils.h
parentc7ac91b21d1a15c14e29d69ff02b48c485962b0d (diff)
Improve string splitting
String splitting is something that we often have to do but our support code for doing so is not the best. Add support for using std::string_view in many circumstances and add support for making an iterator of splits without allocation. Test: ./test.py --host Change-Id: I1b56b7e10926a064b64011326b508dd4af707df9
Diffstat (limited to 'libartbase/base/utils.h')
-rw-r--r--libartbase/base/utils.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/libartbase/base/utils.h b/libartbase/base/utils.h
index 66a5699519..7160302daa 100644
--- a/libartbase/base/utils.h
+++ b/libartbase/base/utils.h
@@ -44,7 +44,16 @@ std::string PrettySize(uint64_t size_in_bytes);
// Splits a string using the given separator character into a vector of
// strings. Empty strings will be omitted.
-void Split(const std::string& s, char separator, std::vector<std::string>* result);
+template<typename StrIn, typename Str>
+void Split(const StrIn& s, char separator, std::vector<Str>* out_result);
+
+template<typename Str>
+void Split(const Str& s, char separator, size_t len, Str* out_result);
+
+template<typename StrIn, typename Str, size_t kLen>
+void Split(const StrIn& s, char separator, std::array<Str, kLen>* out_result) {
+ Split<Str>(Str(s), separator, kLen, &((*out_result)[0]));
+}
// Returns the calling thread's tid. (The C libraries don't expose this.)
uint32_t GetTid();