Ejemplo n.º 1
0
 @Specialization
 public RubyArray unpack(RubyString string, RubyString format) {
   final org.jruby.RubyArray jrubyArray =
       Pack.unpack(getContext().getRuntime(), string.getBytes(), format.getBytes());
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), jrubyArray.toArray());
 }
Ejemplo n.º 2
0
 @Specialization
 public RubyString add(RubyString a, RubyString b) {
   // TODO(CS): which encoding do we get here?
   final RubyString string =
       new RubyString(getContext().getCoreLibrary().getStringClass(), new ByteList());
   string.getBytes().append(a.getBytes());
   string.getBytes().append(b.getBytes());
   return string;
 }
Ejemplo n.º 3
0
    @Specialization
    public RubyRegexp initialize(RubyRegexp regexp, RubyString string) {
      notDesignedForCompilation();

      regexp.initialize(this, string.getBytes());
      return regexp;
    }
Ejemplo n.º 4
0
    @Specialization
    public Object match(RubyRegexp regexp, RubyString string) {
      notDesignedForCompilation();

      return regexp.matchCommon(string.getBytes(), true, false)
          != getContext().getCoreLibrary().getNilObject();
    }
Ejemplo n.º 5
0
    @Specialization
    public RubyString escape(RubyString pattern) {
      notDesignedForCompilation();

      return getContext()
          .makeString(
              org.jruby.RubyRegexp.quote19(new ByteList(pattern.getBytes()), true).toString());
    }
Ejemplo n.º 6
0
    @Specialization
    public RubyArray chomp(RubyString string) {
      final byte[] bytes = string.getBytes().bytes();

      final int[] ints = new int[bytes.length];

      for (int n = 0; n < ints.length; n++) {
        ints[n] = RubyFixnum.toUnsignedInt(bytes[n]);
      }

      return new RubyArray(
          getContext().getCoreLibrary().getArrayClass(), new IntegerArrayStore(ints));
    }
Ejemplo n.º 7
0
 @Specialization
 public int getByte(RubyString string, int index) {
   return string.getBytes().get(index);
 }
Ejemplo n.º 8
0
 @Specialization
 public RubyString concat(RubyString string, RubyString other) {
   string.getBytes().append(other.getBytes());
   return string;
 }
Ejemplo n.º 9
0
 @Specialization
 public Object match(RubyRegexp regexp, RubyString string) {
   return regexp.matchCommon(string.getBytes(), false, false);
 }