Add tags

Add tags to the following comment

一番のりを狙って書きました。起動パラメータに与えられたJavaのソースファイルからコメントを削除し、".out" 拡張子つきのファイルに書き込みます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.regex.*;
import java.io.*;

public class Decomment {

    static final Pattern COMMENT1 = Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL);
    static final Pattern COMMENT2 = Pattern.compile("//.*");
    
    public static void main(String[] args) throws IOException {
        for (String name : args) {
            BufferedReader r = new BufferedReader(new FileReader(name));
            FileWriter w = new FileWriter(name + ".out");
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = r.readLine()) != null) {
                sb.append(line).append(System.getProperty("line.separator"));
            }
            String s1 = COMMENT1.matcher(sb).replaceAll("");
            String result = COMMENT2.matcher(s1).replaceAll("");
            w.write(result);
            w.close();
        }
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...