01: /*******************************************************************************
02: * Copyright (c) 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * wharley@bea.com - initial API and implementation
10: *
11: *******************************************************************************/package org.eclipse.jdt.apt.pluggable.tests;
12:
13: import java.io.File;
14:
15: /**
16: * @since 3.3
17: */
18: public class TestUtils {
19:
20: /**
21: * Convert an array of strings into a path.
22: * E.g., turn { "a", "b", "c.d" } into a File representing "a/b/c.d".
23: */
24: public static File concatPath(String... names) {
25: StringBuilder sb = new StringBuilder();
26: for (int i = 0; i < names.length; ++i) {
27: if (i > 0) {
28: sb.append(File.separator);
29: }
30: sb.append(names[i]);
31: }
32: return new File(sb.toString());
33: }
34:
35: public static String convertToIndependentLineDelimiter(String source) {
36: if (source.indexOf('\n') == -1 && source.indexOf('\r') == -1)
37: return source;
38: StringBuffer buffer = new StringBuffer();
39: for (int i = 0, length = source.length(); i < length; i++) {
40: char car = source.charAt(i);
41: if (car == '\r') {
42: buffer.append('\n');
43: if (i < length - 1 && source.charAt(i + 1) == '\n') {
44: i++; // skip \n after \r
45: }
46: } else {
47: buffer.append(car);
48: }
49: }
50: return buffer.toString();
51: }
52: }
|