//-----------------------------------------------------------------------
 /// <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);
 }
Example #2
0
 public static int CodePointBefore(CharSequence seq, int index)
 {
     if (index == 1 || !IsLowSurrogate(seq.CharAt(index - 1)) || !IsHighSurrogate(seq.CharAt(index - 2)))
     {
         return(seq.CharAt(index - 1));
     }
     return(ToCodePoint(seq.CharAt(index - 2), seq.CharAt(index - 1)));
 }
Example #3
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)));
     }
 }
Example #4
0
        /// <summary>
        /// Parse a two digit zero-prefixed number.
        /// </summary>
        /// <param name="offsetId">  the offset ID, not null </param>
        /// <param name="pos">  the position to parse, valid </param>
        /// <param name="precededByColon">  should this number be prefixed by a precededByColon </param>
        /// <returns> the parsed number, from 0 to 99 </returns>
        private static int ParseNumber(CharSequence offsetId, int pos, bool precededByColon)
        {
            if (precededByColon && offsetId.CharAt(pos - 1) != ':')
            {
                throw new DateTimeException("Invalid ID for ZoneOffset, colon not found when expected: " + offsetId);
            }
            char ch1 = offsetId.CharAt(pos);
            char ch2 = offsetId.CharAt(pos + 1);

            if (ch1 < '0' || ch1 > '9' || ch2 < '0' || ch2 > '9')
            {
                throw new DateTimeException("Invalid ID for ZoneOffset, non numeric characters found: " + offsetId);
            }
            return((ch1 - 48) * 10 + (ch2 - 48));
        }
Example #5
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);
        }
Example #6
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);
 }
Example #7
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);
 }
Example #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);
 }
Example #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);
        }
Example #10
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);
        }
Example #11
0
 public sealed override char Get()
 {
     return(Str.CharAt(NextGetIndex() + Offset));
 }