Skip to content

Commit

Permalink
Invisible Characters (applied-geodesy#529)
Browse files Browse the repository at this point in the history
- Remove invisible characters via `isIdentifierIgnorable(codePoint)`
  • Loading branch information
loesler authored Oct 11, 2024
1 parent df4f029 commit 28d889f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
36 changes: 17 additions & 19 deletions JAG3D/src/org/applied_geodesy/util/io/LockFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,28 @@ private String removeNonBMPCharacters(final String str) {
if (str == null || str.isBlank())
return str;

final int len = str.length();
if (len == 0)
return str;

// https://stackoverflow.com/questions/6198986/how-can-i-replace-non-printable-unicode-characters-in-java
final int len = str.length();
StringBuilder stringBuilder = new StringBuilder(len);
for (int offset = 0; offset < len;) {
int codePoint = str.codePointAt(offset);
offset += Character.charCount(codePoint);

// Replace invisible control characters and unused code points
switch (Character.getType(codePoint)) {
case Character.CONTROL: // \p{Cc}
case Character.FORMAT: // \p{Cf}
case Character.PRIVATE_USE: // \p{Co}
case Character.SURROGATE: // \p{Cs}
case Character.UNASSIGNED: // \p{Cn}
break;
default:
stringBuilder.append(Character.toChars(codePoint));
break;
}
if (!Character.isIdentifierIgnorable(codePoint))
stringBuilder.append(Character.toChars(codePoint));
// else {
// // Replace invisible control characters and unused code points
// switch (Character.getType(codePoint)) {
// case Character.CONTROL: // \p{Cc} <-- enthaelt Tab
// case Character.FORMAT: // \p{Cf}
// case Character.PRIVATE_USE: // \p{Co}
// case Character.SURROGATE: // \p{Cs}
// case Character.UNASSIGNED: // \p{Cn}
// break;
// default:
// stringBuilder.append(Character.toChars(codePoint));
// break;
// }
// }
}

return stringBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class Version {
private final static Map<VersionType, Integer> versions = Map.of(
VersionType.ADJUSTMENT_CORE, 20230726,
VersionType.USER_INTERFACE, 20241009
VersionType.USER_INTERFACE, 20241011
);

private Version() {}
Expand Down
2 changes: 1 addition & 1 deletion JAG3D/src/org/applied_geodesy/version/jag3d/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Version {
private final static Map<VersionType, Integer> versions = Map.of(
VersionType.ADJUSTMENT_CORE, 20231208,
VersionType.DATABASE, 20240417,
VersionType.USER_INTERFACE, 20241009
VersionType.USER_INTERFACE, 20241011
);

private Version() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class Version {
private final static Map<VersionType, Integer> versions = Map.of(
VersionType.ADJUSTMENT_CORE, 20231020,
VersionType.USER_INTERFACE, 20241009
VersionType.USER_INTERFACE, 20241011
);

private Version() {}
Expand Down

0 comments on commit 28d889f

Please sign in to comment.