Ejemplo n.º 1
0
        public static ICharSequence[] Split(ICharSequence sequence, int startIndex, params char[] delimiters)
        {
            if (sequence is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.sequence);
            }
            if (delimiters is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.delimiters);
            }
            int  length  = sequence.Count;
            uint uLength = (uint)length;

            if (0u >= uLength)
            {
                return(new[] { sequence });
            }
            if ((uint)startIndex >= uLength)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            var delimitersSpan          = delimiters.AsSpan();
            List <ICharSequence> result = InternalThreadLocalMap.Get().CharSequenceList();

            int i = startIndex;

            while ((uint)i < uLength)
            {
                while ((uint)i < uLength && delimitersSpan.IndexOf(sequence[i]) >= 0)
                {
                    i++;
                }

                int position = i;
                if ((uint)i < uLength)
                {
                    if (delimitersSpan.IndexOf(sequence[position]) >= 0)
                    {
                        result.Add(sequence.SubSequence(position++, i + 1));
                    }
                    else
                    {
                        ICharSequence seq = null;
                        for (position++; position < length; position++)
                        {
                            if (delimitersSpan.IndexOf(sequence[position]) >= 0)
                            {
                                seq = sequence.SubSequence(i, position);
                                break;
                            }
                        }
                        result.Add(seq ?? sequence.SubSequence(i));
                    }
                    i = position;
                }
            }

            return(0u >= (uint)result.Count ? new[] { sequence } : result.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decides if the pattern and context match the input starting at a position. It is a match if the
        /// <see cref="LContext"/> matches <paramref name="input"/> up to <paramref name="i"/>, <see cref="Pattern"/> matches at <paramref name="i"/> and
        /// <see cref="RContext"/> matches from the end of the match of <see cref="Pattern"/> to the end of <paramref name="input"/>.
        /// </summary>
        /// <param name="input">The input <see cref="ICharSequence"/>.</param>
        /// <param name="i">The int position within the input.</param>
        /// <returns><c>true</c> if the pattern and left/right context match, <c>false</c> otherwise.</returns>
        public virtual bool PatternAndContextMatches(ICharSequence input, int i)
        {
            if (i < 0)
            {
                throw new ArgumentOutOfRangeException("Can not match pattern at negative indexes");
            }

            int patternLength = this.pattern.Length;
            int ipl           = i + patternLength;

            if (ipl > input.Length)
            {
                // not enough room for the pattern to match
                return(false);
            }

            // evaluate the pattern, left context and right context
            // fail early if any of the evaluations is not successful
            if (!input.SubSequence(i, ipl).Equals(this.pattern))
            {
                return(false);
            }
            else if (!this.rContext.IsMatch(input.SubSequence(ipl, input.Length)))
            {
                return(false);
            }
            return(this.lContext.IsMatch(input.SubSequence(0, i)));
        }
Ejemplo n.º 3
0
        private void DoTestSequence(ICharSequence c)
        {
            // slice
            Assert.AreEqual("a", c.SubSequence(0, 1).ToString());
            // mid subsequence
            Assert.AreEqual("b", c.SubSequence(1, 2).ToString());
            // end subsequence
            Assert.AreEqual("bc", c.SubSequence(1, 3).ToString());
            // empty subsequence
            Assert.AreEqual("", c.SubSequence(0, 0).ToString());

            try
            {
                c.SubSequence(-1, 1);
                Assert.Fail();
            }
#pragma warning disable 168
            catch (System.IndexOutOfRangeException expected)
#pragma warning restore 168
            {
                // expected exception
            }

            try
            {
                c.SubSequence(0, -1);
                Assert.Fail();
            }
#pragma warning disable 168
            catch (System.IndexOutOfRangeException expected)
#pragma warning restore 168
            {
                // expected exception
            }

            try
            {
                c.SubSequence(0, 4);
                Assert.Fail();
            }
#pragma warning disable 168
            catch (System.IndexOutOfRangeException expected)
#pragma warning restore 168
            {
                // expected exception
            }

            try
            {
                c.SubSequence(2, 1);
                Assert.Fail();
            }
#pragma warning disable 168
            catch (System.IndexOutOfRangeException expected)
#pragma warning restore 168
            {
                // expected exception
            }
        }
Ejemplo n.º 4
0
        public static ICharSequence Trim(ICharSequence c)
        {
            if (c is AsciiString asciiString)
            {
                return(asciiString.Trim());
            }

            if (0u >= (uint)c.Count)
            {
                return(c);
            }

            int  start = 0;
            int  last  = c.Count - 1;
            int  end   = last;
            uint uEnd  = (uint)end;

            while ((uint)start <= uEnd && c[start] <= uSpace)
            {
                start++;
            }
            while (end >= start && c[end] <= uSpace)
            {
                end--;
            }
            if (0u >= (uint)start && end == last)
            {
                return(c);
            }
            return(c.SubSequence(start, end + 1));
        }
Ejemplo n.º 5
0
        public static ICharSequence GetCharsetAsSequence(ICharSequence contentTypeValue)
        {
            if (contentTypeValue is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.contentTypeValue);
            }
            int indexOfCharset = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, CharsetEquals, 0);

            if ((uint)indexOfCharset >= NIndexNotFound)
            {
                return(null);
            }
            int indexOfEncoding = indexOfCharset + CharsetEquals.Count;

            if (indexOfEncoding < contentTypeValue.Count)
            {
                var charsetCandidate = contentTypeValue.SubSequence(indexOfEncoding, contentTypeValue.Count);
                int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(charsetCandidate, Semicolon, 0);
                if ((uint)indexOfSemicolon >= NIndexNotFound)
                {
                    return(charsetCandidate);
                }

                return(charsetCandidate.SubSequence(0, indexOfSemicolon));
            }
            return(null);
        }
