package net.miz_hi.smileessence.command.post;

import net.miz_hi.smileessence.command.MenuCommand;
import net.miz_hi.smileessence.system.PostSystem;

public class CommandZekamashi extends MenuCommand
{

    @Override
    public void workOnUiThread()
    {
        String text = PostSystem.getText();
        int start = PostSystem.getSelectionStart();
        int end = PostSystem.getSelectionEnd();
        PostSystem.setText(edit(text, start, end));
        PostSystem.openPostPage();
    }

    private String edit(String text, int start, int end)
    {
        StringBuilder master = new StringBuilder(text);
        if (start == end)
        {
            return master.reverse().toString();
        }
        else
        {
            String selected = text.substring(start, end);
            StringBuilder target = new StringBuilder(selected);
            target.reverse();
            selected = target.toString();
            String temp = "########TEMP########";
            for (String bracket : brackets)
            {
                String first = bracket.split(",")[0];
                String second = bracket.split(",")[1];
                selected = selected.replace(first, temp).replace(second, first).replace(temp, second);
            }
            return master.replace(start, end, selected).toString();
        }
    }

    private String[] brackets = new String[]{"（,）", "(,)", "「,」", "[,]", "{,}", "<,>", "/,\\"};


    @Override
    public String getName()
    {
        return "ぜかまし";
    }
}

@@ -658,42 +658,436 @@
     
-return master.reverse().toString()
+master.reverse();%0A            String selected = master.toString();%0A            String temp = %22########TEMP########%22;%0A            for (String bracket : brackets)%0A            %7B%0A                String first = bracket.split(%22,%22)%5B0%5D;%0A                String second = bracket.split(%22,%22)%5B1%5D;%0A                selected = selected.replace(first, temp).replace(second, first).replace(temp, second);%0A            %7D%0A            return selected
 ;%0A  
@@ -1823,16 +1823,23 @@
 , %22/,%5C%5C%22
+, %22%EF%BC%BC,%EF%BC%8F%22
 %7D;%0A%0A%0A   
@@ -1911,11 +1911,187 @@
 %22;%0A    %7D
+%0A%0A    public static void main(String%5B%5D args)%0A    %7B%0A        CommandZekamashi c = new CommandZekamashi();%0A        System.out.println(c.edit(%22%EF%BC%88(%E3%80%8C%5B%7B%3C%5C%5C%EF%BC%BC%E3%81%9C%E3%81%8B%E3%81%BE%E3%81%97%EF%BC%8F/%3E%7D%5D%E3%80%8D)%EF%BC%89%22, 0, 0));%0A    %7D
 %0A%7D%0A

Fix Zekamashi