首页 > 解决方案 > Scala 编辑擦除

问题描述

我有一系列需要通过的测试,其中一个是编辑擦除。

/**
   * Edit Erase  (forward delete).  Delete the character to the right of the
   * cursor. If the cursor is at the end of the buffer then ignore this command
   * (there is no character to the right of the cursor). If deletion succeeds
   * then do not change the cursor position.  The marker position is not
   * changed UNLESS the deletion has caused it to point beyond the end of the
   * (updated) buffer. In this case make the marker equal to end.
   */

Marker 和 Cursor 是 Int 并且缓冲区是一个字符串。

我需要做的是,如果光标是结尾(buffer.length),则需要忽略该命令,但是我坚持的位是仅在删除导致标记时才使标记移动到结尾大于缓冲区长度。

我已经写了一些代码,但是对此有什么建议吗?

def ee() {
  if(cursor != end) {
    buffer.delete(cursor,cursor+ 1) 
    if(marker > end) 
      marker = buffer.length
  }
}

标签: scala

解决方案


推荐阅读