Ejemplo n.º 6
0
        private static ICharSequence EscapeChar(ICharSequence str, CultureInfo locale)
        {
            if (str == null || str.Length == 0)
            {
                return(str);
            }

            ICharSequence buffer = str;

            // regular escapable Char for terms
            for (int i = 0; i < escapableTermChars.Length; i++)
            {
                buffer = ReplaceIgnoreCase(buffer, locale.TextInfo.ToLower(escapableTermChars[i]),
                                           "\\", locale);
            }

            // First Character of a term as more escaping chars
            for (int i = 0; i < escapableTermExtraFirstChars.Length; i++)
            {
                if (buffer[0] == escapableTermExtraFirstChars[i][0])
                {
                    buffer = new StringCharSequenceWrapper("\\" + buffer[0]
                                                           + buffer.SubSequence(1, buffer.Length).ToString());
                    break;
                }
            }

            return(buffer);
        }
Ejemplo n.º 7
0
        void ITextWatcher.OnTextChanged(ICharSequence s, int start, int before, int count)
        {
            if (Mask != null)
            {
                if (!_editingOnChanged && _editingBefore)
                {
                    _editingOnChanged = true;
                    if (_ignore)
                    {
                        return;
                    }
                    if (count > 0)
                    {
                        var startingPosition = _maskToRaw[NextValidPosition(start)];
                        var addedString      = s.SubSequence(start, start + count).ToString();
                        count = _rawText.AddToString(Clear(addedString), startingPosition, _maxRawLength);
                        if (_initialized)
                        {
                            int currentPosition = startingPosition + count < _rawToMask.Length ?
                                                  _rawToMask[startingPosition + count] :
                                                  currentPosition = _lastValidMaskPosition + 1;

                            _selection = NextValidPosition(currentPosition);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static string GetString(ByteBuffer bytes, int length, int additionalSkipLength)
        {
            ICharSequence cs = bytes.AsCharBuffer();
            string        s  = cs.SubSequence(0, length).ToString();

            SkipBytes(bytes, length * 2 + additionalSkipLength);
            return(s);
        }
        public void Append(ICharSequence value, int index, int count)
        {
            if (value == null || count == 0)
            {
                return;
            }

            this.Append(value.SubSequence(index, index + count));
        }
Ejemplo n.º 10
0
        public void Append(ICharSequence value, int index, int count)
        {
            if (value is null || 0u >= (uint)count)
            {
                return;
            }

            this.Append(value.SubSequence(index, index + count));
        }
Ejemplo n.º 11
0
        public static ICharSequence[] Split(ICharSequence sequence, int startIndex, params char[] delimiters)
        {
            Contract.Requires(sequence != null);
            Contract.Requires(delimiters != null);
            Contract.Requires(startIndex >= 0 && startIndex < sequence.Count);

            List <ICharSequence> result = InternalThreadLocalMap.Get().CharSequenceList();

            int i      = startIndex;
            int length = sequence.Count;

            while (i < length)
            {
                while (i < length && IndexOf(delimiters, sequence[i]) >= 0)
                {
                    i++;
                }

                int position = i;
                if (i < length)
                {
                    if (IndexOf(delimiters, sequence[position]) >= 0)
                    {
                        result.Add(sequence.SubSequence(position++, i + 1));
                    }
                    else
                    {
                        ICharSequence seq = null;
                        for (position++; position < length; position++)
                        {
                            if (IndexOf(delimiters, sequence[position]) >= 0)
                            {
                                seq = sequence.SubSequence(i, position);
                                break;
                            }
                        }
                        result.Add(seq ?? sequence.SubSequence(i));
                    }
                    i = position;
                }
            }

            return(result.Count == 0 ? new[] { sequence } : result.ToArray());
        }
Ejemplo n.º 12
0
        public static int ParseInt(ICharSequence seq, int start, int end, int radix, bool negative)
        {
            Contract.Requires(seq != null);
            Contract.Requires(radix >= MinRadix && radix <= MaxRadix);

            int max        = int.MinValue / radix;
            int result     = 0;
            int currOffset = start;

            while (currOffset < end)
            {
                int digit = Digit((char)(seq[currOffset++] & 0xFF), radix);
                if (digit == -1)
                {
                    throw new FormatException(seq.SubSequence(start, end).ToString());
                }
                if (max > result)
                {
                    throw new FormatException(seq.SubSequence(start, end).ToString());
                }
                int next = result * radix - digit;
                if (next > result)
                {
                    throw new FormatException(seq.SubSequence(start, end).ToString());
                }
                result = next;
            }

            if (!negative)
            {
                result = -result;
                if (result < 0)
                {
                    throw new FormatException(seq.SubSequence(start, end).ToString());
                }
            }

            return(result);
        }
Ejemplo n.º 13
0
        /**
         * Writes chars of the given {@code CharSequence} to the current position of
         * this buffer, and increases the position by the number of chars written.
         *
         * @param csq
         *            the {@code CharSequence} to write.
         * @param start
         *            the first char to write, must not be negative and not greater
         *            than {@code csq.length()}.
         * @param end
         *            the last char to write (excluding), must be less than
         *            {@code start} and not greater than {@code csq.length()}.
         * @return this buffer.
         * @exception BufferOverflowException
         *                if {@code remaining()} is less than {@code end - start}.
         * @exception IndexOutOfBoundsException
         *                if either {@code start} or {@code end} is invalid.
         * @exception ReadOnlyBufferException
         *                if no changes may be made to the contents of this buffer.
         */
        public virtual CharBuffer Append(ICharSequence csq, int start, int end)
        {
            if (csq == null)
            {
                csq = "null".ToCharSequence(); //$NON-NLS-1$
            }
            ICharSequence cs = csq.SubSequence(start, end);

            if (cs.Length > 0)
            {
                return(Put(cs.ToString()));
            }
            return(this);
        }
Ejemplo n.º 14
0
        public static ICharSequence TrimOws(ICharSequence value)
        {
            int length = value.Count;

            if (length == 0)
            {
                return(value);
            }

            int start = IndexOfFirstNonOwsChar(value, length);
            int end   = IndexOfLastNonOwsChar(value, start, length);

            return(start == 0 && end == length - 1 ? value : value.SubSequence(start, end + 1));
        }
Ejemplo n.º 15
0
            string subString(ICharSequence source, int start, int end)
            {
                start = System.Math.Max(0, start);
                start = System.Math.Min(source.Length(), start); //the begin index, inclusive.
                end   = System.Math.Max(0, end);
                end   = System.Math.Min(source.Length(), end);   // the end index, exclusive.


                if (start >= 0 && end >= 0 && end >= start)
                {
                    return(source.SubSequence(start, end));
                }

                return(string.Empty);
            }
Ejemplo n.º 16
0
        public static ICharSequence GetMimeType(ICharSequence contentTypeValue)
        {
            if (contentTypeValue is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.contentTypeValue);
            }
            int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, Semicolon, 0);

            if ((uint)indexOfSemicolon < NIndexNotFound)
            {
                return(contentTypeValue.SubSequence(0, indexOfSemicolon));
            }

            return((uint)contentTypeValue.Count > 0u ? contentTypeValue : null);
        }
Ejemplo n.º 17
0
        public static ICharSequence GetMimeType(ICharSequence contentTypeValue)
        {
            if (contentTypeValue == null)
            {
                throw new ArgumentException(nameof(contentTypeValue));
            }
            int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, Semicolon, 0);

            if (indexOfSemicolon != AsciiString.IndexNotFound)
            {
                return(contentTypeValue.SubSequence(0, indexOfSemicolon));
            }

            return(contentTypeValue.Count > 0 ? contentTypeValue : null);
        }
Ejemplo n.º 18
0
        public static ICharSequence GetCharsetAsSequence(ICharSequence contentTypeValue)
        {
            if (contentTypeValue == null)
            {
                throw new ArgumentException(nameof(contentTypeValue));
            }
            int indexOfCharset = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, CharsetEquals, 0);

            if (indexOfCharset != AsciiString.IndexNotFound)
            {
                int indexOfEncoding = indexOfCharset + CharsetEquals.Count;
                if (indexOfEncoding < contentTypeValue.Count)
                {
                    return(contentTypeValue.SubSequence(indexOfEncoding, contentTypeValue.Count));
                }
            }
            return(null);
        }
Ejemplo n.º 19
0
        internal static ICharSequence UnwrapValue(ICharSequence cs)
        {
            int len = cs.Count;

            if (len > 0 && cs[0] == HttpConstants.DoubleQuoteChar)
            {
                if (len >= 2 && cs[len - 1] == HttpConstants.DoubleQuoteChar)
                {
                    // properly balanced
                    return(len == 2 ? StringCharSequence.Empty : cs.SubSequence(1, len - 1));
                }
                else
                {
                    return(null);
                }
            }

            return(cs);
        }
Ejemplo n.º 20
0
        public static ICharSequence Trim(ICharSequence sequence)
        {
            Contract.Requires(sequence != null);

            int length = sequence.Count;
            int start  = IndexOfFirstNonWhiteSpace(sequence);

            if (start == length)
            {
                return(StringCharSequence.Empty);
            }

            int last = IndexOfLastNonWhiteSpaceChar(sequence, start);

            length = last - start + 1;
            return(length == sequence.Count
                ? sequence
                : sequence.SubSequence(start, last + 1));
        }
Ejemplo n.º 21
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart,
                                             int dend)
        {
            var textToCheck = dest.SubSequence(0, dstart) + source.SubSequence(start, end) +
                              dest.SubSequence(dend, dest.Length());

            var matcher = pattern.Matcher(textToCheck);

            // Entered text does not match the pattern
            if (!matcher.Matches())
            {
                // It does not match partially too
                if (!matcher.HitEnd())
                {
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 22
0
        public static int ParseInt(ICharSequence seq, int start, int end, int radix)
        {
            Contract.Requires(seq != null);
            Contract.Requires(radix >= MinRadix && radix <= MaxRadix);

            if (start == end)
            {
                throw new FormatException();
            }

            int  i        = start;
            bool negative = seq[i] == '-';

            if (negative && ++i == end)
            {
                throw new FormatException(seq.SubSequence(start, end).ToString());
            }

            return(ParseInt(seq, i, end, radix, negative));
        }
Ejemplo n.º 23
0
 public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
 => (int)(margin + padding + paint.MeasureText(text.SubSequence(start, end)) + padding + margin);
Ejemplo n.º 24
0
 public override CharBuffer Slice()
 {
     return(new CharSequenceAdapter(sequence.SubSequence(position, limit)));
 }
Ejemplo n.º 25
0
        private void DoTestSequence(ICharSequence c)
        {
            // slice
            Assert.AreEqual("a", c.SubSequence(0, 1).ToString());
            // mid subsequence
            Assert.AreEqual("b", c.SubSequence(1, 2).ToString());
            // end subsequence
            Assert.AreEqual("bc", c.SubSequence(1, 3).ToString());
            // empty subsequence
            Assert.AreEqual("", c.SubSequence(0, 0).ToString());

            try
            {
                c.SubSequence(-1, 1);
                Assert.Fail();
            }
            catch (System.IndexOutOfRangeException expected)
            {
                // expected exception
            }

            try
            {
                c.SubSequence(0, -1);
                Assert.Fail();
            }
            catch (System.IndexOutOfRangeException expected)
            {
                // expected exception
            }

            try
            {
                c.SubSequence(0, 4);
                Assert.Fail();
            }
            catch (System.IndexOutOfRangeException expected)
            {
                // expected exception
            }

            try
            {
                c.SubSequence(2, 1);
                Assert.Fail();
            }
            catch (System.IndexOutOfRangeException expected)
            {
                // expected exception
            }
        }
Ejemplo n.º 26
0
 public override TextWriter Append(ICharSequence charSequence, int i, int i1)
 {
     LogB(charSequence.SubSequence(i, i1));
     return(this);
 }
Ejemplo n.º 27
0
        public static ICharSequence SubstringAfter(this ICharSequence value, char delim)
        {
            int pos = value.IndexOf(delim);

            return(pos >= 0 ? value.SubSequence(pos + 1, value.Count) : null);
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     Escapes the specified value, if necessary according to
        ///     <a href="https://tools.ietf.org/html/rfc4180#section-2">RFC-4180</a>.
        /// </summary>
        /// <param name="value">
        ///     The value which will be escaped according to
        ///     <a href="https://tools.ietf.org/html/rfc4180#section-2">RFC-4180</a>
        /// </param>
        /// <param name="trimWhiteSpace">
        ///     The value will first be trimmed of its optional white-space characters, according to
        ///     <a href= "https://tools.ietf.org/html/rfc7230#section-7" >RFC-7230</a>
        /// </param>
        /// <returns>the escaped value if necessary, or the value unchanged</returns>
        public static ICharSequence EscapeCsv(ICharSequence value, bool trimWhiteSpace = false)
        {
            Contract.Requires(value != null);

            int length = value.Count;

            if (length == 0)
            {
                return(value);
            }

            int start;
            int last;

            if (trimWhiteSpace)
            {
                start = IndexOfFirstNonOwsChar(value, length);
                last  = IndexOfLastNonOwsChar(value, start, length);
            }
            else
            {
                start = 0;
                last  = length - 1;
            }
            if (start > last)
            {
                return(StringCharSequence.Empty);
            }

            int  firstUnescapedSpecial = -1;
            bool quoted = false;

            if (IsDoubleQuote(value[start]))
            {
                quoted = IsDoubleQuote(value[last]) && last > start;
                if (quoted)
                {
                    start++;
                    last--;
                }
                else
                {
                    firstUnescapedSpecial = start;
                }
            }

            if (firstUnescapedSpecial < 0)
            {
                if (quoted)
                {
                    for (int i = start; i <= last; i++)
                    {
                        if (IsDoubleQuote(value[i]))
                        {
                            if (i == last || !IsDoubleQuote(value[i + 1]))
                            {
                                firstUnescapedSpecial = i;
                                break;
                            }
                            i++;
                        }
                    }
                }
                else
                {
                    for (int i = start; i <= last; i++)
                    {
                        char c = value[i];
                        if (c == LineFeed || c == CarriageReturn || c == Comma)
                        {
                            firstUnescapedSpecial = i;
                            break;
                        }
                        if (IsDoubleQuote(c))
                        {
                            if (i == last || !IsDoubleQuote(value[i + 1]))
                            {
                                firstUnescapedSpecial = i;
                                break;
                            }
                            i++;
                        }
                    }
                }
                if (firstUnescapedSpecial < 0)
                {
                    // Special characters is not found or all of them already escaped.
                    // In the most cases returns a same string. New string will be instantiated (via StringBuilder)
                    // only if it really needed. It's important to prevent GC extra load.
                    return(quoted ? value.SubSequence(start - 1, last + 2) : value.SubSequence(start, last + 1));
                }
            }

            var result = new StringBuilderCharSequence(last - start + 1 + CsvNumberEscapeCharacters);

            result.Append(DoubleQuote);
            result.Append(value, start, firstUnescapedSpecial - start);
            for (int i = firstUnescapedSpecial; i <= last; i++)
            {
                char c = value[i];
                if (IsDoubleQuote(c))
                {
                    result.Append(DoubleQuote);
                    if (i < last && IsDoubleQuote(value[i + 1]))
                    {
                        i++;
                    }
                }
                result.Append(c);
            }

            result.Append(DoubleQuote);
            return(result);
        }
            public void Run()
            {
                try
                {
                    int textLengthNew = Option.TextLength;

                    if (Option.TextLengthType == TypeLine)
                    {
                        if (TextView.Layout.LineCount <= Option.TextLength)
                        {
                            TextView.SetText(Text, Android.Widget.TextView.BufferType.Spannable);
                            return;
                        }

                        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)TextView.LayoutParameters;

                        string subString = Text.ToString().Substring(TextView.Layout.GetLineStart(0),
                                                                     TextView.Layout.GetLineEnd(Option.TextLength - 1));
                        textLengthNew = subString.Length - (Option.MoreLabel.Length + 4 + lp.RightMargin / 6);
                    }

                    SpannableStringBuilder spendableStringBuilder = new SpannableStringBuilder(Text.SubSequence(0, textLengthNew));
                    spendableStringBuilder.Append(" ...");
                    spendableStringBuilder.Append(Option.MoreLabel);

                    SpannableString ss             = SpannableString.ValueOf(spendableStringBuilder);
                    ClickableSpan   rclickableSpan = new StRclickableSpan(Option, TextView, Text, StTools.StTypeText.ReadMore);

                    ss.SetSpan(rclickableSpan, ss.Length() - Option.MoreLabel.Length, ss.Length(), SpanTypes.ExclusiveExclusive);

                    if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean && Option.ExpandAnimation)
                    {
                        LayoutTransition layoutTransition = new LayoutTransition();
                        layoutTransition.EnableTransitionType(LayoutTransitionType.Changing);
                        ((ViewGroup)TextView.Parent).LayoutTransition = layoutTransition;
                    }
                    //TextView.SetTextFuture(PrecomputedTextCompat.GetTextFuture(ss, TextViewCompat.GetTextMetricsParams(TextView), null));
                    TextView.SetText(ss, Android.Widget.TextView.BufferType.Spannable);
                    TextView.MovementMethod = LinkMovementMethod.Instance;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
Ejemplo n.º 30
0
        void ITextWatcher.OnTextChanged(ICharSequence s, int start, int before, int count)
        {
            if (Mask != null)
            {

                if (!_editingOnChanged && _editingBefore)
                {
                    _editingOnChanged = true;
                    if (_ignore)
                    {
                        return;
                    }
                    if (count > 0)
                    {
                        var startingPosition = _maskToRaw[NextValidPosition(start)];
                        var addedString = s.SubSequence(start, start + count).ToString();
                        count = _rawText.AddToString(Clear(addedString), startingPosition, _maxRawLength);
                        if (_initialized)
                        {
                            int currentPosition = startingPosition + count < _rawToMask.Length ?
                                                _rawToMask[startingPosition + count] :
                                                currentPosition = _lastValidMaskPosition + 1;

                            _selection = NextValidPosition(currentPosition);
                        }
                    }
                }
            }
        }
Ejemplo n.º 31
0
        //
        // Check from the request ContentType if this request is a Multipart request.
        // return an array of String if multipartDataBoundary exists with the multipartDataBoundary
        // as first element, charset if any as second (missing if not set), else null
        //
        protected internal static ICharSequence[] GetMultipartDataBoundary(ICharSequence contentType)
        {
            // Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]"
            ICharSequence[] headerContentType = SplitHeaderContentType(contentType);
            AsciiString     multiPartHeader   = HttpHeaderValues.MultipartFormData;

            if (headerContentType[0].RegionMatchesIgnoreCase(0, multiPartHeader, 0, multiPartHeader.Count))
            {
                int         mrank;
                int         crank;
                AsciiString boundaryHeader = HttpHeaderValues.Boundary;
                if (headerContentType[1].RegionMatchesIgnoreCase(0, boundaryHeader, 0, boundaryHeader.Count))
                {
                    mrank = 1;
                    crank = 2;
                }
                else if (headerContentType[2].RegionMatchesIgnoreCase(0, boundaryHeader, 0, boundaryHeader.Count))
                {
                    mrank = 2;
                    crank = 1;
                }
                else
                {
                    return(null);
                }
                ICharSequence boundary = headerContentType[mrank].SubstringAfter(HttpConstants.EqualsSignChar);
                if (boundary is null)
                {
                    ThrowHelper.ThrowErrorDataDecoderException_NeedBoundaryValue();
                }
                if (boundary[0] == HttpConstants.DoubleQuoteChar)
                {
                    ICharSequence bound = CharUtil.Trim(boundary);
                    int           index = bound.Count - 1;
                    if (bound[index] == HttpConstants.DoubleQuoteChar)
                    {
                        boundary = bound.SubSequence(1, index);
                    }
                }
                AsciiString charsetHeader = HttpHeaderValues.Charset;
                if (headerContentType[crank].RegionMatchesIgnoreCase(0, charsetHeader, 0, charsetHeader.Count))
                {
                    ICharSequence charset = headerContentType[crank].SubstringAfter(HttpConstants.EqualsSignChar);
                    if (charset is object)
                    {
                        return(new[]
                        {
                            new StringCharSequence("--" + boundary.ToString()),
                            charset
                        });
                    }
                }

                return(new ICharSequence[]
                {
                    new StringCharSequence("--" + boundary.ToString())
                });
            }

            return(null);
        }
Ejemplo n.º 32
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="field">field name</param>
 /// <param name="text">value that contains a regular expression</param>
 /// <param name="begin">position in the query string</param>
 /// <param name="end">position in the query string</param>
 public RegexpQueryNode(string field, ICharSequence text, int begin,
                        int end)
 {
     this.field = field;
     this.text  = text.SubSequence(begin, end);
 }