From 1c852c25df52476b73aa6f6da7330f0cbf8e7753 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 9 Jul 2014 01:22:41 +0200 Subject: [PATCH] Add utility method shortening a string to a maximum length Change-Id: I6d354e065688b6dc1c891d4d95096ad57e6c8309 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/egit/core/internal/Utils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java index bca96ecd2..eb854fa07 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java @@ -63,4 +63,17 @@ public class Utils { } return result.toString(); } + + /** + * @param text + * @param maxLength + * @return {@code text} shortened to {@code maxLength} characters if its + * string length exceeds {@code maxLength} and an ellipsis is + * appended to the shortened text + */ + public static String shortenText(final String text, final int maxLength) { + if (text.length() > maxLength) + return text.substring(0, maxLength - 1) + "\u2026"; // ellipsis "…" (in UTF-8) //$NON-NLS-1$ + return text; + } } -- 2.11.4.GIT