• R/O
  • SSH
  • HTTPS

smart-gs: コミット


コミットメタ情報

リビジョン1202 (tree)
日時2016-11-09 22:30:40
作者ohura

ログメッセージ

[editor-simplyhtml-merge] SG commentの中の空白文字のdecode、encode
SG commentの中の空白文字(改行、空白、タブ)をdecode、encodeするコードを追加。
'\r'を"r"に'\n'を"n"に、空白を"s"にタブを"t"にそれぞれ変換する。

変更サマリ

差分

--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocument.java (revision 1201)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocument.java (revision 1202)
@@ -231,6 +231,7 @@
231231 lineList.add(linetag);
232232 }
233233 } else if(comment.startsWith("sg:resource")){ // sg:resource id="url"
234+ comment = URLcode.decodeResource(comment);
234235 String id = getAttrib(comment, "id");
235236 resourceList.add(new SGSResourceTag(id, startOffset));
236237 } else if(comment.startsWith("sg:gt")){ // sg:gt tagid="...."
@@ -299,8 +300,9 @@
299300 } else {
300301 url = resource.getId();
301302 }
302- url = URLcode.encode(url);
303+// url = URLcode.encode(url);
303304 String sgResource = "<!--sg:resource id=" + "\"" + url + "\"-->";
305+ sgResource = URLcode.encodeResource(sgResource);
304306 try {
305307 doc.remove(resource.getStartOffset(), 1);
306308 editorKit.insertHTML(doc, resource.getStartOffset(), sgResource, 0, 0, HTML.Tag.COMMENT);
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/URLcode.java (revision 1201)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/URLcode.java (revision 1202)
@@ -49,4 +49,93 @@
4949 return url;
5050 }
5151
52+ public static String encodeResource(String sgResource) {
53+ String list = "[]";
54+ ArrayList<Integer> dhlist = new ArrayList<Integer>();
55+ sgResource = sgResource.substring(4,sgResource.length()-3);
56+ if(sgResource.endsWith("]")){
57+ return sgResource;
58+ }
59+ for(int i=0;i<sgResource.length();i++){
60+ if(sgResource.charAt(i)=='\r' || sgResource.charAt(i)=='\n' || sgResource.charAt(i)=='\t'
61+ || sgResource.charAt(i)==' '){
62+ dhlist.add(i);
63+ }
64+ if(sgResource.charAt(i)=='-' && sgResource.charAt(i+1)=='-' ){
65+ dhlist.add(i);
66+ i++;
67+ }
68+ }
69+
70+ for(int j=0;j<dhlist.size();j++){
71+ char ch = sgResource.charAt(dhlist.get(j));
72+ switch(ch){
73+ case '\r':
74+ sgResource = sgResource.substring(0, dhlist.get(j)) + "r" + sgResource.substring(dhlist.get(j)+1);
75+ break;
76+ case '\n':
77+ sgResource = sgResource.substring(0, dhlist.get(j)) + "n" + sgResource.substring(dhlist.get(j)+1);
78+ break;
79+ case '\t':
80+ sgResource = sgResource.substring(0, dhlist.get(j)) + "t" + sgResource.substring(dhlist.get(j)+1);
81+ break;
82+ case ' ':
83+ sgResource = sgResource.substring(0, dhlist.get(j)) + "s" + sgResource.substring(dhlist.get(j)+1);
84+ break;
85+ case '-':
86+ sgResource = sgResource.substring(0, dhlist.get(j)) + "@@" + sgResource.substring(dhlist.get(j)+2);
87+ break;
88+ default:
89+ break;
90+ }
91+ if(list.length()==2){
92+ list = "[" + dhlist.get(j) + "]";
93+ } else {
94+ list = list.substring(0, list.length()-1) + " " + dhlist.get(j) + "]";
95+ }
96+ }
97+ return "<!--" + sgResource + list + "-->";
98+
99+ }
100+
101+ public static String decodeResource(String comment) {
102+ ArrayList<Integer> dhlist = new ArrayList<Integer>();
103+ if(!comment.endsWith("]")){
104+ return comment;
105+ }
106+ if(comment.endsWith("[]")){
107+ return comment.substring(0, comment.length()-2);
108+ }
109+
110+ String list = comment.substring(comment.lastIndexOf('[')+1, comment.length()-1);
111+ comment = comment.substring(0, comment.lastIndexOf('['));
112+ String[] list2 = list.split(" ");
113+ for(int i=0;i<list2.length;i++){
114+ dhlist.add(Integer.decode(list2[i]));
115+ }
116+ for(int j=0;j<dhlist.size();j++){
117+ char ch = comment.charAt(dhlist.get(j));
118+ switch(ch){
119+ case 'r':
120+ comment = comment.substring(0, dhlist.get(j)) + "\r" + comment.substring(dhlist.get(j)+1);
121+ break;
122+ case 'n':
123+ comment = comment.substring(0, dhlist.get(j)) + "\n" + comment.substring(dhlist.get(j)+1);
124+ break;
125+ case 't':
126+ comment = comment.substring(0, dhlist.get(j)) + "\t" + comment.substring(dhlist.get(j)+1);
127+ break;
128+ case 's':
129+ comment = comment.substring(0, dhlist.get(j)) + " " + comment.substring(dhlist.get(j)+1);
130+ break;
131+ case '@':
132+ comment = comment.substring(0, dhlist.get(j)) + "--" + comment.substring(dhlist.get(j)+2);
133+ break;
134+ default:
135+ break;
136+ }
137+
138+ }
139+ return comment;
140+ }
52141 }
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSHTMLEditorActions.java (revision 1201)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSHTMLEditorActions.java (revision 1202)
@@ -846,8 +846,9 @@
846846 try {
847847 TextSegment segment = new TextSegment(markup, document, 0); // TODO
848848 String url = segment.createURI();
849- url = URLcode.encode(url);
849+// url = URLcode.encode(url);
850850 String sgResource = "<!--sg:resource id=" + "\"" + url + "\"-->";
851+ sgResource = URLcode.encodeResource(sgResource);
851852 editorKit.insertHTML(doc, editorPane.getSelectionStart(), sgResource, 0, 0, HTML.Tag.COMMENT);
852853 editorKit.insertHTML(doc, editorPane.getSelectionStart(),
853854 "<!--sg:gt tagid=\"" + markup + "\"-->", 0, 0, HTML.Tag.COMMENT);
旧リポジトリブラウザで表示