public void eachRange(Range r, Func f) { int s = r.start(m_size); int e = r.end(m_size); int n = e - s + 1; if (n < 0) { throw IndexErr.make(r).val; } if (f.arity() == 1) { for (int i = s; i <= e; ++i) { f.call(m_values[i]); } } else { for (int i = s; i <= e; ++i) { f.call(m_values[i], i); } } }
public List removeRange(Range r) { modify(); int s = r.start(m_size); int e = r.end(m_size); int n = e - s + 1; if (n < 0) { throw IndexErr.make(r).val; } int shift = m_size - s - n; if (shift > 0) { Array.Copy(m_values, s + n, m_values, s, shift); } m_size -= n; for (int i = m_size; i < m_size + n; ++i) { m_values[i] = null; } return(this); }
public Long indexSame(object val, long off) { if (m_size == 0) { return(null); } int start = (int)off; if (start < 0) { start = m_size + start; } if (start >= m_size) { throw IndexErr.make(off).val; } try { for (int i = start; i < m_size; i++) { if (val == m_values[i]) { return(Long.valueOf(i)); } } return(null); } catch (IndexOutOfRangeException) { throw IndexErr.make(off).val; } }
public object[] copyInto(object[] a, int off, int len) { try { Array.Copy(m_values, 0, a, off, len); return(a); } catch (IndexOutOfRangeException) { throw IndexErr.make().val; } }
public object[] toArray(object[] a, int start, int len) { try { Array.Copy(m_values, start, a, 0, len); return(a); } catch (IndexOutOfRangeException) { throw IndexErr.make().val; } }
public object[] toArray(object[] a) { try { Array.Copy(m_values, 0, a, 0, m_size); return(a); } catch (IndexOutOfRangeException) { throw IndexErr.make().val; } }
public StrBuf removeRange(Range r) { int s = r.start(sb.Length); int e = r.end(sb.Length); int n = e - s + 1; if (n < 0) { throw IndexErr.make(r).val; } sb.Remove(s, n); return(this); }
public long get(long pos) { long size = getSize(); if (pos < 0) { pos = size + pos; } if (pos < 0 || pos >= size) { throw IndexErr.make(pos).val; } return(getByte(pos)); }
public long start(long group) { // to match java if (!matches()) { throw new System.Exception(); } if (group < 0 || group >= m_match.Groups.Count) { throw IndexErr.make(group).val; } return(m_match.Groups[(int)group].Index); }
public static string getRange(string self, Range r) { int size = self.Length; int s = r.start(size); int e = r.end(size); if (e + 1 < s) { throw IndexErr.make(r).val; } return(self.Substring(s, (e - s) + 1)); }
internal long start(long size) { long x = m_start; if (x < 0) { x = size + x; } if (x > size) { throw IndexErr.make(this).val; } return(x); }
public string getRange(Range r) { int size = sb.Length; int s = r.start(size); int e = r.end(size); if (e + 1 < s) { throw IndexErr.make(r).val; } return(sb.ToString().Substring(s, (e - s) + 1)); }
////////////////////////////////////////////////////////////////////////// // Slice Utils ////////////////////////////////////////////////////////////////////////// internal int start(int size) { int x = (int)m_start; if (x < 0) { x = size + x; } if (x > size) { throw IndexErr.make(this).val; } return(x); }
public object get(int i) { try { if (i >= m_size) { throw IndexErr.make("" + i).val; } return(m_values[i]); } catch (IndexOutOfRangeException) { throw IndexErr.make("" + i).val; } }
public StrBuf remove(long index) { int i = (int)index; if (i < 0) { i = sb.Length + i; } if (i >= sb.Length) { throw IndexErr.make(index).val; } sb.Remove(i, 1); return(this); }
public List insert(long index, object val) { // modify in insert(int, object) int i = (int)index; if (i < 0) { i = m_size + i; } if (i > m_size) { throw IndexErr.make(index).val; } return(insert(i, val)); }
////////////////////////////////////////////////////////////////////////// // Modification ////////////////////////////////////////////////////////////////////////// public Buf set(long pos, long b) { long size = getSize(); if (pos < 0) { pos = size + pos; } if (pos < 0 || pos >= size) { throw IndexErr.make(pos).val; } setByte(pos, (int)b); return(this); }
public List insertAll(long index, List list) { // modify in insertAll(int, List) int i = (int)index; if (i < 0) { i = m_size + i; } if (i > m_size || i < 0) { throw IndexErr.make(index).val; } return(insertAll(i, list)); }
public Buf seek(long pos) { long p = pos; long size = getSize(); if (p < 0) { p = size + p; } if (p < 0 || p > size) { throw IndexErr.make(pos).val; } setPos(p); return(this); }
public StrBuf insert(long index, object x) { string s = (x == null) ? "null" : toStr(x); int i = (int)index; if (i < 0) { i = sb.Length + i; } if (i > sb.Length) { throw IndexErr.make(index).val; } sb.Insert(i, s); return(this); }
public long end(long group) { // to match java if (!matches()) { throw new System.Exception(); } if (group < 0 || group >= m_match.Groups.Count) { throw IndexErr.make(group).val; } Group g = m_match.Groups[(int)group]; return(g.Index + g.Length); }
////////////////////////////////////////////////////////////////////////// // Operators ////////////////////////////////////////////////////////////////////////// public static long get(string self, long index) { try { int i = (int)index; if (i < 0) { i = self.Length + i; } return(self[i]); } catch (System.IndexOutOfRangeException) { throw IndexErr.make(index).val; } }
public long get(long index) { try { int i = (int)index; if (i < 0) { i = sb.Length + i; } return(sb[i]); } catch (System.ArgumentOutOfRangeException e) { throw IndexErr.make(e).val; } }
public Long indexr(object val, long off) { if (m_size == 0) { return(null); } int start = (int)off; if (start < 0) { start = m_size + start; } if (start >= m_size) { throw IndexErr.make(off).val; } try { if (val == null) { for (int i = start; i >= 0; --i) { if (m_values[i] == null) { return(Long.valueOf(i)); } } } else { for (int i = start; i >= 0; --i) { object obj = m_values[i]; if (obj != null && obj.Equals(val)) { return(Long.valueOf(i)); } } } return(null); } catch (IndexOutOfRangeException) { throw IndexErr.make(off).val; } }
public StrBuf set(long index, long ch) { try { int i = (int)index; if (i < 0) { i = sb.Length + i; } sb[i] = (char)ch; return(this); } catch (System.ArgumentOutOfRangeException e) { throw IndexErr.make(e).val; } }
internal long end(long size) { long x = m_end; if (x < 0) { x = size + x; } if (m_exclusive) { x--; } if (x >= size) { throw IndexErr.make(this).val; } return(x); }
internal int end(int size) { int x = (int)m_end; if (x < 0) { x = size + x; } if (m_exclusive) { x--; } if (x >= size) { throw IndexErr.make(this).val; } return(x); }
public object get(long index) { try { int i = (int)index; if (i < 0) { i = m_size + i; } if (i >= m_size) { throw IndexErr.make(index).val; } return(m_values[i]); } catch (IndexOutOfRangeException) { throw IndexErr.make(index).val; } }
public Buf getRange(Range range) { long size = getSize(); long s = range.start(size); long e = range.end(size); int n = (int)(e - s + 1); if (n < 0) { throw IndexErr.make(range).val; } byte[] slice = new byte[n]; getBytes(s, slice, 0, n); Buf result = new MemBuf(slice, n); result.charset(charset()); return(result); }
public object removeAt(long index) { modify(); int i = (int)index; if (i < 0) { i = m_size + i; } if (i >= m_size) { throw IndexErr.make(index).val; } object old = m_values[i]; if (i < m_size - 1) { Array.Copy(m_values, i + 1, m_values, i, m_size - i - 1); } m_size--; return(old); }