/** Clear {@link #splitMap}. */ public void clearSplitMap() { splitMap.clear(); }
/** * Split line by regex. * * @param re {@link RegexEnum} * @param line line to split * @return list of strings split by regex */ public String[] split(RegexEnum re, String line) { return splitMap.getSplit(re, line); }
/** * Replace all using pattern. * * @param re {@link RegexEnum} * @param split list to split * @param index index of word in split * @param replace string to replace * @return fixed string */ public String patternReplaceAll(RegexEnum re, String[] split, int index, String replace) { return splitMap.getPatternReplaceAll(re, split, index, replace); }
/** Apply fixes to text. */ public void fix() { if (text == null || text.isEmpty()) { return; } text = text.trim(); text = RemoveEmpty.fix(text, this); if (text.isEmpty()) { return; } // TODO: comment this text = RemoveEndingCharacter.fix(text, '<', '>', this); text = RemoveEndingCharacter.fix(text, '{', '}', this); text = RemoveEndingCharacter.fix(text, '[', ']', this); if (ManuelFix.MANUEL_FIX.containsKey(text)) { text = ManuelFix.MANUEL_FIX.get(text); return; } else if (DoNotFix.DO_NOT_FIX.contains(text)) { return; } if (text.startsWith("#") && !text.endsWith("#")) { text += " #"; } text = RemoveEndingCharacter.fix(text, '(', ')', this); text = FixNonTraditionalStrings.fix(text, this); // TODO: messy (see "...with the .22?") if (text.startsWith("-") && !text.startsWith("- ")) { text = "- " + text.substring(1); splitMap.clear(); // TODO: clean up } text = FixEllipses.fix(text, this); text = FixSingleDoubleQuotes.fix(text, this); String result = ""; int removedNames = 0; String originalText = text; text = FixUnbalancedDashes.fix(text); boolean fixedUnbalancedDashes = !originalText.equals(text); if (!text.startsWith("-")) { // text = text.replace("\n", " "); // TODO: explain this } String temp; for (String line : RegexUtil.split(RegexEnum.NEWLINE, text)) { // TODO: if contains punctuation line = line.trim(); splitMap.clear(); line = PrepareLine.fix(line, this); split(RegexEnum.SPACE, line); temp = line; line = RemoveCharacterName.fix(line, this); if (!temp.equals(line)) { ++removedNames; } line = FixSpelling.fix(line, this); if (!SrtFixerConfig.isToggleCorrectCapitalization()) { line = FixToUppercase.fix( line, this); // TODO: remove this once all bugs in FixCapitalization is fixed } line = ChangeLsToIs.fix(line, this); line = FixDashes.fix(line, this); line = RemoveEmpty.fix(line, this); if (SrtFixerConfig.isToggleCorrectCapitalization()) { line = FixCapitalization.fix(line, this); } line = FixAmpersand.fix(line, this); line = FixHeight.fix(line, this); line = FixWebsites.fix(line, this); line = FixTime.fix(line, this); line = FixNumbers.fix(line, this); line = FixAbbreviations.fix(line, this); line = FixContractions.fix(line, this); line = FixAcronym.fix(line, this); line = FixLetterS.fix(line, this); line = FixMisplacedQuotes.fix(line, this); line = FixSpacing.fix(line, this); line = FixCommonErrors.fix(line, this); line = FixEnding.fix(line, this); if (!line.isEmpty()) { line = FixMultilineDashes.fix(result, line); // TODO: why doesn't this work??? if (!result.isEmpty()) { result = FixMultilineDashes.fix(line, result); } StringBuilder builder = new StringBuilder(); if (removedNames == 2) { builder.append("- "); builder.append(result); builder.append("- "); builder.append(line); result = builder.toString(); continue; } builder.append(result); builder.append(line); builder.append('\n'); result = builder.toString(); } } result = FixEllipses.fix(result, this); result = result.trim(); result = FixMultilineQuotes.fix(result, this); result = FixThreeLines.fix(result); result = FixTwoLines.fix(result); result = FixOneLine.fix(result); if (StringUtil.count(originalText, '\n') <= 1 && SubtitleUtil.isApproximatelyEqual(result, originalText) && !fixedUnbalancedDashes) { result = originalText; } text = result; }