String.st
changeset 1143 27325100bdf4
parent 1138 993e6ffdbf51
child 1218 5ed62714c8d1
equal deleted inserted replaced
1142:3964108b86ca 1143:27325100bdf4
   277      This method is the same as at:."
   277      This method is the same as at:."
   278 
   278 
   279 %{  /* NOCONTEXT */
   279 %{  /* NOCONTEXT */
   280 
   280 
   281     REGISTER int indx;
   281     REGISTER int indx;
   282     REGISTER OBJ cls;
   282     REGISTER OBJ slf, cls;
   283 
   283 
   284     if (__isSmallInteger(index)) {
   284     if (__isSmallInteger(index)) {
   285 	indx = __intVal(index);
   285 	indx = __intVal(index) - 1;
   286 	if (indx > 0) {
   286 	slf = self;
   287 	    cls = __qClass(self);
   287 
   288 	    if (cls != String)
   288 	cls = __qClass(slf);
   289 		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   289 	if (cls != String)
   290 	    if (indx <= (__stringSize(self))) {
   290 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   291 		RETURN ( __MKCHARACTER(__stringVal(self)[indx-1] & 0xFF) );
   291 	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
   292 	    }
   292 	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
   293 	}
   293 	}
   294     }
   294     }
   295 %}.
   295 %}.
   296     ^ self subscriptBoundsError:index
   296     ^ self subscriptBoundsError:index
   297 !
   297 !
   303      This method is the same as basicAt:put:."
   303      This method is the same as basicAt:put:."
   304 
   304 
   305 %{  /* NOCONTEXT */
   305 %{  /* NOCONTEXT */
   306 
   306 
   307     REGISTER int value, indx;
   307     REGISTER int value, indx;
   308 
   308     REGISTER OBJ slf;
   309     if (__isString(self)) {
   309 
       
   310     slf = self;
       
   311 
       
   312     if (__isString(slf)) {
   310 	if (__isCharacter(aCharacter)) {
   313 	if (__isCharacter(aCharacter)) {
   311 	    value = __intVal(_characterVal(aCharacter));
   314 	    value = __intVal(_characterVal(aCharacter));
   312 #ifdef OLD
   315 	    if (((unsigned)value <= 0xFF)
   313 	    if ((value > 0) 
       
   314 	     && (value <= 255)
       
   315 #else
       
   316 	    if (((value & ~0xFF) == 0)
       
   317 #endif
       
   318 	     && __isSmallInteger(index)) {
   316 	     && __isSmallInteger(index)) {
   319 		indx = __intVal(index);
   317 		indx = __intVal(index) - 1;
   320 		if (indx > 0) {
   318 		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
   321 		    if (indx <= (__stringSize(self))) {
   319 		    __stringVal(slf)[indx] = value;
   322 			__stringVal(self)[indx-1] = value;
   320 		    RETURN ( aCharacter );
   323 			RETURN ( aCharacter );
       
   324 		    }
       
   325 		}
   321 		}
   326 	    }
   322 	    }
   327 	}
   323 	}
   328     }
   324     }
   329 %}.
   325 %}.
   354      - reimplemented here since we return characters"
   350      - reimplemented here since we return characters"
   355 
   351 
   356 %{  /* NOCONTEXT */
   352 %{  /* NOCONTEXT */
   357 
   353 
   358     REGISTER int indx;
   354     REGISTER int indx;
   359     REGISTER OBJ cls;
   355     REGISTER OBJ slf, cls;
   360 
   356 
   361     if (__isSmallInteger(index)) {
   357     if (__isSmallInteger(index)) {
   362 	indx = __intVal(index);
   358 	indx = __intVal(index) - 1;
   363 	if (indx > 0) {
   359 
   364 	    cls = __qClass(self);
   360 	slf = self;
   365 	    if (cls != String)
   361 	cls = __qClass(slf);
   366 		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   362 	if (cls != String)
   367 	    if (indx <= (__stringSize(self))) {
   363 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   368 		RETURN ( __MKCHARACTER(__stringVal(self)[indx-1] & 0xFF) );
   364 	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
   369 	    }
   365 	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
   370 	}
   366 	}
   371     }
   367     }
   372 %}.
   368 %}.
   373     ^ self subscriptBoundsError:index
   369     ^ self subscriptBoundsError:index
   374 !
   370 !
   375 
   371 
   376 basicAt:index put:aCharacter
   372 basicAt:index put:aCharacter
   377     "store the argument, aCharacter at position index, an Integer
   373     "store the argument, aCharacter at position index, an Integer
   378      - reimplemented here since we store characters
   374      - reimplemented here since we store characters"
   379      (but only for Strings, since subclasses may redefine basicAt:put:)."
       
   380 
   375 
   381 %{  /* NOCONTEXT */
   376 %{  /* NOCONTEXT */
   382 
   377 
   383     REGISTER int value, indx;
   378     REGISTER int value, indx;
   384 
   379     REGISTER OBJ slf;
   385     if (__isString(self)) {
   380     REGISTER OBJ cls;
   386 	if (__isCharacter(aCharacter)) {
   381 
   387 	    value = __intVal(_characterVal(aCharacter));
   382     slf = self;
   388 	    if ((value > 0) 
   383 
   389 	     && (value <= 255)
   384     if (__isCharacter(aCharacter)) {
   390 	     && __isSmallInteger(index)) {
   385 	value = __intVal(_characterVal(aCharacter));
   391 		indx = __intVal(index);
   386 	if (((unsigned)value <= 0xFF)
   392 		if (indx > 0) {
   387 	 && __isSmallInteger(index)) {
   393 		    if (indx <= (__stringSize(self))) {
   388 	    indx = __intVal(index) - 1;
   394 			__stringVal(self)[indx-1] = value;
   389 	    cls = __qClass(slf);
   395 			RETURN ( aCharacter );
   390 	    if (cls != String)
   396 		    }
   391 	        indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   397 		}
   392 	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
       
   393 		__stringVal(slf)[indx] = value;
       
   394 		RETURN ( aCharacter );
   398 	    }
   395 	    }
   399 	}
   396 	}
   400     }
   397     }
   401 %}.
   398 %}.
   402     (self isMemberOf:String) ifFalse:[
       
   403 	^ super basicAt:index put:aCharacter
       
   404     ].
       
   405 
       
   406     (aCharacter isMemberOf:Character) ifFalse:[
   399     (aCharacter isMemberOf:Character) ifFalse:[
   407 	"
   400 	"
   408 	 tried to store something which is not a character
   401 	 tried to store something which is not a character
   409 	"
   402 	"
   410 	^ self elementNotCharacter
   403 	^ self elementNotCharacter
   424 basicSize
   417 basicSize
   425     "return the number of characters in myself.
   418     "return the number of characters in myself.
   426      Redefined here to exclude the 0-byte at the end."
   419      Redefined here to exclude the 0-byte at the end."
   427 
   420 
   428 %{  /* NOCONTEXT */
   421 %{  /* NOCONTEXT */
   429     REGISTER OBJ cls;
   422     REGISTER OBJ slf, cls;
   430 
   423 
   431     cls = __qClass(self);
   424     slf = self;
       
   425 
       
   426     cls = __qClass(slf);
   432     if (cls == String) {
   427     if (cls == String) {
   433 	RETURN ( __MKSMALLINT(__stringSize(self)) );
   428 	RETURN ( __MKSMALLINT(__stringSize(slf)) );
   434     }
   429     }
   435     RETURN ( __MKSMALLINT(__stringSize(self)
   430     RETURN ( __MKSMALLINT(__stringSize(slf)
   436 			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
   431 	                  - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
   437 %}
   432 %}
   438 !
   433 !
   439 
   434 
   440 size
   435 size
   441     "return the number of characters in myself.
   436     "return the number of characters in myself.
   442      Reimplemented here to avoid the additional size->basicSize send
   437      Reimplemented here to avoid the additional size->basicSize send
   443      (which we can do here, since size is obviously not redefined in a subclass).
   438      (which we can do here, since size is obviously not redefined in a subclass).
   444      This method is the same as basicSize."
   439      This method is the same as basicSize."
   445 
   440 
   446 %{  /* NOCONTEXT */
   441 %{  /* NOCONTEXT */
   447     REGISTER OBJ cls;
   442     REGISTER OBJ cls, slf;
   448 
   443 
   449     cls = __qClass(self);
   444     slf = self;
       
   445     cls = __qClass(slf);
   450     if (cls == String) {
   446     if (cls == String) {
   451 	RETURN ( __MKSMALLINT(__stringSize(self)) );
   447 	RETURN ( __MKSMALLINT(__stringSize(slf)) );
   452     }
   448     }
   453     RETURN ( __MKSMALLINT(__stringSize(self)
   449     RETURN ( __MKSMALLINT(__stringSize(slf)
   454 			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
   450 			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
   455 %}
   451 %}
   456 ! !
   452 ! !
   457 
   453 
   458 !String ignoredMethodsFor:'binary storage'!
   454 !String ignoredMethodsFor:'binary storage'!
  2191 ! !
  2187 ! !
  2192 
  2188 
  2193 !String class methodsFor:'documentation'!
  2189 !String class methodsFor:'documentation'!
  2194 
  2190 
  2195 version
  2191 version
  2196     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.67 1996-04-06 13:22:51 cg Exp $'
  2192     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.68 1996-04-09 20:46:43 cg Exp $'
  2197 ! !
  2193 ! !