Class: String

Inherits:
Object show all
Defined in:
lib/source/ruby.rb

Overview

A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using String::new or as literals. Typically, methods with names ending in “!” modify their receiver, while those without a “!” return a new String.

Instance Method Summary collapse

Constructor Details

#initialize(string = `''`) ⇒ String

call-seq:

String.new(str = '') -> string

Returns a new string object containing a copy of str.



5257
5258
5259
# File 'lib/source/ruby.rb', line 5257

def initialize(string = `''`)
  `this._value=string._value||string`
end

Instance Method Details

#%(arg) ⇒ Object

call-seq:

str % arg -> string

Format – uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array containing the values to be substituted. See Kernel::sprintf for details of the format string.

"%05d" % 123                        #=> "00123"
"%s: %08x" % ['ID', self.__id__]    #=> "ID: 200e14d6"


5273
5274
5275
5276
# File 'lib/source/ruby.rb', line 5273

def %(arg)
  `arg.m$class()==c$Array?arg.unshift(this):arg=[this,arg]`
  `m$sprintf.apply(null,arg)`
end

#*(n) ⇒ Object

call-seq:

str * num -> string

Copy – returns a new string containing num copies of str.

'abc ' * 3    #=> "abc abc abc "


5285
5286
5287
5288
# File 'lib/source/ruby.rb', line 5285

def *(n)
  `for(var i=0,str=this._value,result='';i<n;++i){result+=str;}`
  return `$q(result)`
end

#+(str) ⇒ Object

call-seq:

str + other -> string

Concatenation – returns a new string containing other concatenated to str.

'abc' + 'def'   #=> 'abcdef'


5298
5299
5300
# File 'lib/source/ruby.rb', line 5298

def +(str)
  `$q(this._value + str._value)`
end

#<<(obj) ⇒ Object

call-seq:

str << num      -> str
str << obj      -> str
str.concat(num) -> str
str.concat(obj) -> str

Append – concatenates the given object to str. If the object is an integer between 0 and 255, it is converted to a character before concatenation.

s = 'abc'

s << 'def'         #=> "abcdef"
s << 103 << 104    #=> "abcdefgh"


5317
5318
5319
5320
# File 'lib/source/ruby.rb', line 5317

def <<(obj)
  `this._value+=(typeof(obj)=='number'?String.fromCharCode(obj):obj._value)`
  return self
end

#<=>(str) ⇒ Object

call-seq:

str <=> other -> -1, 0, 1

Comparison – returns -1 if other is less than, 0 if other is equal to, and 1 if other is greater than str. If the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered greater than the shorter one.

<=> is the basis for the methods <, <=, >, >=, and between?, included from module Comparable. The method String#== does not use Comparable#==.

'abcdef' <=> 'abcde'     #=> 1
'abcdef' <=> 'abcdef'    #=> 0
'abcdef' <=> 'abcdefg'   #=> -1
'abcdef' <=> 'ABCDEF'    #=> 1


5341
5342
5343
5344
5345
5346
5347
5348
# File 'lib/source/ruby.rb', line 5341

def <=>(str)
  `if(str.m$class()!=c$String){return nil;}`
  `var tv=this._value,sv=str._value`
  `if(tv>sv){return 1;}`
  `if(tv==sv){return 0;}`
  `if(tv<sv){return -1;}`
  return nil
end

#==(str) ⇒ Object

call-seq:

str == other -> true or false

Equality – if other is not a String, returns false. Otherwise, returns true if str <=> obj returns zero.



5356
5357
5358
5359
# File 'lib/source/ruby.rb', line 5356

def ==(str)
  `if(str.m$class()!=c$String){return false;}`
  return `this.m$_ltgt(str)==0`
end

#=~(str) ⇒ Object

FIX: Incomplete



5362
5363
# File 'lib/source/ruby.rb', line 5362

def =~(str)
end

#[]Object

call-seq:

str[num]               -> integer or nil
str[num, num]          -> string or nil
str[range]             -> string or nil
str[regexp]            -> string or nil
str[regexp, num]       -> string or nil
str[other]             -> string or nil
str.slice(num)         -> integer or nil
str.slice(num, num)    -> string or nil
str.slice(range)       -> string or nil
str.slice(regexp)      -> string or nil
str.slice(regexp, num) -> string or nil
str.slice(other)       -> string or nil

FIX: Incomplete



5380
5381
# File 'lib/source/ruby.rb', line 5380

def []
end

#[]=Object

call-seq:

