View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.core.util;
16  
17  import ch.qos.logback.core.CoreConstants;
18  
19  /**
20   * @since 1.5.0
21   */
22  public class StringUtil {
23  
24      public static String nullStringToEmpty(String input) {
25          if (input != null)
26              return input;
27          else
28              return CoreConstants.EMPTY_STRING;
29      }
30  
31      /**
32       * Returns true if input str is null or empty.
33       *
34       * @param str
35       * @return
36       */
37      public static boolean isNullOrEmpty(String str) {
38          return ((str == null) || str.isEmpty());
39      }
40  
41      /**
42       * Returns true if input str is not null nor empty.
43       *
44       * @param str
45       * @return
46       */
47      public static boolean notNullNorEmpty(String str) {
48          return !isNullOrEmpty(str);
49      }
50  
51      public static String capitalizeFirstLetter(String name) {
52          if (isNullOrEmpty(name))
53              return name;
54  
55          if (name.length() == 1) {
56              return name.toUpperCase();
57          } else
58              return name.substring(0, 1).toUpperCase() + name.substring(1);
59      }
60  
61      public static String lowercaseFirstLetter(String name) {
62          if (isNullOrEmpty(name))
63              return name;
64  
65          if (name.length() == 1) {
66              return name.toLowerCase();
67          } else
68              return name.substring(0, 1).toLowerCase() + name.substring(1);
69      }
70  
71  }