コード例 #1
0
ファイル: WWUtil.cs プロジェクト: zhj149/WorldWindJava.NET
        /**
         * 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));
        }
コード例 #2
0
ファイル: SgmlParser.cs プロジェクト: quicquam/opennlp4net
        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);
        }
コード例 #3
0
 public override Appendable append(CharSequence csq, int start, int end)
 {
     reserve(end - start);
     for (int i = start; i < end; i++)
     {
         unsafeWrite(csq.charAt(i));
     }
     return(this);
 }
コード例 #4
0
ファイル: SgmlParser.cs プロジェクト: quicquam/opennlp4net
        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!");
        }
コード例 #5
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();
         }
     }
 }
コード例 #6
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());
        }
コード例 #7
0
 public override Appendable append(CharSequence csq, int start, int end)
 {
     reserve(end - start);
     for (int i = start; i < end; i++)
     {
       unsafeWrite(csq.charAt(i));
     }
     return this;
 }
コード例 #8
0
ファイル: Character.cs プロジェクト: sailesh341/JavApi
        /**
         * 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;
        }
コード例 #9
0
ファイル: Character.cs プロジェクト: sailesh341/JavApi
        /**
         * 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;
        }
コード例 #10
0
ファイル: Character.cs プロジェクト: sailesh341/JavApi
        /**
         * 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;
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public int codePointAt(final CharSequence seq, final int offset)
            public override int codePointAt(CharSequence seq, int offset)
            {
                return(seq.charAt(offset));
            }
コード例 #12
0
ファイル: java.lang.Character.cs プロジェクト: gadfly/nofs
        /**
         * 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;
        }
コード例 #13
0
 internal char charAt(int i)
 {
     return(text.charAt(i));
 }