Skip to content

Commit

Permalink
fix: fix a parsing error and turns it into a singleton using enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Feb 23, 2025
1 parent 611adf5 commit 7e9657c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions megamek/src/megamek/client/generator/RandomCallsignGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ private void loadCallsignsFromFile(File file, Map<String, Integer> callsigns) {

while (input.hasNextLine()) {
lineNumber++;
String[] values = input.nextLine().split(",");
if (values.length == 2) {
String line = input.nextLine();
int lastCommaIndex = line.lastIndexOf(",");
if (lastCommaIndex == -1 || line.length() == lastCommaIndex + 1) {
logger.debug("Not enough fields in {} on {}",file, lineNumber);
continue;
}

String[] values = {line.substring(0, lastCommaIndex), line.substring(lastCommaIndex + 1)};

try {
callsigns.put(values[0], Integer.parseInt(values[1].trim()));
} else if (values.length < 2) {
logger.warn("Not enough fields in {} on {}",file, lineNumber);
} else {
logger.warn("Too many fields in {} on {}", file, lineNumber);
} catch (NumberFormatException e) {
logger.warn("Invalid weight in {} on {}", file, lineNumber);
}
}
} catch (Exception e) {
Expand Down

0 comments on commit 7e9657c

Please sign in to comment.