/** Returns the position at which {@code seek} first occurs in this byte * string, or -1 if it does not occur. */ public int indexOf(ByteString seek) { return indexOf(seek, 0); }
/** SQL {@code POSITION(seek IN string)} function for byte strings. */ public static int position(ByteString seek, ByteString s) { return s.indexOf(seek) + 1; }
/** SQL {@code POSITION(seek IN string)} function for byte strings. */ public static int position(ByteString seek, ByteString s) { return s.indexOf(seek) + 1; }
/** Returns the position at which {@code seek} first occurs in this byte * string, or -1 if it does not occur. */ public int indexOf(ByteString seek) { return indexOf(seek, 0); }
/** SQL {@code POSITION(seek IN string)} function for byte strings. */ public static int position(ByteString seek, ByteString s) { return s.indexOf(seek) + 1; }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }
/** SQL {@code POSITION(seek IN string FROM integer)} function for byte * strings. */ public static int position(ByteString seek, ByteString s, int from) { final int from0 = from - 1; if (from0 > s.length() || from0 < 0) { return 0; } // ByteString doesn't have indexOf(ByteString, int) until avatica-1.9 // (see [CALCITE-1423]), so apply substring and find from there. Bug.upgrade("in avatica-1.9, use ByteString.substring(ByteString, int)"); final int p = s.substring(from0).indexOf(seek); if (p < 0) { return 0; } return p + from; }
assertThat(s.indexOf(s3), is(0)); assertThat(s.indexOf(s3, 5), is(5)); assertThat(s.indexOf(s3, 15), is(-1)); assertThat(s.indexOf(s4), is(4)); assertThat(s.indexOf(s4, 4), is(4)); assertThat(s.indexOf(s4, 5), is(7)); assertThat(s.indexOf(s5), is(2)); assertThat(s.indexOf(s5, 2), is(2)); assertThat(s.indexOf(s5, 3), is(-1)); assertThat(s.indexOf(s5, 7), is(-1));
assertThat(s.indexOf(s3), is(0)); assertThat(s.indexOf(s3, 5), is(5)); assertThat(s.indexOf(s3, 15), is(-1)); assertThat(s.indexOf(s4), is(4)); assertThat(s.indexOf(s4, 4), is(4)); assertThat(s.indexOf(s4, 5), is(7)); assertThat(s.indexOf(s5), is(2)); assertThat(s.indexOf(s5, 2), is(2)); assertThat(s.indexOf(s5, 3), is(-1)); assertThat(s.indexOf(s5, 7), is(-1));