Ignore:
Timestamp:
2008-12-23T15:07:05+01:00 (17 years ago)
Author:
stoecker
Message:

removed usage of tab stops

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java

    r1149 r1169  
    77
    88public class PushbackTokenizer {
    9         private PushbackReader search;
     9    private PushbackReader search;
    1010
    11         private LinkedList<String> pushBackBuf = new LinkedList<String>();
     11    private LinkedList<String> pushBackBuf = new LinkedList<String>();
    1212
    13         public PushbackTokenizer(PushbackReader search) {
    14                 this.search = search;
    15         }
     13    public PushbackTokenizer(PushbackReader search) {
     14        this.search = search;
     15    }
    1616
    17         /**
    18         * The token returned is <code>null</code> or starts with an identifier character:
    19         * - for an '-'. This will be the only character
    20         * : for an key. The value is the next token
    21         * | for "OR"
    22         * ' ' for anything else.
    23         * @return The next token in the stream.
    24         */
    25         public String nextToken() {
    26                 if (!pushBackBuf.isEmpty()) {
    27                         return pushBackBuf.removeLast();
    28                 }
     17    /**
     18    * The token returned is <code>null</code> or starts with an identifier character:
     19    * - for an '-'. This will be the only character
     20    * : for an key. The value is the next token
     21    * | for "OR"
     22    * ' ' for anything else.
     23    * @return The next token in the stream.
     24    */
     25    public String nextToken() {
     26        if (!pushBackBuf.isEmpty()) {
     27            return pushBackBuf.removeLast();
     28        }
    2929
    30                 try {
    31                         int next;
    32                         char c = ' ';
    33                         while (c == ' ' || c == '\t' || c == '\n') {
    34                                 next = search.read();
    35                                 if (next == -1)
    36                                         return null;
    37                                 c = (char)next;
    38                         }
    39                         StringBuilder s;
    40                         switch (c) {
    41                         case ':':
    42                                 next = search.read();
    43                                 c = (char) next;
    44                                 if (next == -1 || c == ' ' || c == '\t') {
    45                                         pushBack(" ");
    46                                 } else {
    47                                         search.unread(next);
    48                                 }
    49                                 return ":";
    50                         case '-':
    51                                 return "-";
    52                         case '(':
    53                                 return "(";
    54                         case ')':
    55                                 return ")";
    56                         case '|':
    57                                 return "|";
    58                         case '"':
    59                                 s = new StringBuilder(" ");
    60                                 for (int nc = search.read(); nc != -1 && nc != '"'; nc = search.read())
    61                                         s.append((char)nc);
    62                                 return s.toString();
    63                         default:
    64                                 s = new StringBuilder();
    65                         for (;;) {
    66                                 s.append(c);
    67                                 next = search.read();
    68                                 if (next == -1) {
    69                                         if (s.toString().equals("OR"))
    70                                                 return "|";
    71                                         return " "+s.toString();
    72                                 }
    73                                 c = (char)next;
    74                                 if (c == ' ' || c == '\t' || c == '"' || c == ':' || c == '(' || c == ')' || c == '|') {
    75                                         search.unread(next);
    76                                         if (s.toString().equals("OR"))
    77                                                 return "|";
    78                                         return " "+s.toString();
    79                                 }
    80                         }
    81                         }
    82                 } catch (IOException e) {
    83                         throw new RuntimeException(e.getMessage(), e);
    84                 }               
    85         }
     30        try {
     31            int next;
     32            char c = ' ';
     33            while (c == ' ' || c == '\t' || c == '\n') {
     34                next = search.read();
     35                if (next == -1)
     36                    return null;
     37                c = (char)next;
     38            }
     39            StringBuilder s;
     40            switch (c) {
     41            case ':':
     42                next = search.read();
     43                c = (char) next;
     44                if (next == -1 || c == ' ' || c == '\t') {
     45                    pushBack(" ");
     46                } else {
     47                    search.unread(next);
     48                }
     49                return ":";
     50            case '-':
     51                return "-";
     52            case '(':
     53                return "(";
     54            case ')':
     55                return ")";
     56            case '|':
     57                return "|";
     58            case '"':
     59                s = new StringBuilder(" ");
     60                for (int nc = search.read(); nc != -1 && nc != '"'; nc = search.read())
     61                    s.append((char)nc);
     62                return s.toString();
     63            default:
     64                s = new StringBuilder();
     65            for (;;) {
     66                s.append(c);
     67                next = search.read();
     68                if (next == -1) {
     69                    if (s.toString().equals("OR"))
     70                        return "|";
     71                    return " "+s.toString();
     72                }
     73                c = (char)next;
     74                if (c == ' ' || c == '\t' || c == '"' || c == ':' || c == '(' || c == ')' || c == '|') {
     75                    search.unread(next);
     76                    if (s.toString().equals("OR"))
     77                        return "|";
     78                    return " "+s.toString();
     79                }
     80            }
     81            }
     82        } catch (IOException e) {
     83            throw new RuntimeException(e.getMessage(), e);
     84        }
     85    }
    8686
    87         public boolean readIfEqual(String tok) {
    88                 String nextTok = nextToken();
    89                 if (nextTok == null ? tok == null : nextTok.equals(tok)) 
    90                         return true;
    91                 pushBack(nextTok);
    92                 return false;
    93         }
     87    public boolean readIfEqual(String tok) {
     88        String nextTok = nextToken();
     89        if (nextTok == null ? tok == null : nextTok.equals(tok))
     90            return true;
     91        pushBack(nextTok);
     92        return false;
     93    }
    9494
    95         public String readText() {
    96                 String nextTok = nextToken();
    97                 if (nextTok != null && nextTok.startsWith(" "))
    98                         return nextTok.substring(1);
    99                 pushBack(nextTok);
    100                 return null;
    101         }
     95    public String readText() {
     96        String nextTok = nextToken();
     97        if (nextTok != null && nextTok.startsWith(" "))
     98            return nextTok.substring(1);
     99        pushBack(nextTok);
     100        return null;
     101    }
    102102
    103         public void pushBack(String tok) {
    104                 pushBackBuf.addLast(tok);
    105         }
     103    public void pushBack(String tok) {
     104        pushBackBuf.addLast(tok);
     105    }
    106106}
Note: See TracChangeset for help on using the changeset viewer.