stevethecoder
12/03/2015, 12:53 PMclass AddOperationToken : DataOperationCommandToken {
override val setSBit : Boolean
get() = field
override val conditionInt : Int
get() = field
constructor(content : String) : super(content) {
val pairOfData : Pair<Boolean, Int> = threeLetterOptionSCommandParse(content)
setSBit = pairOfData.first
conditionInt = pairOfData.second
}
}
// in a seperate .kt file
fun threeLetterOptionSCommandParse(optionalCommandString : String) : Pair<Boolean, Int> {
val settingS : Boolean
val finalConditionInt : Int
when (optionalCommandString.length) {
3, 4 -> {
settingS = optionalCommandString.last() == 'S'
finalConditionInt = conditionCodeValue("")
}
5 -> {
settingS = false // ORR<c>optionalCommandString[3]
finalConditionInt = conditionCodeValue(optionalCommandString.substring(3))
}
6 -> {
if (optionalCommandString[3] == 'S') {
settingS = true
} else {
error("Illegal token passed to ORR{S}: ${optionalCommandString[3]}")
}
finalConditionInt = conditionCodeValue(optionalCommandString.substring(4))
}
else -> {
error("ORR Token attempted initialization failed with args: optionalCommandString = $optionalCommandString")
}
}
val pair = Pair(settingS, finalConditionInt)
println("returning pair = $pair")
return pair
}