blob: 273b5a273c9d7cecbabf964b5334499565b93354 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package org.pacien.tincapp.data
import org.apache.commons.configuration2.ex.ConversionException
/**
* @author pacien
*/
data class CidrAddress(val address: String, val prefix: Int) {
companion object {
private val SEPARATOR = "/"
fun fromSlashSeparated(s: String) = try {
CidrAddress(s.substringBefore(SEPARATOR), Integer.parseInt(s.substringAfter(SEPARATOR)))
} catch (e: Exception) {
throw ConversionException(e.message, e)
}
}
fun toSlashSeparated() = address + SEPARATOR + prefix
}
|