str[num] = num            -> num
str[num] = string         -> string
str[num, num] = string    -> string
str[range] = string       -> string
str[regexp] = string      -> string
str[regexp, num] = string -> string
str[other] = string       -> string

FIX: Incomplete



5393
5394
# File 'lib/source/ruby.rb', line 5393

def []=
end

#capitalizeObject

call-seq:

str.capitalize -> string

Returns a copy of str with the first character converted to uppercase and the remainder to lowercase.

'abcdef'.capitalize   #=> "Abcdef"
'ABCDEF'.capitalize   #=> "Abcdef"
'123ABC'.capitalize   #=> "123abc"


5406
5407
5408
5409
# File 'lib/source/ruby.rb', line 5406

def capitalize
  `var v=this._value`
  `$q(v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase())`
end

#capitalize!Object

call-seq:

str.capitalize! -> str or nil

Returns str with the first character converted to uppercase and the remainder to lowercase, or nil if no changes were made.

s = 'abcdef'

s.capitalize!   #=> "Abcdef"
s.capitalize!   #=> nil
s               #=> "Abcdef"


5423
5424
5425
5426
5427
# File 'lib/source/ruby.rb', line 5423

def capitalize!
  `var v=this._value`
  `this._value=v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase()`
  return `v==this._value?nil:this`
end

#casecmp(str) ⇒ Object

call-seq:

str.casecmp(other) -> -1, 0, 1

Case-insensitive version of String#<=>.

'abcdef'.casecmp('abcde')     #=> 1
'aBcDeF'.casecmp('abcdef')    #=> 0
'abcdef'.casecmp('abcdefg')   #=> -1
'abcdef'.casecmp('ABCDEF')    #=> 0


5439
5440
5441
5442
5443
5444
5445
5446
# File 'lib/source/ruby.rb', line 5439

def casecmp(str)
  `if(str.m$class()!=c$String){return nil;}`
  `var tv=this._value.toLowerCase(),sv=str._value.toLowerCase()`
  `if(tv>sv){return 1;}`
  `if(tv==sv){return 0;}`
  `if(tv<sv){return -1;}`
  return nil
end

#centerObject

FIX: Incomplete



5449
5450
# File 'lib/source/ruby.rb', line 5449

def center
end

#chompObject

FIX: Incomplete



5453
5454
# File 'lib/source/ruby.rb', line 5453

def chomp
end

#chomp!Object

FIX: Incomplete



5457
5458
# File 'lib/source/ruby.rb', line 5457

def chomp!
end

#chopObject

FIX: Incomplete



5461
5462
# File 'lib/source/ruby.rb', line 5461

def chop
end

#chop!Object

FIX: Incomplete



5465
5466
# File 'lib/source/ruby.rb', line 5465

def chop!
end

#concat(obj) ⇒ Object

call-seq:

str << num      -> str
str << obj      -> str
str.concat(num) -> str
str.concat(obj) -> str

Append – concatenates the given object to str. If the object is an integer between 0 and 255, it is converted to a character before concatenation.

a = 'abc'

a.concat('def')              #=> "abcdef"
a.concat(103).concat(104)    #=> "abcdefgh"


5483
5484
5485
5486
# File 'lib/source/ruby.rb', line 5483

def concat(obj)
  `this._value+=(typeof(obj)=='number'?String.fromCharCode(obj):obj._value)`
  return self
end

#countObject

FIX: Incomplete



5489
5490
# File 'lib/source/ruby.rb', line 5489

def count
end

#cryptObject

FIX: Incomplete



5493
5494
# File 'lib/source/ruby.rb', line 5493

def crypt
end

#deleteObject

FIX: Incomplete



5497
5498
# File 'lib/source/ruby.rb', line 5497

def delete
end

#delete!Object

FIX: Incomplete



5501
5502
# File 'lib/source/ruby.rb', line 5501

def delete!
end

#downcaseObject

call-seq:

str.downcase -> string

Returns a copy of str with all uppercase letters replaced with their lowercase counterparts.

'aBCDEf'.downcase   #=> "abcdef"


5512
5513
5514
# File 'lib/source/ruby.rb', line 5512

def downcase
  `$q(this._value.toLowerCase())`
end

#downcase!Object

call-seq:

str.downcase! -> str or nil

Returns str with all uppercase letters replaced with their lowercase counterparts, or nil if no changes were made.

s = 'aBCDEf'

s.downcase!   #=> "abcdef"
s.downcase!   #=> nil
s             #=> "abcdef"


