public Object execute(VirtualFrame frame) {
    final Object childValue = child.execute(frame);

    if (!(RubyGuards.isRubyString(childValue)) && childValue != nil()) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(getContext().getCoreLibrary().typeErrorMustBe("$/", "String", this));
    }

    return childValue;
  }
Esempio n. 2
0
 private String toString(Object methodName) {
   if (methodName instanceof String) {
     return (String) methodName;
   } else if (RubyGuards.isRubyString(methodName)) {
     return methodName.toString();
   } else if (RubyGuards.isRubySymbol(methodName)) {
     return Layouts.SYMBOL.getString((DynamicObject) methodName);
   } else {
     throw new UnsupportedOperationException();
   }
 }
Esempio n. 3
0
 @Override
 public Object execute(VirtualFrame frame) {
   if (RubyGuards.isRubyString(ForeignAccess.getReceiver(frame))) {
     final DynamicObject string = (DynamicObject) ForeignAccess.getReceiver(frame);
     final int index = (int) ForeignAccess.getArguments(frame).get(labelIndex);
     if (index >= Layouts.STRING.getRope(string).byteLength()) {
       return 0;
     } else {
       return (byte) StringOperations.getByteListReadOnly(string).get(index);
     }
   } else {
     CompilerDirectives.transferToInterpreter();
     throw new IllegalStateException("Not implemented");
   }
 }
Esempio n. 4
0
  public static boolean isRopeBuffer(DynamicObject string) {
    assert RubyGuards.isRubyString(string);

    return rope(string) instanceof RopeBuffer;
  }
Esempio n. 5
0
 public static boolean isEmpty(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return Layouts.STRING.getRope(string).isEmpty();
 }
Esempio n. 6
0
 public static boolean isBrokenCodeRange(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return StringOperations.codeRange(string) == CodeRange.CR_BROKEN;
 }
Esempio n. 7
0
 public static boolean isValidUtf8(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return StringOperations.isCodeRangeValid(string)
       && Layouts.STRING.getRope(string).getEncoding().isUTF8();
 }
Esempio n. 8
0
 public static boolean isFixedWidthEncoding(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return Layouts.STRING.getRope(string).getEncoding().isFixedWidth();
 }
Esempio n. 9
0
 public static boolean isAsciiCompatible(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return Layouts.STRING.getRope(string).getEncoding().isAsciiCompatible();
 }
Esempio n. 10
0
 public static boolean is7Bit(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return StringOperations.codeRange(string) == CodeRange.CR_7BIT;
 }
Esempio n. 11
0
 public static boolean isSingleByteOptimizable(DynamicObject string) {
   assert RubyGuards.isRubyString(string);
   return Layouts.STRING.getRope(string).isSingleByteOptimizable();
 }