/// <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(nameof(i), "Can not match pattern at negative indexes");// LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention) } 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 - i).Equals(this.pattern)) // LUCENENET: Corrected 2nd Subseqence parameter { return(false); } else if (!this.rContext.IsMatch(input.Subsequence(ipl, input.Length - ipl))) // LUCENENET: Corrected 2nd Subseqence parameter { return(false); } return(this.lContext.IsMatch(input.Subsequence(0, i - 0))); // LUCENENET: Corrected 2nd Subseqence parameter }
private void DoTestSequence(ICharSequence c) { // slice Assert.AreEqual("a", c.Subsequence(0, 1 - 0).ToString()); // LUCENENET: Corrected 2nd parameter // mid subsequence Assert.AreEqual("b", c.Subsequence(1, 2 - 1).ToString()); // LUCENENET: Corrected 2nd parameter // end subsequence Assert.AreEqual("bc", c.Subsequence(1, 3 - 1).ToString()); // LUCENENET: Corrected 2nd parameter // empty subsequence Assert.AreEqual("", c.Subsequence(0, 0 - 0).ToString()); // LUCENENET: Corrected 2nd parameter try { c.Subsequence(-1, 1 - -1); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } #pragma warning disable 168 catch (ArgumentOutOfRangeException expected) #pragma warning restore 168 { // expected exception } try { c.Subsequence(0, -1 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } #pragma warning disable 168 catch (ArgumentOutOfRangeException expected) #pragma warning restore 168 { // expected exception } try { c.Subsequence(0, 4 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } #pragma warning disable 168 catch (ArgumentOutOfRangeException expected) #pragma warning restore 168 { // expected exception } try { c.Subsequence(2, 1 - 2); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } #pragma warning disable 168 catch (ArgumentOutOfRangeException expected) #pragma warning restore 168 { // expected exception } }
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 StringCharSequence("\\" + buffer[0] + buffer.Subsequence(1, buffer.Length - 1).ToString()); // LUCENENET: Corrected 2nd Subsequence parameter break; } } return(buffer); }
public static string GetString(ByteBuffer bytes, int length, int additionalSkipLength) { ICharSequence cs = bytes.AsCharBuffer(); string s = cs.Subsequence(0, length - 0).ToString(); // ICU4N: Checked 2nd parameter math SkipBytes(bytes, length * 2 + additionalSkipLength); return(s); }
private void Test(ICharSequence input) { for (int i = 0; i < input.Length; i++) { for (int j = i; j <= input.Length; j++) { input.Subsequence(i, (j - i)); } } }
private void DoTestSequence(ICharSequence c) { // slice Assert.AreEqual("a", c.Subsequence(0, 1 - 0).ToString()); // LUCENENET: Corrected 2nd parameter // mid subsequence Assert.AreEqual("b", c.Subsequence(1, 2 - 1).ToString()); // LUCENENET: Corrected 2nd parameter // end subsequence Assert.AreEqual("bc", c.Subsequence(1, 3 - 1).ToString()); // LUCENENET: Corrected 2nd parameter // empty subsequence Assert.AreEqual("", c.Subsequence(0, 0 - 0).ToString()); // LUCENENET: Corrected 2nd parameter try { c.Subsequence(-1, 1 - -1); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } catch (Exception expected) when(expected.IsIndexOutOfBoundsException()) { // expected exception } try { c.Subsequence(0, -1 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } catch (Exception expected) when(expected.IsIndexOutOfBoundsException()) { // expected exception } try { c.Subsequence(0, 4 - 0); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } catch (Exception expected) when(expected.IsIndexOutOfBoundsException()) { // expected exception } try { c.Subsequence(2, 1 - 2); // LUCENENET: Corrected 2nd parameter Assert.Fail(); } catch (Exception expected) when(expected.IsIndexOutOfBoundsException()) { // expected exception } }
/// <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) // LUCENENET TODO: API - Change to use length rather than end index to match .NET { this.field = field; this.text = text.Subsequence(begin, end - begin); }
public override CharBuffer Slice() { return(new CharSequenceAdapter(sequence.Subsequence(position, limit - position))); // J2N: Corrected 2nd parameter }