2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.gardena.internal.util;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * Some String operations from commons lang.
21 * @author Gerhard Riegler - Initial contribution
24 public class StringUtils {
26 * Gets the substring before the first occurrence of a separator.
28 public static @Nullable String substringBefore(@Nullable String str, String separator) {
29 if (str != null && !str.isEmpty()) {
30 int pos = str.indexOf(separator);
31 return pos == -1 ? str : str.substring(0, pos);
38 * Gets the substring before the last occurrence of a separator.
40 public static @Nullable String substringBeforeLast(@Nullable String str, String separator) {
41 if (str != null && !str.isEmpty()) {
42 int pos = str.lastIndexOf(separator);
43 return pos == -1 ? str : str.substring(0, pos);
50 * Gets the substring after the last occurrence of a separator.
52 public static @Nullable String substringAfterLast(@Nullable String str, String separator) {
53 if (str != null && !str.isEmpty()) {
54 int pos = str.lastIndexOf(separator);
55 return pos != -1 && pos != str.length() - separator.length() ? str.substring(pos + separator.length()) : "";