code: public static <PS, SEG, S> ReadOnlyStyledDocument<PS, SEG, S> fromString(String str, PS paragraphStyle, S style, TextOps<SEG, S> segmentOps) {
          Matcher m = LINE_TERMINATOR.matcher(str);
  
          int n = 1;
          while(m.find()) ++n;
          List<Paragraph<PS, SEG, S>> res = new ArrayList<>(n);
  
          int start = 0;
          m.reset();
          while(m.find()) {
              String s = str.substring(start, m.start());
              res.add(new Paragraph<>(paragraphStyle, segmentOps, segmentOps.create(s), style));
              start = m.end();
          }
          String last = str.substring(start);
          res.add(new Paragraph<>(paragraphStyle, segmentOps, segmentOps.create(last), style));
  
          return new ReadOnlyStyledDocument<>(res);
      }
docs: Creates a {@link ReadOnlyStyledDocument} from the given string.
  
  @param str the text to use to create the segments
  @param paragraphStyle the paragraph style to use for each paragraph in the returned document
  @param style the style to use for each segment in the document
  @param segmentOps the operations object that can create a segment froma given text
  @param <PS> The type of the paragraph style.
  @param <SEG> The type of the segments in the paragraph (e.g. {@link String}).
  @param <S> The type of the style of individual segments.