< Summary - SonghayCore

Information
Class: Songhay.Globalization.TextInfoUtility
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Globalization/TextInfoUtility.cs
Line coverage
100%
Covered lines: 68
Uncovered lines: 0
Coverable lines: 68
Total lines: 95
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToTitleCase(...)100%2100%
get_EnglishWordsNotCapitalized()100%1100%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Globalization/TextInfoUtility.cs

#LineLine coverage
 1namespace Songhay.Globalization;
 2
 3/// <summary>
 4/// Helper members for <see cref="System.Globalization.TextInfo" />.
 5/// </summary>
 6public static class TextInfoUtility
 7{
 8    /// <summary>
 9    /// Wraps <see cref="System.Globalization.TextInfo.ToTitleCase"/>
 10    /// to add support for articles, conjunctions and prepositions.
 11    /// </summary>
 12    /// <param name="input">The input.</param>
 13    [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
 14        Justification = "This member is not making a security decision based on the result.")]
 15    public static string ToTitleCase(string input)
 316    {
 317        var culture = Thread.CurrentThread.CurrentCulture;
 318        var textInfo = culture.TextInfo;
 319        input = textInfo.ToTitleCase(input);
 20
 321        var firstWord = input.Split(' ').First();
 322        var wordsAfterFirstWord = string.Join(" ",
 323            input.Split(' ').Skip(1).ToArray());
 24
 325        EnglishWordsNotCapitalized
 45026            .Where(word => word.Contains(' '))
 327            .ForEachInEnumerable(word =>
 10828            {
 10829                wordsAfterFirstWord = wordsAfterFirstWord
 10830                    .Replace(textInfo.ToTitleCase(word), word);
 11131            });
 32
 333        input = $"{firstWord} {wordsAfterFirstWord}";
 34
 335        var words = input.Split(' ')
 336            .Skip(1)
 1637            .Select(word => EnglishWordsNotCapitalized
 1638                .Contains(word.ToLowerInvariant())
 1639                ? word.ToLowerInvariant()
 1640                : word);
 341        input = $"{firstWord} {string.Join(" ", words.ToArray())}";
 42
 343        return input;
 344    }
 45
 46    /// <summary>
 47    /// “A virtually complete list of English words that are are NOT capitalized in titles.”
 48    /// [http://www.cumbrowski.com/CarstenC/articles/20070623_Title_Capitalization_in_the_English_Language.asp]
 49    /// </summary>
 50    public static ReadOnlyCollection<string> EnglishWordsNotCapitalized =>
 1651        new ReadOnlyCollection<string>(new List<string>
 1652        {
 1653            //Articles:
 1654            "a", "an", "the",
 1655
 1656            //Conjunctions
 1657            "and", "but", "or", "so", "after",
 1658            "before", "when", "while", "since",
 1659            "until", "although", "even if",
 1660            "because", "both", "not only", "but also",
 1661
 1662            //Prepositions
 1663            "aboard", "about", "above", "absent", "across",
 1664            "after", "against", "along", "alongside", "amid",
 1665            "amidst", "among", "amongst", "around", "as", "aslant",
 1666            "astride", "at", "atop", "barring", "before", "behind",
 1667            "below", "beneath", "beside", "besides", "between",
 1668            "beyond", "but", "by", "despite", "down", "during", "except",
 1669            "failing", "following", "for", "from", "in", "inside", "into",
 1670            "like", "merry", "mid", "minus", "near", "next", "notwithstanding",
 1671            "of", "off", "on", "onto", "opposite", "outside", "over", "past", "plus",
 1672            "regarding", "round", "save", "since", "than", "through", "throughout",
 1673            "till", "times", "to", "toward", "towards", "under", "underneath", "unlike",
 1674            "until", "up", "upon", "via", "with", "within", "without",
 1675
 1676            //Prepositions; Two words:
 1677            "according to", "ahead of", "as to", "aside from",
 1678            "because of", "close to", "due to", "far from", "in to",
 1679            "inside of", "instead of", "near to", "next to", "on to", "out of",
 1680            "outside of", "owing to", "prior to", "subsequent to",
 1681
 1682            //Prepositions; Three words:
 1683            "as far as", "as well as", "by means of", "in accordance with",
 1684            "in addition to", "in front of", "in place of", "in spite of",
 1685            "on account of", "on behalf of", "on top of", "with regard to", "in case of",
 1686
 1687            //Prepositions; Archaic or infrequently used:
 1688            "anti", "betwixt", "circa", "cum", "in lieu of",
 1689            "per", "qua", "sans", "unto", "versus", "vis-a-vis",
 1690
 1691            //Prepositions; Postpositions:
 1692            "ago", "apart", "aside", "away", "hence",
 1693            "notwithstanding", "on", "through", "withal"
 1694        });
 95}