/*
Splits a dir string into a dir Array and cleans up common issues.
321226
function splitDirs(dirString)
{
	var dirs,i,len;
	var output = [];
	
	// Speed optimization
	if (dirString !== "/")
	{
		dirs = dirString.split("/");
		len = dirs.length;
		
		for (i=0; i<len; i++)
		{
			// Cleanup -- splitting "/dir/" becomes ["","dir",""]
			if (dirs[i] !== "")
			{
				output.push( dirs[i] );
			}
		}
	}
	
	return output;
}
1009570
function getFolders(dir) {
  try {
    return fs.readdirSync(dir)
      .filter(function (file) {
        return exports.isDirectory(path.join(dir, file));
      });
  } catch (ex) {
    return [];
  }
}
852456
function readDir(dir) {
    var files = [];
    var root = fs.readdirSync(dir);
    var readMe = false;
    for (var i = 0; i < root.length; i++) {
        var filePath = dir + '/' + root[i];
        var stat = fs.statSync(filePath);
        //console.log(filePath,dir);
        filePath = path.relative(dir, filePath);
        if (stat && stat.isDirectory()) {
            files.push({
                dir: true,
                path: filePath
            });
        } else {
            files.push({
                dir: false,
                path: filePath
            });
        }

        // check if it is readme
        if(root[i].toLowerCase() === 'readme.md'){
            readMe = dir + '/' + root[i];
        }
    }
    return {
        files: files,
        readMe : readMe
    };
}
471083
private ArrayList<String> getFiles(String dir, String subDir) {
    ArrayList<String> files = new ArrayList<>();
    String fullDir = subDir == null ? dir : dir + File.separator + subDir;
    File[] listOfFiles = (new File(fullDir)).listFiles();
    if (listOfFiles != null) {
      for (File file : listOfFiles) {
        String fullName = subDir == null ? file.getName() : subDir + File.separator + file.getName();
        if (file.isFile()) {
          files.add(fullName);
        } else if (file.isDirectory()) {
          files.addAll(getFiles(dir, fullName));
        }
      }
    }
    return files;
  }
1206470
function splitNewlines(str) {
	if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
		return str.split('\n');
	}
	return str;
}
1247934
function splitByDot(str) {
    var result = [];
    var s = "";

    for (var i = 0; i < str.length; i++) {
        if (str[i] == "\\" && str[i+1] == ".") {
            i++;
            s += ".";
            continue;
        }

        if (str[i] == ".") {
            result.push(s);
            s = "";
            continue;
        }

        s += str[i];
    }

    if (s) {
        result.push(s);
    }

    return result;
}
450083
function split(arr, size) {
  var out = [];
  var sizes = [];
  var where = size - 1;
  var ptr = 0;
  var i, j;

  for (i = arr.length - 1; i >= 0; i--) {
    sizes[where] = (sizes[where] || 0) + 1;
    if (--where === -1) where = size - 1;
  }

  for (i = 0; i < size; i++) {
    for (j = 0; j < sizes[i]; j++) {
      if (j === 0) out[i] = [arr[ptr]];
      else out[i].push(arr[ptr]);
      ptr++;
    }
  }

  return out;
}
12295
function (path) {
            var result = path.match(splitPathRe) || [],
                root = result[1] || '',
                dir = result[2] || '';

            if (!root && !dir) {
                // No dirname
                return '.';
            }

            if (dir) {
                // It has a dirname, strip trailing slash
                dir = dir.substring(0, dir.length - 1);
            }

            return root + dir;
        }
1368760
function (path) {
    var pathSep = require('path').sep;
    var dirs = path.split(pathSep);
    var root = '';

    while (dirs.length > 0) {
      var dir = dirs.shift();
      if (dir === '') {
        root = pathSep;
      }
      if (!fs.existsSync(root + dir)) {
        fs.mkdirSync(root + dir);
      }
      root += dir + pathSep;
    }
  }
598099
def __split_path(string):
        
        out = []
        position = string.find(':')
        if position != -1:
            # A position of 0+ means that ":" was found in the string
            key = string[:position]
            val = string[position+1:]
            out.append(key)
            out.append(val)
            if ('-' in key) and ('Funding' not in key) and ('Grant' not in key):
                out = key.split('-')
                out.append(val)
        return out
55646
function splitPath(path) {
  if (Array.isArray(path)) {
    return path
  }
  if (path[0] === '/') {
    path = path.substr(1)
  }
  if (path[path.length-1] === '/') {
    path = path.substr(0, path.length-1)
  }
  return path.split('/')
}
1218637
def include_dir(self, root):
        """"""
        parts = [root]
        parts.extend(self.pathname.split(os.path.sep))
        return "/".join(parts)
447773
function mkdir(dirname, options = {}) {
  if (fs.existsSync(dirname)) return;
  assert.equal(typeof dirname, 'string', 'expected dirname to be a string');
  let opts = Object.assign({ cwd: process.cwd(), fs }, options);
  let mode = opts.mode || 0o777 & ~process.umask();
  let segs = path.relative(opts.cwd, dirname).split(path.sep);
  let make = dir => !exists(dir, opts) && fs.mkdirSync(dir, mode);
  for (let i = 0; i <= segs.length; i++) {
    try {
      make((dirname = path.join(opts.cwd, ...segs.slice(0, i))));
    } catch (err) {
      handleError(dirname, opts)(err);
    }
  }
  return dirname;
}
825093
public static List<String> splitString( String string, int limit ) {
        List<String> list = new ArrayList<String>();

        char[] chars = string.toCharArray();
        boolean endOfString = false;
        int start = 0;
        int end = start;
        while( start < chars.length - 1 ) {
            int charCount = 0;
            int lastSpace = 0;
            while( charCount < limit ) {
                if (chars[charCount + start] == ' ') {
                    lastSpace = charCount;
                }
                charCount++;
                if (charCount + start == string.length()) {
                    endOfString = true;
                    break;
                }
            }
            end = endOfString ? string.length() : (lastSpace > 0) ? lastSpace + start : charCount + start;
            list.add(string.substring(start, end));
            start = end + 1;
        }
        return list;
    }
600114
function readDir (dir, regex = /^(?:)$/) {
  return new Promise((resolve, reject) =>
    fs.readdir(dir, (err, files) => err
      ? reject(err)
      : resolve(Promise.all(files.map(checkFileName.bind(null, dir, regex))))))
    .then(values =>
      [].concat(...values)
        .filter(i => i))
}
1201819
function _split(source) {
  var buf = [];
  var reg = /'[^']+'|"[^"]+"|[^\s/=]+=?/g;
  reg.lastIndex = 0;
  var match = reg.exec(source);

  while (match) {
    buf.push(match);
    match = reg.exec(source);
  }

  return buf;
}
797642
private Node tryFoldStringSplit(Node n, Node stringNode, Node arg1) {
    if (late) {
      return n;
    }

    checkArgument(n.isCall());
    checkArgument(stringNode.isString());

    String separator = null;
    String stringValue = stringNode.getString();

    // Maximum number of possible splits
    int limit = stringValue.length() + 1;

    if (arg1 != null) {
      if (arg1.isString()) {
        separator = arg1.getString();
      } else if (!arg1.isNull()) {
        return n;
      }

      Node arg2 = arg1.getNext();
      if (arg2 != null) {
        if (arg2.isNumber()) {
          limit = Math.min((int) arg2.getDouble(), limit);
          if (limit < 0) {
            return n;
          }
        } else {
          return n;
        }
      }
    }

    // Split the string and convert the returned array into JS nodes
    String[] stringArray = jsSplit(stringValue, separator, limit);
    Node arrayOfStrings = IR.arraylit();
    for (String element : stringArray) {
      arrayOfStrings.addChildToBack(IR.string(element).srcref(stringNode));
    }

    Node parent = n.getParent();
    parent.replaceChild(n, arrayOfStrings);
    reportChangeToEnclosingScope(parent);
    return arrayOfStrings;
  }