2 * $Id: StringDivider.java,v 1.1 2004-10-05 20:51:57 jsurfer Exp $
3 * Copyright Narushima Hironori. All rights reserved.
5 package net.sourceforge.phpeclipse.wizards.html;
7 import java.util.Arrays;
8 import java.util.regex.Pattern;
10 public class StringDivider {
12 static Pattern tagNameChoosePattern = Pattern.compile("<[\\s/]*(\\w+)\\s*.*>");
14 String[] splitRegexpCandidates = {
21 public StringDivider() {
24 public String[][] divide(String content){
25 return divide(content, getDivideSuitedRegexp(content));
28 public String[][] divide(String content, String regexp){
29 String[] lines = content.split("\n");
30 int len = lines.length;
31 String[][] dist = new String[len][];
33 int max = Integer.MIN_VALUE;
34 for (int i = 0; i < len; i++) {
35 String line = lines[i];
36 String[] cells = line.split(regexp);
38 if(max < cells.length){
42 for (int i = 0; i < len; i++) {
43 String[] newArray = new String[max];
44 Arrays.fill(newArray, "");
45 System.arraycopy(dist[i], 0, newArray, 0, dist[i].length);
51 public String getDivideSuitedRegexp(String content){
52 String[] lines = content.split("\n");
54 String resultRegexp = null;
55 int score = Integer.MAX_VALUE, cellCount = Integer.MIN_VALUE;
57 for (int i = 0; i < splitRegexpCandidates.length; i++) {
58 String regexp = splitRegexpCandidates[i];
59 int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
60 for (int j = 0; j < lines.length; j++) {
61 String[] vals = lines[j].split(regexp);
62 if(max < vals.length){
65 if(min > vals.length){
70 if( score > s || (score == s && max > cellCount)){
73 resultRegexp = regexp;