From 507b36468b299173da06f4a21583763f2697541d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 2 Jan 2023 14:06:19 +0100 Subject: [PATCH] Update docs on UserId parsing --- docs/source/pgpainless-core/userids.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/source/pgpainless-core/userids.md b/docs/source/pgpainless-core/userids.md index 78126828..d2b5730e 100644 --- a/docs/source/pgpainless-core/userids.md +++ b/docs/source/pgpainless-core/userids.md @@ -29,4 +29,19 @@ UserId full = UserId.newBuilder() .withComment("Work Address") .build(); assertEquals("Peter Pattern (Work Address) ", full.toString()); -``` \ No newline at end of file +``` + +If you have a User-ID in form of a string (e.g. because a user provided it via a text field), +you can parse it into its components like this: + +```java +String string = "John Doe "; +UserId userId = UserId.parse(string); + +// Now you can access the different components +assertEquals("John Doe", userId.getName()); +assertEquals("john@doe.corp", userId.getEmail()); +assertNull(userId.getComment()); +``` + +The method `UserId.parse(String string)` will throw an `IllegalArgumentException` if the User-ID is malformed.