Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Dębski Piotr S16213
- *
- */
- package zad2;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Finder {
- public int count = 0;
- public int countString = 0;
- public String source;
- Pattern p = Pattern.compile("if\\s*\\(");
- Pattern p1 = Pattern.compile("\\/\\*(.|[\\r\\n])*?\\*\\/"); // wyszukuje wszystkie komentarze multiline
- Pattern p3 = Pattern.compile("//(\\s|\\w|\\n|\\r)+"); //wyszukuje wszystkie komentarze online
- Pattern p4 = Pattern.compile("\"(.)+\""); // wyszukuje wszystkie Stringi
- Pattern p2;
- String content;
- public Finder(String source) throws IOException{
- File f = new File(source);
- if(f.exists() && !f.isDirectory()){
- this.source = source;
- content = new String(Files.readAllBytes(Paths.get(this.source)));
- } else{
- System.out.println("Error! File not found");
- }
- }
- public int getIfCount() throws IOException{
- content = content.replaceAll("\\/\\*(.|[\\r\\n])*?\\*\\/", "");
- content = content.replaceAll("//(\\s|\\w|\\n|\\r)+", "");
- content = content.replaceAll("\"(.)+\"", "");
- Matcher m = p.matcher(content);
- while(m.find()){
- count++;
- }
- return count;
- }
- public int getStringCount(String s){
- p2 = Pattern.compile(s);
- Matcher m = p2.matcher(content);
- while(m.find()){
- countString++;
- }
- return countString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement