e4e92f77e9abef1e0310960aabcd40f3e5beaae7
[debian/jabref.git] / src / java / net / sf / jabref / export / layout / AbstractParamLayoutFormatter.java
1 package net.sf.jabref.export.layout;
2
3 import net.sf.jabref.export.layout.LayoutFormatter;
4
5 import java.util.List;
6 import java.util.ArrayList;
7
8 public abstract class AbstractParamLayoutFormatter implements ParamLayoutFormatter {
9
10     private static char SEPARATOR = ',';
11         
12     public static String[] parseArgument(String arg) {
13         List<String> parts = new ArrayList<String>();
14         StringBuilder current = new StringBuilder();
15         boolean escaped = false;
16         for (int i=0; i<arg.length(); i++) {
17             if ((arg.charAt(i) == SEPARATOR) && !escaped) {
18                 parts.add(current.toString());
19                 current = new StringBuilder();
20             } else if (arg.charAt(i) == '\\') {
21                 if (escaped) {
22                     escaped = false;
23                     current.append(arg.charAt(i));
24                 } else
25                     escaped = true;
26             } else if (escaped) {
27                 if ((arg.charAt(i) != ',') && (arg.charAt(i) != '"'))
28                     current.append('\\');
29                 current.append(arg.charAt(i));
30                 escaped = false;
31             } else
32                 current.append(arg.charAt(i));
33         }
34         parts.add(current.toString());
35         return parts.toArray(new String[parts.size()]);
36
37     }
38
39
40 }