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;
  }
Exemplo 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();
   }
 }
Exemplo 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");
   }
 }
Exemplo n.º 4
0
  public static boolean isRopeBuffer(DynamicObject string) {
    assert RubyGuards.isRubyString(string);

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