5528
5529
5530
5531
5532
# File 'lib/source/ruby.rb', line 5528

def downcase!
  `var v=this._value`
  `this._value=v.toLowerCase()`
  return `v==this._value?nil:this`
end

#eachObject

FIX: Incomplete



5535
5536
# File 'lib/source/ruby.rb', line 5535

def each
end

#each_byteObject

FIX: Incomplete



5539
5540
# File 'lib/source/ruby.rb', line 5539

def each_byte
end

#each_lineObject

FIX: Incomplete



5543
5544
# File 'lib/source/ruby.rb', line 5543

def each_line
end

#empty?Boolean

call-seq:

str.empty? -> true or false

Returns true if str has a length of zero.

'abcdef'.empty?   #=> false
''.empty?         #=> true

Returns:

  • (Boolean)


5554
5555
5556
# File 'lib/source/ruby.rb', line 5554

def empty?
  `this._value==''`
end

#eql?(str) ⇒ Boolean

call-seq:

str.eql?(other) -> true or false

Two strings are equal if they have the same length and content.

Returns:

  • (Boolean)


5563
5564
5565
5566
# File 'lib/source/ruby.rb', line 5563

def eql?(str)
  `if(str.m$class()!=c$String){return false;}`
  `this._value==str._value`
end

#gsubObject

FIX: Incomplete



5569
5570
# File 'lib/source/ruby.rb', line 5569

def gsub
end

#gsub!Object

FIX: Incomplete



5573
5574
# File 'lib/source/ruby.rb', line 5573

def gsub!
end

#hashObject

:nodoc:



5576
5577
5578
# File 'lib/source/ruby.rb', line 5576

def hash # :nodoc:
  `'q_'+this._value`
end

#hexObject

call-seq:

str.hex -> num

Treats leading characters from str as a string of hexadecimal digits (with an optional sign and an optional 0x) and returns the corresponding number. Zero is returned on error.

'0x0a'.hex      #=> 10
'-1234'.hex     #=> -4660
'0'.hex         #=> 0
'abcdef'.hex    #=> 0


5592
5593
5594
5595
# File 'lib/source/ruby.rb', line 5592

def hex
  `var result=parseInt(this._value,16)`
  return `result.toString()=='NaN'?0:result`
end

#include?(obj) ⇒ Boolean

call-seq:

str.include?(other) -> true or false
str.include?(num)   -> true or false

Returns true if str contains the given string or character.

'abcdef'.include?('bc')   #=> true
'abcdef'.include?('xy')   #=> false
'abcdef'.include?(?c)     #=> true

Returns:

  • (Boolean)


5607
5608
5609
# File 'lib/source/ruby.rb', line 5607

def include?(obj)
  `new(RegExp)(typeof(obj)=='number'?String.fromCharCode(obj):obj._value).test(this._value)`
end

#indexObject

FIX: Incomplete



5612
5613
# File 'lib/source/ruby.rb', line 5612

def index
end

#insertObject

FIX: Incomplete



5616
5617
# File 'lib/source/ruby.rb', line 5616

def insert
end

#inspectObject

FIX: Incomplete



5620
5621
5622
# File 'lib/source/ruby.rb', line 5620

def inspect
  `$q('"'+this._value.replace(/\\\\/g,'\\\\\\\\').replace(/"/g,'\\\\"')+'"')`
end

#internObject

call-seq:

str.intern -> symbol
str.to_sym -> symbol

Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See also Symbol#id2name.

'abcdef'.intern   #=> :abcdef


5633
5634
5635
# File 'lib/source/ruby.rb', line 5633

def intern
  `$s(this._value)`
end

#lengthObject

call-seq:

str.length -> integer
str.size   -> integer

Returns the number of characters in str.

'abcdef'.length   #=> 6
'ab\ncd'.length   #=> 5


5646
5647
5648
# File 'lib/source/ruby.rb', line 5646

def length
  `this._value.length`
end

#ljustObject

FIX: Incomplete



5651
5652
# File 'lib/source/ruby.rb', line 5651

def ljust
end

#lstripObject

call-seq:

str.lstrip -> string

Returns a copy of str with leading whitespace removed.

'  abcdef'.lstrip   #=> "abcdef"
'\tabcdef'.lstrip   #=> "abcdef"


5662
5663
5664
# File 'lib/source/ruby.rb', line 5662

def lstrip
  `$q(this._value.replace(/^\\s*/,''))`
end

#lstrip!Object

call-seq:

str.lstrip! -> str

