mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 06:12:06 +01:00
Update docs on UserId parsing
This commit is contained in:
parent
b36494ecd4
commit
507b36468b
1 changed files with 16 additions and 1 deletions
|
@ -30,3 +30,18 @@ UserId full = UserId.newBuilder()
|
||||||
.build();
|
.build();
|
||||||
assertEquals("Peter Pattern (Work Address) <peter@pgpainless.org>", full.toString());
|
assertEquals("Peter Pattern (Work Address) <peter@pgpainless.org>", full.toString());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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 <john@doe.corp>";
|
||||||
|
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.
|
||||||
|
|
Loading…
Reference in a new issue