CharacterArray.st
changeset 17000 28e08401d7ae
parent 16899 c8de03aacca0
child 17021 c7ac4c24c541
equal deleted inserted replaced
16999:4d5ceea1cea6 17000:28e08401d7ae
  1622     ^ true
  1622     ^ true
  1623 ! !
  1623 ! !
  1624 
  1624 
  1625 !CharacterArray methodsFor:'JavaScript support'!
  1625 !CharacterArray methodsFor:'JavaScript support'!
  1626 
  1626 
       
  1627 quote
       
  1628     "add double quotes around the receiver (unless already quoted).
       
  1629      This is the JavaSccript standard quote function."
       
  1630 
       
  1631     ((self first == $") and:[self last == $"]) ifFalse:[
       
  1632         ^ '"',self,'"'
       
  1633     ].
       
  1634     ^ self
       
  1635 
       
  1636     "
       
  1637      'hello' quote
       
  1638 
       
  1639      JavaScriptParser evaluate:'''hello''.quote.unquote' 
       
  1640     "
       
  1641 !
       
  1642 
  1627 unquote
  1643 unquote
  1628     "removes double quotes from the receiver"
  1644     "removes double quotes from the receiver.
  1629 
  1645      This is the JavaSccript standard unquote function."
  1630     self size >= 2 ifTrue:[
  1646 
  1631         (self startsWith:$") ifTrue:[
  1647     |mySize|
  1632             (self endsWith:$") ifTrue:[
  1648 
  1633                 ^ self copyFrom:2 to:self size-1
  1649     (mySize := self size) >= 2 ifTrue:[
  1634             ].
  1650         ((self first == $") and:[self last == $"]) ifTrue:[
       
  1651             ^ self copyFrom:2 to:mySize-1
  1635         ].
  1652         ].
  1636     ].
  1653     ].
  1637     ^ self
  1654     ^ self
  1638 
  1655 
  1639     "
  1656     "
  1640      JavaScriptParser
  1657      'hello' quote unquote
  1641         evaluate:'''hello''.quote.unquote'
  1658 
       
  1659      JavaScriptParser evaluate:'''hello''.quote.unquote' 
  1642     "
  1660     "
  1643 ! !
  1661 ! !
  1644 
  1662 
  1645 
  1663 
  1646 !CharacterArray methodsFor:'character searching'!
  1664 !CharacterArray methodsFor:'character searching'!
  5893         \\      the \ character itself
  5911         \\      the \ character itself
  5894         \xnn    two digit hex number defining the characters ascii value
  5912         \xnn    two digit hex number defining the characters ascii value
  5895         \unnnn  four digit hex number defining the characters ascii value
  5913         \unnnn  four digit hex number defining the characters ascii value
  5896         \Unnnnnnnn  eight digit hex number defining the characters ascii value
  5914         \Unnnnnnnn  eight digit hex number defining the characters ascii value
  5897      This is the opposite of withoutCEscapes.
  5915      This is the opposite of withoutCEscapes.
       
  5916 
       
  5917      Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs),
       
  5918            but it cannot be changed easily, as these methods are already used heavily
  5898     "
  5919     "
  5899 
  5920 
  5900     |anyEscapeNeeded out seq|
  5921     |anyEscapeNeeded out seq|
  5901 
  5922 
  5902     "
  5923     "
  5948         ].
  5969         ].
  5949     ].
  5970     ].
  5950     ^ out contents
  5971     ^ out contents
  5951 
  5972 
  5952     "
  5973     "
  5953      'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes.  
  5974      'hello\n\tworld' withoutCEscapes. 
       
  5975      'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes.
       
  5976      ('hello ',(Character value:16r1234),' world') withCEscapes 
  5954     "
  5977     "
  5955 
  5978 
  5956     "Created: / 25-01-2012 / 11:08:16 / cg"
  5979     "Created: / 25-01-2012 / 11:08:16 / cg"
  5957 !
  5980 !
  5958 
  5981 
  6260      and place a modified string constant into the binary/byte-code.
  6283      and place a modified string constant into the binary/byte-code.
  6261      Therefore, no runtime penalty will be payed for using these escapes.
  6284      Therefore, no runtime penalty will be payed for using these escapes.
  6262      (not in pre 2.11 versions)
  6285      (not in pre 2.11 versions)
  6263 
  6286 
  6264      This is the opposite of withCEscapes.
  6287      This is the opposite of withCEscapes.
       
  6288 
       
  6289      Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs),
       
  6290            but it cannot be changed easily, as these methods are already used heavily
  6265     "
  6291     "
  6266 
  6292 
  6267     |val     "{ SmallInteger }"
  6293     |val     "{ SmallInteger }"
  6268      in out nextChar nDigits|
  6294      in out nextChar nDigits|
  6269 
  6295 
  6453      'helloworld' withoutPrefix:'foo'
  6479      'helloworld' withoutPrefix:'foo'
  6454     "
  6480     "
  6455 !
  6481 !
  6456 
  6482 
  6457 withoutQuotes
  6483 withoutQuotes
  6458     "remove quotes ("" and ') from the front and the end of myself"
  6484     "/ remove quotes ($" and $') from the front and end of myself (if matching)"
  6459 
  6485 
  6460     |result quote|
  6486     |firstChar|
  6461 
  6487 
  6462     result := self.
  6488     firstChar := self first.
  6463     ((result startsWith:$") or:[(result startsWith:$')]) ifTrue:[
  6489     ((firstChar == $") or:[firstChar == $']) ifFalse:[^ self].
  6464         quote := result at:1.
  6490 
  6465         result := result copyFrom:2.
  6491     self last == firstChar ifTrue:[
  6466         (result endsWith:quote) ifTrue:[
  6492         ^ self copyFrom:2 to:(self size-1)
  6467             result := result copyButLast:1
  6493     ].
  6468         ].
  6494     ^ self
  6469     ].
  6495 
  6470     ^ result
  6496     "/
  6471 
  6497     "/ '"hello"' withoutQuotes     
  6472 "/     '"hello"' withoutQuotes
  6498     "/ '''hello''' withoutQuotes   
  6473 "/     '''hello''' withoutQuotes
  6499     "/ 'hello' withoutQuotes 
  6474 "/     'hello' withoutQuotes
  6500     "/ '"hello' withoutQuotes 
       
  6501     "/ 'hello"' withoutQuotes  
       
  6502     "/
  6475 !
  6503 !
  6476 
  6504 
  6477 withoutSeparators
  6505 withoutSeparators
  6478     "return a copy of myself without leading and trailing whitespace.
  6506     "return a copy of myself without leading and trailing whitespace.
  6479      (but whiteSpace in-between is preserved)
  6507      (but whiteSpace in-between is preserved)
  7112 ! !
  7140 ! !
  7113 
  7141 
  7114 !CharacterArray class methodsFor:'documentation'!
  7142 !CharacterArray class methodsFor:'documentation'!
  7115 
  7143 
  7116 version
  7144 version
  7117     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.546 2014-10-09 12:35:52 cg Exp $'
  7145     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.547 2014-11-08 09:35:08 cg Exp $'
  7118 !
  7146 !
  7119 
  7147 
  7120 version_CVS
  7148 version_CVS
  7121     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.546 2014-10-09 12:35:52 cg Exp $'
  7149     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.547 2014-11-08 09:35:08 cg Exp $'
  7122 ! !
  7150 ! !
  7123 
  7151 
  7124 
  7152 
  7125 CharacterArray initialize!
  7153 CharacterArray initialize!