From aa70f1bbe2c5acaefbb0a5958055ca4e0aa875d4 Mon Sep 17 00:00:00 2001 From: 493msi <493msi@gmail.com> Date: Mon, 21 Sep 2020 00:05:43 +0200 Subject: [PATCH] [PlutoCommandParser] Code cleanup --- UPDATE_NOTES.md | 1 + .../pluto/command/context/CommandContextBuilder.java | 2 +- .../java/cz/tefek/pluto/command/parser/CommandParser.java | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/UPDATE_NOTES.md b/UPDATE_NOTES.md index fc1582f..61317c9 100644 --- a/UPDATE_NOTES.md +++ b/UPDATE_NOTES.md @@ -17,6 +17,7 @@ can now only be modified only through public setters * `[PlutoCore]` Refactored `InputBus` and added several convenience methods * `[PlutoCore]` Refactored input callbacks * `[PlutoStatic]` Slight cleanup in the `Display` and `DisplayBuilder` classes +* `[PlutoCommandParser]` Code cleanup ## 20.2.0.0-alpha.1 * `[PlutoLib#cz.tefek.pluto.io.logger]` Refactored the Logger subsystem diff --git a/plutocommandparser/src/main/java/cz/tefek/pluto/command/context/CommandContextBuilder.java b/plutocommandparser/src/main/java/cz/tefek/pluto/command/context/CommandContextBuilder.java index 758b7eb..083b2fd 100644 --- a/plutocommandparser/src/main/java/cz/tefek/pluto/command/context/CommandContextBuilder.java +++ b/plutocommandparser/src/main/java/cz/tefek/pluto/command/context/CommandContextBuilder.java @@ -4,7 +4,7 @@ import cz.tefek.pluto.command.CommandBase; public class CommandContextBuilder { - private CommandContext ctx; + private final CommandContext ctx; public CommandContextBuilder() { diff --git a/plutocommandparser/src/main/java/cz/tefek/pluto/command/parser/CommandParser.java b/plutocommandparser/src/main/java/cz/tefek/pluto/command/parser/CommandParser.java index 8f2dfbd..fcf93a5 100644 --- a/plutocommandparser/src/main/java/cz/tefek/pluto/command/parser/CommandParser.java +++ b/plutocommandparser/src/main/java/cz/tefek/pluto/command/parser/CommandParser.java @@ -14,7 +14,7 @@ import cz.tefek.pluto.command.registry.CommandRegistry; public class CommandParser { - private String text; + private final String text; private Set prefixes; private EnumParserState state; @@ -196,7 +196,11 @@ public class CommandParser this.state = EnumParserState.READING_PREFIX; } - this.text.codePoints().takeWhile(this::readCodepoint); + var cps = this.text.codePoints(); + + for (var cpIt = cps.iterator(); cpIt.hasNext(); ) + if (!this.readCodepoint(cpIt.next())) + break; // Update the state for EOF switch (this.state)