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.sensibo.internal.util;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * The {@link StringUtils} class defines some static string utility methods
24 * @author Leo Siepel - Initial contribution
27 public class StringUtils {
29 public static String capitalizeFully(String input) {
30 final String delimiter = "_";
31 String capitalizedFully = "";
32 for (String str : input.split(delimiter)) {
33 String properlyCapitalized = "";
34 if (str.length() > 0) {
35 properlyCapitalized = str.substring(0, 1).toUpperCase();
37 if (str.length() > 1) {
38 properlyCapitalized = str.substring(1).toLowerCase();
40 capitalizedFully = capitalizedFully + properlyCapitalized;
43 return capitalizedFully;
46 public static String[] splitByCharacterType(@Nullable String input) {
50 if (input.isBlank()) {
53 List<String> cache = new ArrayList<>();
54 char[] inputAsCharArray = input.toCharArray();
55 int prevType = Character.getType(inputAsCharArray[0]);
56 int prevTypeStart = 0;
57 for (int i = prevTypeStart + 1; i < inputAsCharArray.length; i++) {
58 int curType = Character.getType(inputAsCharArray[i]);
59 if (prevType == curType) {
62 if (curType == Character.LOWERCASE_LETTER && prevType == Character.UPPERCASE_LETTER) {
64 if (tmpStart != prevTypeStart) {
65 cache.add(new String(inputAsCharArray, prevTypeStart, tmpStart - prevTypeStart));
66 prevTypeStart = tmpStart;
69 cache.add(new String(inputAsCharArray, prevTypeStart, i - prevTypeStart));
74 cache.add(new String(inputAsCharArray, prevTypeStart, inputAsCharArray.length - prevTypeStart));
75 return cache.toArray(String[]::new);