1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Obeo and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Obeo - initial API and implementation
10 * Philip Langer - adds method removeLineBreaks(String)
11 *******************************************************************************/
12 package org
.eclipse
.emf
.compare
.provider
.spec
;
15 * Utility class for {@link String}s objects.
17 * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
19 public final class Strings
{
22 * Private constructor to avoid instantiation.
28 * Shorten the given {@code original} string and append the given {@code suffix} if it is longest than the
29 * defined {@code max} length minus the length of the {@code suffix}.
31 * The returned String length will always be in {@code Math.min(original.length, max)}.
34 * the original string to elide if necessary.
36 * the maximum length of the returned string.
38 * the suffix to append in case the original String is too long.
39 * @return the elided string or the original string.
41 public static String
elide(String original
, int max
, String suffix
) {
42 if (original
.length() > max
) {
43 String elided
= original
.substring(0, max
- suffix
.length());
44 return elided
+ suffix
;
50 * Removes line-breaks (\r\n or \r or \n) from the given {@code original} and replaces it with blanks.
53 * the original string to remove line breaks from.
54 * @return the string without line breaks but blanks instead.
57 public static String
removeLineBreaks(String original
) {
58 return original
.replaceAll("\\r\\n|\\r|\\n", " "); //$NON-NLS-1$ //$NON-NLS-2$