titovtima

Untitled

Mar 7th, 2021
670
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private fun doReplace(replace: Command.Replace): CommandResult {
  2.         val elementPath = currentPath.plus(replace.path)
  3.         val toReplace = elementPath.getElement(rootElement)
  4.         if (toReplace != null) {
  5.             val parent = ElementPath(elementPath.segments.dropLast(1)).getElement(rootElement)
  6.             when (parent) {
  7.                 is MutableElement.ArrayElement -> {
  8.                     val index = replace.path.segments.last().substring(1,2).toInt()
  9.                     parent.items[index] = replace.newElement.invoke()
  10.                     return CommandResult.Success
  11.                 }
  12.                 is MutableElement.ObjectElement -> {
  13.                     val index = replace.path.segments.last()
  14.                     parent.items[index] = replace.newElement.invoke()
  15.                     return CommandResult.Success
  16.                 }
  17.             }
  18.         }
  19.         return findInvalidPath(replace.path)
  20.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×