protected void RaiseUnknownProperty(ModelMap model, Utf8String propName)
 {
     if (UnknownProperty != null)
     {
         UnknownProperty?.Invoke($"{model.Name}.{propName.ToString()}");
     }
 }
示例#2
0
        public void Utf8StringToUtf16StringToUtf8StringRoundTrip(string str)
        {
            Utf8String utf8String  = new Utf8String(str);
            string     utf16String = utf8String.ToString();

            TestHelper.Validate(utf8String, new Utf8String(utf16String));
        }
示例#3
0
    // We need to set the correct collection for the actual material path that is loaded
    // before actually loading the file.
    private bool MtrlLoadHandler(Utf8String split, Utf8String path, ResourceManager *resourceManager,
                                 SeFileDescriptor *fileDescriptor, int priority, bool isSync, out byte ret)
    {
        ret = 0;
        if (fileDescriptor->ResourceHandle->FileType != ResourceType.Mtrl)
        {
            return(false);
        }

        var lastUnderscore = split.LastIndexOf(( byte )'_');
        var name           = lastUnderscore == -1 ? split.ToString() : split.Substring(0, lastUnderscore).ToString();

        if (Penumbra.CollectionManager.ByName(name, out var collection))
        {
#if DEBUG
            PluginLog.Verbose("Using MtrlLoadHandler with collection {$Split:l} for path {$Path:l}.", name, path);
#endif
            SetCollection(path, collection);
        }
        else
        {
#if DEBUG
            PluginLog.Verbose("Using MtrlLoadHandler with no collection for path {$Path:l}.", path);
#endif
        }

        // Force isSync = true for this call. I don't really understand why,
        // or where the difference even comes from.
        // Was called with True on my client and with false on other peoples clients,
        // which caused problems.
        ret = Penumbra.ResourceLoader.DefaultLoadResource(path, resourceManager, fileDescriptor, priority, true);
        PathCollections.TryRemove(path, out _);
        return(true);
    }
示例#4
0
 public object ToObject()
 {
     if (_object != null)
     {
         return(_object);
     }
     if (_type == JsonReader.JsonValueType.Null)
     {
         return(null);
     }
     if (_type == JsonReader.JsonValueType.True)
     {
         return(true);
     }
     if (_type == JsonReader.JsonValueType.False)
     {
         return(false);
     }
     if (_type == JsonReader.JsonValueType.String)
     {
         return(_value);
     }
     if (_type == JsonReader.JsonValueType.Number)
     {
         return(double.Parse(_value.ToString()));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#5
0
        public unsafe void ToStringTest()
        {
            byte[] utf8Bytes  = Encoding.UTF8.GetBytes("1258Hello");
            var    utf8String = new Utf8String(utf8Bytes);

            Assert.Equal("1258Hello", utf8String.ToString());
        }
示例#6
0
        public unsafe void StringEqualsConvertedToUtf16String(bool expected, string str1, string str2)
        {
            Utf8String s1 = new Utf8String(str1);
            Utf8String s2 = new Utf8String(str2);

            Assert.Equal(expected, s1.Equals(s2.ToString()));
            Assert.Equal(expected, s2.Equals(s1.ToString()));
        }
示例#7
0
    // Returns the converted string if the filter matches, and null otherwise.
    // The filter matches if it is empty, if it is a valid and matching regex or if the given string contains it.
    private string?Match(Utf8String data)
    {
        var s = data.ToString();

        return(Filter.Length == 0 || (_filterRegex?.IsMatch(s) ?? s.Contains(Filter, StringComparison.InvariantCultureIgnoreCase))
            ? s
            : null);
    }
示例#8
0
        public void Bug869DoesNotRepro()
        {
            var bytes       = new byte[] { 0xF0, 0xA4, 0xAD, 0xA2 };
            var utf8String  = new Utf8String(bytes);
            var str         = "𤭢";
            var strFromUtf8 = utf8String.ToString();

            Assert.Equal(str, strFromUtf8);
        }
示例#9
0
 public unsafe void ToStringPointerTest()
 {
     byte[] utf8Bytes = Encoding.UTF8.GetBytes("1258Hello");
     fixed(byte* bytes = utf8Bytes)
     {
         var utf8String = new Utf8String(bytes, utf8Bytes.Length);
         Assert.Equal("1258Hello", utf8String.ToString());
     }
 }
示例#10
0
文件: Bugs.cs 项目: jkotas/corefxlab
        //[Fact(Skip = "issue #869")]
        public void Bug869DoesNotRepro()
        {
            var bytes = new byte[] { 0xF0, 0xA4, 0xAD, 0xA2 };
            var utf8String = new Utf8String(bytes);
            var str = "𤭢";
            var strFromUtf8 = utf8String.ToString();

            Assert.Equal(str, strFromUtf8);
        }
示例#11
0
        public unsafe void ToStringPointerTest()
        {
            byte[] utf8Bytes = Encoding.UTF8.GetBytes("1258Hello");
            fixed(byte *bytes = utf8Bytes)
            {
                var utf8String = new Utf8String(bytes, utf8Bytes.Length);

                Assert.Equal("1258Hello", utf8String.ToString());
            }
        }
        private static void RunTestJsonNet(string str, bool output)
        {
            var utf8Str = new Utf8String(str);

            Timer.Restart();
            for (var i = 0; i < NumberOfIterations; i++)
            {
                JsonNetReaderHelper(new StringReader(utf8Str.ToString()), output);
            }
            TimingResultsJsonNet.Add(Timer.ElapsedMilliseconds);
        }
示例#13
0
        public static void ToString_ReturnsUtf16_WithFixups()
        {
            Utf8String newString = new Utf8String("Hello");

            fixed(byte *pNewString = newString)
            {
                pNewString[2] = 0xFF; // corrupt this data
            }

            Assert.Equal("He\uFFFDlo", newString.ToString());
        }
示例#14
0
        static void RunLoop(bool log)
        {
            var loop = new UVLoop();

            var listener  = new TcpListener(s_ipAddress, s_port, loop);
            var formatter = new ArrayFormatter(512, EncodingData.InvariantUtf8);

            listener.ConnectionAccepted += (Tcp connection) =>
            {
                if (log)
                {
                    Console.WriteLine("connection accepted");
                }

                connection.ReadCompleted += (data) =>
                {
                    if (log)
                    {
                        unsafe
                        {
                            var requestString = new Utf8String(data);
                            Console.WriteLine("*REQUEST:\n {0}", requestString.ToString());
                        }
                    }

                    formatter.Clear();
                    formatter.Append("HTTP/1.1 200 OK");
                    formatter.Append("\r\n\r\n");
                    formatter.Append("Hello World!");
                    if (log)
                    {
                        formatter.Format(" @ {0:O}", DateTime.UtcNow);
                    }

                    var segment = formatter.Formatted;
                    unsafe
                    {
                        fixed(byte *p = segment.Array)
                        {
                            var response = new Memory <byte>(segment.Array, segment.Offset, segment.Count, pointer: p);

                            connection.TryWrite(response);
                        }
                    }

                    connection.Dispose();
                };

                connection.ReadStart();
            };

            listener.Listen();
            loop.Run();
        }
示例#15
0
        private Utf8String ComputeMangledMethodName(MethodDesc method)
        {
            // Method is either a generic method instantiation or an instance method of a generic type instantiation
            var        methodDefinition = method.GetMethodDefinition();
            Utf8String utf8MangledName  = ComputeMangledNameMethodWithoutInstantiation(methodDefinition);

            // Append the instantiation vector for a generic method instantiation
            if (methodDefinition != method)
            {
                string mangledInstantiation = "";
                var    inst = method.Instantiation;
                for (int i = 0; i < inst.Length; i++)
                {
                    string instArgName = GetMangledTypeName(inst[i]);
                    if (i > 0)
                    {
                        mangledInstantiation += "__";
                    }
                    mangledInstantiation += instArgName;
                }

                mangledInstantiation = NestMangledName(mangledInstantiation);

                string mangledName = utf8MangledName.ToString();

                // Do not need the deDuplicator (which is not stable across builds) if the method has an importExport ordinal
                uint ordinal;
                if (GetMethodOrdinal(method, out ordinal))
                {
                    mangledName  = RemoveDeduplicatePrefix(mangledName);
                    mangledName += mangledInstantiation;
                    mangledName += OrdinalPrefix + ordinal;
                }
                else
                {
                    mangledName += mangledInstantiation;
                }

                mangledName = TruncateName(mangledName);

                lock (this)
                {
                    utf8MangledName = new Utf8String(mangledName);
                    if (!_mangledMethodNames.ContainsKey(method))
                    {
                        _mangledMethodNames = _mangledMethodNames.Add(method, utf8MangledName);
                    }
                }
            }

            return(utf8MangledName);
        }
示例#16
0
        public void TrimTest(string s)
        {
            Utf8String u8s = new Utf8String(s);

            string expected = s.Trim();
            Utf8String u8expected = new Utf8String(expected);

            Utf8String u8trimmed = u8s.Trim();
            Assert.Equal(u8expected, u8trimmed);

            string trimmed = u8trimmed.ToString();
            Assert.Equal(expected, trimmed);
        }
示例#17
0
        //[Fact(Skip = "System.TypeLoadException : The generic type 'System.IEquatable`1' was used with an invalid instantiation in assembly 'System.Private.CoreLib")]
        public void NestedEagerWrite()
        {
            var jsonText           = new Utf8String("{\"FirstName\":\"John\",\"LastName\":\"Smith\",\"Address\":{\"Street\":\"21 2nd Street\",\"City\":\"New York\",\"State\":\"NY\",\"Zip\":\"10021-3100\"},\"IsAlive\":true,\"Age\":25,\"Spouse\":null}");
            JsonDynamicObject json = JsonDynamicObject.Parse(jsonText, 100);
            var formatter          = new ArrayFormatter(1024, SymbolTable.InvariantUtf8);

            formatter.Append(json);
            var formattedText = new Utf8String(formatter.Formatted);

            // The follwoing check only works given the current implmentation of Dictionary.
            // If the implementation changes, the properties might round trip to different places in the JSON text.
            Assert.Equal(jsonText.ToString(), formattedText.ToString());
        }
示例#18
0
        public void TrimEndTest(string s)
        {
            Utf8String u8s = new Utf8String(s);

            string     expected   = s.TrimEnd();
            Utf8String u8expected = new Utf8String(expected);

            Utf8String u8trimmed = u8s.TrimEnd();

            TestHelper.Validate(u8expected, u8trimmed);

            string trimmed = u8trimmed.ToString();

            Assert.Equal(expected, trimmed);
        }
示例#19
0
    static void RunLoop(bool log)
    {
        var loop = new UVLoop();

        var listener  = new TcpListener("127.0.0.1", 8080, loop);
        var formatter = new BufferFormatter(512, FormattingData.InvariantUtf8);

        listener.ConnectionAccepted += (Tcp connection) =>
        {
            if (log)
            {
                Console.WriteLine("connection accepted");
            }

            connection.ReadCompleted += (ByteSpan data) =>
            {
                if (log)
                {
                    unsafe
                    {
                        var requestString = new Utf8String(data.UnsafeBuffer, data.Length);
                        Console.WriteLine("*REQUEST:\n {0}", requestString.ToString());
                    }
                }

                formatter.Clear();
                formatter.Append("HTTP/1.1 200 OK");
                formatter.Append("\r\n\r\n");
                formatter.Append("Hello World!");
                if (log)
                {
                    formatter.Format(" @ {0:O}", DateTime.UtcNow);
                }

                var      response = formatter.Buffer.Slice(0, formatter.CommitedByteCount); // formatter should have a property for written bytes
                GCHandle gcHandle;
                var      byteSpan = response.Pin(out gcHandle);
                connection.TryWrite(byteSpan);
                connection.Dispose();
                gcHandle.Free(); // TODO: formatter should format to ByteSpan, to avoid pinning
            };

            connection.ReadStart();
        };

        listener.Listen();
        loop.Run();
    }
示例#20
0
        // Implementations are intentionally split to avoid boxing
        private void TestCodePointForwardEnumerator(string s, Utf8String u8s)
        {
            List<UnicodeCodePoint> codePoints = new List<UnicodeCodePoint>();
            Utf8String.CodePointEnumerator it = u8s.CodePoints.GetEnumerator();
            while (it.MoveNext())
            {
                codePoints.Add(it.Current);
            }

            Utf16LittleEndianCodePointEnumerable utf16CodePoints = new Utf16LittleEndianCodePointEnumerable(s);
            Assert.Equal(utf16CodePoints, codePoints);

            Utf8String u8s2 = new Utf8String(codePoints);
            Assert.Equal(u8s, u8s2);
            Assert.Equal(s, u8s2.ToString());
        }
示例#21
0
        static void RunLoop(bool log)
        {
            var loop = new UVLoop();

            var listener = new TcpListener(s_ipAddress, s_port, loop);

            listener.ConnectionAccepted += (Tcp connection) =>
            {
                if (log)
                {
                    Console.WriteLine("connection accepted");
                }

                connection.ReadCompleted += (data) =>
                {
                    if (log)
                    {
                        unsafe
                        {
                            var requestString = new Utf8String(data.Span);
                            Console.WriteLine("*REQUEST:\n {0}", requestString.ToString());
                        }
                    }

                    var formatter = new ArrayFormatter(512, TextEncoder.Utf8);
                    formatter.Clear();
                    formatter.Append("HTTP/1.1 200 OK");
                    formatter.Append("\r\n\r\n");
                    formatter.Append("Hello World!");
                    if (log)
                    {
                        formatter.Format(" @ {0:O}", DateTime.UtcNow);
                    }

                    var segment = formatter.Formatted;
                    using (var memory = new OwnedPinnedBuffer <byte>(segment.Array)) {
                        connection.TryWrite(memory.Buffer.Slice(segment.Offset, segment.Count));
                        connection.Dispose();
                    }
                };

                connection.ReadStart();
            };

            listener.Listen();
            loop.Run();
        }
示例#22
0
    static void RunLoop(bool log)
    {
        var loop = new UVLoop();

        var listener  = new TcpListener(s_ipAddress, s_port, loop);
        var formatter = new BufferFormatter(512, FormattingData.InvariantUtf8);

        listener.ConnectionAccepted += (Tcp connection) =>
        {
            if (log)
            {
                Console.WriteLine("connection accepted");
            }

            connection.ReadCompleted += (Span <byte> data) =>
            {
                if (log)
                {
                    unsafe
                    {
                        var requestString = new Utf8String(data);
                        Console.WriteLine("*REQUEST:\n {0}", requestString.ToString());
                    }
                }

                formatter.Clear();
                formatter.Append("HTTP/1.1 200 OK");
                formatter.Append("\r\n\r\n");
                formatter.Append("Hello World!");
                if (log)
                {
                    formatter.Format(" @ {0:O}", DateTime.UtcNow);
                }

                var response = formatter.Buffer.Slice(0, formatter.CommitedByteCount); // formatter should have a property for written bytes

                connection.TryWrite(response);
                connection.Dispose();
            };

            connection.ReadStart();
        };

        listener.Listen();
        loop.Run();
    }
示例#23
0
 public static void Parse(this TypedPointer p, Utf8String s)
 {
     if (p.Type == typeof(string))
     {
         p.Ref <string>() = s.ToString();                          // ここの ToString が唯一のアロケーション
     }
     else if (p.Type == typeof(int))
     {
         p.Ref <int>() = (int)ParseInt(s);
     }
     else if (p.Type == typeof(long))
     {
         p.Ref <long>() = ParseInt(s);
     }
     else if (p.Type == typeof(byte))
     {
         p.Ref <byte>() = (byte)ParseInt(s);
     }
     //todo: 対応する型を増やす
 }
示例#24
0
        private void TestCodePointReverseEnumerator(string s, Utf8String u8s)
        {
            List <uint> codePoints = new List <uint>();

            Utf8String.CodePointReverseEnumerator it = u8s.CodePoints.GetReverseEnumerator();
            while (it.MoveNext())
            {
                codePoints.Add(it.Current);
            }

            codePoints.Reverse();

            Utf16LittleEndianCodePointEnumerable utf16CodePoints = new Utf16LittleEndianCodePointEnumerable(s);

            Assert.Equal(utf16CodePoints, codePoints);

            Utf8String u8s2 = new Utf8String(codePoints);

            TestHelper.Validate(u8s, u8s2);
            Assert.Equal(s, u8s2.ToString());
        }
示例#25
0
 public static object Parse(Type t, Utf8String s)
 {
     if (t == typeof(string))
     {
         return(s.ToString());                     // ここの ToString が唯一のアロケーション
     }
     else if (t == typeof(int))
     {
         return((int)ParseInt(s));
     }
     else if (t == typeof(long))
     {
         return(ParseInt(s));
     }
     else if (t == typeof(byte))
     {
         return((byte)ParseInt(s));
     }
     throw new NotSupportedException();
     //todo: 対応する型を増やす
 }
示例#26
0
            public override int Compare(Utf8String?x, Utf8String?y)
            {
                // TODO_UTF8STRING: Avoid the allocations below.

                return(string.CompareOrdinal(x?.ToString(), y?.ToString()));
            }
 public void Utf16StringToUtf8StringToUtf16StringRoundTrip(string utf16String)
 {
     Utf8String utf8String = new Utf8String(utf16String);
     Assert.Equal(utf16String, utf8String.ToString());
 }
示例#28
0
 public void ToString(string expected, Utf8String s)
 {
     Assert.Equal(expected, s.ToString());
 }
示例#29
0
 public unsafe void StringEqualsConvertedToUtf16String(bool expected, Utf8String s1, Utf8String s2)
 {
     Assert.Equal(expected, s1.Equals(s2.ToString()));
     Assert.Equal(expected, s2.Equals(s1.ToString()));
 }
示例#30
0
 public void RoundTrip(string s)
 {
     Utf8String u8s = new Utf8String(s);
     Assert.Equal(s, u8s.ToString());
 }
示例#31
0
        public void ToString(string expected, string str)
        {
            Utf8String s = new Utf8String(str);

            Assert.Equal(expected, s.ToString());
        }
示例#32
0
 public void ToStringTest(string s)
 {
     var utf8string = new Utf8String(Encoding.UTF8.GetBytes(s));
     Assert.Equal(s, utf8string.ToString());
 }
示例#33
0
            public override int Compare(Utf8String?x, Utf8String?y)
            {
                // TODO_UTF8STRING: Avoid the allocations below.

                return(_compareInfo.Compare(x?.ToString(), y?.ToString(), _options));
            }
示例#34
0
            public override bool Equals(Utf8String?x, Utf8String?y)
            {
                // TODO_UTF8STRING: Avoid the allocations below.

                return(StringComparer.OrdinalIgnoreCase.Equals(x?.ToString(), y?.ToString()));
            }
示例#35
0
 public unsafe void ToStringTest()
 {
     byte[] utf8Bytes = Encoding.UTF8.GetBytes("1258Hello");
     var utf8String = new Utf8String(utf8Bytes);
     Assert.Equal("1258Hello", utf8String.ToString());
 }
示例#36
0
            public override int GetHashCode(Utf8String obj)
            {
                // TODO_UTF8STRING: Avoid the allocations below.

                return(StringComparer.OrdinalIgnoreCase.GetHashCode(obj.ToString()));
            }
示例#37
0
 public void ToString(string expected, Utf8String s)
 {
     Assert.Equal(expected, s.ToString());
 }
示例#38
0
        private void TestCodePointReverseEnumerator(string s, Utf8String u8s)
        {
            List<UnicodeCodePoint> codePoints = new List<UnicodeCodePoint>();
            Utf8String.CodePointReverseEnumerator it = u8s.CodePoints.GetReverseEnumerator();
            while (it.MoveNext())
            {
                codePoints.Add(it.Current);
            }

            codePoints.Reverse();

            Utf16LittleEndianCodePointEnumerable utf16CodePoints = new Utf16LittleEndianCodePointEnumerable(s);
            Assert.Equal(utf16CodePoints, codePoints);

            Utf8String u8s2 = new Utf8String(codePoints);
            Assert.Equal(u8s, u8s2);
            Assert.Equal(s, u8s2.ToString());
        }
示例#39
0
 public unsafe void StringEqualsConvertedToUtf16String(bool expected, Utf8String s1, Utf8String s2)
 {
     Assert.Equal(expected, s1.Equals(s2.ToString()));
     Assert.Equal(expected, s2.Equals(s1.ToString()));
 }