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
This commit is contained in:
Josh Gao 2019-02-20 19:36:00 -08:00
parent aeca208385
commit ac8da2a7df
1 changed files with 8 additions and 0 deletions

View File

@ -141,3 +141,11 @@ inline bool ParseUint(T* result, std::string_view str, std::string_view* remaini
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;
}