Skip to content

Commit

Permalink
feature: 修复长度溢出问题
Browse files Browse the repository at this point in the history
  • Loading branch information
bin-tenkuu committed Aug 6, 2022
1 parent e9f3a6c commit 790bd07
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/bin/morelogic/statement/StringOp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ enum class StringOp(
SubString("SubString") {
override fun invoke(args: IntArray): Op = OpI(args)
override fun buttonTooltip(cell: Cell<Button>) {
cell.tooltip("截取打印缓存中的字符串")
cell.tooltip("截取打印缓存中的字符串,第二个参数可为负数")
}

override fun PrintBufferStatement.invoke(table: Table) {
Expand Down Expand Up @@ -167,7 +167,7 @@ enum class StringOp(
CodePointAt("CodePointAt") {
override fun invoke(args: IntArray): Op = OpI(args)
override fun buttonTooltip(cell: Cell<Button>) {
cell.tooltip("打印缓存中字符")
cell.tooltip("获取打印缓存中某一位字符的码点")
}

override fun PrintBufferStatement.invoke(table: Table) {
Expand All @@ -185,15 +185,19 @@ enum class StringOp(
private inner class OpI(args: IntArray) : Op(args) {
override fun run(exec: LExecutor) {
val buffer = exec.textBuffer
val start = exec.numi(args[1]).coerceIn(0, buffer.length)
if (buffer.isEmpty()) {
exec.setnum(args[0], 0.0)
return
}
val start = exec.numi(args[1]).coerceIn(0, buffer.length - 1)
exec.setnum(args[0], buffer.codePointAt(start).toDouble())
}
}
},
AddCodePoint("AddCodePoint") {
override fun invoke(args: IntArray): Op = OpI(args)
override fun buttonTooltip(cell: Cell<Button>) {
cell.tooltip("打印缓存中字符")
cell.tooltip("将码点转换为字符添加到打印缓存")
}

override fun PrintBufferStatement.invoke(table: Table) {
Expand Down

0 comments on commit 790bd07

Please sign in to comment.