Skip to content

Commit

Permalink
Fix bookmarks parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiesler committed Mar 8, 2023
1 parent 74359e5 commit ea07fa6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Expand Up @@ -59,7 +59,7 @@ private static String stringSetToString(Set<String> set) {
*/
private static @Nonnull List<String> parseStringList(@Nonnull String str) {
// escape special chars (in particular the comma)
return Arrays.stream(str.split(SET_DELIMITER)).map(s -> SettingsConverter.convert(s, true))
return Arrays.stream(str.split(SET_DELIMITER)).map(SettingsConverter::decodeString)
.collect(Collectors.toCollection(ArrayList::new));
}

Expand All @@ -69,7 +69,7 @@ private static String stringSetToString(Set<String> set) {
*/
private static @Nonnull String stringListToString(@Nonnull List<String> seq) {
// escape special chars (in particular the comma)
return seq.stream().map(s -> SettingsConverter.convert(s, false))
return seq.stream().map(SettingsConverter::encodeString)
.collect(Collectors.joining(SET_DELIMITER));
}

Expand Down
Expand Up @@ -59,7 +59,26 @@ public final class SettingsConverter {
/**
* The class doesn't need to be instantiated as it only contains static methods.
*/
private SettingsConverter() {
private SettingsConverter() {}

/**
* Replace occurrences of Strings in {@link #ENCODINGS} by their corresponding encoding String.
*
* @param str the String to be encoded
* @return the encoded String
*/
public static String encodeString(String str) {
return convert(str, true);
}

/**
* Replace occurrences of Strings in {@link #ENCODINGS} by their corresponding decoding String.
*
* @param str the String to be decoded
* @return the decoded String
*/
public static String decodeString(String str) {
return convert(str, false);
}

/**
Expand All @@ -76,7 +95,7 @@ private SettingsConverter() {
* @param encode true if the String should be encoded, false if it should be decoded
* @return the encoded/decoded String
*/
public static String convert(String str, boolean encode) {
private static String convert(String str, boolean encode) {
String result = str;
for (int i = 0; i < ENCODINGS.length; i++) {
// The order of replacements has to be reversed when decoding the String.
Expand Down Expand Up @@ -119,7 +138,7 @@ public static String decode(@Nonnull String str) {
}
i = str.lastIndexOf(POSTFIX);
str = str.substring(0, i);
return convert(str, false);
return decodeString(str);
}

/**
Expand All @@ -144,7 +163,7 @@ public static String decode(@Nonnull String str) {
* @return the encoded version of str
*/
public static String encode(@Nonnull String str) {
return PREFIX + convert(str, true) + POSTFIX;
return PREFIX + encodeString(str) + POSTFIX;
}


Expand Down
Expand Up @@ -101,9 +101,7 @@ private void setBookmark() {
}

private void loadBookmarks() {
viewSettings.getFolderBookmarks().forEach(it ->
// make absolute? .getAbsoluteFile())
bookmarks.addElement(new File(it)));
viewSettings.getFolderBookmarks().forEach(it -> bookmarks.addElement(new File(it)));
}

private void saveBookmarks() {
Expand Down

0 comments on commit ea07fa6

Please sign in to comment.