001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014
015package ch.qos.logback.core.util;
016
017import ch.qos.logback.core.CoreConstants;
018
019/**
020 * @since 1.5.0
021 */
022public class StringUtil {
023
024    public static String nullStringToEmpty(String input) {
025        if (input != null)
026            return input;
027        else
028            return CoreConstants.EMPTY_STRING;
029    }
030
031    /**
032     * Returns true if input str is null or empty.
033     *
034     * @param str
035     * @return
036     */
037    public static boolean isNullOrEmpty(String str) {
038        return ((str == null) || str.isEmpty());
039    }
040
041    /**
042     * Returns true if input str is not null nor empty.
043     *
044     * @param str
045     * @return
046     */
047    public static boolean notNullNorEmpty(String str) {
048        return !isNullOrEmpty(str);
049    }
050
051    public static String capitalizeFirstLetter(String name) {
052        if (isNullOrEmpty(name))
053            return name;
054
055        if (name.length() == 1) {
056            return name.toUpperCase();
057        } else
058            return name.substring(0, 1).toUpperCase() + name.substring(1);
059    }
060
061    public static String lowercaseFirstLetter(String name) {
062        if (isNullOrEmpty(name))
063            return name;
064
065        if (name.length() == 1) {
066            return name.toLowerCase();
067        } else
068            return name.substring(0, 1).toLowerCase() + name.substring(1);
069    }
070
071}