;lib: export textQuoteIfNeeded
[ci skip]
This commit is contained in:
		
							parent
							
								
									56b51c1961
								
							
						
					
					
						commit
						bb6e1e3ce2
					
				| @ -14,7 +14,7 @@ module Hledger.Utils.Text | |||||||
|   textUnbracket, |   textUnbracket, | ||||||
|  -- -- quoting |  -- -- quoting | ||||||
|   quoteIfSpaced, |   quoteIfSpaced, | ||||||
|  -- quoteIfNeeded, |   textQuoteIfNeeded, | ||||||
|  -- singleQuoteIfNeeded, |  -- singleQuoteIfNeeded, | ||||||
|  -- -- quotechars, |  -- -- quotechars, | ||||||
|  -- -- whitespacechars, |  -- -- whitespacechars, | ||||||
| @ -127,7 +127,7 @@ textElideRight width t = | |||||||
| quoteIfSpaced :: T.Text -> T.Text | quoteIfSpaced :: T.Text -> T.Text | ||||||
| quoteIfSpaced s | isSingleQuoted s || isDoubleQuoted s = s | quoteIfSpaced s | isSingleQuoted s || isDoubleQuoted s = s | ||||||
|                 | not $ any (`elem` (T.unpack s)) whitespacechars = s |                 | not $ any (`elem` (T.unpack s)) whitespacechars = s | ||||||
|                 | otherwise = quoteIfNeeded s |                 | otherwise = textQuoteIfNeeded s | ||||||
| 
 | 
 | ||||||
| -- -- | Wrap a string in double quotes, and \-prefix any embedded single | -- -- | Wrap a string in double quotes, and \-prefix any embedded single | ||||||
| -- -- quotes, if it contains whitespace and is not already single- or | -- -- quotes, if it contains whitespace and is not already single- or | ||||||
| @ -139,9 +139,9 @@ quoteIfSpaced s | isSingleQuoted s || isDoubleQuoted s = s | |||||||
| 
 | 
 | ||||||
| -- -- | Double-quote this string if it contains whitespace, single quotes | -- -- | Double-quote this string if it contains whitespace, single quotes | ||||||
| -- -- or double-quotes, escaping the quotes as needed. | -- -- or double-quotes, escaping the quotes as needed. | ||||||
| quoteIfNeeded :: T.Text -> T.Text | textQuoteIfNeeded :: T.Text -> T.Text | ||||||
| quoteIfNeeded s | any (`elem` T.unpack s) (quotechars++whitespacechars) = "\"" <> escapeDoubleQuotes s <> "\"" | textQuoteIfNeeded s | any (`elem` T.unpack s) (quotechars++whitespacechars) = "\"" <> escapeDoubleQuotes s <> "\"" | ||||||
|                 | otherwise = s |                     | otherwise = s | ||||||
| 
 | 
 | ||||||
| -- -- | Single-quote this string if it contains whitespace or double-quotes. | -- -- | Single-quote this string if it contains whitespace or double-quotes. | ||||||
| -- -- No good for strings containing single quotes. | -- -- No good for strings containing single quotes. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user