Пример #1
0
        public bool Equals(CharSequence cs)
        {
            if (cs == null)
            {
                return(false);
            }
            if (cs.Length() == 0 && this._currentIndex == 0)
            {
                return(true);
            }
            CharSequence another = cs;
            int          len     = _currentIndex;

            if (len == another.Length())
            {
                char[] selfChars = _values;
                int    i         = 0;
                while (len-- != 0)
                {
                    if (selfChars[i] != another.CharAt(i))
                    {
                        return(false);
                    }
                    i++;
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
 //-----------------------------------------------------------------------
 /// <summary>
 /// Helper to compare two {@code CharSequence} instances.
 /// This uses <seealso cref="#isCaseSensitive()"/>.
 /// </summary>
 /// <param name="cs1">  the first character sequence, not null </param>
 /// <param name="offset1">  the offset into the first sequence, valid </param>
 /// <param name="cs2">  the second character sequence, not null </param>
 /// <param name="offset2">  the offset into the second sequence, valid </param>
 /// <param name="length">  the length to check, valid </param>
 /// <returns> true if equal </returns>
 internal bool SubSequenceEquals(CharSequence cs1, int offset1, CharSequence cs2, int offset2, int length)
 {
     if (offset1 + length > cs1.Length() || offset2 + length > cs2.Length())
     {
         return(false);
     }
     if (CaseSensitive)
     {
         for (int i = 0; i < length; i++)
         {
             char ch1 = cs1.CharAt(offset1 + i);
             char ch2 = cs2.CharAt(offset2 + i);
             if (ch1 != ch2)
             {
                 return(false);
             }
         }
     }
     else
     {
         for (int i = 0; i < length; i++)
         {
             char ch1 = cs1.CharAt(offset1 + i);
             char ch2 = cs2.CharAt(offset2 + i);
             if (ch1 != ch2 && char.ToUpper(ch1) != char.ToUpper(ch2) && char.ToLower(ch1) != char.ToLower(ch2))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #3
0
 public static byte[] ToSimpleByteArray(CharSequence charSequence)
 {
     byte[] barr = new byte[charSequence.Length()];
     for (int i = 0; i < barr.Length; i++)
     {
         barr[i] = (byte)charSequence.CharAt(i);
     }
     return(barr);
 }
Пример #4
0
        internal StringCharBuffer(CharSequence s, int start, int end) : base(-1, start, end, s.Length())         // package-private
        {
            int n = s.Length();

            if ((start < 0) || (start > n) || (end < start) || (end > n))
            {
                throw new IndexOutOfBoundsException();
            }
            Str = s;
        }
Пример #5
0
 public static byte[] ToAsciiByteArray(CharSequence charSequence)
 {
     byte[] barr = new byte[charSequence.Length()];
     for (int i = 0; i < barr.Length; i++)
     {
         char c = charSequence.CharAt(i);
         barr[i] = (byte)((int)(c <= 0xFF ? c : 0x3F));
     }
     return(barr);
 }
Пример #6
0
 public static int CodePointAt(CharSequence seq, int index)
 {
     if (index >= seq.Length() - 1 || !IsHighSurrogate(seq.CharAt(index)) ||
         !IsLowSurrogate(seq.CharAt(index + 1)))
     {
         return(seq.CharAt(index));
     }
     else
     {
         return(ToCodePoint(seq.CharAt(index), seq.CharAt(index + 1)));
     }
 }
Пример #7
0
        public StrBuilder Insert(int index, CharSequence cs)
        {
            if (cs == null)
            {
                cs = LSystem.NULL.ToJavaString();
            }
            int len = cs.Length();

            UpdateIndex(index, cs.Length());
            if (cs is JavaString strs)
            {
                strs.GetChars(0, len, this._values, index);
            }
            else if (cs is StringBuilder sbr)
            {
                sbr.GetChars(0, len, this._values, index);
            }
            else if (cs is StringBuffer sb)
            {
                sb.GetChars(0, len, this._values, index);
            }
            else if (cs is StrBuilder sbrSelf)
            {
                sbrSelf.GetChars(0, len, this._values, index);
            }
            else
            {
                for (int i = 0, j = this._currentIndex; i < len; i++, j++)
                {
                    this._values[j] = cs.CharAt(i);
                }
            }
            this._currentIndex = MathUtils.Max(this._currentIndex, index) + len;
            this._dirty        = true;
            return(this);
        }
Пример #8
0
 public static bool IsHex(CharSequence ch)
 {
     if (ch == null)
     {
         return(false);
     }
     for (int i = 0; i < ch.Length(); i++)
     {
         int c = ch.CharAt(i);
         if (!IsHexDigit(c))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #9
0
        public StrBuilder Insert(int index, CharSequence cs, int start, int end)
        {
            if (cs == null)
            {
                cs = LSystem.NULL.ToJavaString();
            }
            int charLength = cs.Length();

            if (start > charLength)
            {
                return(this);
            }
            if (start < 0)
            {
                start = 0;
            }
            if (end > charLength)
            {
                end = charLength;
            }
            if (start >= end)
            {
                return(this);
            }
            if (index < 0)
            {
                index = 0;
            }
            int length = end - start;

            UpdateIndex(index, length);
            for (int i = start, j = this._currentIndex; i < end; i++, j++)
            {
                _values[j] = cs.CharAt(i);
            }
            this._currentIndex = MathUtils.Max(this._currentIndex, index) + length;
            this._dirty        = true;
            return(this);
        }
Пример #10
0
        public StringKeyValue PopTag(CharSequence tag)
        {
            string tmp = flags.Pop();

            return(AddValue("</" + ((tag == null || tag.Length() == 0 || " ".Equals(tag.ToString())) ? tmp : tag.ToString()) + ">"));
        }