dotnet / dotnet/dotnet-api-docs

GetCharCount either isn't simulating, or isn't simulating as described

Open
#11,124 3 comments 0 reactions 0 assignees View on GitHub
area-System.Text.Encoding
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Missing information

### Description

> simulate clearing the internal state of the encoder ***after the calculation***

After? What possible value could there be to simulating clearing the internal state _after_ the calculation? Once calculation is complete, the method is done. Simulating a cleared buffer at that point makes no sense. And if we are indeed just 'simulating,' nothing about the decoder's state is actually changing so it's not like any subsequent calls are going to be impacted.

Surely you must mean BEFORE the calculation. If there's leftover data from a previous call to GetChars, whether you include any leftover bytes or not can certainly make a difference in the GetCharCount results. This is also consistent with what I see when I experiment with setting the flag.

Having said that, I just took a look at the source. And despite the fact that we're 'simulating,' there ARE changes to the state of the decoder from the GetCharCount call. Both a variable named _mustFlush and _throwOnOverflow get modified. And while neither variable is read in that source file (I'm looking at DecoderNLS.cs), the values are exposed to callers, so who knows what's up with that.

Simulating clearing the internal state of the encoder 'before' makes sense, but this whole page repeatedly asserts the opposite. And if you really do mean after, then some discussion of what happens after that would be affected by this simulation would be in order.

### Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.text.decoder.getcharcount?view=net-9.0#system-text-decoder-getcharcount(system-byte*-system-int32-system-boolean)

### Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Text/Decoder.xml

### Document Version Independent Id

f6d0f7c6-74c8-db97-da0e-d17770e3360e

### Platform Id

d84fef13-e343-6d3c-0650-7ead5aaf0401

### Article author

@dotnet-bot

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.