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

Split without word-breaking #1

Open
alexkozler opened this issue Jul 14, 2018 · 5 comments
Open

Split without word-breaking #1

alexkozler opened this issue Jul 14, 2018 · 5 comments

Comments

@alexkozler
Copy link

I know this may be out of nowhere and this hasn't been touched in a couple years, but is there any easy way to modify this to optionally not break up words (or URLs) unless it has to?

@janpieterz
Copy link
Owner

Hi @alexthekid07

No worries, it's not been touched but actively used, it does what it says on the tin (so far).
It'd be an interesting option for sure! Would you be in the mood to do a quick proposal of what you'd change in the interface? I feel making it an explicit, SplitIntoReadableParts or even SplitWithWordWrap(WordWrap wrap) might be better than adding a parameter to the current method.

@alexkozler
Copy link
Author

alexkozler commented Jul 16, 2018

@janpieterz SplitWithWordWrap sounds like it would work perfectly fine. The only oddball scenario I see with my request is if someone tries to split an elongated URL like this where word-wrap couldn't come into play:
https://www.google.com/search?ei=Z59MW4OjD4TujwTkrbWQCg&q=long+url&oq=long+url&gs_l=psy-ab.3..0i67k1l2j0l8.3454.4373.0.4430.8.8.0.0.0.0.114.596.5j2.7.0....0...1c.1.64.psy-ab..1.7.595...35i39k1j0i131k1j0i20i264k1j0i131i67k1.0.sqkls_x_O6U

I assume that could be taken care by my ignoring word wrap on strings with a length greater than 1 message length... Also to my knowledge there aren't any other .NET libraries here on GitHub that offer this, hence why I was poking around to see if it was doable 👍

@janpieterz
Copy link
Owner

Interesting use case example as well.
If we make this contract, it's going to be used slightly different than we usually do (calculate after fact).
What would you want to happen here? In CSS the contract would be to return one string, but obviously we need to either allow it, or break it.
Possibly two different WordWrap settings, one which throws on not being able to split up?

@alexkozler
Copy link
Author

alexkozler commented Jul 16, 2018

If you go with SplitWithWordWrap() it might make sense to just have an optional boolean parameter to decide whether or not to throw an exception if the string can't be split.

If we keep following my example of how to handle a long URL (not that anyone should be texting that long of a URL), I suppose the individual "word" would have to be evaluated to determine if it could be split, not just the overall message itself.

Imagine if your string was:

Hello how are you https://www.google.com/search?ei=Z59MW4OjD4TujwTkrbWQCg&q=long+url&oq=long+url&gs_l=psy-ab.3..0i67k1l2j0l8.3454.4373.0.4430.8.8.0.0.0.0.114.596.5j2.7.0....0...1c.1.64.psy-ab..1.7.595...35i39k1j0i131k1j0i20i264k1j0i131i67k1.0.sqkls_x_O6U

If you tried to push the URL to a new part, the Part #1 would end up only "Hello how are you" and Part #2 would end up the entire URL, or even split into a Part #3.

I think ideally in that scenario, it would be better to use this libraries existing/default implementation, where Part #1 = "Hello how are you" + the first chunk of the URL, and Part #2 = the second chunk of the URL. Just because the URL would be too long to fit into a single message. Even despite that, however, I'd still want it to "try" to word-wrap if the URL was small enough to fit into a single text. For example:

https://www.google.com/search?ei=Z59MW4OjD4TukrbWQCg&q=long+url&oq=long+url&gs_l=psy-ab.3..0i67k1lsdfgsfg2j0l8.3454.4373.12340.123412341234 antidisestablishmentarianism

Despite the long URL, it fits in one message, but "antidisestablishmentarianism" gets cut in half into a second message, where ideally Part #1 = URL, Part #2 = "antidisestablishmentarianism"

Hopefully I didn't make that sound too convoluted

@janpieterz
Copy link
Owner

That makes total sense. Not sure about the boolean for throwing an exception, I'd almost want there to be a WordWrap parameter with different settings, maybe one original one (like it currently does), one where it simply cuts it off into two/three, one where it throws if it can't fit a whole section into one part etc.

This way new settings can be created. We'll have to, obviously, add some unit tests for these too.
I'll have a think about what different settings we'd need for this and get back, hopefully soon. If you're in the mood, you could implement the mode you want already (make a WordWrap enum with a description of your method and some unit tests)

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