flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

fix CScript string.compare

Open whitecostume opened this issue 9 months ago • 1 comments

Because the default compare sorting rules of c# string are different from those of cpp, the binary file exported by flatc -b cannot use LookupByKey. Modify the code generator to unify the rules

whitecostume avatar Mar 03 '25 13:03 whitecostume

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Mar 03 '25 13:03 google-cla[bot]

I ran into an issue with the generated C# code for __lookup_by_key.

The binary search uses obj_.Key.CompareTo(key), but this fails to find elements even though the vector is correctly sorted. When I replace it with string.Compare(obj_.Key, key, StringComparison.Ordinal), the lookup works as expected.

I'm new to FlatBuffers, but I feel that reliable key lookups should be a fundamental requirement. Why is CompareTo used here instead of string.Compare(..., StringComparison.Ordinal)? Is this intended behavior or a bug in the C# code generator?

timestee avatar Sep 06 '25 11:09 timestee

I would love to see a regression test for this but happy to merge as is

jtdavis777 avatar Dec 01 '25 03:12 jtdavis777