Returns str with leading whitespace removed, or nil if no changes were made.

s = '    abcdef'

s.lstrip!   #=> "abcdef"
s.lstrip!   #=> nil
s           #=> "abcdef"


5678
5679
5680
5681
5682
# File 'lib/source/ruby.rb', line 5678

def lstrip!
  `var v=this._value`
  `this._value=v.replace(/^\\s*/,'')`
  return `this._value==v?nil:this`
end

#match(pattern) ⇒ Object

call-seq:

str.match(pattern) -> matchdata or nil

Converts pattern to a Regexp (if it isn’t already one), then invokes its match method on str.

'abcdee'.match('(.)\1')       #=> #<MatchData:120>
'abcdee'.match('(.)\1')[0]    #=> "ee"
'abcdee'.match(/(.)\1/)[0]    #=> "ee"
'abcdee'.match('xx')          #=> nil


5695
5696
5697
# File 'lib/source/ruby.rb', line 5695

def match(pattern)
  `$r(pattern._source||pattern._value,pattern._options).m$match(this)`
end

#nextObject

call-seq:

str.next -> string
str.succ -> string

Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case.

If the increment generates a “carry,” the character to the left is also incremented. This process repeats until there is no carry, adding an additional character of the same type as the leftmost alphanumeric, if necessary.

'abcdef'.next     #=> 'abcdeg'
'<<kit9>>'.next   #=> '<<kit10>>'
'1999zzz'.next    #=> '2000aaa'
'ZZZ9999'.next    #=> 'AAAA0000'


5719
5720
5721
5722
5723
5724
5725
5726
# File 'lib/source/ruby.rb', line 5719

def next
  `var v=this._value`
  `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
  `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
  `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
  `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
  return `$q(result)`
end

#next!Object

call-seq:

str.next! -> str
str.succ! -> str

Returns str with its contents replaced by its successor. See String#next for details.



5735
5736
5737
5738
5739
5740
5741
5742
5743
# File 'lib/source/ruby.rb', line 5735

def next!
  `var v=this._value`
  `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
  `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
  `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
  `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
  `this._value=result`
  return self
end

#octObject

call-seq:

str.oct -> num

Treats leading characters from str as a string of hexadecimal digits (with an optional sign) and returns the corresponding number. Zero is returned on error.

'0123'.oct      #=> 83
'-337'.hex      #=> -255
'0'.hex         #=> 0
'abcdef'.hex    #=> 0


5757
5758
5759
5760
# File 'lib/source/ruby.rb', line 5757

def oct
  `var result=parseInt(this._value,8)`
  return `result.toString()=='NaN'?0:result`
end

#replace(str) ⇒ Object

call-seq:

str.replace(other) -> str

Replaces the contents of str with the contents of other.

s = 'abc'

s.replace('def')    #=> "def"
s                   #=> "def"


5772
5773
5774
# File 'lib/source/ruby.rb', line 5772

def replace(str)
  `this._value=str._value`
end

#reverseObject

call-seq:

str.reverse -> string

Returns a new string with the characters from str in reverse order.

'abcdef'.reverse    #=> 'fedcba'


5783
5784
5785
# File 'lib/source/ruby.rb', line 5783

def reverse
  `$q(this._value.split('').reverse().join(''))`
end

#reverse!Object

call-seq:

str.reverse! -> str

Returns str with its characters reversed.

s = 'abcdef'

s.reverse!    #=> 'fedcba'
s             #=> 'fedcba'


5797
5798
5799
5800
# File 'lib/source/ruby.rb', line 5797

def reverse!
  `this._value=this._value.split('').reverse().join('')`
  return self
end

#rindexObject

FIX: Incomplete



5803
5804
# File 'lib/source/ruby.rb', line 5803

def rindex
end

#rjustObject

FIX: Incomplete



5807
5808
# File 'lib/source/ruby.rb', line 5807

def rjust
end

#rstripObject

call-seq:

str.rstrip -> string

Returns a copy of str with trailing whitespace removed.

'abcdef    '.rstrip   #=> "abcdef"
'abcdef\r\n'.rstrip   #=> "abcdef"


5818
5819
5820
# File 'lib/source/ruby.rb', line 5818

def rstrip
  `$q(this._value.replace(/\\s*$/,''))`
end

#rstrip!Object

call-seq:

str.rstrip! -> str

Returns str with trailing whitespace removed, or nil if no changes were made.

s = 'abcdef    '

s.rstrip!   #=> "abcdef"
s.rstrip!   #=> nil
s           #=> "abcdef"


