Esempio 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());
 }
Esempio 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;
 }
Esempio n. 3
0
    @Specialization
    public RubyRegexp initialize(RubyRegexp regexp, RubyString string) {
      notDesignedForCompilation();

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

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

      return getContext()
          .makeString(
              org.jruby.RubyRegexp.quote19(new ByteList(pattern.getBytes()), true).toString());
    }
Esempio 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));
    }
Esempio n. 7
0
 @Specialization
 public int getByte(RubyString string, int index) {
   return string.getBytes().get(index);
 }
Esempio n. 8
0
 @Specialization
 public RubyString concat(RubyString string, RubyString other) {
   string.getBytes().append(other.getBytes());
   return string;
 }
Esempio n. 9
0
 @Specialization
 public Object match(RubyRegexp regexp, RubyString string) {
   return regexp.matchCommon(string.getBytes(), false, false);
 }