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;