Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac8da2a7 authored by Josh Gao's avatar Josh Gao
Browse files

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
parent aeca2083
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;
}