001: /*
002: * ManLine.java
003: *
004: * Copyright (C) 2000-2002 Peter Graves
005: * $Id: ManLine.java,v 1.1.1.1 2002/09/24 16:08:19 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.io.UnsupportedEncodingException;
025:
026: public final class ManLine extends AbstractLine implements Line {
027: private final String rawText;
028:
029: private int flags;
030: private String text;
031:
032: public ManLine(String s) {
033: rawText = s;
034: }
035:
036: public final int flags() {
037: return flags;
038: }
039:
040: public final void setFlags(int flags) {
041: this .flags = flags;
042: }
043:
044: public final String getText() {
045: if (text == null) {
046: FastStringBuffer sb = new FastStringBuffer(256);
047: final int limit = rawText.length();
048: for (int i = 0; i < limit; i++) {
049: char c = rawText.charAt(i);
050: if (c == 8) {
051: int length = sb.length();
052: if (length > 0)
053: sb.setLength(length - 1);
054: } else
055: sb.append(c);
056: }
057: text = sb.toString();
058: }
059: return text;
060: }
061:
062: public final String getRawText() {
063: return rawText;
064: }
065:
066: public final void setText(String s) {
067: }
068:
069: public final char charAt(int i) {
070: return getText().charAt(i);
071: }
072:
073: public final String substring(int beginIndex) {
074: return getText().substring(beginIndex);
075: }
076:
077: public final String substring(int beginIndex, int endIndex) {
078: return getText().substring(beginIndex, endIndex);
079: }
080:
081: public final String trim() {
082: return getText().trim();
083: }
084:
085: public final int length() {
086: return getText().length();
087: }
088:
089: public final byte[] getBytes(String encoding)
090: throws UnsupportedEncodingException {
091: return getText().getBytes(encoding);
092: }
093:
094: public final boolean isBlank() {
095: if (text == null)
096: text = getText();
097: for (int i = text.length(); i-- > 0;)
098: if (!Character.isWhitespace(text.charAt(i)))
099: return false;
100: return true;
101: }
102: }
|