--- a/String.st Tue Apr 14 21:44:09 2015 +0200
+++ b/String.st Wed Apr 15 02:30:56 2015 +0200
@@ -553,7 +553,12 @@
This method is the same as at:."
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (context.stArg(0).isSmallInteger()) {
+ int idx1Based = context.stArg(0).intValue(); // st index is 1 based
+ return context.RETURN( self.basicAt( idx1Based ));
+ }
+#else
REGISTER int indx;
REGISTER OBJ slf, cls;
@@ -570,6 +575,7 @@
}
}
badIndex: ;
+#endif /* ! __JAVA__ */
%}.
^ self basicAt:index
!
@@ -582,7 +588,15 @@
This method is the same as basicAt:put:."
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (context.stArg(0).isSmallInteger()) {
+ int idx1Based = context.stArg(0).intValue(); // st index is 1 based
+ STObject val = context.stArg(1);
+
+ self.basicAt_put_(idx1Based, val );
+ return context.RETURN( val );
+ }
+#else
REGISTER int value, indx;
REGISTER OBJ slf;
@@ -601,6 +615,7 @@
}
}
}
+#endif /* ! __JAVA__ */
%}.
^ self basicAt:index put:aCharacter
!
@@ -610,7 +625,12 @@
- reimplemented here since we return characters"
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (context.stArg(0).isSmallInteger()) {
+ int idx1Based = context.stArg(0).intValue(); // st index is 1 based
+ return context.RETURN( self.basicAt( idx1Based ));
+ }
+#else
REGISTER int indx;
REGISTER OBJ slf, cls;
@@ -627,6 +647,7 @@
}
}
badIndex: ;
+#endif
%}.
index isInteger ifFalse:[
^ self indexNotInteger:index
@@ -643,7 +664,15 @@
- reimplemented here since we store characters"
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (context.stArg(0).isSmallInteger()) {
+ int idx1Based = context.stArg(0).intValue(); // st index is 1 based
+ STObject val = context.stArg(1);
+
+ self.basicAt_put_(idx1Based, val );
+ return context.RETURN( val );
+ }
+#else
REGISTER int value, indx;
REGISTER OBJ slf;
REGISTER OBJ cls;
@@ -667,6 +696,7 @@
}
}
badIndex: ;
+#endif
%}.
(aCharacter isMemberOf:Character) ifFalse:[
"
@@ -772,99 +802,99 @@
OBJ cls;
if (__isStringLike(aCollection)) {
- matchP = __stringVal(aCollection);
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- switch (__stringSize(aCollection)) {
- case 5:
- /* five character search */
- {
- unsigned char c1 = matchP[0];
- unsigned char c2 = matchP[1];
- unsigned char c3 = matchP[2];
- unsigned char c4 = matchP[3];
- unsigned char c5 = matchP[4];
- unsigned char ch;
-
- while (ch = *cp++) {
- if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) {
- RETURN ( true );
- }
- }
- RETURN (false);
- }
-
- case 4:
- /* four character search */
- {
- unsigned char c1 = matchP[0];
- unsigned char c2 = matchP[1];
- unsigned char c3 = matchP[2];
- unsigned char c4 = matchP[3];
- unsigned char ch;
-
- while (ch = *cp++) {
- if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) {
- RETURN ( true );
- }
- }
- RETURN (false);
- }
-
- case 3:
- /* three character search */
- {
- unsigned char c1 = matchP[0];
- unsigned char c2 = matchP[1];
- unsigned char c3 = matchP[2];
- unsigned char ch;
-
- while (ch = *cp++) {
- if ((ch == c1) || (ch == c2) || (ch == c3)) {
- RETURN ( true );
- }
- }
- RETURN (false);
- }
-
- case 2:
- /* two character search */
- {
- unsigned char c1 = matchP[0];
- unsigned char c2 = matchP[1];
- unsigned char ch;
-
- while (ch = *cp++) {
- if ((ch == c1) || (ch == c2)) {
- RETURN ( true );
- }
- }
- RETURN (false);
- }
-
- case 1:
- /* single character search */
- if (strchr(cp, matchP[0])) {
- RETURN ( true );
- }
- RETURN ( false );
-
- case 0:
- RETURN ( false );
- }
-
- {
- unsigned char ch;
-
- while (ch = *cp++) {
- if (strchr(matchP, ch)) {
- RETURN ( true );
- }
- }
- }
- RETURN ( false );
+ matchP = __stringVal(aCollection);
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String)
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ switch (__stringSize(aCollection)) {
+ case 5:
+ /* five character search */
+ {
+ unsigned char c1 = matchP[0];
+ unsigned char c2 = matchP[1];
+ unsigned char c3 = matchP[2];
+ unsigned char c4 = matchP[3];
+ unsigned char c5 = matchP[4];
+ unsigned char ch;
+
+ while (ch = *cp++) {
+ if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) {
+ RETURN ( true );
+ }
+ }
+ RETURN (false);
+ }
+
+ case 4:
+ /* four character search */
+ {
+ unsigned char c1 = matchP[0];
+ unsigned char c2 = matchP[1];
+ unsigned char c3 = matchP[2];
+ unsigned char c4 = matchP[3];
+ unsigned char ch;
+
+ while (ch = *cp++) {
+ if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) {
+ RETURN ( true );
+ }
+ }
+ RETURN (false);
+ }
+
+ case 3:
+ /* three character search */
+ {
+ unsigned char c1 = matchP[0];
+ unsigned char c2 = matchP[1];
+ unsigned char c3 = matchP[2];
+ unsigned char ch;
+
+ while (ch = *cp++) {
+ if ((ch == c1) || (ch == c2) || (ch == c3)) {
+ RETURN ( true );
+ }
+ }
+ RETURN (false);
+ }
+
+ case 2:
+ /* two character search */
+ {
+ unsigned char c1 = matchP[0];
+ unsigned char c2 = matchP[1];
+ unsigned char ch;
+
+ while (ch = *cp++) {
+ if ((ch == c1) || (ch == c2)) {
+ RETURN ( true );
+ }
+ }
+ RETURN (false);
+ }
+
+ case 1:
+ /* single character search */
+ if (strchr(cp, matchP[0])) {
+ RETURN ( true );
+ }
+ RETURN ( false );
+
+ case 0:
+ RETURN ( false );
+ }
+
+ {
+ unsigned char ch;
+
+ while (ch = *cp++) {
+ if (strchr(matchP, ch)) {
+ RETURN ( true );
+ }
+ }
+ }
+ RETURN ( false );
}
%}.
^ super includesAny:aCollection
@@ -2869,7 +2899,7 @@
"Return my UTF-8 representation as a new String"
self contains8BitCharacters ifTrue:[
- ^ self basicUtf8Encoded.
+ ^ self basicUtf8Encoded.
].
"speed up common case"
^ self.
@@ -2879,7 +2909,7 @@
"write to aStream in utf8 encoding"
self contains8BitCharacters ifTrue:[
- aStream nextPutAllUtf8:self.
+ aStream nextPutAllUtf8:self.
].
"speed up common case"
aStream nextPutAll:self.
@@ -3289,7 +3319,7 @@
displayString
"return a string used when displaying the receiver in a view."
- ^ super displayString.
+ ^ super displayString.
"/ ^ self storeString.
"
@@ -3355,7 +3385,12 @@
(but only, as long as Stdout is nil, which is set later after startup)."
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (Smalltalk.getBindingOrNull(STSymbol._new("Stdout")) == null) {
+ System.out.print(self.toString());
+ return context._RETURN(self);
+ }
+#else
if (@global(Stdout) == nil) {
if (__qIsStringLike(self)) {
console_fprintf(stdout, "%s" , __stringVal(self));
@@ -3363,6 +3398,7 @@
RETURN (self);
}
}
+#endif
%}.
super print
!
@@ -3376,7 +3412,12 @@
(but only, as long as Stdout is nil, which is set later after startup)."
%{ /* NOCONTEXT */
-
+#ifdef __JAVA__
+ if (Smalltalk.getBindingOrNull(STSymbol._new("Stdout")) == null) {
+ System.out.println(self.toString());
+ return context._RETURN(self);
+ }
+#else
if (@global(Stdout) == nil) {
if (__qIsStringLike(self)) {
console_fprintf(stdout, "%s\n" , __stringVal(self));
@@ -3384,6 +3425,7 @@
RETURN (self);
}
}
+#endif
%}.
super printCR
!
@@ -3397,7 +3439,7 @@
Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
%{ /* STACK: 1000 */
-
+#ifndef __JAVA__
char buffer[800];
char *buf = buffer;
int bufsize = sizeof(buffer);
@@ -3448,6 +3490,7 @@
}
}
fail:;
+#endif
%}.
self primitiveFailed
@@ -3488,6 +3531,9 @@
Redefined here to exclude the 0-byte at the end."
%{ /* NOCONTEXT */
+#ifdef __JAVA__
+ return context.RETURN( STInteger._new( self.basicSize() ) );
+#else
REGISTER OBJ slf, cls;
slf = self;
@@ -3498,6 +3544,7 @@
}
RETURN ( __mkSmallInteger(__stringSize(slf)
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
+#endif
%}.
^ super basicSize - 1
@@ -3580,6 +3627,9 @@
Can be used to check for existance of a symbol without creating one"
%{ /* NOCONTEXT */
+#ifdef __JAVA__
+ return context._RETURN( (STSymbol.asSymbolIfInterned(self.asSTString("[knownAsSymbol]").asString("")) != null) ? True : False );
+#else
OBJ cls;
int indx;
@@ -3590,6 +3640,7 @@
indx = 0;
}
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) );
+#endif /* ! __JAVA__ */
%}.
"/ ^ self asSymbolIfInterned notNil.
self primitiveFailed
@@ -3614,6 +3665,9 @@
This method is the same as basicSize."
%{ /* NOCONTEXT */
+#ifdef __JAVA__
+ return context.RETURN( STInteger._new( self.basicSize() ) );
+#else
REGISTER OBJ cls, slf;
slf = self;
@@ -3623,6 +3677,7 @@
}
RETURN ( __mkSmallInteger(__stringSize(slf)
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
+#endif
%}.
^ self basicSize
!
@@ -3641,7 +3696,7 @@
"Q: is there a need to redefine it here ?"
%{ /* NOCONTEXT */
-
+#ifndef __JAVA__
REGISTER char c;
REGISTER unsigned char *hip, *lowp;
@@ -3657,6 +3712,7 @@
}
RETURN ( self );
}
+ #endif
%}.
^ super reverse
! !
@@ -3669,6 +3725,7 @@
|notFound|
%{ /* STACK:4000 */
+#ifndef __JAVA__
if (__qIsStringLike(self)
&& __isStringLike(aSubString)
&& (caseSensitive == true)
@@ -3777,6 +3834,7 @@
notFound = true;
}
}
+#endif /* ! __JAVA__ */
%}.
notFound == true ifTrue:[
^ exceptionValue value.
@@ -3793,7 +3851,7 @@
If aStringOrChar is an empty string, true is returned"
%{ /* NOCONTEXT */
-
+#ifndef __JAVA__
int len1, len2;
REGISTER unsigned char *src1, *src2;
unsigned char c;
@@ -3827,6 +3885,7 @@
}
RETURN ( false );
}
+#endif /* ! __JAVA__ */
%}.
^ super endsWith:aStringOrChar
@@ -3846,7 +3905,7 @@
Q: should we care for whiteSpace in general here ?"
%{ /* NOCONTEXT */
-
+#ifndef __JAVA__
REGISTER unsigned char *src;
REGISTER unsigned char c;
OBJ cls;
@@ -3873,6 +3932,7 @@
}
}
RETURN ( true );
+#endif /* ! __JAVA__ */
%}.
^ super isBlank
!
@@ -3882,12 +3942,14 @@
Redefined here for performance"
%{ /* NOCONTEXT */
+#ifndef __JAVA__
OBJ cls;
cls = __qClass(self);
if ((cls == String) || (cls == Symbol)) {
RETURN ( (__stringSize(self) == 0) ? true : false);
}
+#endif /* ! __JAVA__ */
%}.
^ self size == 0
!
@@ -3904,7 +3966,7 @@
substitution, case-change, insertion and deletion of a character."
%{ /* STACK: 2000 */
-
+#ifndef __JAVA__
/*
* this is very heavy used when correcting errors
* (all symbols are searched for best match) - therefore it must be fast
@@ -3992,6 +4054,7 @@
RETURN ( __mkSmallInteger(m) );
}
mallocFailed: ;
+#endif /* ! __JAVA__ */
%}.
^ super levenshteinTo:aString
@@ -4015,12 +4078,14 @@
Redefined here for performance"
%{ /* NOCONTEXT */
+#ifndef __JAVA__
OBJ cls;
cls = __qClass(self);
if ((cls == String) || (cls == Symbol)) {
RETURN ( (__stringSize(self) != 0) ? true : false);
}
+#endif /* ! __JAVA__ */
%}.
^ self size ~~ 0
!
@@ -4032,89 +4097,90 @@
which are both inconsistent w.r.t. an empty argument."
%{ /* NOCONTEXT */
-
+#ifndef __JAVA__
int len1, len2;
REGISTER unsigned char *src1, *src2;
unsigned char c;
REGISTER OBJ slf = self;
if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
- src1 = __stringVal(slf);
- src2 = __stringVal(aStringOrChar);
-
- if (src1[0] != src2[0]) {
- if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
- RETURN (true);
- }
- RETURN ( false );
- }
-
- len1 = __qSize(slf);
- len2 = __qSize(aStringOrChar);
- if (len1 < len2) {
- RETURN ( false );
- }
+ src1 = __stringVal(slf);
+ src2 = __stringVal(aStringOrChar);
+
+ if (src1[0] != src2[0]) {
+ if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
+ RETURN (true);
+ }
+ RETURN ( false );
+ }
+
+ len1 = __qSize(slf);
+ len2 = __qSize(aStringOrChar);
+ if (len1 < len2) {
+ RETURN ( false );
+ }
#ifdef UINT64
- while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
- if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
- RETURN (false);
- }
- len2 -= sizeof(UINT64);
- src1 += sizeof(UINT64);
- src2 += sizeof(UINT64);
- }
+ while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
+ if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
+ RETURN (false);
+ }
+ len2 -= sizeof(UINT64);
+ src1 += sizeof(UINT64);
+ src2 += sizeof(UINT64);
+ }
#else
# ifdef __UNROLL_LOOPS__
- while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
- if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
- RETURN (false);
- }
- len2 -= sizeof(INT)*4;
- src1 += sizeof(INT)*4;
- src2 += sizeof(INT)*4;
- }
+ while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
+ if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
+ RETURN (false);
+ }
+ len2 -= sizeof(INT)*4;
+ src1 += sizeof(INT)*4;
+ src2 += sizeof(INT)*4;
+ }
# endif /* __UNROLL_LOOPS__ */
#endif /* UINT64 */
- while (len2 > (OHDR_SIZE+sizeof(INT))) {
- if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
- RETURN (false);
- }
- len2 -= sizeof(INT);
- src1 += sizeof(INT);
- src2 += sizeof(INT);
- }
-
- while (c = *src2++) {
- if (c != *src1) {
- RETURN ( false );
- }
- src1++;
- }
- RETURN (true);
+ while (len2 > (OHDR_SIZE+sizeof(INT))) {
+ if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+ RETURN (false);
+ }
+ len2 -= sizeof(INT);
+ src1 += sizeof(INT);
+ src2 += sizeof(INT);
+ }
+
+ while (c = *src2++) {
+ if (c != *src1) {
+ RETURN ( false );
+ }
+ src1++;
+ }
+ RETURN (true);
}
if (__isCharacter(aStringOrChar)) {
- int val;
-
- val = __intVal(__characterVal(aStringOrChar));
- if ((unsigned)val <= 0xFF) {
- len1 = __stringSize(slf);
- if (len1 > 0) {
- RETURN ( (__stringVal(slf)[0] == val) ? true : false);
- }
- }
- RETURN ( false );
+ int val;
+
+ val = __intVal(__characterVal(aStringOrChar));
+ if ((unsigned)val <= 0xFF) {
+ len1 = __stringSize(slf);
+ if (len1 > 0) {
+ RETURN ( (__stringVal(slf)[0] == val) ? true : false);
+ }
+ }
+ RETURN ( false );
}
+#endif /* ! __JAVA__ */
%}.
^ super startsWith:aStringOrChar
@@ -4151,10 +4217,10 @@
!String class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.331 2015-03-25 14:18:37 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.332 2015-04-15 00:30:56 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.331 2015-03-25 14:18:37 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.332 2015-04-15 00:30:56 cg Exp $'
! !