예제 #1
0
  public static void readFromFile(KoohiiReader kr, String file) {
    try (CSVReader reader = new CSVReader(new FileReader(file))) {
      String[] fields;
      while ((fields = reader.readNext()) != null) {
        if (fields.length <= 1) continue;
        if (fields.length != 6) {
          System.out.println(
              "Warning: wrong number of elements in line " + Arrays.toString(fields));
          continue;
        }

        KoohiiEntry ke = new KoohiiEntry();
        ke.index = fields[0];
        ke.character = fields[1];
        ke.keyword = fields[2];
        ke.story = fields[5];
        kr.parseStory(ke);
        kr.add(ke);
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  private void parseStory(KoohiiEntry ke) {
    StringBuilder story = new StringBuilder();

    Matcher m = p.matcher(ke.story);
    int lastpos = 0;
    while (m.find()) {
      story.append(ke.story.substring(lastpos, m.start()));
      switch (m.group(1)) {
        case "thanks":
          break;
        case "primitive":
          String arg = m.group(2);
          int splitpos = arg.indexOf(':');
          if (splitpos < 0) {
            ke.primitive = arg;
          } else {
            KoohiiEntry primitive = new KoohiiEntry();
            String firstPart = arg.substring(0, splitpos).trim();
            primitive.story = arg.substring(splitpos + 1).trim();

            splitpos = firstPart.indexOf("|");
            if (splitpos < 0) {
              primitive.primitive = firstPart;
              primitive.character = firstPart;
              primitive.index = primitive.character;
            } else {
              primitive.primitive = firstPart.substring(splitpos + 1).trim();
              primitive.character = firstPart.substring(0, splitpos).trim();
              primitive.index = primitive.primitive;
            }
            add(primitive);
          }

          break;
        default:
          // System.out.println(m.group(0));
      }
      lastpos = m.end();
    }
    story.append(ke.story.substring(lastpos));

    ke.story = story.toString().trim();
  }