/// <summary>
/// Returns the name of modified section or empty string if more than one section has changed
/// </summary>
/// <param name="originalText"></param>
/// <param name="articleText"></param>
/// <returns></returns>
public static string ModifiedSection(string originalText, string articleText)
{
string[] sectionsBefore = Tools.SplitToSections(originalText);
if (sectionsBefore.Length == 0)
return "";
string[] sectionsAfter = Tools.SplitToSections(articleText);
// if number of sections has changed, can't provide section edit summary
if (sectionsAfter.Length != sectionsBefore.Length)
return "";
int sectionsChanged = 0, sectionChangeNumber = 0;
for (int i = 0; i < sectionsAfter.Length; i++)
{
if (!sectionsBefore[i].Equals(sectionsAfter[i]))
{
sectionsChanged++;
sectionChangeNumber = i;
}
// if multiple sections changed, can't provide section edit summary
if (sectionsChanged > 1)
return "";
}
// so SectionsChanged == 1, get heading name from regex
return WikiRegexes.Headings.Match(sectionsAfter[sectionChangeNumber]).Groups[1].Value.Trim();
}