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.magentatv.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * {@link MagentaTVUtil} implements some helper functions.
21 * @author Markus Michels - Initial contribution
24 public class MagentaTVUtil {
25 public static String getString(@Nullable String value) {
26 return value != null ? value : "";
29 public static String substringBefore(@Nullable String string, String pattern) {
31 int pos = string.indexOf(pattern);
33 return string.substring(0, pos);
39 public static String substringBeforeLast(@Nullable String string, String pattern) {
41 int pos = string.lastIndexOf(pattern);
43 return string.substring(0, pos);
49 public static String substringAfter(@Nullable String string, String pattern) {
51 int pos = string.indexOf(pattern);
53 return string.substring(pos + pattern.length());
59 public static String substringAfterLast(@Nullable String string, String pattern) {
61 int pos = string.lastIndexOf(pattern);
63 return string.substring(pos + pattern.length());
69 public static String substringBetween(@Nullable String string, String begin, String end) {
71 int s = string.indexOf(begin);
73 // The end tag might be included before the start tag, e.g.
74 // when using "http://" and ":" to get the IP from http://192.168.1.1:8081/xxx
75 // therefore make it 2 steps
76 String result = string.substring(s + begin.length());
77 return substringBefore(result, end);