Skip to content

Commit

Permalink
fix: string.Trim only trim ' '
Browse files Browse the repository at this point in the history
  • Loading branch information
nan01ab committed Oct 3, 2024
1 parent 2a39c68 commit 749ffae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 749ffae

Please sign in to comment.