-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Dedent() remove surrounding newlines #7
base: master
Are you sure you want to change the base?
Conversation
The most common use-case for Dedent() is a situation like: multiLineString = dedent.Dedent(` This is a multi-line string. `) Most programmers would reasonably expect multiLineString to be equal to `"This is a\nmulti-line string." Currently Dedent() returns `"\nThis is a\nmulti-line string.\n". When using raw string syntax, there is currently no good way to specify a multi-line string without a "\n". This commit strips a "\n" prefix and suffix, only if the string has both a "\n" prefix and a "\n" suffix.
Thanks for taking your time with this. I think I need to think about this for a bit, mainly because this was initially created to mimic Python's >>> import textwrap
>>> textwrap.dedent("""
... This is a
... multi-line string.
... """)
'\nThis is a\nmulti-line string.\n' On the other hand, stripping the newlines is just a |
I recently found another package, heredoc, that seems to solve my use-case. If you want to keep this package a pure port of Thank you again for this package. It's made my tests (especially in Ginkgo) more readable. |
Interesting, seems almost identical except that it trims whitespace from the beginning of the string. I will keep it open for while longer while I ponder things 🧐 I mean, I kind of get the appeal, so adding another method might not be the worst thing in the world. Something like
I'm glad to hear that 😊 |
Yeah, I was thinking of what the name of such a second method could be. The obvious choice would be |
Breaking change! I realise that this would be a breaking change that you might not desire. I'm happy using my fork of this library for my own projects, but I wanted to know your thoughts on this, and if you'd be interested in merging it in or altering this to be a backward compatible change (e.g. adding a new method that does the
Dedent
+ newline trimming.)The most common use-case for Dedent() is a situation like:
Most programmers would reasonably expect multiLineString to be equal to
"This is a\nmulti-line string."
Currently Dedent() returns"\nThis is a\nmulti-line string.\n"
. When using raw string syntax, there is currently no good way to specify a multi-line string without a "\n". This commit strips a "\n" prefix and suffix, only if the string has both a "\n" prefix and a "\n" suffix.