Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package ru.ifmo.rain.akulov;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStreamWriter;
  6. import java.nio.charset.StandardCharsets;
  7. import java.nio.file.Files;
  8. import java.nio.file.Paths;
  9. import java.util.HashMap;
  10. import java.util.Map;
  11.  
  12. public class Main {
  13.  
  14. static int countOpen = 0;
  15. static int countClose = 0;
  16. static final Map<String, String> TAGS_MAP = initTagsMap();
  17.  
  18. static Map<String, String> initTagsMap() {
  19. Map<String, String> map = new HashMap<>();
  20. map.put("[b]", "[/b]");
  21. map.put("[u]", "[/u]");
  22. map.put("[i]", "[/i]");
  23. map.put("[s]", "[/s]");
  24. map.put("[img]", "[/img]");
  25. map.put("[code]", "[/code]");
  26. return map;
  27. }
  28.  
  29. static void correctOrNot(String curString) {
  30. for (int i = 0; i < curString.length(); i++) {
  31. if (curString.charAt(i) == '[') {
  32. countOpen += 1;
  33. } else if (curString.charAt(i) == ']') {
  34. countClose += 1;
  35. }
  36. }
  37. if (countOpen != countClose) {
  38. System.out.println("Не могу нормально распарсить теги, соре");
  39. return;
  40. }
  41. }
  42.  
  43. public static void main(String[] args) {
  44. try {
  45. handleFile(args[0], args[1]);
  46. } catch (IOException e) {
  47. System.err.println("IO?");
  48. }
  49. }
  50.  
  51. private static void handleFile(String inputFileName, String outputFileName) throws IOException {
  52. String content = new String(Files.readAllBytes(Paths.get(inputFileName)), StandardCharsets.UTF_8);
  53. OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFileName), StandardCharsets.UTF_8);
  54. correctOrNot(content);
  55. String s = new NodeDefault(content).toHTML();
  56. out.append(s);
  57. out.close();
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement