Skip to content

Commit

Permalink
Merge pull request #87 from dma-ais/pr/message27fix
Browse files Browse the repository at this point in the history
Pr/message27fix
  • Loading branch information
dimitrispallas authored Jun 5, 2023
2 parents 31920f0 + c7924d7 commit fd35c8c
Showing 1 changed file with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public void parse(String line) throws CommentBlockException {
int start = -1;
int end = -1;
checksum = 0;

if (line.startsWith("\\g:")) {
parseCommentBlockWithLetterG(line);
} else {
System.out.println(line);
validateCommentBlock(line, start, end);
}
}

public void validateCommentBlock(String line, int start, int end) throws CommentBlockException {
// Find start, end, checksum and fields
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
Expand All @@ -59,13 +69,6 @@ public void parse(String line) throws CommentBlockException {
}
}
}
if (start < 0) {
throw new CommentBlockException("No comment block found");
}
if (end < 0) {
throw new CommentBlockException("Malformed comment block");
}

// Check checksum
try {
String given = line.substring(end + 1, end + 3);
Expand Down Expand Up @@ -131,6 +134,36 @@ public void parse(String line) throws CommentBlockException {
}
}

public void parseCommentBlockWithLetterG(String line) throws CommentBlockException {
parameterMap = new HashMap<>();
int start = line.indexOf("\\g:");
int end = line.indexOf("*");

if (start < 0) {
throw new CommentBlockException("No comment block found");
}

if (end < 0) {
throw new CommentBlockException("Malformed comment block");
}

// Extract the parameter values from the line
String params = line.substring(start + 3, end);

// Split the parameters using regular expression
String[] pairs = params.split("(?<!\\\\),");

for (String pair : pairs) {
// Split each pair into parameter code and value
String[] parts = pair.split("(?<!\\\\):");
if (parts.length == 2) {
String parameterCode = parts[0].replaceAll("\\\\,", ",");
String value = parts[1].replaceAll("\\\\:", ":");
parameterMap.put(parameterCode, value);
}
}
}

/**
* Gets total lines.
*
Expand Down

0 comments on commit fd35c8c

Please sign in to comment.