KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > CvsInfo


1 // $Id: CvsInfo.java,v 1.1 2002/01/28 12:46:53 ramsdell Exp $
2

3 // The make class
4

5 /*
6  * Copyright 1997 by John D. Ramsdell
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 package edu.neu.ccs.jmk;
24
25 /**
26  * This class provides support for CVS's
27  * keyword substitution in strings.
28  * @author John D. Ramsdell
29  * @version June 2001
30  */

31 public class CvsInfo
32 {
33     private CvsInfo() {
34     }
35
36     /**
37      * Get the contents of a CVS keyword substitution entry. Returns
38      * null if the input is null, or the string contains less than two
39      * dollar signs. When the result is non-null, it is trimed.
40      */

41     public static String JavaDoc getEntry(String JavaDoc text) {
42     if (text == null)
43         return null;
44     int first = text.indexOf('$');
45     int last = text.lastIndexOf('$');
46     if (last <= first)
47         return null;
48     return text.substring(first + 1, last).trim();
49     }
50
51     /**
52      * Get the value part of a CVS keyword substitution entry. The
53      * getEntry method is applied to the input. This method returns
54      * the contents of the string after the first colon, or the
55      * empty string. When the result is non-null, it is trimed.
56      */

57     public static String JavaDoc getValue(String JavaDoc text) {
58     text = getEntry(text);
59     if (text == null)
60         return null;
61     int first = text.indexOf(':');
62     if (first < 0)
63         return "";
64     return text.substring(first + 1).trim();
65     }
66
67     /**
68      * Get the value part of a CVS keyword substitution entry as in
69      * getValue, but then translates underscores into periods, and
70      * hyphens into spaces. When the result is non-null, it is
71      * trimed.
72      */

73     public static String JavaDoc getTag(String JavaDoc text) {
74     text = getValue(text);
75     if (text == null)
76         return null;
77     return text.replace('_', '.').replace('-', ' ').trim();
78     }
79
80     /**
81      * Get the key part of a CVS keyword substitution entry. The
82      * getEntry method is applied to the input. This method returns
83      * the contents of the string up to the first colon, or the
84      * empty string. When the result is non-null, it is trimed.
85      */

86     public static String JavaDoc getKey(String JavaDoc text) {
87     text = getEntry(text);
88     if (text == null)
89         return null;
90     int first = text.indexOf(':');
91     if (first < 0)
92         return text;
93     return text.substring(0, first).trim();
94     }
95
96     /**
97      * This is a test routine that calls each static method
98      * on each command line argument.
99      */

100     public static void main(String JavaDoc[] args) {
101     for (int i = 0; i < args.length; i++) {
102         System.out.println("args[" + i + "] = \"" + args[i] + "\"");
103         System.out.println("getEntry(args[" + i + "]) = \""
104                    + getEntry(args[i]) + "\"");
105         System.out.println("getValue(args[" + i + "]) = \""
106                    + getValue(args[i]) + "\"");
107         System.out.println("getKey(args[" + i + "]) = \""
108                    + getKey(args[i]) + "\"");
109         System.out.println();
110     }
111     }
112 }
113
Popular Tags