Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84aef55addf17c981a90317aba3759bf0219e703 (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
49
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.externaltools.internal.launchConfigurations;

import java.util.Comparator;

public class IgnoreWhiteSpaceComparator implements Comparator<String> {

	@Override
	public int compare(String o1, String o2) {
		if (o1 == null || o2 == null) {
			if (o1 == o2) {
				return 0;
			}
			return -1;
		}
		int i1 = 0;
		int i2 = 0;
		int l1 = o1.length();
		int l2 = o2.length();
		char ch1 = ' ';
		char ch2 = ' ';
		while (i1 < l1 && i2 < l2) {
			while (i1 < l1 && Character.isWhitespace(ch1 = o1.charAt(i1))) {
				i1++;
			}
			while (i2 < l2 && Character.isWhitespace(ch2 = o2.charAt(i2))) {
				i2++;
			}
			if (i1 == l1 && i2 == l2) {
				return 0;
			}
			if (ch1 != ch2) {
				return -1;
			}
			i1++;
			i2++;
		}
		return 0;
	}
}

Back to the top