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(
1010 companion object {
1111 @JvmStatic
1212 fun parse (value : String ): EmailAddress =
13- value.split (' @' ).let { (leftPart, rightPart) ->
13+ value.splitAroundLast (' @' ).let { (leftPart, rightPart) ->
1414 EmailAddress (leftPart, rightPart)
1515 }
16+ }
17+ }
1618
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 "
2523 }
24+ substring(0 , index) to substring(index + 1 )
2625 }
27- }
26+
You can’t perform that action at this time.
0 commit comments