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

ZnCharacterReadStream (and friends) should publish position in terms of Character position #80

Open
dalehenrich opened this issue Dec 12, 2022 · 3 comments
Assignees

Comments

@dalehenrich
Copy link
Member

dalehenrich commented Dec 12, 2022

The current implementation wraps a Byte stream and the position of the ZnCharaterReadStream is returned using the byte position not character position, so the following test fails returning 4 and not 3 as expected for character position:

	| string bytes stream res |
	string := 'eißendeße'.
	bytes := ZnUTF8Encoder new encodeString: string.
	stream := (ZnCharacterReadStream on: bytes readStreamPortable).
	res := stream next; next; next.
	self assert: res equals: $ß.
	self assert: stream position equals: 3.

This is from the test ZnCharacterStreamTests >> testUtf8EncodingStreamPosition.

dalehenrich added a commit that referenced this issue Dec 14, 2022
…reamTests and ZnLegacyCharacterStreamTests: testUpToAll, testUpToAllTwice and testUtf8EncodingStreamPositionFor...) are all apparently due to Issue #80
@kurtkilpela
Copy link
Member

I took a look at Pharo's behavior around ZnCharacterReadSteam>>#position. Using a similar test case, Pharo's implementation also returns the byte position rather than the character position. Is this a semantic change we want to make? Or do we want to maintain semantics w/ Pharo?

| string bytes stream res |
string := 'eißßßßßßßßßßßßendeße'.
bytes := ZnUTF8Encoder new encodeString: string.
stream := (ZnCharacterReadStream on: bytes readStream).
res := stream next; next; next; next; next.
stream position. "-> 8 rather than 5"

@dalehenrich
Copy link
Member Author

I am in favor of having the code work correctly over Pharo compatibility and skipping 1/2 characters does not seem correct to me ...

@kurtkilpela
Copy link
Member

The tests associated with this issue have been temporarily removed from the test set in ecf4900. They will be restored when this issue is addressed.

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

2 participants