Beispiel #1
0
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     if (source is SpannableStringBuilder)
     {
         var sourceAsSpannableBuilder = (SpannableStringBuilder)source;
         for (var i = end - 1; i >= start; i--)
         {
             if (!isCharacterOk(source.CharAt(i)))
             {
                 sourceAsSpannableBuilder.Delete(i, i + 1);
             }
         }
         return(sourceAsSpannableBuilder);
     }
     else
     {
         var filteredStringBuilder = new SpannableStringBuilder();
         for (int i = start; i < end; i++)
         {
             var currentChar = source.CharAt(i);
             if (isCharacterOk(currentChar))
             {
                 filteredStringBuilder.Append(currentChar);
             }
         }
         return(filteredStringBuilder);
     }
 }
            public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
            {
                for (int i = start; i < end; ++i)
                {
                    if (!Character.IsDigit(source.CharAt(i)) && !backgroundHintTextView.IsCharInFilter(source.CharAt(i)))
                    {
                        return new Java.Lang.String("");
                    }
                }

                return null;
            }
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = start; i < end; i++)
            {
                if ((Character.IsDigit(source.CharAt(i)) || source.CharAt(i) == '-'))
                {
                    sb.Append(source.CharAt(i));
                }
            }
            return((sb.Length() == (end - start)) ? null : new Java.Lang.String(sb.ToString()));
        }
        public int FindTokenStart(ICharSequence text, int cursor)
        {
            int i = cursor;

            while (i > 0 && !SplitChar.Contains(text.CharAt(i - 1)))
            {
                i--;
            }
            while (i < cursor && text.CharAt(i) == ' ')
            {
                i++;
            }

            return i;
        }
