private static ArrayList<ByteList> dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) { ArrayList<ByteList> dirs = new ArrayList<>(); for ( int i = 0; i < args.length; i++ ) { dirs.addAll(Dir.push_glob(context.runtime, cwd, globArgumentAsByteList(context, args[i]), flags)); } return dirs; }
private static ArrayList<ByteList> dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) { ArrayList<ByteList> dirs = new ArrayList<>(); for ( int i = 0; i < args.length; i++ ) { dirs.addAll(Dir.push_glob(context.runtime, cwd, globArgumentAsByteList(context, args[i]), flags)); } return dirs; }
private static List<ByteList> dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) { List<ByteList> dirs = new ArrayList<ByteList>(); for (int i = 0; i < args.length; i++) { dirs.addAll(Dir.push_glob(cwd, globArgumentAsByteList(context, args[i]), flags)); } return dirs; }
private static List<ByteList> dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) { List<ByteList> dirs = new ArrayList<ByteList>(); for (int i = 0; i < args.length; i++) { dirs.addAll(Dir.push_glob(cwd, globArgumentAsByteList(context, args[i]), flags)); } return dirs; }
private static String[] expandGlobs(Ruby runtime, String[] originalArgs) { List<String> expandedList = new ArrayList<String>(originalArgs.length); for (int i = 0; i < originalArgs.length; i++) { if (hasGlobCharacter(originalArgs[i])) { // FIXME: Encoding lost here List<ByteList> globs = Dir.push_glob(runtime, runtime.getCurrentDirectory(), new ByteList(originalArgs[i].getBytes()), 0); for (ByteList glob: globs) { expandedList.add(glob.toString()); } } else { expandedList.add(originalArgs[i]); } } String[] args = new String[expandedList.size()]; expandedList.toArray(args); return args; }
private static String[] expandGlobs(Ruby runtime, String[] originalArgs) { List<String> expandedList = new ArrayList<String>(originalArgs.length); for (int i = 0; i < originalArgs.length; i++) { if (hasGlobCharacter(originalArgs[i])) { // FIXME: Encoding lost here List<ByteList> globs = Dir.push_glob(runtime, runtime.getCurrentDirectory(), new ByteList(originalArgs[i].getBytes()), 0); for (ByteList glob: globs) { expandedList.add(glob.toString()); } } else { expandedList.add(originalArgs[i]); } } String[] args = new String[expandedList.size()]; expandedList.toArray(args); return args; }
dirs = Dir.push_glob(getCWD(runtime), globArgumentAsByteList(context, args[0]), 0); } else { dirs = dirGlobs(context, getCWD(runtime), args, 0);
dirs = Dir.push_glob(runtime, dir, globArgumentAsByteList(context, args[0]), flags[0]); } else { dirs = dirGlobs(context, dir, ((RubyArray) tmp).toJavaArray(), flags[0]);
dirs = Dir.push_glob(runtime, dir, globArgumentAsByteList(context, args[0]), flags[0]); } else { dirs = dirGlobs(context, dir, ((RubyArray) tmp).toJavaArray(), flags[0]);
@JRubyMethod(name = "[]", rest = true, meta = true) public static IRubyObject aref(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; List<ByteList> dirs; if (args.length == 1) { dirs = Dir.push_glob(getCWD(runtime), globArgumentAsByteList(context, args[0]), 0); } else { dirs = dirGlobs(context, getCWD(runtime), args, 0); } return asRubyStringList(runtime, dirs); }
@JRubyMethod(name = "[]", rest = true, meta = true) public static IRubyObject aref(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; String base = globOptions(context, args, null); List<ByteList> dirs; if (args.length == 1) { String dir = base == null || base.isEmpty() ? runtime.getCurrentDirectory() : base; dirs = Dir.push_glob(runtime, dir, globArgumentAsByteList(context, args[0]), 0); } else { IRubyObject[] arefArgs; if (base != null) { // kwargs are present arefArgs = ArraySupport.newCopy(args, args.length - 1); } else { arefArgs = args; base = ""; } String dir = base.isEmpty() ? runtime.getCurrentDirectory() : base; dirs = dirGlobs(context, dir, arefArgs, 0); } return asRubyStringList(runtime, dirs); }
@JRubyMethod(name = "[]", rest = true, meta = true) public static IRubyObject aref(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; String base = globOptions(context, args, null); List<ByteList> dirs; if (args.length == 1) { String dir = base == null || base.isEmpty() ? runtime.getCurrentDirectory() : base; dirs = Dir.push_glob(runtime, dir, globArgumentAsByteList(context, args[0]), 0); } else { IRubyObject[] arefArgs; if (base != null) { // kwargs are present arefArgs = ArraySupport.newCopy(args, args.length - 1); } else { arefArgs = args; base = ""; } String dir = base.isEmpty() ? runtime.getCurrentDirectory() : base; dirs = dirGlobs(context, dir, arefArgs, 0); } return asRubyStringList(runtime, dirs); }
/** * Returns an array of filenames matching the specified wildcard pattern * <code>pat</code>. If a block is given, the array is iterated internally * with each filename is passed to the block in turn. In this case, Nil is * returned. */ @JRubyMethod(required = 1, optional = 1, meta = true) public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; int flags = args.length == 2 ? RubyNumeric.num2int(args[1]) : 0; List<ByteList> dirs; IRubyObject tmp = args[0].checkArrayType(); if (tmp.isNil()) { dirs = Dir.push_glob(runtime.getCurrentDirectory(), globArgumentAsByteList(context, args[0]), flags); } else { dirs = dirGlobs(context, getCWD(runtime), ((RubyArray) tmp).toJavaArray(), flags); } if (block.isGiven()) { for (int i = 0; i < dirs.size(); i++) { Encoding enc = runtime.getDefaultExternalEncoding(); if (enc == null) { enc = UTF8; } block.yield(context, RubyString.newString(runtime, dirs.get(i), enc)); } return runtime.getNil(); } return asRubyStringList(runtime, dirs); }
/** * Returns an array of filenames matching the specified wildcard pattern * <code>pat</code>. If a block is given, the array is iterated internally * with each filename is passed to the block in turn. In this case, Nil is * returned. */ @JRubyMethod(required = 1, optional = 1, meta = true) public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; int flags = args.length == 2 ? RubyNumeric.num2int(args[1]) : 0; List<ByteList> dirs; IRubyObject tmp = args[0].checkArrayType(); if (tmp.isNil()) { dirs = Dir.push_glob(runtime.getCurrentDirectory(), globArgumentAsByteList(context, args[0]), flags); } else { dirs = dirGlobs(context, getCWD(runtime), ((RubyArray) tmp).toJavaArray(), flags); } if (block.isGiven()) { for (int i = 0; i < dirs.size(); i++) { Encoding enc = runtime.getDefaultExternalEncoding(); if (enc == null) { enc = UTF8; } block.yield(context, RubyString.newString(runtime, dirs.get(i), enc)); } return runtime.getNil(); } return asRubyStringList(runtime, dirs); }