com.nflabs.zeppelin.util.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zeppelin-zengine Show documentation
Show all versions of zeppelin-zengine Show documentation
Zengine is java framework for data analysis on Hadoop. see http://nflabs.github.io/zeppelin/#/zengine
package com.nflabs.zeppelin.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Util {
public static String [] split(String str, char split){
return split(str, new String[]{String.valueOf(split)}, false);
}
public static String [] split(String str, String [] splitters, boolean includeSplitter){
String escapeSeq = "\"',;<%>";
char escapeChar = '\\';
String [] blockStart = new String[]{ "\"", "'", "<%" };
String [] blockEnd = new String[]{ "\"", "'", "%>" };
return split(str, escapeSeq, escapeChar, blockStart, blockEnd, splitters, includeSplitter);
}
public static String [] split(
String str,
String escapeSeq,
char escapeChar,
String [] blockStart,
String [] blockEnd,
String [] splitters,
boolean includeSplitter
){
List splits = new ArrayList();
String curString ="";
int ignoreBlockIndex = -1;
boolean escape = false; // true when escape char is found
int lastEscapeOffset = -1;
for(int i=0; i=0){ // inside of block
curString += c;
// check if block is finishing
if(curString.substring(lastEscapeOffset+1).endsWith(blockEnd[ignoreBlockIndex])){
ignoreBlockIndex = -1;
continue;
}
} else { // not in the block
boolean splitted = false;
for(String splitter : splitters){
// forward check for splitter
if(splitter.compareTo(str.substring(i, Math.min(i+splitter.length(), str.length())))==0){
splits.add(curString);
if(includeSplitter==true){
splits.add(splitter);
}
curString = "";
lastEscapeOffset = -1;
i+=splitter.length()-1;
splitted = true;
break;
}
}
if(splitted == true){
continue;
}
// add char to current string
curString += c;
// check if block is started
for(int b=0; b0)
splits.add(curString.trim());
return splits.toArray(new String[]{});
}
}