diff --git a/core/src/net/sf/openrocket/formatting/MotorConfigurationSubstitutor.java b/core/src/net/sf/openrocket/formatting/MotorConfigurationSubstitutor.java
index 864a0ea8a..71f1ae751 100644
--- a/core/src/net/sf/openrocket/formatting/MotorConfigurationSubstitutor.java
+++ b/core/src/net/sf/openrocket/formatting/MotorConfigurationSubstitutor.java
@@ -12,11 +12,11 @@ import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
-import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.util.ArrayList;
import net.sf.openrocket.util.Chars;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@@ -26,8 +26,8 @@ import java.util.regex.Pattern;
* General substitutor for motor configurations. This currently includes substitutions for
* - {motors} - the motor designation (e.g. "M1350-0")
* - {manufacturers} - the motor manufacturer (e.g. "AeroTech")
- * - a combination of motors and manufacturers, e.g. {motors | manufacturers} -> "M1350-0 | AeroTech"
- * You can choose which comes first and what the separator is. E.g. {manufacturers, motors} -> "AeroTech, M1350-0".
+ * - a combination of motors and manufacturers, e.g. {motors manufacturers} -> "M1350-0 AeroTech"
+ * You can choose which comes first is. E.g. {manufacturers motors} -> "AeroTech M1350-0".
*
*
* This substitutor is added through injection. All substitutors with the "@Plugin" tag in the formatting package will
@@ -35,217 +35,250 @@ import java.util.regex.Pattern;
*/
@Plugin
public class MotorConfigurationSubstitutor implements RocketSubstitutor {
- public static final String SUBSTITUTION_START = "{";
- public static final String SUBSTITUTION_END = "}";
- public static final String SUBSTITUTION_MOTORS = "motors";
- public static final String SUBSTITUTION_MANUFACTURERS = "manufacturers";
+ // Substitution start and end
+ public static final String SUB_START = "{";
+ public static final String SUB_END = "}";
- // Substitutions for combinations of motors and manufacturers
- private static final String SUBSTITUTION_PATTERN = "\\" + SUBSTITUTION_START +
- "(" + SUBSTITUTION_MOTORS + "|" + SUBSTITUTION_MANUFACTURERS + ")" +
- "(.*?)" +
- "(" + SUBSTITUTION_MOTORS + "|" + SUBSTITUTION_MANUFACTURERS + ")" +
- "\\" + SUBSTITUTION_END;
+ // Map containing substitution words and their corresponding replacement strings.
+ private static final Map SUBSTITUTIONS = new HashMap<>();
+
+ static {
+ SUBSTITUTIONS.put("motors", new MotorSubstitutor());
+ SUBSTITUTIONS.put("manufacturers", new ManufacturerSubstitutor());
+ SUBSTITUTIONS.put("cases", new CaseSubstitutor());
+ }
@Inject
private Translator trans;
@Override
public boolean containsSubstitution(String input) {
- return getSubstitutionContent(input) != null;
+ Pattern pattern = Pattern.compile("\\" + SUB_START + "(.*?[^\\s])\\" + SUB_END); // ensures non-whitespace content
+ Matcher matcher = pattern.matcher(input);
+
+ while (matcher.find()) {
+ String tagContent = matcher.group(1).trim();
+ for (String key : SUBSTITUTIONS.keySet()) {
+ if (tagContent.contains(key)) {
+ return true;
+ }
+ }
+ }
+ return false;
}
@Override
public String substitute(String input, Rocket rocket, FlightConfigurationId configId) {
- String description = getConfigurationSubstitution(input, rocket, configId);
- String substitutionString = getSubstiutionString(input);
- if (substitutionString != null) {
- return input.replace(substitutionString, description);
+ Pattern pattern = Pattern.compile("\\" + SUB_START + "(.*?)\\" + SUB_END);
+ Matcher matcher = pattern.matcher(input);
+ StringBuilder resultBuffer = new StringBuilder();
+
+ while (matcher.find()) {
+ String tagContent = matcher.group(1).trim();
+ String[] keys = tagContent.split("\\s");
+
+ List