commit | 11fa41d55d2350d9217e6f8777b54f2502f714ba | [log] [tgz] |
---|---|---|
author | Lorenzo Colitti <lorenzo@google.com> | Tue May 19 08:12:55 2020 +0000 |
committer | Lorenzo Colitti <lorenzo@google.com> | Wed May 20 16:07:02 2020 +0000 |
tree | e4206c059bad41232ba8d1d3c956176bc663a444 | |
parent | d25a734d694e62384943c870fc74582c71f040d0 [diff] [blame] |
Add an IPPrefix::forString parsing function. This provides a way to parse IP prefixes from strings, and addresses a TODO. Instead of reusing NetdConstants' parsePrefix function, which it cannot depend on, it implements the parsing using the IPAddress class in the same file and standard string methods. Bug: 153694684 Test: new unit tests Original-Change: https://android-review.googlesource.com/1313840 Merged-In: I47b29c8525f3c0236e48b4bb8dbebb223e83bc31 Change-Id: I47b29c8525f3c0236e48b4bb8dbebb223e83bc31
diff --git a/libnetdutils/include/netdutils/InternetAddresses.h b/libnetdutils/include/netdutils/InternetAddresses.h index e817b78..d5cbe2b 100644 --- a/libnetdutils/include/netdutils/InternetAddresses.h +++ b/libnetdutils/include/netdutils/InternetAddresses.h
@@ -195,7 +195,12 @@ class IPPrefix { public: - // TODO: "static forString(...)" using NetdConstants' parsePrefix(). + static bool forString(const std::string& repr, IPPrefix* prefix); + static IPPrefix forString(const std::string& repr) { + IPPrefix prefix; + if (!forString(repr, &prefix)) return IPPrefix(); + return prefix; + } IPPrefix() = default; IPPrefix(const IPPrefix&) = default;