File: FlowInterning.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (61 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.ArrayList;
import java.util.List;

public class FlowInterning {

    // @skip-test
    // Look at issue 47
    //  public boolean isSame(Object a, Object b) {
    //    return ((a == null)
    //            ? (a == b)
    //            : (a.equals(b)));
    //  }

    public void testAppendingChar() {
        String arg = "";
        arg += ' ';

        // Interning Checker should NOT suggest == here.
        if (!arg.equals("")) ;
    }

    public String[] parse(String args) {

        // Split the args string on whitespace boundaries accounting for quoted
        // strings.
        args = args.trim();
        List<String> arg_list = new ArrayList<>();
        String arg = "";
        char active_quote = 0;
        for (int ii = 0; ii < args.length(); ii++) {
            char ch = args.charAt(ii);
            if ((ch == '\'') || (ch == '"')) {
                arg += ch;
                ii++;
                while ((ii < args.length()) && (args.charAt(ii) != ch)) {
                    arg += args.charAt(ii++);
                }
                arg += ch;
            } else if (Character.isWhitespace(ch)) {
                // System.out.printf ("adding argument '%s'%n", arg);
                arg_list.add(arg);
                arg = "";
                while ((ii < args.length()) && Character.isWhitespace(args.charAt(ii))) {
                    ii++;
                }
                if (ii < args.length()) {
                    ii--;
                }
            } else { // must be part of current argument
                arg += ch;
            }
        }
        // Interning Checker should NOT suggest == here.
        if (!arg.equals("")) {
            arg_list.add(arg);
        }

        String[] argsArray = arg_list.toArray(new String[arg_list.size()]);
        return argsArray;
    }
}