5834
5835
5836
5837
5838
# File 'lib/source/ruby.rb', line 5834

def rstrip!
  `var v=this._value`
  `this._value=v.replace(/\\s*$/,'')`
  return `this._value==v?nil:this`
end

#scanObject

FIX: Incomplete



5841
5842
# File 'lib/source/ruby.rb', line 5841

def scan
end

#sizeObject

call-seq:

str.length -> integer
str.size   -> integer

Returns the number of characters in str.

'abcdef'.size   #=> 6
'ab\ncd'.size   #=> 5


5853
5854
5855
# File 'lib/source/ruby.rb', line 5853

def size
  `this._value.length`
end

#sliceObject

call-seq:

str[num]               -> integer or nil
str[num, num]          -> string or nil
str[range]             -> string or nil
str[regexp]            -> string or nil
str[regexp, num]       -> string or nil
str[other]             -> string or nil
str.slice(num)         -> integer or nil
str.slice(num, num)    -> string or nil
str.slice(range)       -> string or nil
str.slice(regexp)      -> string or nil
str.slice(regexp, num) -> string or nil
str.slice(other)       -> string or nil

FIX: Incomplete



5872
5873
# File 'lib/source/ruby.rb', line 5872

def slice
end

#slice!Object

call-seq:

str.slice!(num)      -> num or nil
str.slice!(num, num) -> string or nil
str.slice!(range)    -> string or nil
str.slice!(regexp)   -> string or nil
str.slice!(other)    -> string or nil

FIX: Incomplete



5883
5884
# File 'lib/source/ruby.rb', line 5883

def slice!
end

#split(pattern = /\s+/, limit = nil) ⇒ Object

FIX: Incomplete



5887
5888
5889
5890
5891
# File 'lib/source/ruby.rb', line 5887

def split(pattern = /\s+/, limit = nil)
  `var a=this._value.split(pattern._value),result=[]`
  `for(var i=0,l=a.length;i<l;++i){result.push($q(a[i]));}`
  return `result`
end

#squeezeObject

FIX: Incomplete



5894
5895
# File 'lib/source/ruby.rb', line 5894

def squeeze
end

#stripObject

call-seq:

str.strip -> string

Returns a copy of str with leading and trailing whitespace removed.

'   abcdef   '.strip    #=> "abcdef"
'\tabcdef\r\n'.strip    #=> "abcdef"


5905
5906
5907
# File 'lib/source/ruby.rb', line 5905

def strip
  `$q(this._value.replace(/^\\s*|\\s*$/,''))`
end

#strip!Object

call-seq:

str.strip! -> str

Returns str with leading and trailing whitespace removed, or nil if no changes were made.

s = '   abcdef   '

s.strip!    #=> "abcdef"
s.strip!    #=> nil
s           #=> "abcdef"


5921
5922
5923
5924
5925
# File 'lib/source/ruby.rb', line 5921

def strip!
  `var v=this._value`
  `this._value=v.replace(/^\\s*|\\s*$/,'')`
  return `this._value==v?nil:this`
end

#subObject

FIX: Incomplete



5928
5929
# File 'lib/source/ruby.rb', line 5928

def sub
end

#sub!Object

FIX: Incomplete



5932
5933
# File 'lib/source/ruby.rb', line 5932

def sub!
end

#succObject

call-seq:

str.next -> string
str.succ -> string

Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case.

If the increment generates a “carry,” the character to the left is also incremented. This process repeats until there is no carry, adding an additional character of the same type as the leftmost alphanumeric, if necessary.

'abcdef'.succ     #=> 'abcdeg'
'<<kit9>>'.succ   #=> '<<kit10>>'
'1999zzz'.succ    #=> '2000aaa'
'ZZZ9999'.succ    #=> 'AAAA0000'


5955
5956
5957
5958
5959
5960
5961
5962
# File 'lib/source/ruby.rb', line 5955

def succ
  `var v=this._value`
  `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
  `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
  `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
  `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
  return `$q(result)`
end

#succ!Object

call-seq:

str.next! -> str
str.succ! -> str

Returns str with its contents replaced by its successor. See String#next for details.



5971
5972
5973
5974
5975
5976
5977
5978
5979
# File 'lib/source/ruby.rb', line 5971

def succ!
  `var v=this._value`
  `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
  `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
  `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
  `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
  `this._value=result`
  return self
end

#sumObject

FIX: Incomplete



5982
5983
# File 'lib/source/ruby.rb', line 5982