Beispiel #5
0
        private bool Equals(ICharSequence text1, char[] text2)
        {
            int len = text1.Length;

            if (len != text2.Length)
            {
                return(false);
            }
            if (ignoreCase)
            {
                for (int i = 0; i < len;)
                {
                    int codePointAt = charUtils.CodePointAt(text1, i);
                    if (char.ToLower((char)codePointAt) != charUtils.CodePointAt(text2, i, text2.Length))
                    {
                        return(false);
                    }
                    i += Character.CharCount(codePointAt);
                }
            }
            else
            {
                for (int i = 0; i < len; i++)
                {
                    if (text1.CharAt(i) != text2[i])
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Find the start of the Token
        /// </summary>
        public int FindTokenStart(ICharSequence text, int cursor)
        {
            int i = cursor;

            // Moved i, untill it hits a space, first going back, the going forward
            while (i > 0 && text.CharAt(i - 1) != ' ')
            {
                i--;
            }
            while (i < cursor && text.CharAt(i) == ' ')
            {
                i++;
            }

            return i;
        }
Beispiel #7
0
            public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
            {
                var empty        = string.Empty.AsJavaString();
                var sourceLength = source.Length();

                if (sourceLength > 1)
                {
                    return(source.ToString().AsJavaString());
                }

                if (sourceLength == 0)
                {
                    onDeletionDetected();
                    return("0".AsCharSequence());
                }

                var lastChar = source.CharAt(sourceLength - 1);

                if (char.IsDigit(lastChar))
                {
                    int digit = int.Parse(lastChar.ToString());
                    onDigitEntered(digit);

                    return(empty);
                }

                return(empty);
            }
Beispiel #8
0
 public void Concat(ICharSequence other)
 {
     for (int i = 0; i < other.Length; i++)
     {
         _list.Add(other.CharAt(i));
     }
 }
Beispiel #9
0
        public static int CodePointAt(ICharSequence seq, int index)
        {
            char c1 = seq.CharAt(index++);

            if (char.IsHighSurrogate(c1))
            {
                if (index < seq.Length)
                {
                    char c2 = seq.CharAt(index);
                    if (char.IsLowSurrogate(c2))
                    {
                        return(ToCodePoint(c1, c2));
                    }
                }
            }
            return(c1);
        }
Beispiel #10
0
        public CharBlockArray Append(ICharSequence chars, int start, int length)
        {
            int end = start + length;

            for (int i = start; i < end; i++)
            {
                Append(chars.CharAt(i));
            }
            return(this);
        }
Beispiel #11
0
            public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
            {
                for (int i = start; i < end; ++i)
                {
                    if (!Character.IsDigit(source.CharAt(i)) && !backgroundHintTextView.IsCharInFilter(source.CharAt(i)))
                    {
                        return(new Java.Lang.String(""));
                    }
                }

                return(null);
            }
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     for (int i = start; i < end; i++)
     {
         int type = Character.GetType(source.CharAt(i));
         if (type == Character.Surrogate || type == Character.OtherSymbol)
         {
             return(emptyString);
         }
     }
     return(null);
 }
Beispiel #13
0
        private int[] BuildNext(ICharSequence pattern)
        {
            int j = 0;
            int m = pattern.Length;

            int[] res = new int[m];
            int   t   = res[0] = -1;

            while (j < m - 1)
            {
                if (0 > t || pattern.CharAt(j) == pattern.CharAt(t))
                {
                    j++;
                    t++;
                    res[j] = t;
                }
                else
                {
                    t = res[t];
                }
            }
            return(res);
        }
Beispiel #14
0
 public bool Equals(ICharSequence other)
 {
     if (other.Length != Length)
     {
         return(false);
     }
     for (int i = 0; i < Length; i++)
     {
         if (other.CharAt(i) != CharAt(i))
         {
             return(false);
         }
     }
     return(true);
 }
        public int FindTokenEnd(ICharSequence text, int cursor)
        {
            int i = cursor;
            int len = text.Length();

            while (i < len)
            {
                if (SplitChar.Contains(text.CharAt(i)))
                {
                    return i;
                }
                else
                {
                    i++;
                }
            }

            return len;
        }
Beispiel #16
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
        {
            if (source != null && source.Length() > 0)
            {
                var includesInvalidCharacter = false;

                var destLength  = dend - dstart + 1;
                var adjustStart = source.Length() - destLength;

                var sb = new StringBuilder(end - start);
                for (var i = start; i < end; i++)
                {
                    var c = source.CharAt(i);
                    if (IsCharAllowed(c))
                    {
                        if (i >= adjustStart)
                        {
                            sb.Append(source, i, i + 1);
                        }
                    }
                    else
                    {
                        includesInvalidCharacter = true;
                    }
                }

                if (!includesInvalidCharacter)
                {
                    return(null);
                }

                if (source is ISpanned spanned)
                {
                    var sp = new SpannableString(sb);
                    TextUtils.CopySpansFrom(spanned, start, sb.Length(), null, sp, 0);
                    return(sp);
                }

                return(sb);
            }
            return(null);
        }
Beispiel #17
0
        /// <summary>
        /// Find the end of the Token
        /// </summary>
        public int FindTokenEnd(ICharSequence text, int cursor)
        {
            int i = cursor;
            int len = text.Length();

            while (i < len)
            {
                // If a space is hit, then the token has ended
                if (text.CharAt(i) == ' ')
                {
                    return i;
                }
                else
                {
                    i++;
                }
            }

            return len;
        }
Beispiel #18
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end,
                                             ISpanned dest, int dstart, int dend)
        {
            if (_editor.Modified &&
                end - start == 1 &&
                start < source.Length() &&
                dstart < dest.Length())
            {
                char c = source.CharAt(start);

                if (c == '\n')
                {
                    return(_editor.AutoIndent(
                               source,
                               dest,
                               dstart,
                               dend));
                }
            }
            return(source);
        }
Beispiel #19
0
        private int Match(ICharSequence pattern)
        {
            int[] next = BuildNext(pattern);
            int   i    = 0;
            int   j    = 0;
            int   m    = pattern.Length;
            int   n    = Length;

            while (j < m && i < n)
            {
                if (0 > j || CharAt(i) == pattern.CharAt(j))
                {
                    i++;
                    j++;
                }
                else
                {
                    j = next[j];
                }
            }
            return(i - j);
        }
Beispiel #20
0
        private static ISpanned RemoveTrailingNewLines(ICharSequence text)
        {
            var builder = new SpannableStringBuilder(text);

            var count = 0;

            for (int i = 1; i <= text.Length(); i++)
            {
                if (!'\n'.Equals(text.CharAt(text.Length() - i)))
                {
                    break;
                }

                count++;
            }

            if (count > 0)
            {
                _ = builder.Delete(text.Length() - count, text.Length());
            }

            return(builder);
        }
        public ICharSequence TerminateTokenFormatted(ICharSequence text)
        {
            int i = text.Length();

            while (i > 0 && text.CharAt(i - 1) == ' ') {
            i--;
            }

            if (i > 0 && SplitChar.Contains(text.CharAt(i - 1))) {
            return text;
            } else {
            // Try not to use a space as a token character
            var token = (SplitChar.Count > 1 && SplitChar[0] == ' ' ? SplitChar[1] : SplitChar[0]) + " ";

            if (text is ISpanned) {
                SpannableString sp = new SpannableString(text + token);

                TextUtils.CopySpansFrom((ISpanned)text, 0, text.Length(), null, sp, 0);
                return sp;
            } else {
                return (text + token).ToAndroidString();
            }
            }
        }
        public override ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart,
                                                      int dend)
        {
            // Borrowed heavily from the Android source
            ICharSequence filterFormatted = base.FilterFormatted(source, start, end, dest, dstart, dend);

            if (filterFormatted != null)
            {
                source = filterFormatted;
                start  = 0;
                end    = filterFormatted.Length();
            }

            int sign = -1;
            int dec  = -1;
            int dlen = dest.Length();

            // Find out if the existing text has a sign or decimal point characters.
            for (var i = 0; i < dstart; i++)
            {
                char c = dest.CharAt(i);
                if (IsSignChar(c))
                {
                    sign = i;
                }
                else if (IsDecimalPointChar(c))
                {
                    dec = i;
                }
            }

            for (int i = dend; i < dlen; i++)
            {
                char c = dest.CharAt(i);
                if (IsSignChar(c))
                {
                    return(new String(""));                    // Nothing can be inserted in front of a sign character.
                }

                if (IsDecimalPointChar(c))
                {
                    dec = i;
                }
            }

            // If it does, we must strip them out from the source.
            // In addition, a sign character must be the very first character,
            // and nothing can be inserted before an existing sign character.
            // Go in reverse order so the offsets are stable.
            SpannableStringBuilder stripped = null;

            for (int i = end - 1; i >= start; i--)
            {
                char c     = source.CharAt(i);
                var  strip = false;

                if (IsSignChar(c))
                {
                    if (i != start || dstart != 0)
                    {
                        strip = true;
                    }
                    else if (sign >= 0)
                    {
                        strip = true;
                    }
                    else
                    {
                        sign = i;
                    }
                }
                else if (IsDecimalPointChar(c))
                {
                    if (dec >= 0)
                    {
                        strip = true;
                    }
                    else
                    {
                        dec = i;
                    }
                }

                if (strip)
                {
                    if (end == start + 1)
                    {
                        return(new String(""));                        // Only one character, and it was stripped.
                    }
                    if (stripped == null)
                    {
                        stripped = new SpannableStringBuilder(source, start, end);
                    }
                    stripped.Delete(i - start, i + 1 - start);
                }
            }

            return(stripped ?? filterFormatted);
        }
