当前位置: 首页>>代码示例>>C#>>正文


C# Slice.Len方法代码示例

本文整理汇总了C#中Slice.Len方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.Len方法的具体用法?C# Slice.Len怎么用?C# Slice.Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slice的用法示例。


在下文中一共展示了Slice.Len方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEmptySliceAtEnd

        public void TestEmptySliceAtEnd()
        {
            Slice<char> x = new Slice<char>("test!");
            x = x.Slc(x.Len());

            Assert.AreEqual("", x.ToString());
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:7,代码来源:SliceTest.cs

示例2: TestGetHashCodeIsZeroForEmptySlice

        public void TestGetHashCodeIsZeroForEmptySlice()
        {
            var s = new Slice<int>(new int[0]);
            Assert.AreEqual(0, s.GetHashCode());

            s = new Slice<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            s = s.Slc(5, 5);
            Assert.AreEqual(0, s.Len());
            Assert.AreEqual(0, s.GetHashCode());
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:10,代码来源:SliceTest.cs

示例3: TestIndexOfSlice

        public void TestIndexOfSlice()
        {
            var s = new Slice<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            int i;
            for (i = 0; i < s.Len(); i++)
            {
                Assert.AreEqual(i + 1, s[i]);
            }
            Assert.Throws<IndexOutOfRangeException>(() => { int a = s[i]; });
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:11,代码来源:SliceTest.cs

示例4: leadingInt

 /// <summary>
 /// leadingInt consumes the leading [0-9]* from s.
 /// </summary>
 private static long leadingInt(ref Slice<char> s)
 {
     int i = 0;
     long x = 0;
     for (; i < s.Len(); i++)
     {
         char c = s[i];
         if (c < '0' || c > '9')
         {
             break;
         }
         if (x >= (long.MaxValue - 10) / 10)
         {
             // overflow
             throw new OverflowException(s.ToString());
         }
         x = x * 10 + (c - '0');
     }
     s = s.Slc(i);
     return x;
 }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:24,代码来源:Time.cs

示例5: ParseDuration

        /// <summary>
        /// ParseDuration parses a duration string.
        /// A duration string is a possibly signed sequence of
        /// decimal numbers, each with optional fraction and a unit suffix,
        /// such as "300ms", "-1.5h" or "2h45m".
        /// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed duration.</returns>
        public static long ParseDuration(string value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            // [-+]?([0-9]*(\.[0-9]*)?[a-z]+)+
            string orig = value;
            long f = 0;
            bool neg = false;
            Slice<char> s = new Slice<char>(value);

            // Consume [-+]?
            if (s != "")
            {
                var c = s[0];
                if (c == '-' || c == '+')
                {
                    neg = (c == '-');
                    s = s.Slc(1);
                }
            }

            // Special case: if all that is left is "0", this is zero.
            if (s == "0")
            {
                return 0;
            }

            if (s == "")
            {
                throw new InvalidDataException("time: invalid duration " + orig);
            }

            while (s != "")
            {
                // The next character must be [0-9.]
                if (!(s[0] == '.' || ('0' <= s[0] && s[0] <= '9')))
                {
                    throw new InvalidDataException("time: invalid duration " + orig);
                }

                // Consume [0-9]*
                var pl1 = s.Len();
                long x = leadingInt(ref s);

                double g = x;
                bool pre = (pl1 != s.Len()); // whether we consumed anything before a period

                // Consume (\.[0-9]*)?
                bool post = false;
                if (s != "" && s[0] == '.')
                {
                    s = s.Slc(1);
                    int pl2 = s.Len();
                    x = leadingInt(ref s);
                    double scale = 1.0;
                    for (var n = pl2 - s.Len(); n > 0; n--)
                    {
                        scale *= 10;
                    }
                    g += x / scale;
                    post = (pl2 != s.Len());
                }
                if (!pre && !post)
                {
                    // no digits (e.g. ".s" or "-.s")
                    throw new InvalidDataException("time: invalid duration " + orig);
                }

                // Consume unit.
                int i = 0;
                for (; i < s.Len(); i++)
                {
                    char c = s[i];
                    if (c == '.' || ('0' <= c && c <= '9'))
                    {
                        break;
                    }
                }
                if (i == 0)
                {
                    throw new InvalidDataException("time: missing unit in duration " + orig);
                }
                var u = s.Slc(0, i);
                s = s.Slc(i);

                double unit;
                bool ok = _unitMap.TryGetValue(u.ToString(), out unit);
                if (!ok)
                {
                    throw new InvalidDataException("time: unknown unit " + u + " in duration " + orig);
//.........这里部分代码省略.........
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:101,代码来源:Time.cs

示例6: TestSlcHasNoSideEffects

        public void TestSlcHasNoSideEffects()
        {
            Slice<char> x = new Slice<char>("hello world");
            x.Slc(2, 8);

            Assert.AreEqual("hello world".Length, x.Len());
            Assert.AreEqual("hello world", x.ToString());
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:8,代码来源:SliceTest.cs


注:本文中的Slice.Len方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。