File tree 1 file changed +14
-0
lines changed
log4j-api/src/main/java/org/apache/logging/log4j/util 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 21
21
import java .util .Iterator ;
22
22
import java .util .Locale ;
23
23
import java .util .Objects ;
24
+ import java .util .Optional ;
24
25
25
26
/**
26
27
* <em>Consider this class private.</em>
@@ -288,6 +289,19 @@ public static String trimToNull(final String str) {
288
289
return isEmpty (ts ) ? null : ts ;
289
290
}
290
291
292
+ /**
293
+ * Removes control characters from both ends of this String returning {@code Optional.empty()} if the String is
294
+ * empty ("") after the trim or if it is {@code null}.
295
+ * @param str The String to trim.
296
+ * @return An Optional containing the String.
297
+ *
298
+ * @see #trimToNull(String)
299
+ * @since 2.24.0
300
+ */
301
+ public static Optional <String > trimToOptional (final String str ) {
302
+ return Optional .ofNullable (str ).map (String ::trim ).filter (s -> !s .isEmpty ());
303
+ }
304
+
291
305
private Strings () {
292
306
// empty
293
307
}
You can’t perform that action at this time.
0 commit comments