示例#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;
  }
示例#2
0
  // @RubyLevelMethod(name="upcase")
  public RubyString upcase() {
    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 < ca.length; i++) {
      ca[i] = Character.toUpperCase(ca[i]);
    }

    return ObjectFactory.createString(new StringBuffer().append(ca));
  }
示例#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));
  }