diff options
author | Josh Gao <jmgao@google.com> | 2019-02-26 20:55:19 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-02-26 20:55:19 +0000 |
commit | 216d158daf88edfd954dc03c65b339698319f63d (patch) | |
tree | f925f4c4dec9a8e1c25943920c0ad882dd8e5b47 /adb/adb_utils.h | |
parent | 1706eb08fe8a7600d4698566b3d779b97bd1e279 (diff) | |
parent | 43f3805950d69f9da87664ada214d5af0e02753f (diff) |
Merge changes I86c3ec0f,I57d1a30a,Ib50d289b,I791a4f82,I316a8799, ...
* changes:
adb: switch sockets.cpp to ConsumePrefix.
adbd: switch abb to ConsumePrefix.
adb: increment server version.
adb: wait for device to disconnect upon `adb root`.
adb: implement wait-for-disconnect.
adb: tell the client what transport it received.
adbd: switch daemon/services to ConsumePrefix.
adb: switch host_service_to_socket to string_view.
adb: switch handle_host_request to string_view.
adb: switch adb_io.h to string_view.
adb: add helper to consume a prefix on a string_view.
adb: make ParseUint reject garbage at the end by default.
Diffstat (limited to 'adb/adb_utils.h')
-rw-r--r-- | adb/adb_utils.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/adb/adb_utils.h b/adb/adb_utils.h index a85ca8c844..5800a62f75 100644 --- a/adb/adb_utils.h +++ b/adb/adb_utils.h @@ -110,7 +110,7 @@ inline std::string_view StripTrailingNulls(std::string_view str) { // Base-10 stroll on a string_view. template <typename T> -inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining) { +inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining = nullptr) { if (str.empty() || !isdigit(str[0])) { return false; } @@ -135,6 +135,17 @@ inline bool ParseUint(T* result, std::string_view str, std::string_view* remaini *result = value; if (remaining) { *remaining = str.substr(it - str.begin()); + } else { + return it == str.end(); } + + 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; } |