-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1681ef
commit ca11575
Showing
22 changed files
with
125 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/lyo-core-settings/src/main/java/org/eclipse/lyo/core/util/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 1.0 | ||
* which is available at http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.lyo.core.util; | ||
|
||
import java.text.Normalizer; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @since 7.0.0 | ||
*/ | ||
public class StringUtils { | ||
/** | ||
* Pattern to match control characters in the Unicode Cc category that are not CR, LF, or TAB | ||
*/ | ||
private static final Pattern CONTROL_CHAR_PATTERN = Pattern.compile("^\\p{Cc}&&[^\\r\\n\\t]+$"); | ||
|
||
/** | ||
* Trim and strip control chars (in the Unicode Cc category that are not CR, LF, or TAB) | ||
*/ | ||
public static String cleanWithoutNormalization(String str) { | ||
if (str == null) return null; | ||
|
||
return CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim(); | ||
} | ||
|
||
/** | ||
* Trim and strip control chars (in the Unicode Cc category that are not CR, LF, or TAB); | ||
* returns an empty string if a null is encountered | ||
*/ | ||
public static String cleanWithoutNormalizationNonNull(String str) { | ||
if (str == null) return ""; | ||
|
||
return CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim(); | ||
} | ||
|
||
/** | ||
* Trim, strip control chars (in the Unicode Cc category that are not CR, LF, or TAB), and | ||
* normalize the string to NFC as per W3C recommendations | ||
*/ | ||
public static String clean(String str) { | ||
if (str == null) return null; | ||
|
||
return Normalizer.normalize(CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim(), | ||
Normalizer.Form.NFC); | ||
} | ||
|
||
/** | ||
* Trim, strip control chars (in the Unicode Cc category that are not CR, LF, or TAB), and | ||
* normalize the string to NFC as per W3C recommendations; | ||
* returns an empty string if a null is encountered | ||
*/ | ||
public static String cleanNonNull(String str) { | ||
if (str == null) return ""; | ||
|
||
return Normalizer.normalize(CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim(), | ||
Normalizer.Form.NFC); | ||
} | ||
|
||
public static boolean isNullOrWhitespace(String str) { | ||
return str == null || str.isBlank(); | ||
} | ||
|
||
public static boolean isNullOrEmpty(String str) { | ||
return str == null || str.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.