Example #1
0
            internal SplitEnumerator(Ps <T> ps, T separator)
            {
                pointer = ps.Pointer;
                length  = ps.Length;

                this.separator = separator;

                Current = default;
            }
        public int GetHashCode(Ps <Utf8Byte> str)
        {
            if (IgnoreCase)
            {
                return(GetHashCodeWithIgnoreCase(str));
            }

            return(StringHelper.GetHashCode(str));
        }
        public int ElementAt(Ps <Utf8Byte> str, int index)
        {
            if (IgnoreCase)
            {
                return(ToLower(str.Pointer[index]));
            }

            return(str.Pointer[index]);
        }
        public bool Equals(Ps <Utf8Byte> x, Ps <Utf8Byte> y)
        {
            if (IgnoreCase)
            {
                return(EqualsWithIgnoreCase(x, y));
            }

            return(StringHelper.Equals(x, y));
        }
Example #5
0
        public static int GetHashCode(Ps <char> utf16)
        {
            int r = 0;

            for (int i = 0; i < utf16.Length; ++i)
            {
                r ^= (utf16.Pointer[i] + i) * Mult;
            }

            return(r);
        }
Example #6
0
        public static int GetHashCodeWithIgnoreCase(Ps <Utf8Byte> utf8)
        {
            int r = 0;

            for (int i = 0; i < utf8.Length; ++i)
            {
                r ^= (ToLower(utf8.Pointer[i]) + i) * Mult;
            }

            return(r);
        }
Example #7
0
        public static int GetHashCode(Ps <Utf8Byte> utf8)
        {
            int r = 0;

            for (int i = 0; i < utf8.Length; ++i)
            {
                r ^= (utf8.Pointer[i] + i) * Mult;
            }

            return(r);
        }
