]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/internal/CharacterSet.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / markdown / internal / CharacterSet.java
1 package org.simantics.scl.compiler.markdown.internal;
2
3 public class CharacterSet {
4     private int minChar;
5     private int maxChar;
6     boolean[] table;
7     
8     public CharacterSet(String chars) {
9         if(chars.isEmpty())
10             throw new IllegalArgumentException();
11         minChar = Integer.MAX_VALUE;
12         maxChar = Integer.MIN_VALUE;
13         for(int i=0;i<chars.length();++i) {
14             int c = (int)chars.charAt(i);
15             if(c == '-' && i > 0 && i < chars.length()-1)
16                 continue;
17             minChar = Math.min(minChar, c);
18             maxChar = Math.max(maxChar, c);
19         }
20         
21         table = new boolean[maxChar-minChar+1];
22         for(int i=0;i<chars.length();++i) {
23             int c = (int)chars.charAt(i);
24             if(i < chars.length()-2 && chars.charAt(i+1)=='-') {
25                 int c2 = (int)chars.charAt(i+2);
26                 if(c > c2) {
27                     int temp = c;
28                     c = c2;
29                     c2 = temp;
30                 }
31                 for(int j=c;j<=c2;++j)
32                     table[j - minChar] = true;
33                 i+=2;
34             }
35             else 
36                 table[c - minChar] = true;
37         }
38     }
39     
40     public boolean contains(char c_) {
41         int c = (int)c_;
42         return c >= minChar && c <= maxChar && table[c - minChar];
43     }
44 }