Example #1
0
        public AtomicString(ReadOnlyMemory <char> Data, EAtomicStringFlags Flags)
        {
            Hash = new CachedValue <int>(() =>
            {
                if (0 != (Flags & EAtomicStringFlags.CaseInsensitive | EAtomicStringFlags.HasUppercase))
                {// This atomic-string wants to always be compared case insensitevly, but has uppercase character in it's string
                    return(StringCommon.Transform(Data, UnicodeCommon.To_ASCII_Lower_Alpha).GetHashCode(StringComparison.InvariantCulture));
                }
                else
                {
                    //return new string(Data.ToArray()).GetHashCode();
                    return(Data.Pin().GetHashCode());
                }
            });

            Hash_Lower = new CachedValue <int>(() =>
            {
                /* Check if our string actually has uppercased characters, if it does then we need to lowercase it and get its hash */
                if (0 != (Flags & EAtomicStringFlags.HasUppercase))
                {// This atomic string has uppercase characters so we do infact need to create the caseless-hash
                    return(StringCommon.Transform(Data, UnicodeCommon.To_ASCII_Lower_Alpha).GetHashCode(StringComparison.Ordinal));
                }

                return(GetHashCode());
            });

            this.Data = Data;

            /*this.Data = new Memory<char>(Data.Length);
             * Data.CopyTo(this.Data);*/

            this.Flags = Flags;

            if (StringCommon.Contains(Data.Span, c => char.IsUpper(c)))
            {
                Flags |= EAtomicStringFlags.HasUppercase;
            }
        }
Example #2
0
 public AtomicString(string String, EAtomicStringFlags Flags) : this(String.AsMemory(), Flags)
 {
 }