KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > Language > Common


1 package SnowMailClient.Language;
2
3 import java.util.*;
4 import java.util.zip.*;
5 import java.io.*;
6 import javax.swing.table.*;
7
8 import snow.utils.storage.*;
9
10 public final class Common
11 {
12
13    private Common()
14    {
15    }
16
17    /** @return the number of spaces at the begining of the string
18      this is used to avoid translating "hello" and " hello "
19    */

20    public static int getNumberOfSpacesAtBegining(String JavaDoc s)
21    {
22       for(int i=0; i<s.length(); i++)
23       {
24         if(s.charAt(i)!=' ') return i;
25       }
26       return s.length();
27    }
28
29    /** @return the number of spaces at the end of the string
30    */

31    public static int getNumberOfSpacesAtEnd(String JavaDoc s)
32    {
33       for(int i=0; i<s.length(); i++)
34       {
35         if(s.charAt(s.length()-i-1)!=' ') return i;
36       }
37       return s.length();
38    }
39
40   /** @return 0 if no arguments are detected in the sentence (%)
41        1 if one % is present
42        2 if %1 and %2 are present
43   */

44    public static int getNumberOfParametersInSentence(String JavaDoc sentence) throws Exception JavaDoc
45    {
46      if(sentence.indexOf("%2")!=-1)
47      {
48         if(sentence.indexOf("%1")==-1)
49         {
50           throw new Exception JavaDoc("Sentence has only argument %2, %1 is missing ?");
51         }
52         return 2;
53      }
54      if(sentence.indexOf("%1")!=-1)
55      {
56         if(sentence.indexOf("%2")==-1)
57         {
58           throw new Exception JavaDoc("Sentence has only argument %1, %2 is missing ?");
59         }
60         return 2;
61      }
62
63      if(sentence.indexOf("%")!=-1)
64      {
65        return 1;
66      }
67
68      return 0;
69    }
70
71    /** Language/hello.java => Language.hello
72    */

73    public static String JavaDoc convertPathToJavaClassPathSyntax(String JavaDoc _path)
74    {
75      String JavaDoc path = _path;
76      // 1) supperss .java
77
if(path.endsWith(".java")) path = path.substring(0, path.length()-5);
78
79      // 2) convert \ to .
80
int pos = -1;
81      while((pos=path.indexOf("\\"))!=-1)
82      {
83        path = path.substring(0,pos)+"."+path.substring(pos+1);
84      }
85
86      return path;
87    }
88
89
90
91
92
93 } // Common
Popular Tags