Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5dcbab1a2b2f4bc44c9e1dc0db2d97d28b16bc80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************************************
 *  Copyright (c) 2008, 2017 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.core.helpers;

import java.util.ArrayList;
import java.util.List;

public class StringHelper {

	public static String[] EMPTY_ARRAY = new String[0];

	public static String[] getArrayFromString(String spec, char c) {
		String[] resultArr = EMPTY_ARRAY;
		if (spec != null) {
			int splitIdx = spec.indexOf(c);
			if (splitIdx <= 0) {
				spec = spec.trim();
				if (spec.length() > 0)
					resultArr = new String[] {spec};
			} else {
				List<String> result = new ArrayList<>();
				while (splitIdx >= 0) {
					String part = spec.substring(0, splitIdx).trim();
					if (part.length() > 0)
						result.add(part);
					spec = spec.substring(splitIdx + 1);
					splitIdx = spec.indexOf(c);
				}
				spec = spec.trim();
				if (spec.length() > 0)
					result.add(spec);
				resultArr = result.toArray(new String[result.size()]);
			}
		}
		return resultArr;
	}
}

Back to the top