OSDN Git Service

r74までのコメントのみに関わる変更.
[coroid/inqubus.git] / frontend / src / saccubus / util / FileUtil.java
1 /**
2  * \83t\83@\83C\83\8b\82É\8aÖ\82·\82é\83\86\81[\83e\83B\83\8a\83e\83B
3  */
4 package saccubus.util;
5
6 import java.io.File;
7 import java.util.regex.Pattern;
8
9 /**
10  * @author PSI
11  *
12  */
13 public class FileUtil {
14         private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
15         public static String safeFileName(String str) {
16                 //\8eÀ\91Ì\8eQ\8fÆ\82Ì\83p\81[\83X
17                 int old_index = 0;
18                 int new_index = 0;
19                 StringBuffer sb = new StringBuffer();
20                 String ch;
21                 while((new_index = str.indexOf("&#",old_index)) >= 0){
22                         sb.append(str,old_index,new_index);
23                         old_index = str.indexOf(";",new_index);
24                         ch = str.substring(new_index+2,old_index);
25                         sb.append(new String(new char[]{(char) Integer.parseInt(ch)}));
26                         old_index++;
27                 }
28                 //\8dÅ\8cã\82É\92Ç\89Á
29                 sb.append(str,old_index,str.length());
30                 str = sb.toString();
31                 //\83t\83@\83C\83\8b\83V\83X\83e\83\80\82Å\88µ\82¦\82é\8c`\82É
32                 str = str.replace('/', '\81^');
33                 str = str.replace('\\', '\81\8f');
34                 str = str.replace('?', '\81H');
35                 str = str.replace('*', '\81\96');
36                 str = str.replace(':', '\81F');
37                 str = str.replace('|', '\81b');
38                 str = str.replace('\"', '\81h');
39                 str = str.replace('<', '\81\83');
40                 str = str.replace('>', '\81\84');
41                 str = str.replace('.', '\81D');
42                 str = safeFileName_SPACE.matcher(str).replaceAll(" ");
43                 return str;
44         }
45
46 }