def sum
end

#swapcaseObject

call-seq:

str.swapcase -> string

Returns a copy of str with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase.

'aBc123'.swapcase   #=> "AbC123"


5993
5994
5995
# File 'lib/source/ruby.rb', line 5993

def swapcase
  `$q(this._value.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();}))`
end

#swapcase!Object

call-seq:

str.swapcase! -> str or nil

Returns str with its uppercase alphabetic characters converted to lowercase and its lowercase characters converted to uppercase, or nil if no changes were made.

s1 = 'abcDEF'
s2 = '123'

s1.swapcase!    #=> "ABCdef"
s2.swapcase!    #=> nil
s1              #=> "ABCdef"
s2              #=> "123"


6012
6013
6014
6015
6016
# File 'lib/source/ruby.rb', line 6012

def swapcase!
  `var v=this._value`
  `this._value=v.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();})`
  return `this._value==v?nil:this`
end

#to_fObject

call-seq:

str.to_f -> float

Returns the result of interpreting leading characters in str as a floating point number, or 0 if there is not a valid number at the start of str.

'1.2345e3'.to_f       #=> 1234.5
'98.6 degrees'.to_f   #=> 98.6
'abc123'.to_f         #=> 0


6029
6030
6031
6032
# File 'lib/source/ruby.rb', line 6029

def to_f
  `var result=parseFloat(this)`
  return `result.toString()=='NaN'?0:result`
end

#to_i(base = 10) ⇒ Object

call-seq:

str.to_i -> integer

Returns the result of interpreting leading characters in str as an integer of base base, or 0 if there is not a valid number at the start of str.

'12345'.to_i          #=> 12345
'76 trombones'.to_i   #=> 76
'0a'.to_i             #=> 0
'0a'.to_i(16)         #=> 10
'abcdef'.to_i         #=> 0
'1100101'.to_i(2)     #=> 101
'1100101'.to_i(8)     #=> 294977
'1100101'.to_i(10)    #=> 1100101
'1100101'.to_i(16)    #=> 17826049


6051
6052
6053
6054
# File 'lib/source/ruby.rb', line 6051

def to_i(base = 10)
  `var result=parseInt(this,base)`
  return `result.toString()=='NaN'?0:result`
end

#to_sObject

call-seq:

str.to_s   -> str
str.to_str -> str

Returns str.



6062
6063
6064
# File 'lib/source/ruby.rb', line 6062

def to_s
  return self
end

#to_strObject

call-seq:

str.to_s   -> str
str.to_str -> str

Returns str.



6072
6073
6074
# File 'lib/source/ruby.rb', line 6072

def to_str
  return self
end

#to_symObject

call-seq:

str.intern -> symbol
str.to_sym -> symbol

Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See also Symbol#id2name.

'abcdef'.to_sym   #=> :abcdef


6085
6086
6087
# File 'lib/source/ruby.rb', line 6085

def to_sym
  `$s(this._value)`
end

#trObject

FIX: Incomplete



6090
6091
# File 'lib/source/ruby.rb', line 6090

def tr
end

#tr!Object

FIX: Incomplete



6094
6095
# File 'lib/source/ruby.rb', line 6094

def tr!
end

#tr_sObject

FIX: Incomplete



6098
6099
# File 'lib/source/ruby.rb', line 6098

def tr_s
end

#tr_s!Object

FIX: Incomplete



6102
6103
# File 'lib/source/ruby.rb', line 6102

def tr_s!
end

#upcaseObject

call-seq:

str.upcase -> string

Returns a copy of str with all lowercase letters replaced with their uppercase counterparts.

'aBCDEf'.upcase   #=> "ABCDEF"


6113
6114
6115
# File 'lib/source/ruby.rb', line 6113

def upcase
  `$q(this._value.toUpperCase())`
end

#upcase!Object

call-seq:

str.upcase! -> str or nil

Returns str with all lowercase letters replaced with their uppercase counterparts, or nil if no changes were made.

s = 'aBCDEf'

s.upcase!   #=> "ABCDEF"
s.upcase!   #=> nil
s           #=> "ABCDEF"


6129
6130
6131
6132
6133
# File 'lib/source/ruby.rb', line 6129

def upcase!
  `var v=this._value`
  `this._value=v.toUpperCase()`
  return `v==this._value?nil:this`
end

#upto(str, &block) ⇒ Object

FIX: Incomplete



6136
6137
# File 'lib/source/ruby.rb', line 6136

def upto(str,&block)
end