From 4b07e293a1fe0fc8fc38eb9bc24c8c010bc894e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 19 Nov 2024 14:22:22 +0100 Subject: [PATCH] Adding StringUtil#substringBetween --- .../identityconnectors/common/StringUtil.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java b/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java index b9f56c13..a0d8fe43 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java @@ -28,9 +28,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.Random; import java.util.regex.Matcher; +import java.util.stream.Stream; /** * String Utilities. @@ -612,4 +614,22 @@ public static String join(final Object[] array, final char separator, final int } return buf.toString(); } + + public static boolean allNotNull(final Object... values) { + return values != null && Stream.of(values).noneMatch(Objects::isNull); + } + + public static String substringBetween(final String str, final String open, final String close) { + if (!allNotNull(str, open, close)) { + return null; + } + final int start = str.indexOf(open); + if (start != -1) { + final int end = str.indexOf(close, start + open.length()); + if (end != -1) { + return str.substring(start + open.length(), end); + } + } + return null; + } }