Beispiel #1
0
        public static bool IsNullOrWhiteSpace(MutableString obj)
        {
            if (null == obj)
            {
                return(true);
            }

#if NET20
            if (0 == obj.Length)
            {
                return(true);
            }

            for (var i = 0; i < obj.Length; i++)
            {
                if (CharExtensionMethods.IsWhiteSpace(obj[i]))
                {
                    continue;
                }

                return(false);
            }

            return(true);
#else
            return(0 == obj.Length || obj.All(x => obj[0].IsWhiteSpace()));
#endif
        }
Beispiel #2
0
        public MutableString NormalizeToEnglishAlphabet()
        {
            if (0 == _value.Length)
            {
                return(this);
            }

            for (var i = _value.Length - 1; i > -1; i--)
            {
                var c = _value[i];
                if (' ' == c)
                {
                    continue;
                }

                if (char.IsDigit(c))
                {
                    continue;
                }

                if (Characters.EnglishUppercase.Contains(c))
                {
                    continue;
                }

                if (Characters.EnglishLowercase.Contains(c))
                {
                    continue;
                }

#if NET20
                var english = CharExtensionMethods.ToEnglishAlphabet(c);
#else
                var english = c.ToEnglishAlphabet();
#endif
                if (!english.HasValue)
                {
                    continue;
                }

                _value[i] = english.Value;
            }

            return(this);
        }
Beispiel #3
0
        public IEnumerable <string> Words()
        {
            var buffer = new StringBuilder();

            for (var i = 0; i < _value.Length; i++)
            {
                if (char.IsLetterOrDigit(_value[i]))
                {
                    buffer.Append(_value[i]);
                    continue;
                }

#if NET20
                if (!CharExtensionMethods.IsWhiteSpace(_value[i]))
#else
                if (!_value[i].IsWhiteSpace())
#endif
                {
                    continue;
                }

                if (0 == buffer.Length)
                {
                    continue;
                }

                yield return(buffer.ToString());

#if NET20 || NET35
                buffer.Remove(0, buffer.Length);
#else
                buffer.Clear();
#endif
            }

            if (0 == buffer.Length)
            {
                yield break;
            }

            yield return(buffer.ToString());
        }
Beispiel #4
0
        public MutableString NormalizeWhiteSpace()
        {
            for (var i = 0; i < _value.Length; i++)
            {
                var c = _value[i];
                if (' ' == c)
                {
                    continue;
                }

#if NET20
                if (CharExtensionMethods.IsWhiteSpace(c))
#else
                if (c.IsWhiteSpace())
#endif
                {
                    _value[i] = ' ';
                }
            }

            return(this);
        }
Beispiel #5
0
        public MutableString RemoveWhiteSpace()
        {
#if NET20
            if (0 == _value.Length)
            {
                return(this);
            }

            for (var i = _value.Length - 1; i > -1; i--)
            {
                if (!CharExtensionMethods.IsWhiteSpace(_value[i]))
                {
                    continue;
                }

                Remove(i, 1);
            }

            return(this);
#else
            return(RemoveCharacters(CharExtensionMethods.IsWhiteSpace));
#endif
        }