示例#1
0
	/// <summary>Replaces all occurences of some text with the specified replacement.</summary>
	/// <param name="regex">A regular expression used to find the text to be replaced.</param>
	/// <param name="replacement">The text that will be used as a replacement.</param>
	/// <param name="lineBreak">The line break to use between multiple lines of text in each subtitle.</param>
	/// <returns>The previous text of the replaced subtitles.</returns>
	public ArrayList ReplaceAll (Regex regex, string replacement, string lineBreak) {
		ArrayList replaced = new ArrayList();
		MatchEvaluationCounter counter = new MatchEvaluationCounter(replacement);

		for (int subtitleNumber = 0 ; subtitleNumber < subtitles.Collection.Count ; subtitleNumber++) {
			Subtitle subtitle = subtitles.Collection[subtitleNumber];

			/* Handle text */
			string oldText = subtitle.Text.Get(lineBreak);
			string newText = ReplaceText(oldText, regex, replacement, counter);
			string textToStore = null;
			if (newText != null) {
				subtitle.Text.Set(newText, lineBreak, false);
				textToStore = oldText;
			}

			/* Handle translation */
			string oldTranslation = subtitle.Translation.Get(lineBreak);
			string newTranslation = ReplaceText(oldTranslation, regex, replacement, counter);
			string translationToStore = null;
			if (newTranslation != null) {
				subtitle.Translation.Set(newTranslation, lineBreak, false);
				translationToStore = oldTranslation;
			}

			if ((textToStore != null) || (translationToStore != null)) {
				replaced.Add(new SubtitleReplaceResult(subtitleNumber, textToStore, translationToStore));
			}
		}

		return replaced;
	}
示例#2
0
        private string ReplaceText(string text, Regex regex, string replacement, MatchEvaluationCounter counter)
        {
            counter.EvaluationOccured = false;
            string newText = regex.Replace(text, counter.Evaluator);

            return(counter.EvaluationOccured ? newText : null);
        }
示例#3
0
        /// <summary>Replaces all occurences of some text with the specified replacement.</summary>
        /// <param name="regex">A regular expression used to find the text to be replaced.</param>
        /// <param name="replacement">The text that will be used as a replacement.</param>
        /// <param name="lineBreak">The line break to use between multiple lines of text in each subtitle.</param>
        /// <returns>The previous text of the replaced subtitles.</returns>
        public ArrayList ReplaceAll(Regex regex, string replacement, string lineBreak)
        {
            ArrayList replaced             = new ArrayList();
            MatchEvaluationCounter counter = new MatchEvaluationCounter(replacement);

            for (int subtitleNumber = 0; subtitleNumber < subtitles.Collection.Count; subtitleNumber++)
            {
                Subtitle subtitle = subtitles.Collection[subtitleNumber];

                /* Handle text */
                string oldText     = subtitle.Text.Get(lineBreak);
                string newText     = ReplaceText(oldText, regex, replacement, counter);
                string textToStore = null;
                if (newText != null)
                {
                    subtitle.Text.Set(newText, lineBreak, false);
                    textToStore = oldText;
                }

                /* Handle translation */
                string oldTranslation     = subtitle.Translation.Get(lineBreak);
                string newTranslation     = ReplaceText(oldTranslation, regex, replacement, counter);
                string translationToStore = null;
                if (newTranslation != null)
                {
                    subtitle.Translation.Set(newTranslation, lineBreak, false);
                    translationToStore = oldTranslation;
                }

                if ((textToStore != null) || (translationToStore != null))
                {
                    replaced.Add(new SubtitleReplaceResult(subtitleNumber, textToStore, translationToStore));
                }
            }

            return(replaced);
        }
示例#4
0
	private string ReplaceText (string text, Regex regex, string replacement, MatchEvaluationCounter counter) {
		counter.EvaluationOccured = false;
		string newText = regex.Replace(text, counter.Evaluator);
		return (counter.EvaluationOccured ? newText : null);
	}