001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/TKStringConverter.java,v 1.5 2000/05/22 15:01:21 careck Exp $
003: *
004: */
005: package com.teamkonzept.lib;
006:
007: /**
008: Konvertierungsklasse fuer String-Text-Codierung
009: */
010: public class TKStringConverter extends TKConverter {
011: public final static String CONV_ID = "STRING";
012: public final static String CONV_NAME = "STRING-ISO-8859_1";
013:
014: public String getName() {
015: return CONV_NAME;
016: }
017:
018: public final static String[] STRING_CODES = {
019: /* 0*/null, null, null, null, null, null, null, null, null, null,
020: /* 10*/null, null, null, null, null, null, null, null, null, null,
021: /* 20*/null, null, null, null, null, null, null, null, null, null,
022: /* 30*/null, null, null, null, "\\\"", null, null, null, null,
023: null,
024: /* 40*/null, null, null, null, null, null, null, null,
025: null, null,
026: /* 50*/null, null, null, null, null, null, null, null,
027: null, null,
028: /* 60*/null, null, null, null, null, null, null, null,
029: null, null,
030: /* 70*/null, null, null, null, null, null, null, null,
031: null, null,
032: /* 80*/null, null, null, null, null, null, null, null,
033: null, null,
034: /* 90*/null, null, "\\\\", null, null, null, null, null,
035: null, null,
036: /*100*/null, null, null, null, null, null, null, null,
037: null, null,
038: /*110*/null, null, null, null, null, null, null, null,
039: null, null,
040: /*120*/null, null, null, null, null, null, null, null,
041: null, null,
042: /*130*/null, null, null, null, null, null, null, null,
043: null, null,
044: /*140*/null, null, null, null, null, null, null, null,
045: null, null,
046: /*150*/null, null, null, null, null, null, null, null,
047: null, null,
048: /*160*/null, null, null, null, null, null, null, null,
049: null, null,
050: /*170*/null, null, null, null, null, null, null, null,
051: null, null,
052: /*180*/null, null, null, null, null, null, null, null,
053: null, null,
054: /*190*/null, null, null, null, null, null, null, null,
055: null, null,
056: /*200*/null, null, null, null, null, null, null, null,
057: null, null,
058: /*210*/null, null, null, null, null, null, null, null,
059: null, null,
060: /*220*/null, null, null, null, null, null, null, null,
061: null, null,
062: /*230*/null, null, null, null, null, null, null, null,
063: null, null,
064: /*240*/null, null, null, null, null, null, null, null,
065: null, null,
066: /*250*/null, null, null, null, null, null, null, null,
067: null, null };
068:
069: public final static byte BACKSLASH = (byte) '\\';
070:
071: public int getMaxBytesPerChar() {
072: return 8;
073: }
074:
075: public int minCharSize(int byteCount) {
076: return byteCount;
077: }
078:
079: public int charsToBytes(char src[], byte dst[], int srcBegin,
080: int length, int dstBegin) {
081: int lastPos = srcBegin + length;
082: int firstPos = dstBegin;
083: for (int i = srcBegin; i < lastPos; i++) {
084: char c = src[i];
085: byte b = (byte) c;
086: int code = (int) c;
087: String subst = STRING_CODES[code];
088: if (subst == null) {
089: dst[dstBegin++] = b;
090: } else {
091: int len = subst.length();
092: subst.getBytes(0, len, dst, dstBegin);
093: dstBegin += len;
094: }
095: }
096:
097: return dstBegin - firstPos;
098: }
099:
100: public int bytesToChars(byte src[], char dst[], int srcBegin,
101: int length, int dstBegin) {
102: int lastPos = srcBegin + length;
103: int firstPos = dstBegin;
104: int i = srcBegin;
105:
106: while (i < lastPos) {
107: byte b = src[i++];
108:
109: if (b == BACKSLASH) {
110: if (i >= lastPos)
111: break;
112: b = src[i++];
113: }
114:
115: dst[dstBegin++] = (char) b;
116: }
117: return dstBegin - firstPos;
118: }
119:
120: }
|