예제 #1
0
        internal static bool IsDoubled(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var letters = stringToAdjust.GetGraphemeClusters().ToList();

            var justLetters = new List <string>();

            foreach (var letter in letters)
            {
                if (char.IsLetter(letter[0]))
                {
                    justLetters.Add(letter);
                }
            }

            for (var i = 1; i < justLetters.Count; i += 2)
            {
                if (justLetters[i] != justLetters[i - 1])
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        public static bool HasAddedDiacritics(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var textElements = stringToAdjust.GetGraphemeClusters().ToList();

            if (textElements.Count > 0)
            {
                for (var i = 0; i < textElements.Count; i++)
                {
                    // Find the first text element with added diacritics
                    if (textElements[i].Length > 2)
                    {
                        return(HasSubstringGotAddedDiacritics(textElements[i]));
                    }
                }
            }

            return(false);
        }
예제 #3
0
        internal static string RemoveDoubling(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var padded = PaddingCommand.IsPadded(stringToAdjust);

            if (padded)
            {
                stringToAdjust = PaddingCommand.PaddingLogic(stringToAdjust, ToggleMode.Reverse);
            }

            var letters = stringToAdjust.GetGraphemeClusters().ToList();

            var result = new StringBuilder();

            var i = 0;

            while (i < letters.Count)
            {
                result.Append(letters[i]);

                if (char.IsLetter(letters[i][0]))
                {
                    i += 2;
                }
                else
                {
                    ++i;
                }
            }

            var resultString = result.ToString();

            if (padded)
            {
                resultString = PaddingCommand.PaddingLogic(resultString, ToggleMode.Apply);
            }

            if (surrounded)
            {
                resultString = SurroundCommand.SurroundLogic(resultString, ToggleMode.Apply);
            }

            return(resultString);
        }
예제 #4
0
        public static string RemovePadding(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var result = new StringBuilder();

            if (stringToAdjust.Length < 3)
            {
                result.Append(input);
            }
            else
            {
                var words = stringToAdjust.Split(' ');

                foreach (var word in words)
                {
                    if (word.Length < 2)
                    {
                        result.Append(word);
                    }
                    else
                    {
                        var tempWord = word.Replace("---", " ");

                        tempWord = tempWord.Replace(SeparatorStr, string.Empty);

                        result.Append(tempWord.Replace(" ", SeparatorStr));
                    }

                    result.Append(' ');
                }

                result.Remove(result.Length - 1, 1);
            }

            if (surrounded)
            {
                return(SurroundCommand.SurroundLogic(result.ToString(), ToggleMode.Apply));
            }
            else
            {
                return(result.ToString());
            }
        }
예제 #5
0
        internal static string Double(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var padded = PaddingCommand.IsPadded(stringToAdjust);

            if (padded)
            {
                stringToAdjust = PaddingCommand.RemovePadding(stringToAdjust);
            }

            var letters = stringToAdjust.GetGraphemeClusters().ToList();

            var result = new StringBuilder();

            foreach (var letter in letters)
            {
                if (char.IsLetter(letter[0]))
                {
                    result.Append(letter);
                }

                result.Append(letter);
            }

            var finalResult = result.ToString();

            if (padded)
            {
                finalResult = PaddingCommand.AddPadding(finalResult);
            }

            if (surrounded)
            {
                finalResult = SurroundCommand.SurroundLogic(finalResult, ToggleMode.Apply);
            }

            return(finalResult);
        }
예제 #6
0
        public static string RemoveDiacritics(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var letters = stringToAdjust.GetGraphemeClusters().ToList();

            var result = new StringBuilder();

            foreach (var letter in letters)
            {
                // It should never be null, but want to check for whitespace
                if (string.IsNullOrWhiteSpace(letter) || letter == PaddingCommand.SeparatorStr)
                {
                    result.Append(letter);
                }
                else
                {
                    if (HasSubstringGotAddedDiacritics(letter))
                    {
                        result.Append(letter.Substring(0, letter.Length - 2));
                    }
                    else
                    {
                        result.Append(letter);
                    }
                }
            }

            if (surrounded)
            {
                return(SurroundCommand.SurroundLogic(result.ToString(), ToggleMode.Apply));
            }
            else
            {
                return(result.ToString());
            }
        }
예제 #7
0
        public static bool IsPadded(string input)
        {
            if (string.IsNullOrEmpty(input) || input.Length < 3)
            {
                return(false);
            }
            else
            {
                if (SurroundCommand.IsSurrounded(input))
                {
                    input = SurroundCommand.RemoveSurrounds(input);
                }

                var countOfLetters    = input.Count(char.IsLetter);
                var countOfSeparators = input.Count(i => i == Separator);

                return(countOfSeparators >= (countOfLetters / 2));
            }
        }
예제 #8
0
        public static string ReverseLogic(string input)
        {
            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToReverse = input;

            if (surrounded)
            {
                stringToReverse = SurroundCommand.RemoveSurrounds(input);
            }

            var result = stringToReverse.ReverseGraphemeClusters();

            if (surrounded)
            {
                result = SurroundCommand.SurroundLogic(result, ToggleMode.Apply);
            }

            return(result);
        }
예제 #9
0
        public static string AddPadding(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            var surrounded = SurroundCommand.IsSurrounded(input);

            var stringToAdjust = input;

            if (surrounded)
            {
                stringToAdjust = SurroundCommand.RemoveSurrounds(input);
            }

            var result = new StringBuilder();

            if (stringToAdjust.Length < 2)
            {
                result.Append(stringToAdjust);
            }
            else if (stringToAdjust.Length == 2)
            {
                if (char.IsLetter(stringToAdjust[0]) && char.IsLetter(stringToAdjust[1]))
                {
                    result.Append(stringToAdjust[0]);
                    result.Append(Separator);
                    result.Append(stringToAdjust[1]);
                }
                else
                {
                    result.Append(stringToAdjust);
                }
            }
            else
            {
                var words = stringToAdjust.Split(' ');

                foreach (var word in words)
                {
                    if (word.Length < 2)
                    {
                        result.Append(word);
                    }
                    else
                    {
                        var paddedWord = new StringBuilder();

                        foreach (var character in word.GetGraphemeClusters())
                        {
                            paddedWord.Append($"{character}{Separator}");
                        }

                        result.Append(paddedWord.ToString().TrimEnd(Separator));
                    }

                    result.Append(' ');
                }

                result.Remove(result.Length - 1, 1);
            }

            if (surrounded)
            {
                return(SurroundCommand.SurroundLogic(result.ToString(), ToggleMode.Apply));
            }
            else
            {
                return(result.ToString());
            }
        }