You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2021/09/29 14:37:48 UTC
[empire-db] branch master updated: EMPIREDB-354 add String truncate
method to StringUtils.
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new 1a188c9 EMPIREDB-354 add String truncate method to StringUtils.
1a188c9 is described below
commit 1a188c92627429b0e4ec625603e45ff5a451cd47
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Wed Sep 29 16:37:45 2021 +0200
EMPIREDB-354
add String truncate method to StringUtils.
---
.../main/java/org/apache/empire/commons/StringUtils.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
index 9b7a20a..edd9cde 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
@@ -568,4 +568,20 @@ public class StringUtils
return start.toLowerCase()+s.substring(count);
}
+ /**
+ * truncates a string to a maximum number of chars
+ * @param s the source string
+ * @param the maximum number of chars
+ * @return the result string
+ */
+ public static String truncate(String s, int maxChar)
+ {
+ if (isEmpty(s))
+ return StringUtils.EMPTY;
+ if (maxChar<1 || s.length()<maxChar)
+ return s;
+ // trunc
+ return s.substring(0, maxChar);
+ }
+
}