Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 213   Methods: 10
NCLOC: 124 Classes: 2
 
Source File Conditionals Statements Methods TOTAL
Utilities\StringTokenizer.cs 88.9 % 87.2 % 80.0 % 86.7 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   using System;
28   using System.Collections;
29   using System.Text;
30  
31   namespace IBatisNet.Common.Utilities
32   {
33  
34   /// <summary>
35   /// A StringTokenizer java like object
36   /// </summary>
37   public class StringTokenizer : IEnumerable
38   {
39  
40   private static readonly string _defaultDelim=" \t\n\r\f";
41   string _origin = string.Empty;
42   string _delimiters = string.Empty;
43   bool _returnDelimiters = false;
44  
45   /// <summary>
46   /// Constructs a StringTokenizer on the specified String, using the
47   /// default delimiter set (which is " \t\n\r\f").
48   /// </summary>
49   /// <param name="str">The input String</param>
50 0 public StringTokenizer(string str)
51   {
52   _origin = str;
53   _delimiters = _defaultDelim;
54   _returnDelimiters = false;
55   }
56  
57  
58   /// <summary>
59   /// Constructs a StringTokenizer on the specified String,
60   /// using the specified delimiter set.
61   /// </summary>
62   /// <param name="str">The input String</param>
63   /// <param name="delimiters">The delimiter String</param>
64 525 public StringTokenizer(string str, string delimiters)
65   {
66 525 _origin = str;
67 525 _delimiters = delimiters;
68 525 _returnDelimiters = false;
69   }
70  
71  
72   /// <summary>
73   /// Constructs a StringTokenizer on the specified String,
74   /// using the specified delimiter set.
75   /// </summary>
76   /// <param name="str">The input String</param>
77   /// <param name="delimiters">The delimiter String</param>
78   /// <param name="returnDelimiters">Returns delimiters as tokens or skip them</param>
79 69952 public StringTokenizer(string str, string delimiters, bool returnDelimiters)
80   {
81 69952 _origin = str;
82 69952 _delimiters = delimiters;
83 69952 _returnDelimiters = returnDelimiters;
84   }
85  
86  
87   /// <summary>
88   ///
89   /// </summary>
90   /// <returns></returns>
91 70477 public IEnumerator GetEnumerator()
92   {
93 70477 return new StringTokenizerEnumerator(this);
94   }
95  
96  
97   /// <summary>
98   /// Returns the number of tokens in the String using
99   /// the current deliminter set. This is the number of times
100   /// nextToken() can return before it will generate an exception.
101   /// Use of this routine to count the number of tokens is faster
102   /// than repeatedly calling nextToken() because the substrings
103   /// are not constructed and returned for each token.
104   /// </summary>
105   public int TokenNumber
106   {
107 3910 get
108   {
109 3910 int count = 0;
110 3910 int currpos = 0;
111 3910 int maxPosition = _origin.Length;
112  
113 17000 while (currpos < maxPosition)
114   {
115 13090 while (!_returnDelimiters &&
116   (currpos < maxPosition) &&
117   (_delimiters.IndexOf(_origin[currpos]) >= 0))
118   {
119 0 currpos++;
120   }
121  
122 13090 if (currpos >= maxPosition)
123   {
124 0 break;
125   }
126  
127 13090 int start = currpos;
128 96390 while ((currpos < maxPosition) &&
129   (_delimiters.IndexOf(_origin[currpos]) < 0))
130   {
131 83300 currpos++;
132   }
133 13090 if (_returnDelimiters && (start == currpos) &&
134   (_delimiters.IndexOf(_origin[currpos]) >= 0))
135   {
136 4590 currpos++;
137   }
138 13090 count++;
139   }
140 3910 return count;
141  
142   }
143  
144   }
145  
146  
147   private class StringTokenizerEnumerator : IEnumerator
148   {
149   private StringTokenizer _stokenizer;
150   private int _cursor = 0;
151   private string _next = null;
152  
153 70477 public StringTokenizerEnumerator(StringTokenizer stok)
154   {
155 70477 _stokenizer = stok;
156   }
157  
158 373267 public bool MoveNext()
159   {
160 373267 _next = GetNext();
161 373267 return _next != null;
162   }
163  
164 0 public void Reset()
165   {
166   _cursor = 0;
167   }
168  
169   public object Current
170   {
171 301430 get
172   {
173 301430 return _next;
174   }
175   }
176  
177 373793 private string GetNext()
178   {
179 373793 char c;
180 373793 bool isDelim;
181  
182 373793 if( _cursor >= _stokenizer._origin.Length )
183 67247 return null;
184  
185 306546 c = _stokenizer._origin[_cursor];
186 306546 isDelim = (_stokenizer._delimiters.IndexOf(c) != -1);
187  
188 306546 if ( isDelim )
189   {
190 132069 _cursor++;
191 132069 if ( _stokenizer._returnDelimiters )
192   {
193 131543 return c.ToString();
194   }
195 526 return GetNext();
196   }
197  
198 174477 int nextDelimPos = _stokenizer._origin.IndexOfAny(_stokenizer._delimiters.ToCharArray(), _cursor);
199 174477 if (nextDelimPos == -1)
200   {
201 43428 nextDelimPos = _stokenizer._origin.Length;
202   }
203  
204 174477 string nextToken = _stokenizer._origin.Substring(_cursor, nextDelimPos - _cursor);
205 174477 _cursor = nextDelimPos;
206 174477 return nextToken;
207   }
208  
209   }
210   }
211  
212   }
213