Created
July 15, 2011 17:56
-
-
Save rohit-nsit08/1085172 to your computer and use it in GitHub Desktop.
jsString in PIR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.namespace [] | |
.sub main | |
$P1 = subclass 'String', 'jsString' # subclass default string pmc into jsString type | |
addattribute $P1, 'primitive' | |
$P7 = box "ROHIT" | |
$P2 = new 'jsString' # instantiate the new string object | |
setattribute $P2, "primitive", $P7 | |
#_________________testing________________ | |
$P10 = getattribute $P2, "primitive" | |
#say $P10 | |
$I0 = 2 | |
$S3= $P2.'charAt'($I0) | |
say $S3 | |
$I2 = $P2.'length'() | |
say $I2 | |
$I3 = $P2.'indexof'("hit",0) | |
say $I3 | |
$S4 = $P2.'slice'(2,4) | |
say $S4 | |
$P2.'toLowerCase'() | |
$P0 = getattribute $P2, 'primitive' | |
say $P0 | |
$P2.'toUpperCase'() | |
$P0 = getattribute $P2, 'primitive' | |
say $P0 | |
#_________________________________________ | |
.end | |
.namespace ['jsString'] | |
.sub 'charAt' :method # returns the character at given position | |
.param int indexat | |
dec indexat | |
$P0 = getattribute self, 'primitive' | |
$S2 = substr $P0, indexat, 1 | |
.return ($S2) | |
.end | |
.sub 'length' :method # returns the length of the string | |
$P0 = getattribute self, 'primitive' | |
$S0 = $P0 | |
$I0 = length $S0 | |
.return ($I0) | |
.end | |
.sub 'concat' :method # will return the concatenated string | |
.end | |
.sub 'indexof' :method # returns the index of a particular substring | |
.param string searchstring | |
.param int position | |
$P0 = getattribute self, 'primitive' | |
$S0 = $P0 | |
$I1 = index $S0, searchstring, position | |
.return ($I1) | |
.end | |
.sub 'replace' :method #TODO: implement regexp object type | |
.param string searchString #searchstring is regexp | |
.param string replaceString | |
.end | |
.sub 'search' :method | |
.param string regexp | |
.end | |
.sub 'slice' :method # implements javascript's splice method | |
.param int start | |
.param int finish | |
.local int diff | |
diff = finish - start | |
$P0 = getattribute self, 'primitive' | |
$S0 = substr $P0, start, diff | |
.return ($S0) | |
.end | |
.sub 'split' :method # TODO : | |
.param string separator | |
.param int limit | |
.end | |
.sub 'substring' :method # returns substring | |
.param int start | |
.param int end | |
$P0 = getattribute self, 'primitive' | |
$S0 = substr $P0, start, end | |
.return ($S0) | |
.end | |
.sub 'toLowerCase' :method # converts string to lower case | |
$P0 = getattribute self, 'primitive' | |
$S0 = $P0 | |
$S1 = downcase $S0 | |
$P1 = box $S1 | |
setattribute self, 'primitive', $P1 | |
.end | |
.sub 'toUpperCase' :method # converts string to upper case | |
$P0 = getattribute self, 'primitive' | |
$S0 = $P0 | |
$S1 = upcase $S0 | |
$P1 = box $S1 | |
setattribute self, 'primitive', $P1 | |
.end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment