KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > ManLine


1 /*
2  * ManLine.java
3  *
4  * Copyright (C) 2000-2002 Peter Graves
5  * $Id: ManLine.java,v 1.1.1.1 2002/09/24 16:08:19 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.io.UnsupportedEncodingException JavaDoc;
25
26 public final class ManLine extends AbstractLine implements Line
27 {
28     private final String JavaDoc rawText;
29
30     private int flags;
31     private String JavaDoc text;
32
33     public ManLine(String JavaDoc s)
34     {
35         rawText = s;
36     }
37
38     public final int flags()
39     {
40         return flags;
41     }
42
43     public final void setFlags(int flags)
44     {
45         this.flags = flags;
46     }
47
48     public final String JavaDoc getText()
49     {
50         if (text == null) {
51             FastStringBuffer sb = new FastStringBuffer(256);
52             final int limit = rawText.length();
53             for (int i = 0; i < limit; i++) {
54                 char c = rawText.charAt(i);
55                 if (c == 8) {
56                     int length = sb.length();
57                     if (length > 0)
58                         sb.setLength(length - 1);
59                 } else
60                     sb.append(c);
61             }
62             text = sb.toString();
63         }
64         return text;
65     }
66
67     public final String JavaDoc getRawText()
68     {
69         return rawText;
70     }
71
72     public final void setText(String JavaDoc s) {}
73
74     public final char charAt(int i)
75     {
76         return getText().charAt(i);
77     }
78
79     public final String JavaDoc substring(int beginIndex)
80     {
81         return getText().substring(beginIndex);
82     }
83
84     public final String JavaDoc substring(int beginIndex, int endIndex)
85     {
86         return getText().substring(beginIndex, endIndex);
87     }
88
89     public final String JavaDoc trim()
90     {
91         return getText().trim();
92     }
93
94     public final int length()
95     {
96         return getText().length();
97     }
98
99     public final byte[] getBytes(String JavaDoc encoding) throws UnsupportedEncodingException JavaDoc
100     {
101         return getText().getBytes(encoding);
102     }
103
104     public final boolean isBlank()
105     {
106         if (text == null)
107             text = getText();
108         for (int i = text.length(); i-- > 0;)
109             if (!Character.isWhitespace(text.charAt(i)))
110                 return false;
111         return true;
112     }
113 }
114
Popular Tags