View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.dynamic.sql.util;
17  
18  public interface StringUtilities {
19  
20      static String spaceAfter(String in) {
21          return in + " "; //$NON-NLS-1$
22      }
23  
24      static String spaceBefore(String in) {
25          return " " + in; //$NON-NLS-1$
26      }
27  
28      static String toCamelCase(String inputString) {
29          StringBuilder sb = new StringBuilder();
30  
31          boolean nextUpperCase = false;
32  
33          for (int i = 0; i < inputString.length(); i++) {
34              char c = inputString.charAt(i);
35              if (Character.isLetterOrDigit(c)) {
36                  if (nextUpperCase) {
37                      sb.append(Character.toUpperCase(c));
38                      nextUpperCase = false;
39                  } else {
40                      sb.append(Character.toLowerCase(c));
41                  }
42              } else {
43                  if (!sb.isEmpty()) {
44                      nextUpperCase = true;
45                  }
46              }
47          }
48  
49          return sb.toString();
50      }
51  
52      static String formatConstantForSQL(String in) {
53          String escaped = in.replace("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
54          return "'" + escaped + "'"; //$NON-NLS-1$ //$NON-NLS-2$
55      }
56  
57      static <T> T upperCaseIfPossible(T value) {
58          if (value instanceof String) {
59              @SuppressWarnings("unchecked")
60              T t = (T) ((String) value).toUpperCase();
61              return t;
62          }
63  
64          return value;
65      }
66  }