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

More control over case conversions? #35

Closed
alexmoon opened this issue Aug 1, 2024 · 2 comments · Fixed by #40
Closed

More control over case conversions? #35

alexmoon opened this issue Aug 1, 2024 · 2 comments · Fixed by #40

Comments

@alexmoon
Copy link
Contributor

alexmoon commented Aug 1, 2024

Right now converting names from pascal case to snake case can lead to some undesirable word boundaries. For example I2cSettings turns into i_2_c_settings in snake case and I2CSettings (note the capital C) in pascal case. I'm not sure what the best solution would be to give the user more control over those conversions. One option would be to use an unambiguous casing as the input in all cases (such as snake case). Another option would be to let the user optionally specify the casings somehow.

I would consider this a pretty minor issue, but something worth thinking about; particularly if you move forward with something like #34.

@diondokter
Copy link
Owner

Yeah that's true. Can be annoying at times. I made it like this so it's easy to copy from datasheets which are not always consistent.

I want to have some global settings and the casing can be part of that. The current could be called 'best guess', but others could maybe specify that the input case is always Pascal.

@diondokter
Copy link
Owner

So what I've settled on now is being able to specify the word boundaries yourself fully in the global config:

//! _GlobalConfig_:
//! > (`type` `DefaultRegisterAccess` `=` _Access_`;`)
//! > | (`type` `DefaultFieldAccess` `=` _Access_`;`)
//! > | (`type` `DefaultBufferAccess` `=` _Access_`;`)
//! > | (`type` `DefaultByteOrder` `=` _ByteOrder_`;`)
//! > | (`type` `DefaultBitOrder` `=` _BitOrder_`;`)
//! > | (`type` `RegisterAddressType` `=` _IntegerType_`;`)
//! > | (`type` `CommandAddressType` `=` _IntegerType_`;`)
//! > | (`type` `BufferAddressType` `=` _IntegerType_`;`)
//! > | (`type` `NameWordBoundaries` `=` _NameWordBoundaries_`;`)
//!
//! _NameWordBoundaries_:
//! This specifies the input, not the output. Only applies to object and field names.
//! > [_Boundary_*]
//! > | _String_

You can specify the boundaries as an array: https://docs.rs/convert_case/latest/convert_case/enum.Boundary.html
Or as a string: https://docs.rs/convert_case/latest/convert_case/enum.Boundary.html#method.list_from

@diondokter diondokter mentioned this issue Sep 14, 2024
27 tasks
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

Successfully merging a pull request may close this issue.

2 participants