blob: e15dc5553f63c589b7d900388811b7120592e9e6 (
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
|
/*******************************************************************************
* Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
*******************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.xtext.glue.edit.part;
/**
* @author koehnlein
*/
public class StringUtil {
/**
* This element comes from the XText/GMF integration example, and was not originally documented.
* @param s
* @return int
*/
public static int[] getNumLinesNumColumns(String s) {
int numLines = 1;
int numColumns = 0;
int[] dimensions = new int[2] ;
dimensions[0] = numLines ;
dimensions[1] = 0 ;
for (char c : s.toCharArray()) {
if (c == '\n') {
++numLines;
dimensions[1] = Math.max(dimensions[1], numColumns) ;
numColumns = 0 ;
}
else {
++numColumns;
}
}
dimensions[0] = numLines ;
dimensions[1] = Math.max(dimensions[1], numColumns) ;
return dimensions;
}
}
|