1 package com.quadcap.util.text; 2 3 40 41 46 public class OctetMap { 47 boolean[] isValid = new boolean[256]; 48 49 public static OctetMap tokenChars; 50 public static OctetMap uriChars; 51 public static OctetMap numberChars; 52 public static OctetMap fieldValueChars; 53 public static OctetMap wsChars; 54 public static OctetMap crlfChars; 55 56 public static OctetMap dquoteChar = new OctetMap('"'); 57 58 static { 59 tokenChars = new OctetMap(32, 126); 60 tokenChars.exclude("()<>@,;:\\\"/[]?={} "); 61 62 uriChars = new OctetMap(0, 255); 63 uriChars.exclude("? \r\n"); 64 65 numberChars = new OctetMap('0', '9'); 66 numberChars.include('.', '.'); 67 68 fieldValueChars = new OctetMap(32, 126); 69 70 wsChars = new OctetMap(' '); 71 wsChars.include('\t'); 72 73 crlfChars = new OctetMap('\r'); 74 crlfChars.include('\n'); 75 } 76 77 public OctetMap(int c) { 78 include(c); 79 } 80 81 public OctetMap(int start, int end) { 82 include(start, end); 83 } 84 85 public OctetMap(String s) { 86 include(s); 87 } 88 89 public void include(int start, int end) { 90 for (int i = start; i <= end; i++) isValid[i] = true; 91 } 92 93 public void include(int c) { 94 isValid[c] = true; 95 } 96 97 public void exclude(int start, int end) { 98 for (int i = start; i <= end; i++) isValid[i] = false; 99 } 100 101 public void exclude(String s) { 102 for (int i = 0; i < s.length(); i++) { 103 isValid[(byte)s.charAt(i)] = false; 104 } 105 } 106 107 public void include(String s) { 108 for (int i = 0; i < s.length(); i++) { 109 isValid[(byte)s.charAt(i)] = true; 110 } 111 } 112 113 public boolean has(int b) { return isValid[b & 0xff]; } 114 } 115 | Popular Tags |