--- a/String.st Fri Aug 22 15:18:10 1997 +0200
+++ b/String.st Fri Aug 22 15:20:20 1997 +0200
@@ -1667,8 +1667,7 @@
^ super copyWith:aCharacter
!
-deepCopy
- "return a copy of the receiver"
+return a copy of the receiver"
"
could be an instance of a subclass which needs deepCopy
@@ -1680,7 +1679,7 @@
^ super deepCopy
!
-deepCopyUsing:aDictionary
+aDictionary
"return a copy of the receiver - reimplemented to be a bit faster"
"
@@ -1693,8 +1692,7 @@
^ super deepCopy
!
-shallowCopy
- "return a copy of the receiver"
+"return a copy of the receiver"
(self isMemberOf:String) ifTrue:[
^ self copyFrom:1
@@ -1702,8 +1700,7 @@
^ super shallowCopy
!
-simpleDeepCopy
- "return a copy of the receiver"
+"return a copy of the receiver"
"
could be an instance of a subclass which needs deepCopy
@@ -1717,7 +1714,7 @@
!String methodsFor:'filling and replacing'!
-atAllPut:aCharacter
+acter
"replace all elements with aCharacter
- reimplemented here for speed"
@@ -1756,7 +1753,7 @@
"
!
-replaceAll:oldCharacter by:newCharacter
+Character by:newCharacter
"replace all oldCharacters by newCharacter in the receiver"
%{ /* NOCONTEXT */
@@ -1786,7 +1783,7 @@
"
!
-replaceFrom:start to:stop with:aString startingAt:repStart
+art to:stop with:aString startingAt:repStart
"replace the characters starting at index start, anInteger and ending
at stop, anInteger with characters from aString starting at repStart.
@@ -1876,8 +1873,7 @@
!
-reverse
- "in-place reverse the characters of the string."
+"in-place reverse the characters of the string."
"Q: is there a need to redefine it here ?"
@@ -1915,60 +1911,87 @@
startIndex := 0.
%{
+ REGISTER unsigned char *cp;
+ REGISTER unsigned char *ep;
+ REGISTER unsigned char c;
REGISTER unsigned char *cp0;
- REGISTER unsigned char *cp;
- REGISTER unsigned char c;
+ REGISTER unsigned char *ep0;
/* ignore instances of subclasses ... */
if (__qClass(self) == String) {
- cp = cp0 = __stringVal(self);
+ cp = cp0 = __stringVal(self);
+ /*
+ * find first non-whiteSpace from beginning
+ */
#ifndef NON_ASCII
# ifdef alpha64
while (*((unsigned INT *)cp) == 0x2020202020202020L) {
- cp += 8;
+ cp += 8;
}
# endif
while (*((unsigned *)cp) == 0x20202020) {
- cp += 4;
+ cp += 4;
}
#endif
- while ((c = *cp)
+ while ((c = *cp)
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
- && (c <= ' ')
+ && (c <= ' ')
#endif
- && ((c == ' ') || (c == '\n') || (c == '\t')
- || (c == '\r') || (c == '\f'))
- ) {
- cp++;
- }
- startIndex = __MKSMALLINT(cp - cp0 + 1);
- cp = cp + strlen(cp) - 1;
- while ((cp >= cp0) && (*cp == ' ')) cp--;
- c = *cp;
- while ((cp >= cp0) &&
+ && ((c == ' ') || (c == '\n') || (c == '\t')
+ || (c == '\r') || (c == '\f'))
+ ) {
+ cp++;
+ }
+
+ /*
+ * find first non-whiteSpace from end
+ */
+ ep = ep0 = cp0 + __stringSize(self) - 1;
+ while ((ep >= cp) && (*ep == ' ')) ep--;
+ c = *ep;
+ while ((ep >= cp) &&
#ifndef NON_ASCII
- (c <= ' ') &&
+ (c <= ' ') &&
#endif
- ((c == ' ') || (c == '\n') || (c == '\t')
- || (c == '\r') || (c == '\f'))) {
- cp--;
- c = *cp;
- }
- endIndex = __MKSMALLINT(cp - cp0 + 1);
+ ((c == ' ') || (c == '\n') || (c == '\t')
+ || (c == '\r') || (c == '\f'))) {
+ ep--;
+ c = *ep;
+ }
+
+ /*
+ * no whiteSpace ?
+ */
+ if ((cp == cp0) && (ep == ep0)) {
+ RETURN(self);
+ }
+
+ startIndex = __MKSMALLINT(cp - cp0 + 1);
+ endIndex = __MKSMALLINT(ep - cp0 + 1);
}
%}.
startIndex == 0 ifTrue:[^ super withoutSeparators].
startIndex > endIndex ifTrue:[^ ''].
- ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
^ self copyFrom:startIndex to:endIndex
+
+ "
+ 'hello' withoutSeparators
+ ' hello' withoutSeparators
+ ' hello ' withoutSeparators
+ ' hello ' withoutSeparators
+ ' hello ' withoutSeparators
+ ' hello ' withoutSeparators
+ ' ' withoutSeparators
+ "
+
!
withoutSpaces
"return a string containing the characters of myself
without leading and trailing spaces.
- If there are no spaces, the receiver is returned.
+ If there are no spaces, the receiver is returned unchanged.
Notice, this is different from String>>withoutSeparators."
|startIndex "{ Class: SmallInteger }"
@@ -1977,49 +2000,72 @@
startIndex := 0.
%{
- REGISTER unsigned char *cp0;
REGISTER unsigned char *cp;
+ REGISTER unsigned char *ep;
+ unsigned char *cp0;
+ unsigned char *ep0;
/* ignore instances of subclasses ... */
if (__qClass(self) == String) {
- cp = cp0 = __stringVal(self);
+ cp = cp0 = __stringVal(self);
+ /*
+ * find first non-blank from beginning
+ */
#ifndef NON_ASCII
# ifdef alpha64
while (*((unsigned INT *)cp) == 0x2020202020202020L) {
- cp += 8;
+ cp += 8;
}
# endif /* alpha64 */
while (*((unsigned *)cp) == 0x20202020) {
- cp += 4;
+ cp += 4;
}
#endif
- while (*cp == ' ') cp++;
+ while (*cp == ' ') cp++;
+
+ /*
+ * find first non-blank from end
+ */
+ ep = ep0 = cp0 + __stringSize(self) - 1;
+ while ((ep >= cp) && (*ep == ' ')) ep--;
- startIndex = __MKSMALLINT(cp - cp0 + 1);
- cp = cp + strlen(cp) - 1;
- while ((cp >= cp0) && (*cp == ' ')) cp--;
- endIndex = __MKSMALLINT(cp - cp0 + 1);
+ /*
+ * no blanks ?
+ */
+ if ((cp == cp0) && (ep == ep0)) {
+ RETURN(self);
+ }
+
+ startIndex = __MKSMALLINT(cp - cp0 + 1);
+ endIndex = __MKSMALLINT(ep - cp0 + 1);
}
%}.
startIndex == 0 ifTrue:[^ super withoutSpaces].
startIndex > endIndex ifTrue:[^ ''].
- ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
^ self copyFrom:startIndex to:endIndex
+
+ "
+ 'hello' withoutSpaces
+ ' hello' withoutSpaces
+ ' hello ' withoutSpaces
+ ' hello ' withoutSpaces
+ ' hello ' withoutSpaces
+ ' hello ' withoutSpaces
+ ' ' withoutSpaces
+ "
! !
!String methodsFor:'printing & storing'!
-isLiteral
- "return true, if the receiver can be used as a literal
+"return true, if the receiver can be used as a literal
(i.e. can be used in constant arrays)"
^ true
!
-print
- "print the receiver on standard output.
+nt the receiver on standard output.
This method does NOT use the stream classes and will therefore work
even in case of emergency."
@@ -2038,7 +2084,7 @@
^ super print
!
-printfPrintString:formatString
+ing:formatString
"non-portable but sometimes useful.
Return a printed representation of the receiver as specified by formatString,
which is defined by printf.
@@ -2084,7 +2130,7 @@
"
!
-storeOn:aStream
+m
"put the storeString of myself on aStream"
aStream nextPut: $'.
@@ -2099,8 +2145,7 @@
aStream nextPut:$'
!
-storeString
- "return a String for storing myself"
+"return a String for storing myself"
|s n index|
@@ -2125,7 +2170,7 @@
!String methodsFor:'queries'!
-bitsPerCharacter
+er
"return the number of bits each character has.
Here, 8 is returned (storing single byte characters)."
@@ -2134,8 +2179,7 @@
"Modified: 20.4.1996 / 23:08:42 / cg"
!
-isEmpty
- "return true if the receiver is empty (i.e. if size == 0)
+eturn true if the receiver is empty (i.e. if size == 0)
Redefined here for performance"
%{ /* NOCONTEXT */
@@ -2149,8 +2193,7 @@
^ super isEmpty
!
-knownAsSymbol
- "return true, if there is a symbol with same characters in the
+"return true, if there is a symbol with same characters in the
system.
Can be used to check for existance of a symbol without creating one"
@@ -2161,8 +2204,7 @@
!String methodsFor:'regular expression matching'!
-asRegex
- "Compile the receiver as a regex matcher. May raise RxParser>>syntaxErrorSignal
+ompile the receiver as a regex matcher. May raise RxParser>>syntaxErrorSignal
or RxParser>>compilationErrorSignal.
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996.
||| Refer to `documentation' protocol of RxParser class for details."
@@ -2172,7 +2214,7 @@
"Modified: 3.6.1997 / 11:25:25 / cg"
!
-matchesRegex: regexString
+regexString
"Test if the receiver matches a regex. May raise RxParser>>regexErrorSignal or
child signals.
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996.
@@ -2183,7 +2225,7 @@
"Modified: 3.6.1997 / 11:25:30 / cg"
!
-prefixMatchesRegex: regexString
+egex: regexString
"Test if the receiver's prefix matches a regex.
May raise RxParser class>>regexErrorSignal or child signals.
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996.
@@ -2196,7 +2238,7 @@
!String methodsFor:'testing'!
-endsWith:aStringOrChar
+ngOrChar
"return true, if the receiver ends with something, aStringOrChar."
%{ /* NOCONTEXT */
@@ -2237,8 +2279,7 @@
"
!
-isBlank
- "return true, if the receivers size is 0 or if it contains only spaces.
+eturn true, if the receivers size is 0 or if it contains only spaces.
Q: should we care for whiteSpace in general here ?"
%{ /* NOCONTEXT */
@@ -2271,7 +2312,7 @@
^ true
!
-levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
+aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
"parametrized levenshtein. arguments are the costs for
substitution, case-change, insertion and deletion of a character."
@@ -2374,7 +2415,7 @@
'Computer' levenshteinTo:'computer'"
!
-startsWith:aStringOrChar
+ringOrChar
"return true, if the receiver starts with something, aStringOrChar."
%{ /* NOCONTEXT */
@@ -2422,6 +2463,5 @@
!String class methodsFor:'documentation'!
-version
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.97 1997-08-19 17:26:53 cg Exp $'
+'$Header: /cvs/stx/stx/libbasic/String.st,v 1.98 1997-08-22 13:20:20 cg Exp $'
! !