-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add unsafeTextWithLength #230
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,6 +26,9 @@ module Prettyprinter.Internal ( | |||||||||||||||
viaShow, unsafeViaShow, unsafeTextWithoutNewlines, | ||||||||||||||||
emptyDoc, nest, line, line', softline, softline', hardline, | ||||||||||||||||
|
||||||||||||||||
-- ** create doc directly from Text, unsafe | ||||||||||||||||
unsafeTextWithLength, unsafeLazyTextWithLength, | ||||||||||||||||
|
||||||||||||||||
-- ** Primitives for alternative layouts | ||||||||||||||||
group, flatAlt, | ||||||||||||||||
|
||||||||||||||||
|
@@ -452,6 +455,15 @@ instance Pretty a => Pretty (Maybe a) where | |||||||||||||||
-- Manually use @'hardline'@ if you /definitely/ want newlines. | ||||||||||||||||
instance Pretty Text where pretty = vsep . map unsafeTextWithoutNewlines . T.splitOn "\n" | ||||||||||||||||
|
||||||||||||||||
-- | Convert text to Doc. Must not contain newlines. | ||||||||||||||||
-- Useful when dealing with wide characters and emojis | ||||||||||||||||
unsafeTextWithLength :: Text -> Int -> Doc ann | ||||||||||||||||
unsafeTextWithLength txt l = Text l txt | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this definition is a bit misplaced between these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The prettyprinter/prettyprinter/src/Prettyprinter/Internal.hs Lines 153 to 159 in 0dbe08f
|
||||||||||||||||
|
||||||||||||||||
-- | identical to the strict version | ||||||||||||||||
unsafeLazyTextWithLength :: Lazy.Text -> Int -> Doc ann | ||||||||||||||||
unsafeLazyTextWithLength txt l = Text l (Lazy.toStrict txt) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use case for this function? I don't imagine that wide characters and emojis will typically exist in the form of a lazy Text values?! If there's no obvious use case, I'd prefer not to add this function. |
||||||||||||||||
|
||||||||||||||||
-- | (lazy 'Text' instance, identical to the strict version) | ||||||||||||||||
instance Pretty Lazy.Text where pretty = pretty . Lazy.toStrict | ||||||||||||||||
#endif | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should clarify why and how this function is useful for dealing with wide characters and emojis.