@@ -212,7 +212,7 @@ public static boolean isKotlinDataClass(Class<?> clazz) {
212212
213213 private static final List <Predicate <String >> LITERAL_FILTERS = asList (
214214 (value ) -> ObjectUtils .equalsOneOf (value , "true" , "false" ),
215- (value ) -> Result .attempt (() -> Double .parseDouble (value )).isOk ()
215+ (value ) -> Result .supplyThrowing (() -> Double .parseDouble (value )).isOk ()
216216 );
217217
218218 public static String destringify (String raw ) {
@@ -232,25 +232,30 @@ public static String destringify(String raw) {
232232 }
233233
234234 public static boolean isStringified (String value ) {
235- return value .startsWith ("\" " ) && value .endsWith ("\" " );
235+ for (String operator : StandardOperators .STRING_OPERATORS ) {
236+ if (value .startsWith (operator ) && value .endsWith (operator )) {
237+ return true ;
238+ }
239+ }
240+ return false ;
241+ }
242+
243+ public static String stringify (boolean enforce , String value ) {
244+ return enforce ? forceStringify (value ) : value ;
236245 }
237246
238247 public static String stringify (String value ) {
239248 String raw = value .replace (StandardOperators .LINE_SEPARATOR , StandardOperators .RAW_LINE_SEPARATOR );
240249
241250 if (!isStringified (raw )) {
242- if (raw .isEmpty () || raw .trim ().length () != raw .length () || raw .endsWith ("," ) || raw .endsWith ("{" ) || raw .endsWith (":" )) {
243- return " \" " + raw + " \" " ;
251+ if (raw .isEmpty () || raw .trim ().length () != raw .length () || raw .contains ("," ) || raw .contains ("{" ) || raw .contains (":" )) {
252+ return stringifyValue ( raw ) ;
244253 }
245254 }
246255
247256 return raw ;
248257 }
249258
250- public static String stringify (boolean enforce , String value ) {
251- return enforce ? forceStringify (value ) : value ;
252- }
253-
254259 public static String forceStringify (String value ) {
255260 for (Predicate <String > literalFilter : LITERAL_FILTERS ) {
256261 if (literalFilter .test (value )) {
@@ -259,12 +264,25 @@ public static String forceStringify(String value) {
259264 }
260265
261266 if (!isStringified (value )) {
262- return " \" " + value + " \" " ;
267+ return stringifyValue ( value ) ;
263268 }
264269
265270 return value ;
266271 }
267272
273+ private static String stringifyValue (String raw ) {
274+ if (raw .contains ("\" " )) {
275+ if (raw .contains ("'" )) {
276+ if (raw .contains ("`" )) {
277+ throw new IllegalArgumentException ("Cannot stringify value: " + raw );
278+ }
279+ return "`" + raw + "`" ;
280+ }
281+ return "'" + raw + "'" ;
282+ }
283+ return "\" " + raw + "\" " ;
284+ }
285+
268286 public static <K , V , E extends Exception > Map <K , V > streamOfResultPairToMap (PandaStream <Result <Pair <K , V >, E >> stream ) {
269287 return stream
270288 .filter (Result ::isOk )
0 commit comments