diff --git a/IdeaPlugin/src/com/ess/regexutil/ideaplugin/RegexpStateService.java b/IdeaPlugin/src/com/ess/regexutil/ideaplugin/RegexpStateService.java index 79ace2e..1f9eef4 100644 --- a/IdeaPlugin/src/com/ess/regexutil/ideaplugin/RegexpStateService.java +++ b/IdeaPlugin/src/com/ess/regexutil/ideaplugin/RegexpStateService.java @@ -15,8 +15,7 @@ ) public class RegexpStateService implements PersistentStateComponent { - private final State stateHolder = new State(); - private final Map state = stateHolder.map; + private final Map state = new HashMap(); private RegexPanel panel; @@ -46,11 +45,23 @@ public RegexpStateService.State getState() { if (panel != null) { panel.saveState(state); } - return stateHolder; + + State res = new State(); + res.map.putAll(state); + + for (Map.Entry entry : res.map.entrySet()) { + entry.setValue(escape(entry.getValue())); + } + + return res; } public void loadState(RegexpStateService.State state) { Map tmp = new HashMap(state.map); + + for (Map.Entry entry : tmp.entrySet()) { + entry.setValue(unescape(entry.getValue())); + } this.state.clear(); // cleaning of this.state may clean state , so we save state to tmp. this.state.putAll(tmp); @@ -60,6 +71,15 @@ public void loadState(RegexpStateService.State state) { } } + private String escape(String s) { + return s.replaceAll("\\|", "||").replaceAll("\\$", "|d"); + } + + private String unescape(String s) { + return s.replace("|d", "$").replaceAll("\\|\\|", "|"); + } + + public static class State { public Map map = new HashMap(); }