UninterpretedBytes.st
changeset 24901 144086ff0a20
parent 24796 debcca59895b
equal deleted inserted replaced
24900:53b3e1320696 24901:144086ff0a20
  2012 byteAt:byteIndex put:anInteger
  2012 byteAt:byteIndex put:anInteger
  2013     "set the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
  2013     "set the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
  2014      The index is a smalltalk index (i.e. 1-based)."
  2014      The index is a smalltalk index (i.e. 1-based)."
  2015 
  2015 
  2016 %{ /* NOCONTEXT */
  2016 %{ /* NOCONTEXT */
  2017     if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) {
  2017     if (__bothSmallInteger(byteIndex, anInteger)) {
  2018 	unsigned char *cp;
  2018         unsigned char *cp;
  2019 	INT sz;
  2019         INT sz;
  2020 	INT val = __intVal(anInteger);
  2020         INT val = __intVal(anInteger);
  2021 
  2021 
  2022 	if ( ((unsigned INT)val) <= 0xFF ) {
  2022         if ( ((unsigned INT)val) <= 0xFF ) {
  2023 	    __STX_fetchBytePointerAndSize__(self, &cp, &sz);
  2023             __STX_fetchBytePointerAndSize__(self, &cp, &sz);
  2024 	    if (cp) {
  2024             if (cp) {
  2025 		unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
  2025                 unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
  2026 
  2026 
  2027 		if (idx < sz) {
  2027                 if (idx < sz) {
  2028 		    cp[idx] = val & 0xFF;
  2028                     cp[idx] = val & 0xFF;
  2029 		    RETURN (anInteger);
  2029                     RETURN (anInteger);
  2030 		}
  2030                 }
  2031 	    }
  2031             }
  2032 	}
  2032         }
  2033     }
  2033     }
  2034 %}.
  2034 %}.
  2035     byteIndex > self size ifTrue:[ ^ self subscriptBoundsError:byteIndex ].
  2035     byteIndex > self size ifTrue:[ ^ self subscriptBoundsError:byteIndex ].
  2036     ^ self at:byteIndex put:anInteger
  2036     ^ self at:byteIndex put:anInteger
  2037 
  2037 
  2045      b byteAt:2.
  2045      b byteAt:2.
  2046      b byteAt:3.
  2046      b byteAt:3.
  2047     "
  2047     "
  2048 
  2048 
  2049     "Modified (comment): / 07-02-2017 / 19:32:26 / stefan"
  2049     "Modified (comment): / 07-02-2017 / 19:32:26 / stefan"
       
  2050     "Modified: / 15-11-2019 / 17:38:45 / Stefan Vogel"
  2050 !
  2051 !
  2051 
  2052 
  2052 signedByteAt:byteIndex
  2053 signedByteAt:byteIndex
  2053     "return the byte at byteIndex as a signed 8 bit value in the range -128..+127.
  2054     "return the byte at byteIndex as a signed 8 bit value in the range -128..+127.
  2054      The index is a smalltalk index (i.e. 1-based).
  2055      The index is a smalltalk index (i.e. 1-based).