wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * TclList.java |
||
3 | * |
||
4 | * Copyright (c) 1997 Sun Microsystems, Inc. |
||
5 | * |
||
6 | * See the file "license.terms" for information on usage and |
||
7 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
8 | * WARRANTIES. |
||
9 | * |
||
10 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
11 | * |
||
12 | * RCS @(#) $Id: TclString.java,v 1.5 2003/03/08 03:42:56 mdejong Exp $ |
||
13 | * |
||
14 | */ |
||
15 | using System.Text; |
||
16 | namespace tcl.lang |
||
17 | { |
||
18 | |||
19 | // This class implements the string object type in Tcl. |
||
20 | |||
21 | public class TclString : InternalRep |
||
22 | { |
||
23 | /// <summary> Called to convert the other object's internal rep to string. |
||
24 | /// |
||
25 | /// </summary> |
||
26 | /// <param name="tobj">the TclObject to convert to use the TclString internal rep. |
||
27 | /// </param> |
||
28 | private static TclObject StringFromAny |
||
29 | { |
||
30 | set |
||
31 | { |
||
32 | InternalRep rep = value.InternalRep; |
||
33 | |||
34 | if ( !( rep is TclString ) ) |
||
35 | { |
||
36 | // make sure that this object now has a valid string rep. |
||
37 | |||
38 | value.ToString(); |
||
39 | |||
40 | // Change the type of the object to TclString. |
||
41 | |||
42 | value.InternalRep = new TclString(); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | /* |
||
47 | * public static String get(TclObject tobj) {;} |
||
48 | * |
||
49 | * There is no "get" class method for TclString representations. |
||
50 | * Use tobj.toString() instead. |
||
51 | */ |
||
52 | |||
53 | } |
||
54 | |||
55 | // Used to perform "append" operations. After an append op, |
||
56 | // sbuf.toString() will contain the latest value of the string and |
||
57 | // tobj.stringRep will be set to null. This field is not private |
||
58 | // since it will need to be accessed directly by Jacl's IO code. |
||
59 | |||
60 | internal StringBuilder sbuf; |
||
61 | |||
62 | private TclString() |
||
63 | { |
||
64 | sbuf = null; |
||
65 | } |
||
66 | |||
67 | private TclString( StringBuilder sb ) |
||
68 | { |
||
69 | sbuf = sb; |
||
70 | } |
||
71 | |||
72 | /// <summary> Returns a dupilcate of the current object.</summary> |
||
73 | /// <param name="obj">the TclObject that contains this internalRep. |
||
74 | /// </param> |
||
75 | |||
76 | public InternalRep duplicate() |
||
77 | { |
||
78 | return new TclString(); |
||
79 | } |
||
80 | |||
81 | /// <summary> Implement this no-op for the InternalRep interface.</summary> |
||
82 | |||
83 | public void dispose() |
||
84 | { |
||
85 | } |
||
86 | |||
87 | /// <summary> Called to query the string representation of the Tcl object. This |
||
88 | /// method is called only by TclObject.toString() when |
||
89 | /// TclObject.stringRep is null. |
||
90 | /// |
||
91 | /// </summary> |
||
92 | /// <returns> the string representation of the Tcl object. |
||
93 | /// </returns> |
||
94 | public override string ToString() |
||
95 | { |
||
96 | if ( sbuf == null ) |
||
97 | { |
||
98 | return ""; |
||
99 | } |
||
100 | else |
||
101 | { |
||
102 | return sbuf.ToString(); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | /// <summary> Create a new TclObject that has a string representation with |
||
107 | /// the given string value. |
||
108 | /// </summary> |
||
109 | public static TclObject newInstance( string str ) |
||
110 | { |
||
111 | return new TclObject( new TclString(), str ); |
||
112 | } |
||
113 | |||
114 | /// <summary> Create a new TclObject that makes use of the given StringBuffer |
||
115 | /// object. The passed in StringBuffer should not be modified after |
||
116 | /// it is passed to this method. |
||
117 | /// </summary> |
||
118 | internal static TclObject newInstance( StringBuilder sb ) |
||
119 | { |
||
120 | return new TclObject( new TclString( sb ) ); |
||
121 | } |
||
122 | |||
123 | internal static TclObject newInstance( System.Object o ) |
||
124 | { |
||
125 | return newInstance( o.ToString() ); |
||
126 | } |
||
127 | |||
128 | /// <summary> Create a TclObject with an internal TclString representation |
||
129 | /// whose initial value is a string with the single character. |
||
130 | /// |
||
131 | /// </summary> |
||
132 | /// <param name="c">initial value of the string. |
||
133 | /// </param> |
||
134 | |||
135 | internal static TclObject newInstance( char c ) |
||
136 | { |
||
137 | char[] charArray = new char[1]; |
||
138 | charArray[0] = c; |
||
139 | return newInstance( new string( charArray ) ); |
||
140 | } |
||
141 | |||
142 | |||
143 | /// <summary> Appends a string to a TclObject object. This method is equivalent to |
||
144 | /// Tcl_AppendToObj() in Tcl 8.0. |
||
145 | /// |
||
146 | /// </summary> |
||
147 | /// <param name="tobj">the TclObject to append a string to. |
||
148 | /// </param> |
||
149 | /// <param name="string">the string to append to the object. |
||
150 | /// </param> |
||
151 | public static void append( TclObject tobj, string toAppend ) |
||
152 | { |
||
153 | StringFromAny = tobj; |
||
154 | |||
155 | TclString tstr = (TclString)tobj.InternalRep; |
||
156 | if ( tstr.sbuf == null ) |
||
157 | { |
||
158 | tstr.sbuf = new StringBuilder( tobj.ToString() ); |
||
159 | } |
||
160 | tobj.invalidateStringRep(); |
||
161 | tstr.sbuf.Append( toAppend ); |
||
162 | } |
||
163 | |||
164 | /// <summary> Appends an array of characters to a TclObject Object. |
||
165 | /// Tcl_AppendUnicodeToObj() in Tcl 8.0. |
||
166 | /// |
||
167 | /// </summary> |
||
168 | /// <param name="tobj">the TclObject to append a string to. |
||
169 | /// </param> |
||
170 | /// <param name="charArr">array of characters. |
||
171 | /// </param> |
||
172 | /// <param name="offset">index of first character to append. |
||
173 | /// </param> |
||
174 | /// <param name="length">number of characters to append. |
||
175 | /// </param> |
||
176 | public static void append( TclObject tobj, char[] charArr, int offset, int length ) |
||
177 | { |
||
178 | StringFromAny = tobj; |
||
179 | |||
180 | TclString tstr = (TclString)tobj.InternalRep; |
||
181 | if ( tstr.sbuf == null ) |
||
182 | { |
||
183 | tstr.sbuf = new StringBuilder( tobj.ToString() ); |
||
184 | } |
||
185 | tobj.invalidateStringRep(); |
||
186 | tstr.sbuf.Append( charArr, offset, length ); |
||
187 | } |
||
188 | |||
189 | /// <summary> Appends a TclObject to a TclObject. This method is equivalent to |
||
190 | /// Tcl_AppendToObj() in Tcl 8.0. |
||
191 | /// |
||
192 | /// The type of the TclObject will be a TclString that contains the |
||
193 | /// string value: |
||
194 | /// tobj.toString() + tobj2.toString(); |
||
195 | /// </summary> |
||
196 | internal static void append( TclObject tobj, TclObject tobj2 ) |
||
197 | { |
||
198 | append( tobj, tobj2.ToString() ); |
||
199 | } |
||
200 | |||
201 | /// <summary> This procedure clears out an existing TclObject so |
||
202 | /// that it has a string representation of "". |
||
203 | /// </summary> |
||
204 | |||
205 | public static void empty( TclObject tobj ) |
||
206 | { |
||
207 | StringFromAny = tobj; |
||
208 | |||
209 | TclString tstr = (TclString)tobj.InternalRep; |
||
210 | if ( tstr.sbuf == null ) |
||
211 | { |
||
212 | tstr.sbuf = new StringBuilder(); |
||
213 | } |
||
214 | else |
||
215 | { |
||
216 | tstr.sbuf.Length = 0; |
||
217 | } |
||
218 | tobj.invalidateStringRep(); |
||
219 | } |
||
220 | } |
||
221 | } |