/**
         * Appends the contents of the specified substring to the end of this CompoundStringBuilder, incrementing the number
         * of substrings by one. The backing buffer grows to accomodate the sub-buffer if it does not already have enough
         * capacity to hold it.
         *
         * @param charSequence the substring to append.
         *
         * @return the substring's index.
         *
         * @throws ArgumentException if the charSequence is null.
         */
        public int append(CharSequence charSequence)
        {
            if (charSequence == null)
            {
                String message = Logging.getMessage("nullValue.CharSequenceIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            int newCount = 1 + this.count;

            if (newCount > this.capacity)
            {
                this.expandCapacity(newCount);
            }

            int index = this.count;

            this.offsets[index] = this.buffer.length();
            this.lengths[index] = charSequence.length();
            this.buffer.append(charSequence, 0, charSequence.length());
            this.count++;

            return(index);
        }
예제 #2
0
        /**
         * Returns a sub sequence of the specified {@link CharSequence}, with leading and trailing whitespace omitted. If
         * the CharSequence has length zero, this returns a reference to the CharSequence. If the CharSequence represents
         * and empty character sequence, this returns an empty CharSequence.
         *
         * @param charSequence the CharSequence to trim.
         *
         * @return a sub sequence with leading and trailing whitespace omitted.
         *
         * @throws ArgumentException if the charSequence is null.
         */
        public static CharSequence trimCharSequence(CharSequence charSequence)
        {
            if (charSequence == null)
            {
                String message = Logging.getMessage("nullValue.CharSequenceIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            int len = charSequence.length();

            if (len == 0)
            {
                return(charSequence);
            }

            int start, end;

            for (start = 0; (start < len) && charSequence.charAt(start) == ' '; start++)
            {
            }

            for (end = charSequence.length() - 1; (end > start) && charSequence.charAt(end) == ' '; end--)
            {
            }

            return(charSequence.subSequence(start, end + 1));
        }
예제 #3
0
            public virtual void onTextChanged(CharSequence s, int start, int before, int count)
            {
                int chars_left = outerInstance.maxTextLength - s.length();

                outerInstance.mMsgCharsView.Text = (outerInstance.maxTextLength - s.length()).ToString();
                if (chars_left < 10)
                {
                    outerInstance.mMsgCharsView.TextColor = Color.RED;
                }
            }
예제 #4
0
 public void setText(CharSequence cs)
 {
     _textSize.X = _font._spriteFont.MeasureString(cs.toString()).X;
     _textSize.Y = _font.getCapHeight();
     for (var i = 0; i < cs.length(); i++)
     {
         if (cs.charAt(i) == '\n' && i + 1 < cs.length())
         {
             _textSize.Y += _font.getCapHeight();
         }
     }
 }
예제 #5
0
        internal static int[] toCodePoints(CharSequence s)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int[] codePoints = new int[Character.codePointCount(s, 0, s.length())];
            int[] codePoints = new int[char.codePointCount(s, 0, s.length())];
            for (int i = 0, j = 0; i < s.length(); ++j)
            {
                codePoints[j] = char.codePointAt(s, i);
                i            += char.charCount(codePoints[j]);
            }
            return(codePoints);
        }
예제 #6
0
            /// <summary>
            /// Adds an input string and it's stemmer override output to this builder.
            /// </summary>
            /// <param name="input"> the input char sequence </param>
            /// <param name="output"> the stemmer override output char sequence </param>
            /// <returns> <code>false</code> iff the input has already been added to this builder otherwise <code>true</code>. </returns>
            public virtual bool add(CharSequence input, CharSequence output)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int length = input.length();
                int length = input.length();

                if (ignoreCase)
                {
                    // convert on the fly to lowercase
                    charsSpare.grow(length);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final char[] buffer = charsSpare.chars;
                    char[] buffer = charsSpare.chars;
                    for (int i = 0; i < length;)
                    {
                        i += char.toChars(char.ToLower(char.codePointAt(input, i)), buffer, i);
                    }
                    UnicodeUtil.UTF16toUTF8(buffer, 0, length, spare);
                }
                else
                {
                    UnicodeUtil.UTF16toUTF8(input, 0, length, spare);
                }
                if (hash.add(spare) >= 0)
                {
                    outputValues.Add(output);
                    return(true);
                }
                return(false);
            }
예제 #7
0
        protected PluralExprParser(CharSequence expr)
        {
            _expr       = expr;
            _exprLength = expr.length();

            _isInitialized = false;
        }
예제 #8
0
	  /// <summary>
	  /// Find the stem(s) of the provided word
	  /// </summary>
	  /// <param name="word"> Word to find the stems for </param>
	  /// <returns> List of stems for the word </returns>
	  public IList<CharsRef> stem(char[] word, int length)
	  {

		if (dictionary.needsInputCleaning)
		{
		  scratchSegment.Length = 0;
		  scratchSegment.Append(word, 0, length);
		  CharSequence cleaned = dictionary.cleanInput(scratchSegment, segment);
		  scratchBuffer = ArrayUtil.grow(scratchBuffer, cleaned.length());
		  length = segment.Length;
		  segment.getChars(0, length, scratchBuffer, 0);
		  word = scratchBuffer;
		}

		IList<CharsRef> stems = new List<CharsRef>();
		IntsRef forms = dictionary.lookupWord(word, 0, length);
		if (forms != null)
		{
		  // TODO: some forms should not be added, e.g. ONLYINCOMPOUND
		  // just because it exists, does not make it valid...
		  for (int i = 0; i < forms.length; i++)
		  {
			stems.Add(newStem(word, length));
		  }
		}
		stems.AddRange(stem(word, length, -1, -1, -1, 0, true, true, false, false));
		return stems;
	  }
예제 #9
0
        private static IDictionary <string, string> getAttributes(CharSequence tagChars)
        {
            // format:
            // space
            // key
            // =
            // " <- begin
            // value chars
            // " <- end

            IDictionary <string, string> attributes = new Dictionary <string, string>();

            StringBuilder key   = new StringBuilder();
            StringBuilder value = new StringBuilder();

            bool extractKey   = false;
            bool extractValue = false;

            for (int i = 0; i < tagChars.length(); i++)
            {
                // White space indicates begin of new key name
                if (StringUtil.isWhitespace(tagChars.charAt(i)) && !extractValue)
                {
                    extractKey = true;
                }
                // Equals sign indicated end of key name
                else if (extractKey && ('=' == tagChars.charAt(i) || StringUtil.isWhitespace(tagChars.charAt(i))))
                {
                    extractKey = false;
                }
                // Inside key name, extract all chars
                else if (extractKey)
                {
                    key.Append(tagChars.charAt(i));
                }
                // " Indicates begin or end of value chars
                else if ('"' == tagChars.charAt(i))
                {
                    if (extractValue)
                    {
                        attributes[key.ToString()] = value.ToString();

                        // clear key and value buffers
                        key.Length   = 0;
                        value.Length = 0;
                    }

                    extractValue = !extractValue;
                }
                // Inside value, extract all chars
                else if (extractValue)
                {
                    value.Append(tagChars.charAt(i));
                }
            }

            return(attributes);
        }
예제 #10
0
        private static string extractTagName(CharSequence tagChars)
        {
            int fromOffset = 1;

            if (tagChars.length() > 1 && tagChars.charAt(1) == '/')
            {
                fromOffset = 2;
            }

            for (int ci = 1; ci < tagChars.length(); ci++)
            {
                if (tagChars.charAt(ci) == '>' || StringUtil.isWhitespace(tagChars.charAt(ci)))
                {
                    return(tagChars.subSequence(fromOffset, ci).ToString());
                }
            }

            throw new InvalidFormatException("Failed to extract tag name!");
        }
예제 #11
0
        private string StringForIndex(long index)
        {
            int           len = (( int )index) % MAX_CONTENT_SIZE + 1;
            StringBuilder str = new StringBuilder(len);

            while (len-- > 0)
            {
                str.Append(CHARS.charAt(len % CHARS.length()));
            }

            return(str.ToString());
        }
예제 #12
0
 public override Appendable append(CharSequence csq)
 {
     return append(csq, 0, csq.length());
 }
예제 #13
0
		/// <summary>
		/// Adds an input string and it's stemmer override output to this builder.
		/// </summary>
		/// <param name="input"> the input char sequence </param>
		/// <param name="output"> the stemmer override output char sequence </param>
		/// <returns> <code>false</code> iff the input has already been added to this builder otherwise <code>true</code>. </returns>
		public virtual bool add(CharSequence input, CharSequence output)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int length = input.length();
		  int length = input.length();
		  if (ignoreCase)
		  {
			// convert on the fly to lowercase
			charsSpare.grow(length);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final char[] buffer = charsSpare.chars;
			char[] buffer = charsSpare.chars;
			for (int i = 0; i < length;)
			{
				i += char.toChars(char.ToLower(char.codePointAt(input, i)), buffer, i);
			}
			UnicodeUtil.UTF16toUTF8(buffer, 0, length, spare);
		  }
		  else
		  {
			UnicodeUtil.UTF16toUTF8(input, 0, length, spare);
		  }
		  if (hash.add(spare) >= 0)
		  {
			outputValues.Add(output);
			return true;
		  }
		  return false;
		}
예제 #14
0
 public override int codePointCount(CharSequence seq)
 {
     return(seq.length());
 }
예제 #15
0
        /**
         * Returns the code point at {@code index} in the specified sequence of
         * character units. If the unit at {@code index} is a high-surrogate unit,
         * {@code index + 1} is less than the length of the sequence and the unit at
         * {@code index + 1} is a low-surrogate unit, then the supplementary code
         * point represented by the pair is returned; otherwise the {@code char}
         * value at {@code index} is returned.
         *
         * @param seq
         *            the source sequence of {@code char} units.
         * @param index
         *            the position in {@code seq} from which to retrieve the code
         *            point.
         * @return the Unicode code point or {@code char} value at {@code index} in
         *         {@code seq}.
         * @throws NullPointerException
         *             if {@code seq} is {@code null}.
         * @throws IndexOutOfBoundsException
         *             if the {@code index} is negative or greater than or equal to
         *             the length of {@code seq}.
         * @since 1.5
         */
        public static int codePointAt(CharSequence seq, int index)
        {
            if (seq == null)
            {
                throw new NullPointerException();
            }
            int len = seq.length();
            if (index < 0 || index >= len)
            {
                throw new IndexOutOfBoundsException();
            }

            char high = seq.charAt(index++);
            if (index >= len)
            {
                return high;
            }
            char low = seq.charAt(index);
            if (isSurrogatePair(high, low))
            {
                return toCodePoint(high, low);
            }
            return high;
        }
예제 #16
0
 public StringValue encode(StringValue sb, CharSequence str)
 {
     return(encode(sb, str, 0, str.length()));
 }
예제 #17
0
 public StringValue encode(StringValue sb, CharSequence str, bool isReset)
 {
     return(encode(sb, str, 0, str.length(), isReset));
 }
예제 #18
0
        /**
         * Determines the index in the specified character sequence that is offset
         * {@code codePointOffset} code points from {@code index}.
         *
         * @param seq
         *            the character sequence to find the index in.
         * @param index
         *            the start index in {@code seq}.
         * @param codePointOffset
         *            the number of code points to look backwards or forwards; may
         *            be a negative or positive value.
         * @return the index in {@code seq} that is {@code codePointOffset} code
         *         points away from {@code index}.
         * @throws NullPointerException
         *             if {@code seq} is {@code null}.
         * @throws IndexOutOfBoundsException
         *             if {@code index &lt; 0}, {@code index} is greater than the
         *             length of {@code seq}, or if there are not enough values in
         *             {@code seq} to skip {@code codePointOffset} code points
         *             forwards or backwards (if {@code codePointOffset} is
         *             negative) from {@code index}.
         * @since 1.5
         */
        public static int offsetByCodePoints(CharSequence seq, int index,
                int codePointOffset)
        {
            if (seq == null)
            {
                throw new java.lang.NullPointerException();
            }
            int len = seq.length();
            if (index < 0 || index > len)
            {
                throw new IndexOutOfBoundsException();
            }

            if (codePointOffset == 0)
            {
                return index;
            }

            if (codePointOffset > 0)
            {
                int codePoints = codePointOffset;
                int i = index;
                while (codePoints > 0)
                {
                    codePoints--;
                    if (i >= len)
                    {
                        throw new IndexOutOfBoundsException();
                    }
                    if (isHighSurrogate(seq.charAt(i)))
                    {
                        int next = i + 1;
                        if (next < len && isLowSurrogate(seq.charAt(next)))
                        {
                            i++;
                        }
                    }
                    i++;
                }
                return i;
            }

            //assert codePointOffset < 0;
            int codePoints2 = -codePointOffset;
            int i2 = index;
            while (codePoints2 > 0)
            {
                codePoints2--;
                i2--;
                if (i2 < 0)
                {
                    throw new IndexOutOfBoundsException();
                }
                if (isLowSurrogate(seq.charAt(i2)))
                {
                    int prev = i2 - 1;
                    if (prev >= 0 && isHighSurrogate(seq.charAt(prev)))
                    {
                        i2--;
                    }
                }
            }
            return i2;
        }
예제 #19
0
        /**
         * Counts the number of Unicode code points in the subsequence of the
         * specified character sequence, as delineated by {@code beginIndex} and
         * {@code endIndex}. Any surrogate values with missing pair values will be
         * counted as one code point.
         *
         * @param seq
         *            the {@code CharSequence} to look through.
         * @param beginIndex
         *            the inclusive index to begin counting at.
         * @param endIndex
         *            the exclusive index to stop counting at.
         * @return the number of Unicode code points.
         * @throws NullPointerException
         *             if {@code seq} is {@code null}.
         * @throws IndexOutOfBoundsException
         *             if {@code beginIndex &lt; 0}, {@code beginIndex &gt; endIndex} or
         *             if {@code endIndex} is greater than the length of {@code seq}.
         * @since 1.5
         */
        public static int codePointCount(CharSequence seq, int beginIndex,
                int endIndex)
        {
            if (seq == null)
            {
                throw new java.lang.NullPointerException();
            }
            int len = seq.length();
            if (beginIndex < 0 || endIndex > len || beginIndex > endIndex)
            {
                throw new IndexOutOfBoundsException();
            }

            int result = 0;
            for (int i = beginIndex; i < endIndex; i++)
            {
                char c = seq.charAt(i);
                if (isHighSurrogate(c))
                {
                    if (++i < endIndex)
                    {
                        c = seq.charAt(i);
                        if (!isLowSurrogate(c))
                        {
                            result++;
                        }
                    }
                }
                result++;
            }
            return result;
        }
예제 #20
0
        /**
         * Returns the code point that preceds {@code index} in the specified
         * sequence of character units. If the unit at {@code index - 1} is a
         * low-surrogate unit, {@code index - 2} is not negative and the unit at
         * {@code index - 2} is a high-surrogate unit, then the supplementary code
         * point represented by the pair is returned; otherwise the {@code char}
         * value at {@code index - 1} is returned.
         *
         * @param seq
         *            the source sequence of {@code char} units.
         * @param index
         *            the position in {@code seq} following the code
         *            point that should be returned.
         * @return the Unicode code point or {@code char} value before {@code index}
         *         in {@code seq}.
         * @throws NullPointerException
         *             if {@code seq} is {@code null}.
         * @throws IndexOutOfBoundsException
         *             if the {@code index} is less than 1 or greater than the
         *             length of {@code seq}.
         * @since 1.5
         */
        public static int codePointBefore(CharSequence seq, int index)
        {
            if (seq == null)
            {
                throw new java.lang.NullPointerException();
            }
            int len = seq.length();
            if (index < 1 || index > len)
            {
                throw new IndexOutOfBoundsException();
            }

            char low = seq.charAt(--index);
            if (--index < 0)
            {
                return low;
            }
            char high = seq.charAt(index);
            if (isSurrogatePair(high, low))
            {
                return toCodePoint(high, low);
            }
            return low;
        }
예제 #21
0
 internal int getTextLength()
 {
     return(text.length());
 }
예제 #22
0
        private StringValue cleanCookieName(CharSequence name)
        {
            int len = name.length();

            StringValue sb = createStringBuilder();

            int i = 0;

            while (i < len)
            {
                char ch = name[i];

                if (ch == ' ')
                {
                    i++;
                }
                else if (ch == '+')
                {
                    i++;
                }
                else if (i + 2 < len &&
                         ch == '%' &&
                         name[i + 1] == '2' &&
                         name[i + 2] == '0')
                {
                    i += 3;
                }
                else
                {
                    break;
                }
            }

            int spaces = 0;

            for (; i < len; i++)
            {
                char ch = name[i];

                switch (ch)
                {
                case '%':
                    if (i + 2 < len &&
                        name[i + 1] == '2' &&
                        name[i + 2] == '0')
                    {
                        spaces++;
                        i += 2;
                    }
                    else
                    {
                        while (spaces > 0)
                        {
                            sb.append('_');
                            spaces--;
                        }

                        sb.append(ch);
                    }

                    break;

                case '.':
                case '+':
                case ' ':
                    spaces++;
                    break;

                default:
                    while (spaces > 0)
                    {
                        sb.append('_');
                        spaces--;
                    }

                    sb.append(ch);
                }
            }

            return(sb);
        }
예제 #23
0
 internal static int[] toCodePoints(CharSequence s)
 {
     //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
     //ORIGINAL LINE: final int[] codePoints = new int[Character.codePointCount(s, 0, s.length())];
     int[] codePoints = new int[char.codePointCount(s, 0, s.length())];
     for (int i = 0, j = 0; i < s.length(); ++j)
     {
       codePoints[j] = char.codePointAt(s, i);
       i += char.charCount(codePoints[j]);
     }
     return codePoints;
 }
예제 #24
0
 public override Appendable append(CharSequence csq)
 {
     return(append(csq, 0, csq.length()));
 }
예제 #25
0
        public static Value parseStr(Env env,
                                     CharSequence str,
                                     ArrayValue result,
                                     bool isRef,
                                     string encoding,
                                     bool isMagicQuotes,
                                     bool isReplaceSpacesWithUnderscores,
                                     int [] querySeparatorMap)
        {
            try {
                ByteToChar byteToChar = env.getByteToChar();

                if (encoding != null)
                {
                    byteToChar.setEncoding(encoding);
                }

                int len = str.length();

                for (int i = 0; i < len; i++)
                {
                    int ch = 0;
                    byteToChar.clear();

                    for (;
                         i < len && isSeparator(querySeparatorMap, ch = str[i]);
                         i++)
                    {
                    }

                    for (; i < len &&
                         (ch = str[i]) != '=' &&
                         !isSeparator(querySeparatorMap, ch);
                         i++)
                    {
                        i = addQueryChar(byteToChar, str, len, i, ch, querySeparatorMap);
                    }

                    string key = byteToChar.getConvertedString();

                    byteToChar.clear();

                    string value;
                    if (ch == '=')
                    {
                        for (i++; i < len &&
                             !isSeparator(querySeparatorMap, (ch = str[i])); i++)
                        {
                            i = addQueryChar(byteToChar, str, len, i, ch, querySeparatorMap);
                        }

                        value = byteToChar.getConvertedString();
                    }
                    else
                    {
                        value = "";
                    }

                    if (key.length() == 0)
                    {
                        // php/php/080d
                        // http://bugs.caucho.com/view.php?id=4998

                        continue;
                    }
                    else if (isRef)
                    {
                        Post.addFormValue(env, result, key,
                                          new String[] { value },
                                          isMagicQuotes, isReplaceSpacesWithUnderscores);
                    }
                    else
                    {
                        // If key @is an exsiting array, then append
                        // this value to existing array
                        // Only use extract(EXTR_OVERWRITE) on non-array variables or
                        // non-existing arrays
                        int openBracketIndex  = key.indexOf('[');
                        int closeBracketIndex = key.indexOf(']');
                        if (openBracketIndex == 0)
                        {
                            // http://bugs.caucho.com/view.php?id=4998

                            continue;
                        }
                        else if (openBracketIndex > 0)
                        {
                            string arrayName = key.substring(0, openBracketIndex);
                            arrayName = arrayName.replace('.', '_');

                            Value v = env.getVar(arrayName).getRawValue();
                            if (v instanceof ArrayValue)
                            {
                                //Check to make sure valid string (ie: foo[...])
                                if (closeBracketIndex < 0)
                                {
                                    env.warning(L.l("invalid array {0}", key));
                                    return(NullValue.NULL);
                                }

                                if (closeBracketIndex > openBracketIndex + 1)
                                {
                                    string index = key.substring(key.indexOf('[') + 1,
                                                                 key.indexOf(']'));
                                    v.put(env.createString(index), env.createString(value));
                                }
                                else
                                {
                                    v.put(env.createString(value));
                                }
                            }
                            else
                            {
                                Post.addFormValue(env, result, key,
                                                  new String[] { value },
                                                  isMagicQuotes, isReplaceSpacesWithUnderscores);
                            }
                        }
                        else
                        {
                            Post.addFormValue(env, result, key,
                                              new String[] { value },
                                              isMagicQuotes, isReplaceSpacesWithUnderscores);
                        }
                    }
			public virtual void onTextChanged(CharSequence s, int start, int before, int count)
			{
				int chars_left = outerInstance.maxTextLength - s.length();

				outerInstance.mMsgCharsView.Text = (outerInstance.maxTextLength - s.length()).ToString();
				if (chars_left < 10)
				{
					outerInstance.mMsgCharsView.TextColor = Color.RED;
				}
			}
예제 #27
0
 public DateParser(CharSequence s, QDate date)
 {
     _date   = date;
     _s      = s;
     _length = s.length();
 }