Exemplo n.º 1
0
  // @RubyLevelMethod(name="swapcase!")
  public RubyValue swapcaseBang() {
    int length = this.sb_.length();
    if (length == 0) {
      return RubyConstant.QNIL;
    }

    char[] ca = new char[length];
    this.sb_.getChars(0, length, ca, 0);
    boolean modify = false;

    for (int i = 0; i < length; i++) {
      char c = ca[i];
      if (Character.isUpperCase(c)) {
        ca[i] = Character.toLowerCase(c);
        modify = true;
      } else if (Character.isLowerCase(c)) {
        ca[i] = Character.toUpperCase(c);
        modify = true;
      }
    }

    this.sb_.delete(0, ca.length).append(ca);
    if (modify) return this;

    return RubyConstant.QNIL;
    //        return modify ? this : RubyConstant.QNIL;
  }
Exemplo n.º 2
0
  // @RubyLevelMethod(name="capitalize")
  public RubyString capitalize() {
    int length = this.sb_.length();
    if (length == 0) {
      return ObjectFactory.createString();
    }

    char[] ca = new char[length];
    this.sb_.getChars(0, length, ca, 0);

    ca[0] = Character.toUpperCase(ca[0]);
    for (int i = 1; i < length; i++) {
      ca[i] = Character.toLowerCase(ca[i]);
    }

    return ObjectFactory.createString(new StringBuffer().append(ca));
  }
Exemplo n.º 3
0
  // @RubyLevelMethod(name="swapcase")
  public RubyString swapcase() {
    int length = this.sb_.length();
    if (length == 0) {
      return ObjectFactory.createString();
    }

    char[] ca = new char[length];
    this.sb_.getChars(0, length, ca, 0);

    for (int i = 0; i < length; i++) {
      char c = ca[i];
      if (Character.isUpperCase(c)) {
        ca[i] = Character.toLowerCase(c);
      } else if (Character.isLowerCase(c)) {
        ca[i] = Character.toUpperCase(c);
      }
    }

    return ObjectFactory.createString(new StringBuffer().append(ca));
  }