コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("StatementWithEmptyBody") @Override public boolean contains(TextValue other)
        public override bool Contains(TextValue other)
        {
            if (other is UTF8StringValue)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final UTF8StringValue substring = (UTF8StringValue) other;
                UTF8StringValue substring = ( UTF8StringValue )other;
                if (_byteLength == 0)
                {
                    return(substring._byteLength == 0);
                }
                if (substring._byteLength == 0)
                {
                    return(true);
                }
                if (substring._byteLength > _byteLength)
                {
                    return(false);
                }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte first = substring.bytes[substring.offset];
                sbyte first = substring._bytes[substring._offset];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int max = offset + byteLength - substring.byteLength;
                int max = _offset + _byteLength - substring._byteLength;
                for (int pos = _offset; pos <= max; pos++)
                {
                    //find first byte
                    if (_bytes[pos] != first)
                    {
                        while (++pos <= max && _bytes[pos] != first)
                        {
                            //do nothing
                        }
                    }

                    //Now we have the first byte match, look at the rest
                    if (pos <= max)
                    {
                        int i = pos + 1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int end = pos + substring.byteLength;
                        int end = pos + substring._byteLength;
                        for (int j = substring._offset + 1; i < end && _bytes[i] == substring._bytes[j]; j++, i++)
                        {
                            //do nothing
                        }

                        if (i == end)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            return(Value().Contains(other.StringValue()));
        }
コード例 #2
0
        public override int CompareTo(TextValue other)
        {
            if (!(other is UTF8StringValue))
            {
                return(base.CompareTo(other));
            }
            UTF8StringValue otherUTF8 = ( UTF8StringValue )other;

            return(ByteArrayCompare(_bytes, _offset, _byteLength, otherUTF8._bytes, otherUTF8._offset, otherUTF8._byteLength));
        }
コード例 #3
0
        public override bool EndsWith(TextValue other)
        {
            if (other is UTF8StringValue)
            {
                UTF8StringValue suffix = ( UTF8StringValue )other;
                return(StartsWith(suffix, _byteLength - suffix._byteLength));
            }

            return(Value().EndsWith(other.StringValue(), StringComparison.Ordinal));
        }
コード例 #4
0
        public override bool StartsWith(TextValue other)
        {
            if (other is UTF8StringValue)
            {
                UTF8StringValue suffix = ( UTF8StringValue )other;
                return(StartsWith(suffix, 0));
            }

            return(Value().StartsWith(other.StringValue(), StringComparison.Ordinal));
        }
コード例 #5
0
        public override TextValue Plus(TextValue other)
        {
            if (other is UTF8StringValue)
            {
                UTF8StringValue rhs      = ( UTF8StringValue )other;
                sbyte[]         newBytes = new sbyte[_byteLength + rhs._byteLength];
                Array.Copy(_bytes, _offset, newBytes, 0, _byteLength);
                Array.Copy(rhs._bytes, rhs._offset, newBytes, _byteLength, rhs._byteLength);
                return(utf8Value(newBytes));
            }

            return(Values.StringValue(StringValueConflict() + other.StringValue()));
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleAdditionWithOffsetAndNonAscii()
        internal virtual void ShouldHandleAdditionWithOffsetAndNonAscii()
        {
            // Given, two characters that require three bytes each
            sbyte[] bytes = "ⲹ楡".GetBytes(UTF_8);

            // When
            UTF8StringValue a = ( UTF8StringValue )utf8Value(bytes, 0, 3);
            UTF8StringValue b = ( UTF8StringValue )utf8Value(bytes, 3, 3);

            // Then
            AssertSame(a.Plus(a), stringValue("ⲹⲹ"));
            AssertSame(a.Plus(b), stringValue("ⲹ楡"));
            AssertSame(b.Plus(a), stringValue("楡ⲹ"));
            AssertSame(b.Plus(b), stringValue("楡楡"));
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleAdditionWithOffset()
        internal virtual void ShouldHandleAdditionWithOffset()
        {
            // Given
            sbyte[] bytes = "abcdefg".GetBytes(UTF_8);

            // When
            UTF8StringValue a = ( UTF8StringValue )utf8Value(bytes, 1, 2);
            UTF8StringValue b = ( UTF8StringValue )utf8Value(bytes, 3, 3);

            // Then
            AssertSame(a.Plus(a), stringValue("bcbc"));
            AssertSame(a.Plus(b), stringValue("bcdef"));
            AssertSame(b.Plus(a), stringValue("defbc"));
            AssertSame(b.Plus(b), stringValue("defdef"));
        }
コード例 #8
0
        private bool StartsWith(UTF8StringValue prefix, int startPos)
        {
            int thisOffset   = _offset + startPos;
            int prefixOffset = prefix._offset;
            int prefixCount  = prefix._byteLength;

            if (startPos < 0 || prefixCount > _byteLength)
            {
                return(false);
            }

            while (--prefixCount >= 0)
            {
                if (_bytes[thisOffset++] != prefix._bytes[prefixOffset++])
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #9
0
 public override bool Equals(Value value)
 {
     if (value is UTF8StringValue)
     {
         UTF8StringValue other = ( UTF8StringValue )value;
         if (_byteLength != other._byteLength)
         {
             return(false);
         }
         for (int i = _offset, j = other._offset; i < _byteLength; i++, j++)
         {
             if (_bytes[i] != other._bytes[j])
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         return(base.Equals(value));
     }
 }