Beispiel #23
0
 public override int CodePointAt(ICharSequence seq, int offset)
 {
     return(seq.CharAt(offset));
 }
Beispiel #24
0
 public void TestLength()
 {
     Assert.AreEqual(7, _sequece.Length);
     Assert.AreEqual('g', _sequece.CharAt(0));
 }
Beispiel #25
0
 public static int CodePointAt(ICharSequence seq, int index)
 {
     char c1 = seq.CharAt(index++);
     if (char.IsHighSurrogate(c1))
     {
         if (index < seq.Length)
         {
             char c2 = seq.CharAt(index);
             if (char.IsLowSurrogate(c2))
             {
                 return ToCodePoint(c1, c2);
             }
         }
     }
     return c1;
 }
Beispiel #26
0
 /**
  * 计算分享内容的字数,一个汉字=两个英文字母,一个中文标点=两个英文标点 注意:该函数的不适用于对单个字符进行计算,因为单个字符四舍五入后都是1
  *
  * @param c
  * @return
  */
 private long calculateLength(ICharSequence c)
 {
     double len = 0;
     for (var i = 0; i < c.Length(); i++)
     {
         var tmp = (int)c.CharAt(i);
         if (tmp >= 0x4e00 && tmp <= 0x9fbb)//中文
         {
             len += 2;
         }
         else
         {
             len += 1;
         }
         //if (tmp > 0 && tmp < 127)
         //{
         //    len += 0.5;
         //}
         //else
         //{
         //    len++;
         //}
     }
     return (long)System.Math.Round(len);
 }
