MCPcopy Create free account
hub / github.com/beanshell/beanshell / findTemplate

Method findTemplate

src/bsh/servlet/SimpleTemplate.java:151–206  ·  view source on GitHub ↗

Find the starting (inclusive) and ending (exclusive) index of the named template and return them as a two element int []. Or return null if the param is not found.

( String name )

Source from the content-addressed store, hash-verified

149 Or return null if the param is not found.
150 */
151 int [] findTemplate( String name ) {
152 String text = buff.toString();
153 int len = text.length();
154
155 int start = 0;
156
157 while ( start < len ) {
158
159 // Find begin and end comment
160 int cstart = text.indexOf( "<!--", start );
161 if ( cstart == -1 )
162 return null; // no more comments
163 int cend = text.indexOf( "-->", cstart );
164 if ( cend == -1 )
165 return null; // no more complete comments
166 cend += "-->".length();
167
168 // Find template tag
169 int tstart = text.indexOf( "TEMPLATE-", cstart );
170 if ( tstart == -1 ) {
171 start = cend; // try the next comment
172 continue;
173 }
174
175 // Is the tag inside the comment we found?
176 if ( tstart > cend ) {
177 start = cend; // try the next comment
178 continue;
179 }
180
181 // find begin and end of param name
182 int pstart = tstart + "TEMPLATE-".length();
183
184 int pend = len;
185 for ( pend = pstart; pend < len; pend++) {
186 char c = text.charAt( pend );
187 if ( c == ' ' || c == '\t' || c == '-' )
188 break;
189 }
190 if ( pend >= len )
191 return null;
192
193 String param = text.substring( pstart, pend );
194
195 // If it's the correct one, return the comment extent
196 if ( param.equals( name ) )
197 return new int [] { cstart, cend };
198
199//System.out.println( "Found param: {"+param+"} in comment: "+ text.substring(cstart, cend) +"}");
200 // Else try the next one
201 start = cend;
202 }
203
204 // Not found
205 return null;
206 }
207
208 public String toString() {

Callers 1

replaceMethod · 0.95

Calls 2

toStringMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected