From 749ffaed0465f23faf2bd6e632b05b8864dc9be3 Mon Sep 17 00:00:00 2001 From: nan01ab Date: Thu, 3 Oct 2024 10:40:45 +0800 Subject: [PATCH] fix: string.Trim only trim ' ' --- .../MethodConvert/System/SystemCall.String.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.String.cs b/src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.String.cs index 7d1aae642..8b2f4c790 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.String.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.String.cs @@ -318,8 +318,16 @@ private static void HandleStringTrim(MethodConvert methodConvert, SemanticModel methodConvert.AddInstruction(OpCode.DUP); // Duplicate the index methodConvert.AddInstruction(OpCode.LDARG0); // Load the string methodConvert.AddInstruction(OpCode.PICKITEM); // Get the character at the current index + + methodConvert.AddInstruction(OpCode.DUP); + methodConvert.Push((ushort)'\t'); + methodConvert.Push((ushort)'\r' + 1); + methodConvert.AddInstruction(OpCode.WITHIN); // check if '\t' <= c <= '\r' + methodConvert.AddInstruction(OpCode.SWAP); + methodConvert.Push((ushort)' '); // Push space character methodConvert.AddInstruction(OpCode.EQUAL); // Check if character is a space + methodConvert.AddInstruction(OpCode.BOOLOR); // check if '\t' <= c <= '\r' or ' ' == c methodConvert.Jump(OpCode.JMPIFNOT, loopEnd); // If not, exit the loop methodConvert.AddInstruction(OpCode.INC); // Increment the index @@ -344,8 +352,16 @@ private static void HandleStringTrim(MethodConvert methodConvert, SemanticModel methodConvert.AddInstruction(OpCode.DUP); // Duplicate the index methodConvert.AddInstruction(OpCode.LDARG0); // Load the string methodConvert.AddInstruction(OpCode.PICKITEM); // Get the character at the current index + + methodConvert.AddInstruction(OpCode.DUP); + methodConvert.Push((ushort)'\t'); + methodConvert.Push((ushort)'\r' + 1); + methodConvert.AddInstruction(OpCode.WITHIN); // check if '\t' <= c <= '\r' + methodConvert.AddInstruction(OpCode.SWAP); + methodConvert.Push((ushort)' '); // Push space character methodConvert.AddInstruction(OpCode.EQUAL); // Check if character is a space + methodConvert.AddInstruction(OpCode.BOOLOR); // check if '\t' <= c <= '\r' or ' ' == c methodConvert.Jump(OpCode.JMPIFNOT, loopEnd2); // If not, exit the loop methodConvert.AddInstruction(OpCode.DEC); // Decrement the index