python-titlecase icon indicating copy to clipboard operation
python-titlecase copied to clipboard

Add an option to preserve the input space characters

Open robinwhittleton opened this issue 1 year ago • 2 comments

This potentially changes the output in two ways:

  1. We now match (on line 107) any space character rather than just a tab or a space. The test case as it stands continues to pass, and the output remains separated by space characters.

  2. There’s a new boolean parameter called preserve_space_characters that changes the output to use the space characters that were passed in. This is more accurate, but an obvious change to the existing behaviour hence the gating behind a default-False parameter.

I’ve also included a couple of commits here that tidy up comment mistakes found when I was initially going through the code.

robinwhittleton avatar Mar 23 '24 13:03 robinwhittleton

While I see your point re preserving existing behavior, my instinct is that preserving specialty spaces in the input string would actually be the better default behavior — if source text used a special space character, it was likely for good reason.

I suspect this isn't the only change of this flavor that will come in the larger list of improvements from your other issue. I'd be inclined to shift towards 'better defaults' and pushing a new major release once everything is merged.

I looks like all the test cases check the 'strip special spaces' mode; can you add test cases for both sides of that flag?

I think the extra test cases, and inverting the default behavior, and this should be good to go!

ppannuto avatar Mar 25 '24 19:03 ppannuto

Pushed up an inversion to make this the default behaviour with an opt-out switch. I think the new tests were testing everything already (there are two assertEquals per test) but let me know if you want any other tests.

robinwhittleton avatar Mar 26 '24 19:03 robinwhittleton