|
@@ -1,6 +1,14 @@
|
1
|
1
|
package rocks.zipcode;
|
2
|
2
|
|
3
|
|
-import java.io.IOException;
|
|
3
|
+import sun.nio.cs.UTF_32;
|
|
4
|
+
|
|
5
|
+import java.io.*;
|
|
6
|
+import java.nio.file.Files;
|
|
7
|
+import java.nio.file.Paths;
|
|
8
|
+import java.util.regex.Matcher;
|
|
9
|
+import java.util.regex.Pattern;
|
|
10
|
+
|
|
11
|
+import static java.nio.charset.StandardCharsets.UTF_16;
|
4
|
12
|
|
5
|
13
|
/**
|
6
|
14
|
* @author leon on 18/11/2018.
|
|
@@ -12,9 +20,21 @@ public class SpecialCharDocument extends Document {
|
12
|
20
|
|
13
|
21
|
@Override
|
14
|
22
|
public void write(String contentToBeWritten) {
|
|
23
|
+ if (isSpecialCharacters(contentToBeWritten)) {
|
|
24
|
+ try {
|
|
25
|
+ BufferedWriter out = Files.newBufferedWriter(Paths.get(getFile().getAbsolutePath()));
|
|
26
|
+ out.write(contentToBeWritten);
|
|
27
|
+ } catch (IOException io) {
|
|
28
|
+ System.out.println("An unexpected IO exception has occurred: " + io.getMessage());
|
|
29
|
+ }
|
|
30
|
+ } else {
|
|
31
|
+ throw new IllegalArgumentException();
|
|
32
|
+ }
|
15
|
33
|
}
|
16
|
34
|
|
17
|
35
|
private Boolean isSpecialCharacters(String s) {
|
18
|
|
- return null;
|
|
36
|
+ Pattern p = Pattern.compile("[\\w&&[^_]]");
|
|
37
|
+ Matcher m = p.matcher(s);
|
|
38
|
+ return !m.find();
|
19
|
39
|
}
|
20
|
40
|
}
|