Fix some of the warnings
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.edit / src / org / eclipse / emf / compare / provider / spec / Strings.java
blob38127db31bdf3c99fd2f6e588fd24b12640c59a5
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
7 *
8 * Contributors:
9 * Obeo - initial API and implementation
10 * Philip Langer - adds method removeLineBreaks(String)
11 *******************************************************************************/
12 package org.eclipse.emf.compare.provider.spec;
14 /**
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 {
21 /**
22 * Private constructor to avoid instantiation.
24 private Strings() {
27 /**
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}.
30 * <p>
31 * The returned String length will always be in {@code Math.min(original.length, max)}.
33 * @param original
34 * the original string to elide if necessary.
35 * @param max
36 * the maximum length of the returned string.
37 * @param suffix
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;
46 return original;
49 /**
50 * Removes line-breaks (\r\n or \r or \n) from the given {@code original} and replaces it with blanks.
52 * @param original
53 * the original string to remove line breaks from.
54 * @return the string without line breaks but blanks instead.
55 * @since 4.1
57 public static String removeLineBreaks(String original) {
58 return original.replaceAll("\\r\\n|\\r|\\n", " "); //$NON-NLS-1$ //$NON-NLS-2$