adb: add helper to consume a prefix on a string_view.
It's error-prone to manually writing code of the following form:
if (foo.starts_with("some_prefix:")) {
foo.remove_prefix(strlen("some_prefix:"));
}
Add a helper to do that for us.
Test: mma
Change-Id: I5df391deba8b6c036fcbf17a1f1c79af8d9abd2b
diff --git a/adb/adb_utils.h b/adb/adb_utils.h
index 8b0dcee..5800a62 100644
--- a/adb/adb_utils.h
+++ b/adb/adb_utils.h
@@ -141,3 +141,11 @@
return true;
}
+
+inline bool ConsumePrefix(std::string_view* str, std::string_view prefix) {
+ if (str->starts_with(prefix)) {
+ str->remove_prefix(prefix.size());
+ return true;
+ }
+ return false;
+}