Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations regarding characters are not working as intended #681

Open
luc10921 opened this issue Oct 5, 2021 · 4 comments
Open

Operations regarding characters are not working as intended #681

luc10921 opened this issue Oct 5, 2021 · 4 comments

Comments

@luc10921
Copy link

luc10921 commented Oct 5, 2021

Using operations relating to characters is not working as intended, e.g.,:

	public static void Main()
	{
		string Str = "ΔδΣΦφ";
		int LengthOfStr = Str.Length;
		string SubStr1 = Str.Substring(1, 4);
		string SubStr2 = Str.Substring(2, 3);
		string SubStr3 = Str.Substring(3, 2);
		Console.WriteLine(Str);
		Console.WriteLine(LengthOfStr);
		Console.WriteLine(SubStr1);
		Console.WriteLine(SubStr2);
		Console.WriteLine(SubStr3);
	}

Running the code above in C# results in:

ΔδΣΦφ
5
δΣΦφ
ΣΦφ
Φφ

However, when running the same code in Neo, it ends up considering the number of bytes instead of the number of characters, so, every time a char that is not present in the ASCII table is used, the behaviour will diverge from C#.
image

@shargon
Copy link
Member

shargon commented Oct 6, 2021

It seems that it works as a byte array inside the VM

@lock9
Copy link
Contributor

lock9 commented Oct 6, 2021

Yes @shargon , that is the issue, however, it is possible for the compiler to fix this, by checking the byte value

@shargon
Copy link
Member

shargon commented Oct 7, 2021

@lock9 how the compiler will distinguish between a string and a byte array without the type?

@lock9
Copy link
Contributor

lock9 commented Oct 7, 2021

@shargon The compiler is the only one who knows that this is an string, but not the VM. What we probably need, is to add a 'stringSize', in addition to the 'size' opcode - and make the compiler use the correct one. There should be a need of adding other opcodes to be able to work with UTF-8 strings properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants