001: package com.quadcap.util.text;
002:
003: /* Copyright 1997 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: /**
042: * Simple byte membership tables for 8-bit text.
043: *
044: * @author Stan Bailes
045: */
046: public class OctetMap {
047: boolean[] isValid = new boolean[256];
048:
049: public static OctetMap tokenChars;
050: public static OctetMap uriChars;
051: public static OctetMap numberChars;
052: public static OctetMap fieldValueChars;
053: public static OctetMap wsChars;
054: public static OctetMap crlfChars;
055:
056: public static OctetMap dquoteChar = new OctetMap('"');
057:
058: static {
059: tokenChars = new OctetMap(32, 126);
060: tokenChars.exclude("()<>@,;:\\\"/[]?={} ");
061:
062: uriChars = new OctetMap(0, 255);
063: uriChars.exclude("? \r\n");
064:
065: numberChars = new OctetMap('0', '9');
066: numberChars.include('.', '.');
067:
068: fieldValueChars = new OctetMap(32, 126);
069:
070: wsChars = new OctetMap(' ');
071: wsChars.include('\t');
072:
073: crlfChars = new OctetMap('\r');
074: crlfChars.include('\n');
075: }
076:
077: public OctetMap(int c) {
078: include(c);
079: }
080:
081: public OctetMap(int start, int end) {
082: include(start, end);
083: }
084:
085: public OctetMap(String s) {
086: include(s);
087: }
088:
089: public void include(int start, int end) {
090: for (int i = start; i <= end; i++)
091: isValid[i] = true;
092: }
093:
094: public void include(int c) {
095: isValid[c] = true;
096: }
097:
098: public void exclude(int start, int end) {
099: for (int i = start; i <= end; i++)
100: isValid[i] = false;
101: }
102:
103: public void exclude(String s) {
104: for (int i = 0; i < s.length(); i++) {
105: isValid[(byte) s.charAt(i)] = false;
106: }
107: }
108:
109: public void include(String s) {
110: for (int i = 0; i < s.length(); i++) {
111: isValid[(byte) s.charAt(i)] = true;
112: }
113: }
114:
115: public boolean has(int b) {
116: return isValid[b & 0xff];
117: }
118: }
|