Range.
Inheritance: FanObj
Example #1
0
File: Buf.cs Project: nomit007/f4
        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;
        }
Example #2
0
 public static IndexErr make(Range index)
 {
     return make(index.ToString());
 }
Example #3
0
File: StrBuf.cs Project: xored/f4
        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);
        }
Example #4
0
File: StrBuf.cs Project: xored/f4
 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;
 }
Example #5
0
File: List.cs Project: xored/f4
        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;
              }
        }
Example #6
0
File: List.cs Project: xored/f4
        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;
        }
Example #7
0
File: FanStr.cs Project: xored/f4
        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);
        }
Example #8
0
File: List.cs Project: xored/f4
        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);
              }
        }
Example #9
0
File: Uri.cs Project: xored/f4
        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);
        }
Example #10
0
File: Uri.cs Project: xored/f4
 public Uri getRangeToPathAbs(Range range)
 {
     return slice(range, true);
 }
Example #11
0
File: Uri.cs Project: xored/f4
 public Uri getRange(Range range)
 {
     return slice(range, false);
 }
Example #12
0
 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));
 }
Example #13
0
 public static CastErr make(Range index)
 {
     return(make(index.ToString()));
 }