Skip to content

Commit

Permalink
Escape $ in saved state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Evdokimov committed Mar 23, 2014
1 parent be1ae58 commit e5916cf
Showing 1 changed file with 23 additions and 3 deletions.
Expand Up @@ -15,8 +15,7 @@
)
public class RegexpStateService implements PersistentStateComponent<RegexpStateService.State> {

private final State stateHolder = new State();
private final Map<String, String> state = stateHolder.map;
private final Map<String, String> state = new HashMap<String, String>();

private RegexPanel panel;

Expand Down Expand Up @@ -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<String, String> entry : res.map.entrySet()) {
entry.setValue(escape(entry.getValue()));
}

return res;
}

public void loadState(RegexpStateService.State state) {
Map<String, String> tmp = new HashMap<String, String>(state.map);

for (Map.Entry<String, String> 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);
Expand All @@ -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<String, String> map = new HashMap<String, String>();
}
Expand Down

0 comments on commit e5916cf

Please sign in to comment.