示例#1
0
 @Override
 public Pointer apply(SmartList<Pointer> args) {
   String[] split;
   if (args.isEmpty() || args.get(0).type == Constants.NULL_TYPE) {
     split = str.split(" ");
   } else {
     String regex = PointerTools.dereferenceString(args.get(0));
     split = str.split(regex);
   }
   SmartList<Pointer> list = new SmartList<Pointer>();
   for (String eachString : split) {
     list.add(Heap.allocateString(eachString));
   }
   return Heap.allocateList(list);
 }
/** @author Oliver Chu */
public class ViewStrings extends BuiltinSub {
  public static final Pointer EMPTY_LIST = Heap.allocateList(new SmartList<Pointer>());

  @Override
  public Pointer apply(SmartList<Pointer> args) throws MintException {
    short i = 0;
    while (i < Short.MAX_VALUE) {
      try {
        HashMap<Integer, String> strs = Heap.strings;
        if (strs == null) {
          return EMPTY_LIST;
        }
        Table tbl = new Table();
        ArrayList<Integer> keys = new ArrayList<Integer>();
        Set<Integer> s = strs.keySet();
        for (int element : s) {
          keys.add(element);
        }
        s = null;
        for (int key : keys) {
          SmartList<Pointer> pair = new SmartList<Pointer>();
          pair.add(new Pointer(Constants.INT_TYPE, key));
          pair.add(Heap.allocateString(strs.get(key)));
          tbl.addBinding(pair);
        }
        return Heap.allocateTable(tbl);
      } catch (Throwable t) {
      }
      ++i;
    }
    try {
      return Heap.allocateString(Heap.strings.toString());
    } catch (Throwable t) {
      return ChangeString.ERROR;
    }
  }
}