Beispiel #27
0
        public static ICharSequence replaceEmoji(ICharSequence cs, Paint.FontMetricsInt fontMetrics, int size)
        {
            if (cs == null || cs.Length() == 0)
            {
                return(cs);
            }
            ISpannable s;

            if (cs is ISpannable)
            {
                s = (ISpannable)cs;
            }
            else
            {
                s = SpannableFactory.Instance.NewSpannable(cs);
            }
            ulong buf        = 0;
            int   emojiCount = 0;

            try
            {
                for (int i = 0; i < cs.Length(); i++)
                {
                    char c = cs.CharAt(i);
                    if (c == 0xD83C || c == 0xD83D || (buf != 0 && (buf & 0xFFFFFFFF00000000L) == 0 && (c >= 0xDDE6 && c <= 0xDDFA)))
                    {
                        buf <<= 16;
                        buf  |= c;
                    }
                    else if (buf > 0 && (c & 0xF000) == 0xD000)
                    {
                        buf <<= 16;
                        buf  |= c;
                        EmojiDrawable d = Emoji.getEmojiDrawable(buf);
                        if (d != null)
                        {
                            var span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                            emojiCount++;
                            if (c >= 0xDDE6 && c <= 0xDDFA)
                            {
                                s.SetSpan(span, i - 3, i + 1, 0);
                            }
                            else
                            {
                                s.SetSpan(span, i - 1, i + 1, 0);
                            }
                        }
                        buf = 0;
                    }
                    else if (c == 0x20E3)
                    {
                        if (i > 0)
                        {
                            char c2 = cs.CharAt(i - 1);
                            if ((c2 >= '0' && c2 <= '9') || c2 == '#')
                            {
                                buf   = c2;
                                buf <<= 16;
                                buf  |= c;
                                EmojiDrawable d = Emoji.getEmojiDrawable(buf);
                                if (d != null)
                                {
                                    EmojiSpan span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                                    emojiCount++;
                                    s.SetSpan(span, i - 1, i + 1, 0);
                                }
                                buf = 0;
                            }
                        }
                    }
                    else if (inArray(c, emojiChars) == Java.Lang.Boolean.True)
                    {
                        EmojiDrawable d = Emoji.getEmojiDrawable(c);
                        if (d != null)
                        {
                            EmojiSpan span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                            emojiCount++;
                            s.SetSpan(span, i, i + 1, 0);
                        }
                    }
                    if (emojiCount >= 50)
                    {
                        break;
                    }
                }
            }
            catch (Java.Lang.Exception e)
            {
                //FileLog.e("tmessages", e);
                return(cs);
            }
            return(s);
        }
Beispiel #28
0
        /// <summary>
        /// A method for getting tokens containing mutible words
        /// </summary>
        private ICharSequence InnerToken(ICharSequence text)
        {
            int i = text.Length();

            // Find the first space in the Token, going backwards
            while (i > 0 && text.CharAt(i - 1) == ' ')
            {
                i--;
            }

            if (i > 0 && text.CharAt(i - 1) == ' ')
            {
                return text;
            }
            else
            {
                if (text.GetType().IsInstanceOfType(typeof(ISpanned)))
                {
                    SpannableString sp = new SpannableString(text + " ");
                    TextUtils.CopySpansFrom((ISpanned)text, 0, text.Length(), Java.Lang.Class.FromType(typeof(Java.Lang.Object)), sp, 0);
                    return sp;
                }
                else
                {
                    return new Java.Lang.String(text + " ");
                }
            }
        }
 public override int CodePointAt(ICharSequence seq, int offset)
 {
     return seq.CharAt(offset);
 }
Beispiel #30
0
 public CharBlockArray Append(ICharSequence chars, int start, int length)
 {
     int end = start + length;
     for (int i = start; i < end; i++)
     {
         Append(chars.CharAt(i));
     }
     return this;
 }