realignByQuote method

List<String> realignByQuote(
  1. String text,
  2. int lastQuotePos,
  3. String quoteType,
  4. bool useHeuristic,
  5. bool useQuotesBracketsProcessing,
  6. int maxRecoverStep,
  7. int maxRecoverLength,
  8. int recoverStep,
)

Implementation

List<String> realignByQuote(String text, int lastQuotePos, String quoteType, bool useHeuristic, bool useQuotesBracketsProcessing,
    int maxRecoverStep, int maxRecoverLength, int recoverStep) {
  List<String> beforeQuote = splitSentences(
      text.substring(0, lastQuotePos), useHeuristic, useQuotesBracketsProcessing, maxRecoverStep, maxRecoverLength, recoverStep, false);

  String beforeLast = beforeQuote.isNotEmpty ? beforeQuote.last : "";
  beforeQuote = beforeQuote.length == 1 ? [] : beforeQuote;

  List<String> afterQuote = splitSentences(
      text.substring(lastQuotePos + 1), useHeuristic, useQuotesBracketsProcessing, maxRecoverStep, maxRecoverLength, recoverStep, false);

  String afterFirst = afterQuote.isNotEmpty ? afterQuote.first : "";
  afterQuote = afterQuote.length == 1 || afterQuote.isEmpty ? [] : afterQuote.getRange(1, afterQuote.length - 1).toList();

  List<String> middleQuote = [];
  middleQuote.add(beforeLast + quoteType + afterFirst);
  List<String> results = [];

  results.addAll(beforeQuote);
  results.addAll(middleQuote);
  results.addAll(afterQuote);

  return results;
}