示例#1
0
    public static std_core._sslice SliceExtend(std_core._sslice slice, BigInteger bcount)
    {
        int count = IntToInt32(bcount);

        if (count == 0)
        {
            return(slice);
        }
        int i = slice.start + slice.len;

        if (count > 0)
        {
            while (i < slice.str.Length && count > 0)
            {
                count--;
                i += (Char.IsHighSurrogate(slice.str[i]) && i < slice.str.Length - 1 ? 2 : 1);
            }
        }
        else
        {
            while (i > slice.start && i > 0 && count < 0)
            {
                count++;
                i -= (Char.IsLowSurrogate(slice.str[i - 1]) && i > slice.start + 1 ? 2 : 1);
            }
        }
        return(new std_core._sslice(slice.str, slice.start, (i > slice.start ? i - slice.start : 0)));
    }
示例#2
0
 public static string SliceToString(std_core._sslice slice)
 {
     if (slice.start == 0 && slice.len == slice.str.Length)
     {
         return(slice.str);
     }
     return(slice.str.Substring(slice.start, slice.len));
 }
示例#3
0
    public static BigInteger SliceCount(std_core._sslice slice)
    {
        int n = 0;

        for (int i = slice.start; i < slice.start + slice.len; i++)
        {
            n++;
            if (Char.IsHighSurrogate(slice.str[i]))
            {
                i += 1;
            }
        }
        return(new BigInteger(n));
    }
示例#4
0
    public static std_core._sslice SliceAdvance(std_core._sslice slice, BigInteger bcount)
    {
        int count = IntToInt32(bcount);

        if (count == 0)
        {
            return(slice);
        }
        int i          = slice.start;
        int end        = slice.start + slice.len;
        int sliceCount = IntToInt32(SliceCount(slice));
        int extra      = 0;

        if (count > 0)
        {
            while (i < slice.str.Length && extra < count)
            {
                extra++;
                i += (Char.IsHighSurrogate(slice.str[i]) && i < slice.str.Length - 1 ? 2 : 1);
            }
            if (end > i && sliceCount > extra)
            {
                return(SliceExtend(new std_core._sslice(slice.str, i, end - i), extra));
            }
        }
        else
        {
            while (i > 0 && extra < -count)
            {
                extra++;
                i -= (Char.IsLowSurrogate(slice.str[i - 1]) && i > 1 ? 2 : 1);
            }
            if (sliceCount > extra)
            {
                return(SliceExtend(new std_core._sslice(slice.str, i, slice.start - i), sliceCount - extra));
            }
        }
        return(SliceExtend(new std_core._sslice(slice.str, i, 0), sliceCount));
    }
示例#5
0
    public static std_core._maybe <std_core._Tuple2_ <int, std_core._sslice> > SliceNext(std_core._sslice slice)
    {
        if (slice.len <= 0)
        {
            return(std_core._maybe <std_core._Tuple2_ <int, std_core._sslice> > .Nothing_);
        }
        char c = slice.str[slice.start];
        int  n = 1;

        if (Char.IsHighSurrogate(c) && slice.len > 1)
        {
            char lo = slice.str[slice.start + 1];
            if (Char.IsLowSurrogate(lo))
            {
                c = (char)Char.ConvertToUtf32(slice.str, slice.start);
                n = 2;
            }
        }
        return(new std_core._maybe <std_core._Tuple2_ <int, std_core._sslice> >(
                   new std_core._Tuple2_ <int, std_core._sslice>(
                       (int)c, new std_core._sslice(slice.str, slice.start + n, slice.len - n))));
    }