Parcourir la source

completed lab

Tommy Rogers il y a 6 ans
Parent
révision
b18fe1cade
1 fichiers modifiés avec 16 ajouts et 7 suppressions
  1. 16
    7
      src/main/java/HamletParser.java

+ 16
- 7
src/main/java/HamletParser.java Voir le fichier

39
     }
39
     }
40
 
40
 
41
     public String changeWord(String search, String replace){
41
     public String changeWord(String search, String replace){
42
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
43
-        Matcher m = patt.matcher(hamletData);
42
+        String upperCaseS = search.toUpperCase();
43
+        String upperCaseR = replace.toUpperCase();
44
+        String lowerCaseSwapped = replaceWord(search, replace, hamletData);
45
+        return replaceWord(upperCaseS, upperCaseR, lowerCaseSwapped);
46
+    }
47
+
48
+    public String replaceWord(String search, String replace, String text){
49
+        Pattern patt = Pattern.compile("\\b" +search + "\\b");
50
+        Matcher m = patt.matcher(text);
44
         return m.replaceAll("" + replace + "");
51
         return m.replaceAll("" + replace + "");
45
     }
52
     }
46
 
53
 
47
-    public int findWord(String hamletData ,String search) {
48
-        int count = 0;
49
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
54
+
55
+    public int findWord(String hamletData, String search) {
56
+        Pattern patt = Pattern.compile( search , Pattern.CASE_INSENSITIVE);
50
         Matcher m = patt.matcher(hamletData);
57
         Matcher m = patt.matcher(hamletData);
51
-     while (m.find())
52
-            count++;
58
+        int count = 0;
59
+     while (m.find()) {
60
+         count++;
61
+     }
53
      return count;
62
      return count;
54
     }
63
     }
55
 
64