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 static long random(Range r) { rand.GetBytes(randBytes); long v = BitConverter.ToInt64(randBytes, 0); if (r == null) { return(v); } if (v < 0) { v = -v; } long start = r.start(); long end = r.end(); if (r.inclusive()) { ++end; } if (end <= start) { throw ArgErr.make("Range end < start: " + r).val; } return(start + (v % (end - start))); }
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 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 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)); }
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)); }
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 List getRange(Range r) { try { 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; } List acc = new List(m_of, n); acc.m_size = n; Array.Copy(m_values, s, acc.m_values, 0, n); return(acc); } catch (ArgumentOutOfRangeException) { throw IndexErr.make(r).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 StrBuf replaceRange(Range r, string str) { 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); sb.Insert(s, str); return this; }
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); }
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 List getRange(Range r) { try { 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; List acc = new List(m_of, n); acc.m_size = n; Array.Copy(m_values, s, acc.m_values, 0, n); return acc; } catch (ArgumentOutOfRangeException) { throw IndexErr.make(r).val; } }
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 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); }
private Uri slice(Range range, bool forcePathAbs) { if (m_pathStr == null) throw Err.make("Uri has no path: " + this).val; int size = m_path.sz(); int s = range.start(size); int e = range.end(size); int n = e - s + 1; if (n < 0) throw IndexErr.make(range).val; bool head = (s == 0); bool tail = (e == size-1); if (head && tail && (!forcePathAbs || isPathAbs())) return this; Sections t = new Sections(); t.path = m_path.getRange(range); StringBuilder sb = new StringBuilder(m_pathStr.Length); if ((head && isPathAbs()) || forcePathAbs) sb.Append('/'); for (int i=0; i<t.path.sz(); ++i) { if (i > 0) sb.Append('/'); sb.Append(t.path.get(i)); } if (t.path.sz() > 0 && (!tail || isDir())) sb.Append('/'); t.pathStr = sb.ToString(); if (head) { t.scheme = m_scheme; t.userInfo = m_userInfo; t.host = m_host; t.port = m_port; } if (tail) { t.queryStr = m_queryStr; t.query = m_query; t.frag = m_frag; } else { t.query = emptyQuery(); } if (!head && !tail) { t.str = t.pathStr; } return new Uri(t); }
public static long random(Range r) { rand.GetBytes(randBytes); long v = BitConverter.ToInt64(randBytes, 0); if (r == null) return v; if (v < 0) v = -v; long start = r.start(); long end = r.end(); if (r.inclusive()) ++end; if (end <= start) throw ArgErr.make("Range end < start: " + r).val; return start + (v % (end-start)); }