Example #1
0
 public void analyzeAndAdd(String line) {
   if (line == null) {
     throw new IllegalArgumentException();
   }
   line = CharHidder.hide(line);
   if (style.getType() == StripeStyleType.HEADING) {
     atoms.add(AtomText.createHeading(line, fontConfiguration, style.getOrder()));
   } else if (style.getType() == StripeStyleType.HORIZONTAL_LINE) {
     atoms.add(CreoleHorizontalLine.create(fontConfiguration, line, style.getStyle(), skinParam));
   } else {
     modifyStripe(line);
   }
 }
  public CreoleStripeSimpleParser(
      String line,
      CreoleContext creoleContext,
      FontConfiguration fontConfiguration,
      ISkinSimple skinParam,
      CreoleMode modeSimpleLine) {
    this.fontConfiguration = fontConfiguration;
    this.modeSimpleLine = modeSimpleLine;
    this.skinParam = skinParam;
    if (skinParam == null) {
      throw new IllegalArgumentException();
    }

    final Pattern p4 = MyPattern.cmpile("^--([^-]*)--$");
    final Matcher m4 = p4.matcher(line);
    if (m4.find()) {
      this.line = m4.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '-');
      return;
    }

    final Pattern p5 = MyPattern.cmpile("^==([^=]*)==$");
    final Matcher m5 = p5.matcher(line);
    if (m5.find()) {
      this.line = m5.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '=');
      return;
    }
    final Pattern p5b = MyPattern.cmpile("^===*==$");
    final Matcher m5b = p5b.matcher(line);
    if (m5b.find()) {
      this.line = "";
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '=');
      return;
    }

    // if (modeSimpleLine == CreoleMode.FULL) {
    // final Pattern p6 = MyPattern.cmpile("^__([^_]*)__$");
    // final Matcher m6 = p6.matcher(line);
    // if (m6.find()) {
    // this.line = m6.group(1);
    // this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '_');
    // return;
    // }
    // }

    final Pattern p7 = MyPattern.cmpile("^\\.\\.([^\\.]*)\\.\\.$");
    final Matcher m7 = p7.matcher(line);
    if (m7.find()) {
      this.line = m7.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '.');
      return;
    }

    if (modeSimpleLine == CreoleMode.FULL) {
      final Pattern p1 = MyPattern.cmpile("^(\\*+)([^*]+(?:[^*]|\\*\\*[^*]+\\*\\*)*)$");
      final Matcher m1 = p1.matcher(line);
      if (m1.find()) {
        this.line = StringUtils.trin(m1.group(2));
        final int order = m1.group(1).length() - 1;
        this.style = new StripeStyle(StripeStyleType.LIST_WITHOUT_NUMBER, order, '\0');
        return;
      }
    }

    if (modeSimpleLine == CreoleMode.FULL) {
      final Pattern p2 = MyPattern.cmpile("^(#+)(.+)$");
      final Matcher m2 = p2.matcher(CharHidder.hide(line));
      if (m2.find()) {
        this.line = StringUtils.trin(CharHidder.unhide(m2.group(2)));
        final int order = CharHidder.unhide(m2.group(1)).length() - 1;
        this.style = new StripeStyle(StripeStyleType.LIST_WITH_NUMBER, order, '\0');
        return;
      }
    }

    final Pattern p3 = MyPattern.cmpile("^(=+)(.+)$");
    final Matcher m3 = p3.matcher(line);
    if (m3.find()) {
      this.line = StringUtils.trin(m3.group(2));
      final int order = m3.group(1).length() - 1;
      this.style = new StripeStyle(StripeStyleType.HEADING, order, '\0');
      return;
    }

    this.line = line;
    this.style = new StripeStyle(StripeStyleType.NORMAL, 0, '\0');
  }