Example #8
0
        public static bool Equals(Ps <Utf8Byte> utf8x, Ps <Utf8Byte> utf8y)
        {
            if (utf8x.Length != utf8y.Length)
            {
                return(false);
            }

            var i = utf8x.Length;

            while (i >= 8)
            {
                i -= 8;

                if (*(long *)(utf8x.Pointer + i) != *(long *)(utf8y.Pointer + i))
                {
                    return(false);
                }
            }

            if (i >= 4)
            {
                i -= 4;

                if (*(int *)(utf8x.Pointer + i) != *(int *)(utf8y.Pointer + i))
                {
                    return(false);
                }
            }

            if (i >= 2)
            {
                i -= 2;

                if (*(short *)(utf8x.Pointer + i) != *(short *)(utf8y.Pointer + i))
                {
                    return(false);
                }
            }

            if (i >= 1)
            {
                if (*(utf8x.Pointer) != *(utf8y.Pointer))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #9
0
        public static bool EqualsWithIgnoreCase(Ps <char> utf16, string str)
        {
            if (utf16.Length != str.Length)
            {
                return(false);
            }

            for (int i = 0; i < utf16.Length; i++)
            {
                if (utf16.Pointer[i] != str[i] && ToLower(utf16.Pointer[i]) != ToLower(str[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        public static bool EqualsWithIgnoreCase(Ps <Utf8Byte> utf8x, Ps <Utf8Byte> utf8y)
        {
            if (utf8x.Length != utf8y.Length)
            {
                return(false);
            }

            for (int i = 0; i < utf8x.Length; i++)
            {
                if (utf8x.Pointer[i] != utf8y.Pointer[i] && ToLower(utf8x.Pointer[i]) != ToLower(utf8y.Pointer[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #11
0
        public static bool Equals(Ps <char> utf16x, Ps <char> utf16y)
        {
            if (utf16x.Length != utf16y.Length)
            {
                return(false);
            }

            var i = utf16x.Length;

            while (i >= 4)
            {
                i -= 4;

                if (*(long *)(utf16x.Pointer + i) != *(long *)(utf16y.Pointer + i))
                {
                    return(false);
                }
            }

            if (i >= 2)
            {
                i -= 2;

                if (*(int *)(utf16x.Pointer + i) != *(int *)(utf16y.Pointer + i))
                {
                    return(false);
                }
            }

            if (i >= 1)
            {
                if (*(utf16x.Pointer) != *(utf16y.Pointer))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #12
0
            /// <summary>
            /// 移动至下个段落。
            /// </summary>
            /// <returns></returns>
            public bool MoveNext()
            {
                if (length > 0)
                {
                    var count = 0;

                    while (count < length && !Equals(pointer[count], separator))
                    {
                        ++count;
                    }

                    Current = new Ps <T>(pointer, count);

                    ++count;

                    pointer += count;
                    length  -= count;

                    return(true);
                }

                return(false);
            }
Example #13
0
 public static char CharAt(this Ps <char> str, int index) => str.Pointer[index];
Example #14
0
 public int GetLength(Ps <char> str)
 {
     return(str.Length);
 }
Example #15
0
 public static bool EqualsWithIgnoreCase(Ps <Utf8Byte> utf8, string str)
 => Equals((byte *)utf8.Pointer, utf8.Length, ref GetRawStringData(str), str.Length, true);
Example #16
0
 /// <summary>
 /// 比较两个连续内存是否完全相等。
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(Ps <T> other)
 {
     return(other.Length == Length && other.Pointer == Pointer);
 }
Example #17
0
        /// <summary>
        /// 尝试将字符串解析为枚举值。
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="str">字符串</param>
        /// <param name="value">返回枚举值</param>
        /// <returns>返回是否解析成功</returns>
        public static unsafe bool TryParseEnum <T>(Ps <char> str, out T value) where T : struct, Enum
        {
            const char NumberMin = '0';
            const char NumberMax = '9';

            if (str.Length < 0)
            {
                goto False;
            }

            switch (str.Pointer[0])
            {
            case NumberHelper.NegativeSign:
            case NumberHelper.PositiveSign:
            case var digit when digit >= NumberMin && digit <= NumberMax:
                goto Number;
            }

            ulong val = 0;

            var spliter = str.Split(EnumParsingSeperator);

Continue:

            while (spliter.MoveNext())
            {
                var item = spliter.Current;

                item = StringHelper.Trim(item.Pointer, item.Length);

                foreach (var(bits, name) in EnumInterface <T> .Items)
                {
                    if (StringHelper.EqualsWithIgnoreCase(item, name))
                    {
                        val |= bits;

                        goto Continue;
                    }
                }

                if (val != 0)
                {
                    goto False;
                }
                else
                {
                    goto Number;
                }
            }

            value = AsEnum <T>(val);

            return(true);

Number:

            var numberInfo = NumberHelper.GetNumberInfo(str.Pointer, str.Length, 16);

            if (numberInfo.IsNumber && !numberInfo.HaveFractional && !numberInfo.HaveExponent && numberInfo.End == str.Length && numberInfo.IsCommonRadix(out var radix))
            {
                value = numberInfo.IsNegative
                    ? AsEnum <T>((ulong)numberInfo.ToInt64(radix))
                    : AsEnum <T>(numberInfo.ToUInt64(radix));

                return(true);
            }

False:

            value = default;

            return(false);
        }
Example #18
0
 public static int GetLength(this Ps <char> utf16) => utf16.Length;
Example #19
0
        public static string ToStringEx(this Ps <Utf8Byte> utf8)
        {
            var chars = HGlobalCacheExtensions.CharsPool.Current().Grow(GetUtf8MaxCharsLength(utf8.Length)).First;

            return(ToString(chars, GetUtf8Chars((byte *)utf8.Pointer, utf8.Length, ref chars[0])));
        }
Example #20
0
 public static string ToStringEx(this Ps <char> utf16)
 {
     return(ToString(utf16.Pointer, utf16.Length));
 }
Example #21
0
 public static int GetLength(this Ps <Utf8Byte> utf8) => utf8.Length;
 public int GetLength(Ps <Utf8Byte> str)
 {
     return(str.Length);
 }
Example #23
0
 public static Utf8Byte CharAt(this Ps <Utf8Byte> str, int index) => str.Pointer[index];