From c7b4404c361576fe92d024fb8a72be15d2c0019b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 8 Aug 2024 12:19:53 -0400 Subject: [PATCH] Regex used for strsplit --- src/engine/ConfigParsing/EffectsParser.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/engine/ConfigParsing/EffectsParser.java b/src/engine/ConfigParsing/EffectsParser.java index c8f48ffb..6b489d39 100644 --- a/src/engine/ConfigParsing/EffectsParser.java +++ b/src/engine/ConfigParsing/EffectsParser.java @@ -14,6 +14,7 @@ import engine.gameManager.ConfigManager; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -25,7 +26,7 @@ public class EffectsParser { private static final Pattern EFFECT_REGEX = Pattern.compile("(?<=EFFECTBEGIN)(.+?)(?=EFFECTEND)", Pattern.DOTALL); private static final Pattern SOURCE_REGEX = Pattern.compile("(?<=SOURCEBEGIN)(.+?)(?=SOURCEEND)", Pattern.DOTALL); private static final Pattern MODS_REGEX = Pattern.compile("(?<=MODSBEGIN)(.+?)(?=MODSEEND)", Pattern.DOTALL); - + private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\".+?\")\\s*"); public static void init() throws IOException { byte[] fileData = Files.readAllBytes(Paths.get(EffectsPath)); @@ -53,15 +54,20 @@ public class EffectsParser { // Parse effect entry description String firstLine = effectData.substring(0, effectData.indexOf('\n')); - String[] effectDescription = firstLine.split(" "); + ArrayList effectDescription = new ArrayList<>(); + + Matcher matcher = STRSPLIT_REGEX.matcher(firstLine); + + while (matcher.find()) + effectDescription.add(matcher.group(1)); - effectEntry.id = effectDescription[0]; - effectEntry.name = effectDescription[1]; - effectEntry.icon = Integer.parseInt(effectDescription[2]); + effectEntry.id = effectDescription.get(0); + effectEntry.name = effectDescription.get(1); + effectEntry.icon = Integer.parseInt(effectDescription.get(2)); // Parse source entries - Matcher matcher = SOURCE_REGEX.matcher(effectData); + matcher = SOURCE_REGEX.matcher(effectData); while (matcher.find()) effectEntry.sources.add(matcher.group().trim());