public static String[] split(String s, String delimiter){
if (s == null) {
return null;
}
int delimiterLength;
int stringLength = s.length();
if (delimiter == null || (delimiterLength = delimiter.length()) == 0){
return new String[] {s};
}
// a two pass solution is used because a one pass solution would
// require the possible resizing and copying of memory structures
// In the worst case it would have to be resized n times with each
// resize having a O(n) copy leading to an O(n^2) algorithm.
int count;
int start;
int end;
// Scan s and count the tokens.
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
count++;
start = end + delimiterLength;
}
count++;
// allocate an array to return the tokens,
// we now know how big it should be
String[] result = new String[count];
// Scan s again, but this time pick out the tokens
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
result[count] = (s.substring(start, end));
count++;
start = end + delimiterLength;
}
end = stringLength;
result[count] = s.substring(start, end);
return (result);
}
|
(function($){
$.parser = {
auto: true,
plugins:['linkbutton','menu','menubutton','splitbutton','layout',
'tree','window','dialog','datagrid',
'combobox','combotree','numberbox','validatebox',
'calendar','datebox','panel','tabs','accordion'
],
parse: function(context){
if ($.parser.auto){
for(var i=0; i<$.parser.plugins.length; i++){
(function(){
var name = $.parser.plugins[i];
var r = $('.easyui-' + name, context);
if (r.length){
if (r[name]){
r[name]();
} else if (window.easyloader){
easyloader.load(name, function(){
r[name]();
})
}
}
})();
}
}
}
};
$(function(){
$.parser.parse();
});
})(jQuery);
|