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 * <p>
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 * <p>
30 * Example POM:
31 * <pre>
32 * <project>
33 * ...
34 * <matchString>fixme</matchString>
35 * <matchType>ignoreCase</matchType>
36 * ...
37 * </project>
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 /** Check to see if the string contains this tag.
55 * If there is a match, return the index within the string; otherwise,
56 * return NO_MATCH.
57 *
58 * @param currentLine the string for the current line being scanned.
59 * @param locale the Locale of the currentLine.
60 * @return the index within the string of the matched tag, or TagClass.NO_MATCH
61 * if not match was found.
62 */
63 public int contains(final String currentLine, final Locale locale) {
64 int result = AbsTag.NO_MATCH;
65
66 if (currentLine != null) {
67 // Convert current line to lower case before checking
68 // Get index match or -1 if no match
69 result = currentLine.toLowerCase(locale).indexOf(tagString.toLowerCase(locale));
70 }
71
72 return (result);
73 }
74
75 /** Check to see if the string starts with this tag.
76 *
77 * @param currentLine the string for the current line being scanned.
78 * @param locale the Locale of the currentLine.
79 * @return true if the string starts with this tag.
80 */
81 public boolean startsWith(final String currentLine, final Locale locale) {
82 boolean result = false;
83
84 if (currentLine != null) {
85 // Convert current line to lower case before checking
86 result = currentLine.toLowerCase(locale).startsWith(tagString.toLowerCase(locale));
87 }
88
89 return (result);
90 }
91
92 /** Return the length of the last matched tag.
93 * <p>
94 * In the case of a ignore case tag, this is always the length of the tag.
95 *
96 * @return the length of the last matched tag.
97 */
98 public int getLastTagMatchLength() {
99 return (tagString.length());
100 }
101
102 /** Constructor.
103 *
104 * @param tagString the string to match against for this tag.
105 */
106 public IgnoreCaseTag(final String tagString) {
107 super(tagString);
108 }
109 }