File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -10,18 +10,17 @@ data class EmailAddress(
10
10
companion object {
11
11
@JvmStatic
12
12
fun parse (value : String ): EmailAddress =
13
- value.split (' @' ).let { (leftPart, rightPart) ->
13
+ value.splitAroundLast (' @' ).let { (leftPart, rightPart) ->
14
14
EmailAddress (leftPart, rightPart)
15
15
}
16
+ }
17
+ }
16
18
17
- private fun String.split (divider : Char ): Pair <String , String > {
18
- val atIndex = lastIndexOf(divider)
19
- require(! (atIndex < 1 || atIndex == length - 1 )) {
20
- " EmailAddress must be two parts separated by @"
21
- }
22
- val leftPart = substring(0 , atIndex)
23
- val rightPart = substring(atIndex + 1 )
24
- return Pair (leftPart, rightPart)
19
+ private fun String.splitAroundLast (divider : Char ): Pair <String , String > =
20
+ lastIndexOf(divider).let { index ->
21
+ require(index >= 1 && index != length - 1 ) {
22
+ " string must be two non-empty parts separated by $divider "
25
23
}
24
+ substring(0 , index) to substring(index + 1 )
26
25
}
27
- }
26
+
You can’t perform that action at this time.
0 commit comments