View Javadoc
1   package org.codehaus.mojo.taglist.tags;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Locale;
23  
24  /** The ignore case tag class.
25   * 
26   *  This class defines a "case insensitive" match tag.  This tag
27   *  will match if the characters (upper or lower case) in the string listed is found within
28   *  the scanned lines.
29   *  
30   *  Example POM:
31   *  <pre>
32   *   &lt;project&gt;
33   *       ...
34   *       &lt;matchString&gt;fixme&lt;/matchString&gt;
35   *       &lt;matchType&gt;ignoreCase&lt;/matchType&gt;
36   *       ...
37   *   &lt;/project&gt;
38   *  </pre>
39   *  
40   *  Example Java code with match:
41   *  <pre>
42   *     * fixme this will match.
43   *     * FIXME this will match.
44   *     * Fixme this will match.
45   *  </pre>
46   *  
47   *  Example Java code without match:
48   *  <pre>
49   *     * @tdoo this will NOT match.
50   *  </pre>
51   *       
52   */
53  public class IgnoreCaseTag extends AbsTag
54  {
55      /** Check to see if the string contains this tag.  
56       *  If there is a match, return the index within the string; otherwise,
57       *  return NO_MATCH.
58       *  
59       *  @param currentLine the string for the current line being scanned.
60       *  @param locale the Locale of the currentLine.
61       *  @return the index within the string of the matched tag, or TagClass.NO_MATCH
62       *  if not match was found.
63       */
64      public int contains( final String currentLine, final Locale locale )
65      {
66          int result = AbsTag.NO_MATCH;
67          
68          if ( currentLine != null )
69          {
70              // Convert current line to lower case before checking
71              // Get index match or -1 if no match
72              result = currentLine.toLowerCase( locale ).indexOf( tagString.toLowerCase( locale ) );
73          }
74          
75          return ( result );
76      }
77      
78      /** Check to see if the string starts with this tag.  
79       *  
80       *  @param currentLine the string for the current line being scanned.
81       *  @param locale the Locale of the currentLine.
82       *  @return true if the string starts with this tag.
83       */
84      public boolean startsWith( final String currentLine, final Locale locale )
85      {
86          boolean result = false;
87          
88          if ( currentLine != null )
89          {
90              // Convert current line to lower case before checking
91              result = currentLine.toLowerCase( locale ).startsWith( tagString.toLowerCase( locale ) );
92          }
93          
94          return ( result );
95      }
96      
97      /** Return the length of the last matched tag.
98       * 
99       * In the case of a ignore case tag, this is always the length of the tag.
100      *  
101      * @return the length of the last matched tag.
102      */
103     public int getLastTagMatchLength()
104     {
105         return ( tagString.length() );
106     }
107 
108     /** Constructor.
109      * 
110      * @param tagString the string to match against for this tag.
111      */
112     public IgnoreCaseTag ( final String tagString )
113     {
114         super( tagString );
115     }
116 
117 }