Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun doReplace(replace: Command.Replace): CommandResult {
- val elementPath = currentPath.plus(replace.path)
- val toReplace = elementPath.getElement(rootElement)
- if (toReplace != null) {
- val parent = ElementPath(elementPath.segments.dropLast(1)).getElement(rootElement)
- when (parent) {
- is MutableElement.ArrayElement -> {
- val index = replace.path.segments.last().substring(1,2).toInt()
- parent.items[index] = replace.newElement.invoke()
- return CommandResult.Success
- }
- is MutableElement.ObjectElement -> {
- val index = replace.path.segments.last()
- parent.items[index] = replace.newElement.invoke()
- return CommandResult.Success
- }
- }
- }
- return findInvalidPath(replace.path)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement