Skip to content

Commit

Permalink
Fixed issue #988.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Oct 5, 2023
1 parent 08ebbd7 commit ee9a13a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
35 changes: 35 additions & 0 deletions src/org/nschmidt/ldparteditor/data/DatHeaderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,41 @@ private void checkDatHeader() {
}
}
}

// Check on wrong comment lines with just one slash
gd = firstEntry;
if (gd != null) {
lineNumber = 0;
gd = gd.before;
while (gd != null && (gd = gd.next) != null) {
lineNumber += 1;
int type = gd.type();
if (type == 0) {

String trimmedLine = gd.toString().stripLeading();
String[] dataSegments = trimmedLine.split("\\s+"); //$NON-NLS-1$

// Remove double spaces (essential for complex types)
String normalizedLine;
StringBuilder normalized = new StringBuilder();
for (String string : dataSegments) {
normalized.append(string);
normalized.append(" "); //$NON-NLS-1$
}
normalizedLine = normalized.toString().stripLeading();

if (normalizedLine.startsWith("0 / ")) { //$NON-NLS-1$
normalizedLine = normalizedLine.trim();
normalizedLine = normalizedLine.substring(0, Math.min(normalizedLine.length(), 16)) + (normalizedLine.length() > 16 ? "..." : ""); //$NON-NLS-1$ //$NON-NLS-2$
Object[] messageArguments = {normalizedLine};
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_INVALID_COMMENT);
registerFormatHint(lineNumber, "C0", formatter.format(messageArguments), registered, allHints); //$NON-NLS-1$
}
}
}
}

if (firstEntry != null) {
registered[0] = false;
Expand Down
52 changes: 37 additions & 15 deletions src/org/nschmidt/ldparteditor/helper/compositetext/HintFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,49 @@ else if (type == DatType.PRIMITIVE48)
l = h.getLineLICENSE();
text = QuickFixer.insertAfterLine(l, "<br>0 BFC CERTIFY CCW<br>", text); //$NON-NLS-1$
break;
case 254: // There are numbers with scientific notation
StringBuilder sb = new StringBuilder();
String[] dataSegments = line.trim().split(" "); //$NON-NLS-1$
int count = 0;
for (String seg : dataSegments) {
if (!seg.trim().equals("")) { //$NON-NLS-1$
count++;
try {
BigDecimal number = new BigDecimal(seg);
if (seg.toUpperCase().contains("E") && count < 15) { //$NON-NLS-1$
sb.append(MathHelper.bigDecimalToString(number));
case 192: // The comment has just one slash.
{
StringBuilder sb = new StringBuilder();
String trimmedLine = line.trim();
String[] dataSegments = trimmedLine.split("\\s+"); //$NON-NLS-1$
boolean hasFixedSlash = false;
for (String seg : dataSegments) {
if (!seg.trim().equals("")) { //$NON-NLS-1$
if (!hasFixedSlash && "/".equals(seg)) { //$NON-NLS-1$
sb.append("//"); //$NON-NLS-1$
hasFixedSlash = true;
} else {
sb.append(seg);
}
} catch (NumberFormatException nfe) {
sb.append(seg);
}
sb.append(" "); //$NON-NLS-1$
}
text = QuickFixer.setLine(lineNumber + 1, sb.toString().trim(), text);
}
break;
case 254: // There are numbers with scientific notation
{
StringBuilder sb = new StringBuilder();
String[] dataSegments = line.trim().split(" "); //$NON-NLS-1$
int count = 0;
for (String seg : dataSegments) {
if (!seg.trim().equals("")) { //$NON-NLS-1$
count++;
try {
BigDecimal number = new BigDecimal(seg);
if (seg.toUpperCase().contains("E") && count < 15) { //$NON-NLS-1$
sb.append(MathHelper.bigDecimalToString(number));
} else {
sb.append(seg);
}
} catch (NumberFormatException nfe) {
sb.append(seg);
}
}
sb.append(" "); //$NON-NLS-1$
}
sb.append(" "); //$NON-NLS-1$
text = QuickFixer.setLine(lineNumber + 1, sb.toString().trim(), text);
}
text = QuickFixer.setLine(lineNumber + 1, sb.toString().trim(), text);
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions src/org/nschmidt/ldparteditor/i18n/DatParser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ IDENTICAL_VERTICES = Identical vertices
INLINING_RELICT = Inlining relict
INVALID_CASE = Invalid use of upper- & mixed-case in subfile name
INVALID_COLOUR = Invalid colour
INVALID_COMMENT = \"{0}\" is not a properly formatted comment.
INVALID_HEADER = Invalid header line
INVALID_INVERT_NEXT = Invalid use of 'BFC INVERTNEXT'
INVALID_INVERT_NEXT_FLAT = Invalid use of 'BFC INVERTNEXT' / Flat subfile
Expand Down
1 change: 1 addition & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ private static void adjust() { // Calculate line offset
public static final String DATPARSER_INLINING_RELICT = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_CASE = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_COLOUR = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_COMMENT = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_HEADER = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_INVERT_NEXT = DATPARSER.getString(getProperty());
public static final String DATPARSER_INVALID_INVERT_NEXT_FLAT = DATPARSER.getString(getProperty());
Expand Down

0 comments on commit ee9a13a

Please sign in to comment.