chun13009 / zk-cdt

Automatically exported from code.google.com/p/zk-cdt
0 stars 0 forks source link

mold helper #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Create a view to using ${} #{} in mold . ;)

Original issue reported on code.google.com by tonylovejava on 30 May 2011 at 6:57

GoogleCodeExporter commented 9 years ago
Currently the code , but it's not completed. :-(
Have to handle multiple ${} #{} in same string definition.

---
                 public String parseMold(String data) {
                        Pattern p = Pattern.compile("((')(.*?)([#$]\\{(.+?)\\})(.*?'))|(\")(.*?)([#$]\\{(.+?)\\})(.*?\")");
                        // Pattern.compile("('.*?(\\$\\{[.*]+?\\}).*?')|(\".*?(\\$\\{[.*]+?\\}).*?\")");

                        Matcher m = p.matcher(data);
                        StringBuffer result = new StringBuffer();
                        boolean debug = true;
                        while (m.find()) {
                            String quote = m.group(2);

                            int shift = 6; // for another group. we could separate them ,
                            // but I am lazy and this is better for performance.
                            if ("'".equals(quote)) {
                                // System.out.println(m.group()+"=="+m.group(1)+":"+m.group(2)+":"+m.group(3)+":"+m.group(4));
                                System.out.println();
                                String pre = m.group(3);

                                String pattern = m.group(4);
                                boolean concatStrng = pattern.startsWith("#");
                                String divide = concatStrng ? " + " : ",";

                                String process = m.group(2) + ("".equals(pre) ? "" : pre + quote) + divide + m.group(5) + divide + quote
                                        + m.group(6);

                                m.appendReplacement(result, process);
                                if (debug) {
                                    System.out.println("before:" + m.group(0));
                                    System.out.println("after:" + process);
                                }
                            } else {
                                quote = m.group(7);
                                String pre = m.group(shift + 2);
                                String pattern = m.group(shift + 3);
                                boolean concatStrng = pattern.startsWith("#");
                                String divide = concatStrng ? " + " : ",";

                                String process = ("".equals(pre) ? "" : m.group(shift + 1) + pre + quote + divide) + m.group(shift + 4)
                                        + divide + quote + m.group(shift + 5);
                                m.appendReplacement(result, process);
                                if (debug) {
                                    System.out.println("before:" + m.group(0));
                                    System.out.println("after:" + process);
                                }
                            }
                        }
                        m.appendTail(result);

                        return result.toString();
                    }                                               

Original comment by tonylovejava on 30 May 2011 at 6:58