String.st
changeset 299 bc0645db1ab0
parent 286 4374d73b19a8
child 302 1f76060d58a4
equal deleted inserted replaced
298:962712d27c2d 299:bc0645db1ab0
    19 
    19 
    20 String comment:'
    20 String comment:'
    21 COPYRIGHT (c) 1988 by Claus Gittinger
    21 COPYRIGHT (c) 1988 by Claus Gittinger
    22 	     All Rights Reserved
    22 	     All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/String.st,v 1.30 1995-02-27 10:15:42 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/String.st,v 1.31 1995-03-07 19:45:41 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !String class methodsFor:'documentation'!
    27 !String class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/String.st,v 1.30 1995-02-27 10:15:42 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/String.st,v 1.31 1995-03-07 19:45:41 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
   267 	    }
   267 	    }
   268 	}
   268 	}
   269     }
   269     }
   270 %}.
   270 %}.
   271     (aCharacter isMemberOf:Character) ifFalse:[
   271     (aCharacter isMemberOf:Character) ifFalse:[
       
   272 	"
       
   273 	 tried to store something which is not a character
       
   274 	"
   272 	^ self elementNotCharacter
   275 	^ self elementNotCharacter
   273     ] ifTrue:[
   276     ].
   274 	(aCharacter asciiValue between:1 and:255) ifFalse:[
   277     (aCharacter asciiValue between:1 and:255) ifFalse:[
   275 	    ^ self elementBoundsError
   278 	"
   276 	] ifTrue:[
   279 	 tried to store a multibyte character
   277 	    ^ self subscriptBoundsError:index
   280 	"
   278 	]
   281 	^ self elementBoundsError
   279     ]
   282     ].
       
   283     "
       
   284      invalid index
       
   285     "
       
   286     ^ self subscriptBoundsError:index
   280 ! !
   287 ! !
   281 
   288 
   282 !String methodsFor:'converting'!
   289 !String methodsFor:'converting'!
   283 
   290 
   284 asSymbol
   291 asSymbol
   366 
   373 
   367 printfPrintString:formatString
   374 printfPrintString:formatString
   368     "non-portable but sometimes useful.
   375     "non-portable but sometimes useful.
   369      Return a printed representation of the receiver as specified by formatString, 
   376      Return a printed representation of the receiver as specified by formatString, 
   370      which is defined by printf.
   377      which is defined by printf.
   371      No checking on buffer overrun is done.
   378      No checking on buffer overrun is done; the resulting string may not
       
   379      be larger than 799 characters.
   372      This method is NONSTANDARD and may be removed without notice."
   380      This method is NONSTANDARD and may be removed without notice."
   373 
   381 
   374 %{  /* STACK: 1000 */
   382 %{  /* STACK: 1000 */
   375 
   383 
   376     char buffer[800];
   384     char buffer[800];
   394     }
   402     }
   395 %}
   403 %}
   396 .
   404 .
   397     self primitiveFailed
   405     self primitiveFailed
   398 
   406 
   399     "'hello' printfPrintString:'%%s -> %s'"
   407     "
   400     "'hello' printfPrintString:'%%10s -> %10s'"
   408      'hello' printfPrintString:'%%s -> %s'     
   401     "'hello' printfPrintString:'%%-10s -> %-10s'"
   409      'hello' printfPrintString:'%%10s -> %10s'  
       
   410      'hello' printfPrintString:'%%-10s -> %-10s' 
       
   411     "
   402 !
   412 !
   403 
   413 
   404 storeString
   414 storeString
   405     "return a String for storing myself"
   415     "return a String for storing myself"
   406 
   416 
   443 !String methodsFor:'comparing'!
   453 !String methodsFor:'comparing'!
   444 
   454 
   445 > aString
   455 > aString
   446     "Compare the receiver with the argument and return true if the
   456     "Compare the receiver with the argument and return true if the
   447      receiver is greater than the argument. Otherwise return false.
   457      receiver is greater than the argument. Otherwise return false.
   448      No national variants are honred; use after: for this.
   458      No national variants are honored; use after: for this.
   449      In contrast to ST-80, case differences are NOT ignored, thus
   459      In contrast to ST-80, case differences are NOT ignored, thus
   450      'foo' > 'Foo' will return true. 
   460      'foo' > 'Foo' will return true. 
   451      This may change."
   461      This may change."
   452 
   462 
   453 %{  /* NOCONTEXT */
   463 %{  /* NOCONTEXT */
   495 	if ((cmp == 0) && (len1 > len2)) {
   505 	if ((cmp == 0) && (len1 > len2)) {
   496 	    RETURN ( true );
   506 	    RETURN ( true );
   497 	}
   507 	}
   498 	RETURN ( false );
   508 	RETURN ( false );
   499     }
   509     }
   500 %}
   510 %}.
   501 .
       
   502     ^ super > aString
   511     ^ super > aString
   503 !
   512 !
   504 
   513 
   505 = aString
   514 = aString
   506     "Compare the receiver with the argument and return true if the
   515     "Compare the receiver with the argument and return true if the
   507      receiver is equal to the argument. Otherwise return false.
   516      receiver is equal to the argument. Otherwise return false.
   508      This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo')"
   517      This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
       
   518      Use sameAs: to compare with case ignored."
   509 
   519 
   510 %{  /* NOCONTEXT */
   520 %{  /* NOCONTEXT */
   511 
   521 
   512     int l1, l2;
   522     int l1, l2;
   513     REGISTER OBJ s = aString;
   523     REGISTER OBJ s = aString;
   552 	RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false );
   562 	RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false );
   553     }
   563     }
   554 %}
   564 %}
   555 .
   565 .
   556     ^ super = aString
   566     ^ super = aString
       
   567 
       
   568     "
       
   569      'foo' = 'Foo' 
       
   570      'foo' sameAs: 'Foo' 
       
   571     "
   557 !
   572 !
   558 
   573 
   559 ~= aString
   574 ~= aString
   560     "Compare the receiver with the argument and return true if the
   575     "Compare the receiver with the argument and return true if the
   561      receiver is not equal to the argument. Otherwise return false.
   576      receiver is not equal to the argument. Otherwise return false.
   687 	while (*cp) {
   702 	while (*cp) {
   688 	    if (*cp++ == byteValue) count++;
   703 	    if (*cp++ == byteValue) count++;
   689 	}
   704 	}
   690 	RETURN ( _MKSMALLINT(count) );
   705 	RETURN ( _MKSMALLINT(count) );
   691     }
   706     }
   692 %}
   707 %}.
   693 .
       
   694     ^ 0
   708     ^ 0
   695 
   709 
   696     "
   710     "
   697      'hello world' occurrencesOf:$a
   711      'hello world' occurrencesOf:$a
   698      'hello world' occurrencesOf:$w
   712      'hello world' occurrencesOf:$w
   730 	    }
   744 	    }
   731 	    cp++;
   745 	    cp++;
   732 	}
   746 	}
   733 #endif
   747 #endif
   734     }
   748     }
   735 %}
   749 %}.
   736 .
       
   737     ^ false
   750     ^ false
   738 
   751 
   739     "
   752     "
   740      'hello world' includes:$a
   753      'hello world' includes:$a
   741      'hello world' includes:$o  
   754      'hello world' includes:$o  
   742      'hello world' includes:$x  
   755      'hello world' includes:$x  
   743      'hello world' includes:1    
   756      'hello world' includes:1    
       
   757      'hello world' asTwoByteString includes:$o  
   744     "
   758     "
   745 !
   759 !
   746 
   760 
   747 includesAny:aCollection
   761 includesAny:aCollection
   748     "return true, if the receiver includes any of the characters in the
   762     "return true, if the receiver includes any of the characters in the