String.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 01 Dec 2015 07:14:07 +0000
branchjv
changeset 18972 57301b0d5ee1
parent 18971 13360506ef81
child 19000 ebd2ca4ecb51
permissions -rw-r--r--
Removed (wrong) prototype of memchr() in String. GCC (rigthly) refuses to compile a code with two different prototypes for the same function. Rely on function prototype from <string.h>.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    12
"{ Package: 'stx:libbasic' }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    13
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
    14
"{ NameSpace: Smalltalk }"
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
    15
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    16
CharacterArray variableByteSubclass:#String
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    17
	instanceVariableNames:''
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
    18
	classVariableNames:'CRLF CR LF TAB'
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    19
	poolDictionaries:''
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    20
	category:'Collections-Text'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    21
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    23
!String primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
%{
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
    25
3809
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    26
#include <stdio.h>
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    27
#define _STDIO_H_INCLUDED_
14752
201d3e649814 include stdlib.h to define malloc() prototypes
Stefan Vogel <sv@exept.de>
parents: 14664
diff changeset
    28
#include <stdlib.h>
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
#include <ctype.h>
359
claus
parents: 357
diff changeset
    30
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    31
#ifdef LINUX
359
claus
parents: 357
diff changeset
    32
# define __STRINGDEFS__
claus
parents: 357
diff changeset
    33
# include <linuxIntern.h>
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    34
#endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    35
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    36
#ifdef __osx__
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    37
# include <string.h>
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    38
# include <stdlib.h>
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    39
#endif
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    40
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    41
/*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    42
 * old st/x creates strings with spaces in it;
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    43
 * new st/x will fill it with zeros (for st-80 compatibility)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    44
 * the define below sets old behavior.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    45
 */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    46
#define INITIALIZE_WITH_SPACE
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    47
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    48
%}
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    49
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    50
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    51
!String primitiveFunctions!
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    52
%{
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    53
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
    54
static int
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    55
nextOnKeyboard(char1, char2)
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    56
{
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    57
    /* compare two characters if they are next to each other on a (US-) keyboard */
10370
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    58
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    59
    static char *us_keys[] = { "1234567890-",
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    60
			    "*qwertyuiop",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    61
			    "**asdfghjkl:",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    62
			    "***zxcvbnm",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    63
			    0 };
10370
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    64
    static char *de_keys[] = { "1234567890-",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    65
			    "*qwertzuiop",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    66
			    "**asdfghjkl:",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    67
			    "***yxcvbnm",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    68
			    0 };
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    69
    char **keys = us_keys;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    70
    char **line1, **line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    71
    char *col1, *col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    72
    int diff;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    73
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    74
    for (line1 = keys; *line1 != 0; line1++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    75
	for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    76
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    77
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    78
    if (*col1 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    79
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    80
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    81
    for (line2 = keys; *line2 != 0; line2++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    82
	for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    83
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    84
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    85
    if (*col2 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    86
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    87
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    88
    diff = col1 - col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    89
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    90
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    91
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    92
    diff = line1 - line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    93
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    94
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    95
    return(1);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    96
}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    97
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    98
%}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    99
! !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   100
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
!String class methodsFor:'documentation'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
copyright
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   106
	      All Rights Reserved
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
 This software is furnished under a license and may be used
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
 only in accordance with the terms of that license and with the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
 inclusion of the above copyright notice.   This software may not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
 be provided or otherwise made available to, or used by, any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
 other person.  No title to or ownership of the software is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
 hereby transferred.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   116
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
documentation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
    Strings are ByteArrays storing Characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
    Strings are kind of kludgy: to allow for easy handling by c-functions,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
    there is always one 0-byte added at the end, which is not counted
4800
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   123
    in the strings size, and is not accessable from the smalltalk level.
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   124
    This guarantees, that a smalltalk string can always be passed to a
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   125
    C- or a system api function without danger (of course, this does not
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   126
    prevent a nonsense contents ...)
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   127
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
    You cannot add any instvars to String, since the the run time system & compiler
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
    creates literal strings and knows that strings have no named instvars.
3809
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
   130
    If you really need strings with instVars, you have to create a subclass
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   131
    of String (the access functions defined here can handle this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
    A little warning though: not all smalltalk systems allow subclassing String,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   133
    so your program may become unportable if you do so.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   134
7895
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   135
    Strings have an implicit (assumed) encoding of iso8859-1.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   136
    For strings with other encodings, either keep the encoding separately,
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   137
    or use instances of encodedString.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   138
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   139
    [author:]
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   140
	Claus Gittinger
1310
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   141
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   142
    [see also:]
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   143
	Text StringCollection TwoByteString JISEncodedString
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   144
	Symbol
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   146
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   147
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
!String class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
basicNew:anInteger
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   151
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   152
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   153
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   154
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   155
     can be directly used as separator or for formatting."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   158
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   159
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   160
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
    OBJ newString;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   162
    REGISTER INT len, instsize;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
    REGISTER unsigned char *cp;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   164
    int nInstVars;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
252
   166
    if (__isSmallInteger(anInteger)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   167
	len = __intVal(anInteger);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   168
	if (len >= 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   169
	    instsize = OHDR_SIZE + len + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   170
	    if (self == String || self == ImmutableString) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   171
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   172
		    /*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   173
		     * the most common case
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   174
		     */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   175
		    __qCheckedNew(newString, instsize);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   176
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   177
		    __qSTORE(newString, self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   178
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   179
		    cp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   180
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   181
# if defined(memset4) && !defined(NON_ASCII)
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   182
		    {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   183
			/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   184
			 * no sizeof(int) here please -
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   185
			 * - memset4 (if defined) fills 4-bytes on ALL machines
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   186
			 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   187
			int l4 = len >> 2;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   188
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   189
			if (len & 3) l4++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   190
			memset4(cp, 0x20202020, l4);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   191
			cp[len] = '\0';
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   192
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   193
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   194
#  ifdef FAST_MEMSET
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   195
		    memset(cp, ' ', len);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   196
		    cp[len] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   197
#  else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   198
		    for ( ; len >= 8; cp += 8, len -= 8) {
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   199
#   ifndef NON_ASCII       /* i.e. EBCDIC  */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   200
#    ifdef INT64
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   201
			((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   202
#    else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   203
			((int *)cp)[0] = 0x20202020;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   204
			((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   205
#    endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   206
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   207
			cp[0] = cp[1] = cp[2] = cp[3] = ' ';
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   208
			cp[4] = cp[5] = cp[6] = cp[7] = ' ';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   209
#   endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   210
		    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   211
		    while (len--)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   212
			*cp++ = ' ';
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   213
		    *cp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   214
#  endif /* not FAST_MEMSET */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   215
# endif /* not memset4 */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   216
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   217
		    RETURN (newString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   218
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   219
		nInstVars = 0;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   220
	    } else {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   221
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   222
		instsize += __OBJS2BYTES__(nInstVars);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   223
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   224
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   225
	    __PROTECT_CONTEXT__;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   226
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   227
	    __UNPROTECT_CONTEXT__;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   228
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   229
	    if (newString == nil) goto fail;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   230
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   231
	    __InstPtr(newString)->o_class = self;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   232
	    __qSTORE(newString, self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   233
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   234
	    cp = __stringVal(newString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   235
	    if (nInstVars) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   236
		OBJ *op;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   237
		cp += __OBJS2BYTES__(nInstVars);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   238
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   239
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   240
		 * nil-out instvars
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   241
		 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   242
# if defined(memset4)
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   243
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   244
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   245
#  if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   246
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   247
		 * knowing that nil is 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   248
		 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   249
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   250
#  else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   251
		op = __InstPtr(newString)->i_instvars;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   252
		do {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   253
		    *op++ = nil;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   254
		} while (--nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   255
#  endif
357
claus
parents: 347
diff changeset
   256
# endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   257
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   258
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   259
	    /*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   260
	     * fill with spaces
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   261
	     */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   262
# ifdef FAST_MEMSET
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   263
	    memset(cp, ' ', len);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   264
	    *(cp + len) = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   265
# else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   266
	    while (len >= 8) {
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   267
#  ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   268
#   ifdef INT64
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   269
		((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   270
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   271
		((int *)cp)[0] = 0x20202020;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   272
		((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   273
#   endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   274
#  else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   275
		cp[0] = cp[1] = cp[2] = cp[3] = ' ';
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   276
		cp[4] = cp[5] = cp[6] = cp[7] = ' ';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   277
#  endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   278
		cp += 8;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   279
		len -= 8;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   280
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   281
	    while (len--)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   282
		*cp++ = ' ';
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   283
	    *cp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   284
# endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   285
	    RETURN (newString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   286
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   287
    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   288
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   289
#endif /* not __SCHTEAM__ */
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   290
%}.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   291
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   292
     invalid argument, or out-of-memory:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   293
     use error handling in superclass
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   294
    "
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   295
    (anInteger < 0) ifTrue:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   296
	"
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   297
	 the argument is negative,
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   298
	"
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   299
	self error:'bad (negative) argument to new:'.
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
   300
	^ nil
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   301
    ].
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   302
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   303
    ^ (super basicNew:anInteger+1) atAllPut:(Character space)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
new:n
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   307
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   308
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   309
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   310
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   311
     can be directly used as separator or for formatting."
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   312
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    ^ self basicNew:n
347
claus
parents: 345
diff changeset
   314
!
claus
parents: 345
diff changeset
   315
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   316
readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   317
    "read & return the next String from the (character-)stream aStream;
claus
parents: 345
diff changeset
   318
     skipping all whitespace first; return the value of exceptionBlock,
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   319
     if no string can be read. The sequence of characters as read from the
347
claus
parents: 345
diff changeset
   320
     stream must be one as stored via storeOn: or storeString."
claus
parents: 345
diff changeset
   321
claus
parents: 345
diff changeset
   322
    "
claus
parents: 345
diff changeset
   323
     this method is not to be inherited
claus
parents: 345
diff changeset
   324
     (i.e. not ok for subclasses; Symbol, for example)
claus
parents: 345
diff changeset
   325
    "
claus
parents: 345
diff changeset
   326
    self ~~ String ifTrue:[
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
   327
	^ super readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   328
    ].
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   329
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   330
claus
parents: 345
diff changeset
   331
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   332
     String readFrom:('''hello world''' readStream)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   333
     String readFrom:('''hello '''' world''' readStream)
347
claus
parents: 345
diff changeset
   334
     String readFrom:('1 ''hello'' ' readStream)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   335
     String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
3376
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   336
    "
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   337
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   338
    "Modified: / 05-07-2006 / 16:41:29 / cg"
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   339
    "Modified: / 07-08-2006 / 15:03:09 / fm"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   342
uninitializedNew:anInteger
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   343
    "return a new string with anInteger characters but undefined contents.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   344
     Use this, if the string is filled anyway with new data, for example, if
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   345
     used as a stream buffer."
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   346
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   347
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   348
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   349
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   350
#else
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   351
    OBJ newString;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   352
    REGISTER int len;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   353
    REGISTER unsigned char *cp;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   354
    REGISTER OBJ *op;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   355
    int nInstVars, instsize;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   356
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   357
    if (__isSmallInteger(anInteger)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   358
	len = __intVal(anInteger);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   359
	if (len >= 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   360
	    instsize = OHDR_SIZE + len + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   361
	    if (self == String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   362
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   363
		    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   364
		     * the most common case
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   365
		     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   366
		    __qCheckedNew(newString, instsize);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   367
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   368
		    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   369
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   370
		    cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   371
		    cp[len] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   372
		    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   373
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   374
		nInstVars = 0;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   375
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   376
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   377
		instsize += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   378
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   379
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   380
	    __PROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   381
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   382
	    __UNPROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   383
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   384
	    if (newString == nil) goto fail;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   385
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   386
	    __InstPtr(newString)->o_class = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   387
	    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   388
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   389
	    if (nInstVars) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   390
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   391
		 * nil-out instvars
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   392
		 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   393
# if defined(memset4)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   394
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   395
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   396
#  if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   397
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   398
		 * knowing that nil is 0
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   399
		 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   400
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   401
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   402
		op = __InstPtr(newString)->i_instvars;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   403
		do {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   404
		    *op++ = nil;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   405
		} while (--nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   406
#  endif
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   407
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   408
		cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   409
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   410
		cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   411
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   412
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   413
	    *(cp + len) = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   414
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   415
	}
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   416
    }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   417
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   418
#endif /* not __SCHTEAM__ */
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   419
%}.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   420
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   421
     invalid argument, or out-of-memory:
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   422
     use error handling in superclass
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   423
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   424
    (anInteger < 0) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   425
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   426
	 the argument is negative,
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   427
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   428
	self error:'bad (negative) argument to new:'.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   429
	^ nil
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   430
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
    ^ self basicNew:anInteger
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   433
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   434
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   435
     String uninitializedNew:100
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   436
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
8438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   439
!String class methodsFor:'Compatibility-Dolphin'!
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   440
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   441
lineDelimiter
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   442
    "Dolphin compatibility: answer CR LF"
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   443
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   444
    ^ self crlf
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   445
! !
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   446
7302
13a053c255bf category
Claus Gittinger <cg@exept.de>
parents: 7283
diff changeset
   447
!String class methodsFor:'Compatibility-Squeak'!
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   448
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   449
cr
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   450
    "return a string consisting of the cr-Character"
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   451
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   452
    CR isNil ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   453
	CR := String with:Character return
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   454
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   455
    ^ CR
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   456
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   457
    "Modified: / 13.11.1999 / 13:53:36 / cg"
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   458
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   459
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   460
crlf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   461
    "return a string consisting of the cr-lf Characters"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   462
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   463
    CRLF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   464
	CRLF := String
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   465
		    with:Character return
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   466
		    with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   467
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   468
    ^ CRLF
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   469
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   470
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   471
lf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   472
    "return a string consisting of the lf Character"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   473
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   474
    LF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   475
	LF := String with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   476
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   477
    ^ LF
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   478
!
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   479
12344
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   480
stringHash:aString initialHash:speciesHash
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   481
    "for squeak compatibility only; this is NOT the same hash as my instances use"
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   482
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   483
    | stringSize hash low |
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   484
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   485
    stringSize := aString size.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   486
    hash := speciesHash bitAnd: 16rFFFFFFF.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   487
    1 to: stringSize do: [:pos |
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   488
	hash := hash + (aString at: pos) asInteger.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   489
	"Begin hashMultiply"
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   490
	low := hash bitAnd: 16383.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   491
	hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF.
12344
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   492
    ].
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   493
    ^ hash.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   494
!
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   495
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   496
tab
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   497
    "return a string consisting of the tab-Character"
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   498
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   499
    TAB isNil ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   500
	TAB := String with:Character tab
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   501
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   502
    ^ TAB
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   503
! !
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   504
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   505
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
   506
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   507
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   508
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   509
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   510
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   511
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   512
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   513
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   514
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   515
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   516
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   517
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   518
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   519
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   522
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   523
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   524
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   525
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
   526
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
   527
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
   528
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
   529
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   530
!String methodsFor:'Compatibility-VW5.4'!
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   531
17649
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   532
asByteString
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   533
    ^ self asSingleByteString
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   534
!
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   535
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   536
asGUID
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   537
    "return self as a GUID (or UUID if not present)"
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   538
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   539
    GUID notNil ifTrue:[ ^ GUID fromString:self ].
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   540
    ^ self asUUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   541
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   542
    "
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   543
     '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asGUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   544
    "
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   545
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   546
    "Modified: / 12-01-2011 / 12:33:58 / cg"
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   547
! !
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   548
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
   549
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   550
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   551
329
claus
parents: 314
diff changeset
   552
at:index
claus
parents: 314
diff changeset
   553
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   554
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   555
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   556
     This method is the same as at:."
claus
parents: 314
diff changeset
   557
claus
parents: 314
diff changeset
   558
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   559
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   560
    if (index.isSmallInteger()) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   561
	int idx1Based = context.stArg(0).intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   562
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   563
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   564
#else
329
claus
parents: 314
diff changeset
   565
    REGISTER int indx;
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   566
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   567
claus
parents: 314
diff changeset
   568
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   569
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   570
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   571
	indx = __intVal(index) - 1;
18470
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   572
	if (cls == String) {
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   573
	    fetch:
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   574
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   575
	        RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   576
	    }	    
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   577
	   goto badIndex;
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   578
        }
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   579
	if (indx < 0) goto badIndex;
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   580
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9e4db770f8f5 Optimize for fast-path in String >> at:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18407
diff changeset
   581
	goto fetch;
329
claus
parents: 314
diff changeset
   582
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   583
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   584
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   585
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   586
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   587
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   588
329
claus
parents: 314
diff changeset
   589
at:index put:aCharacter
claus
parents: 314
diff changeset
   590
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   591
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   592
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   593
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   594
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   595
claus
parents: 314
diff changeset
   596
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   597
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   598
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   599
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   600
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   601
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   602
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   603
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   604
#else
329
claus
parents: 314
diff changeset
   605
    REGISTER int value, indx;
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   606
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   607
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   608
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   609
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   610
    if (__isString(slf)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   611
	if (__isCharacter(aCharacter)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   612
	    value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   613
	    if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   614
	     && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   615
		indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   616
		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   617
		    __stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   618
		    RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   619
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   620
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   621
	}
329
claus
parents: 314
diff changeset
   622
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   623
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   624
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   625
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   626
!
claus
parents: 314
diff changeset
   627
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   632
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   633
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   634
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   635
	int idx1Based = index.intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   636
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   637
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   638
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   639
    REGISTER int indx;
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   640
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   641
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   642
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   643
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   644
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   645
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   646
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   647
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   648
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   649
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   650
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   651
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   652
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   653
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   654
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   655
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   656
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   657
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   658
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   659
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   660
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   661
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   662
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   663
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   664
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   665
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   666
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   667
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   668
     Returns aCharacter (sigh).
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   669
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   670
a27a279701f8 Initial revision
claus
parents:
diff changeset
   671
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   672
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   673
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   674
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   675
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   676
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   677
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   678
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   679
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   680
    REGISTER int value, indx;
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   681
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   682
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   683
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   684
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   685
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   686
    if (__isCharacter(aCharacter)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   687
	value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   688
	if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   689
	 && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   690
	    cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   691
	    indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   692
	    if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   693
		if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   694
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   695
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   696
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   697
		__stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   698
		RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   699
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   700
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   701
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   702
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   703
#endif /* not __SCHTEAM__ */
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   704
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   705
    (aCharacter isMemberOf:Character) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   706
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   707
	 tried to store something which is not a character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   708
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   709
	^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   710
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   711
    (aCharacter codePoint between:1 and:255) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   712
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   713
	 tried to store a multibyte character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   714
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   715
	^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   716
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   717
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   718
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   719
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   720
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   721
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   722
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   723
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   724
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   725
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   726
    super basicAt:index put:aCharacter codePoint.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   727
    ^ aCharacter
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   728
!
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   729
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   730
first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   731
    "return the first character.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   732
     Reimplemented here for speed"
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   733
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   734
%{  /* NOCONTEXT */
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   735
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   736
    REGISTER int indx;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   737
    REGISTER OBJ slf, cls;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   738
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   739
    slf = self;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   740
    cls = __qClass(slf);
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   741
    indx = 0;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   742
    if (cls != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   743
	if (indx < 0) goto badIndex;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   744
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   745
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   746
    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   747
	RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   748
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   749
badIndex: ;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   750
%}.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   751
    ^ super first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   752
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   753
    "
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   754
     'abc' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   755
     '' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   756
    "
2
claus
parents: 1
diff changeset
   757
! !
claus
parents: 1
diff changeset
   758
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   759
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   760
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   762
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   763
    "return the index of the first occurrences of the argument, aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   764
     in the receiver or 0 if not found - reimplemented here for speed."
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   765
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   766
    ^ self indexOf:aCharacter
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   767
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   768
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   769
     'hello world' identityIndexOf:(Character space)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   770
     'hello world' identityIndexOf:$d
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   771
     'hello world' identityIndexOf:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   772
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   773
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   774
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   775
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   776
    "Modified: / 10-01-2012 / 17:07:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   778
13923
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   779
identityIndexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   780
    "return the index of the first occurrences of the argument, aCharacter
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   781
     in the receiver or 0 if not found - reimplemented here for speed."
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   782
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   783
    ^ self indexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   784
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   785
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   786
     'hello world' identityIndexOf:(Character space)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   787
     'hello world' identityIndexOf:$d
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   788
     'hello world' identityIndexOf:1
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   789
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   790
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   791
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   792
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   793
    "Created: / 10-01-2012 / 17:10:54 / cg"
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   794
!
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   795
10
claus
parents: 5
diff changeset
   796
includesAny:aCollection
claus
parents: 5
diff changeset
   797
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   798
     argument, aCollection.
17573
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   799
     - redefined for speed if the argument is a String; especially optimized,
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   800
     if the searched collection has less than 6 characters."
10
claus
parents: 5
diff changeset
   801
claus
parents: 5
diff changeset
   802
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   803
claus
parents: 5
diff changeset
   804
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   805
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   806
    OBJ cls;
10
claus
parents: 5
diff changeset
   807
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
   808
    if (__isStringLike(aCollection)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   809
	matchP = __stringVal(aCollection);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   810
	cp = __stringVal(self);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   811
	if ((cls = __qClass(self)) != String)
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   812
	    cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   813
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   814
	switch (__stringSize(aCollection)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   815
	    case 5:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   816
		/* five character search */
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   817
		{
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   818
		    unsigned char c1 = matchP[0];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   819
		    unsigned char c2 = matchP[1];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   820
		    unsigned char c3 = matchP[2];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   821
		    unsigned char c4 = matchP[3];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   822
		    unsigned char c5 = matchP[4];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   823
		    unsigned char ch;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   824
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
   825
		    while ((ch = *cp++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   826
			if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   827
			    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   828
			}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   829
		    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   830
		    RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   831
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   832
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   833
	    case 4:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   834
		/* four character search */
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   835
		{
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   836
		    unsigned char c1 = matchP[0];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   837
		    unsigned char c2 = matchP[1];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   838
		    unsigned char c3 = matchP[2];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   839
		    unsigned char c4 = matchP[3];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   840
		    unsigned char ch;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   841
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
   842
		    while ((ch = *cp++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   843
			if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   844
			    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   845
			}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   846
		    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   847
		    RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   848
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   849
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   850
	    case 3:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   851
		/* three character search */
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   852
		{
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   853
		    unsigned char c1 = matchP[0];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   854
		    unsigned char c2 = matchP[1];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   855
		    unsigned char c3 = matchP[2];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   856
		    unsigned char ch;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   857
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
   858
		    while ((ch = *cp++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   859
			if ((ch == c1) || (ch == c2) || (ch == c3)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   860
			    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   861
			}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   862
		    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   863
		    RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   864
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   865
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   866
	    case 2:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   867
		/* two character search */
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   868
		{
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   869
		    unsigned char c1 = matchP[0];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   870
		    unsigned char c2 = matchP[1];
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   871
		    unsigned char ch;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   872
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
   873
		    while ((ch = *cp++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   874
			if ((ch == c1) || (ch == c2)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   875
			    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   876
			}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   877
		    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   878
		    RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   879
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   880
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   881
	    case 1:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   882
		/* single character search */
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   883
		if (strchr(cp, matchP[0])) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   884
		    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   885
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   886
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   887
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   888
	    case 0:
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   889
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   890
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   891
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   892
	{
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   893
	    unsigned char ch;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   894
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
   895
	    while ((ch = *cp++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   896
		if (strchr(matchP, ch)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   897
		    RETURN ( true );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   898
		}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   899
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   900
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   901
	RETURN ( false );
10
claus
parents: 5
diff changeset
   902
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   903
%}.
10
claus
parents: 5
diff changeset
   904
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   905
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   906
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   907
     'hello world' includesAny:'abcd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   908
     'hello world' includesAny:'xyz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   909
     'hello world' includesAny:'xz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   910
     'hello world' includesAny:'od'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   911
     'hello world' includesAny:'xd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   912
     'hello world' includesAny:'dx'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   913
     'hello world' includesAny:(Array with:$a with:$b with:$d)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   914
     'hello world' includesAny:(Array with:$x with:$y)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   915
     'hello world' includesAny:(Array with:1 with:2)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   916
    "
10
claus
parents: 5
diff changeset
   917
!
claus
parents: 5
diff changeset
   918
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   919
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
   920
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   921
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   922
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   923
a27a279701f8 Initial revision
claus
parents:
diff changeset
   924
%{  /* NOCONTEXT */
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   925
#ifdef __SCHTEAM__
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   926
    if (start.isSmallInteger()
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   927
     && aCharacter.isSTCharacter()) {
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   928
        int idx1Based = start.intValue();   // st index is 1 based
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   929
        int jIdx = self.asString().indexOf(aCharacter.charValue(), idx1Based-1);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   930
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   931
        return context._RETURN( jIdx+1 );    // st index is 1 based
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   932
    }
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   933
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   934
#else
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   935
# undef __UNROLL_LOOPS__
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   936
# undef FAST_MEMCHR
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   937
# define V2
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   938
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   939
    REGISTER unsigned char *cp;
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   940
# ifdef FAST_MEMCHR
8923
ba871e13e4f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8922
diff changeset
   941
    REGISTER unsigned char *ncp;
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   942
# endif
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
   943
    REGISTER INT index;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
   944
    REGISTER unsigned byteValue;
8924
eb2dd7dd459f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8923
diff changeset
   945
    int last;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   946
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   947
252
   948
    if (__isSmallInteger(start)) {
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   949
        index = __intVal(start);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   950
        if (index > 0) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   951
            if (__isCharacter(aCharacter)) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   952
                byteValue = __intVal(__characterVal(aCharacter));
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   953
                if (byteValue <= 0xFF) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   954
                    last = __stringSize(self);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   955
                    cp = __stringVal(self);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   956
                    if ((cls = __qClass(self)) != String) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   957
                        int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   958
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   959
                        cp += numInstBytes;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   960
                        last -= numInstBytes;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   961
                    }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   962
                    if (index <= last) {
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   963
# ifdef FAST_MEMCHR
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   964
                        ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   965
                        if (ncp) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   966
                            RETURN ( __mkSmallInteger(ncp - cp + 1) );
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   967
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   968
# else
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   969
#  ifdef __UNROLL_LOOPS__
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   970
                        {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   971
                            int last3 = last-3;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   972
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   973
                            for (; index <= last3; index += 4) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   974
                                if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   975
                                if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   976
                                if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   977
                                if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   978
                            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   979
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   980
#  endif
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   981
#  ifdef V1
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   982
                        for (; index <= last; index++) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   983
                            if (cp[index-1] == byteValue) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   984
                                RETURN ( __mkSmallInteger(index) );
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   985
                            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   986
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   987
#  endif
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
   988
#  ifdef V2
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   989
                        {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   990
                            // see bit twiddling hacks
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   991
#                           define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   992
#                           define hasByteM(v,m)   hasZeroByte( (v) ^ m)
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   993
#   if __POINTER_SIZE__ == 8
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   994
#                           define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   995
#                           define hasByteM8(v,m)   hasZeroByte8( (v) ^ m)
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   996
                            // the following loop checks eight bytes at once
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   997
                            if (((index-1) & 0x7) == 0) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
   998
                                int last8 = last-8;
18950
5fd16edf5a5f Fixed broken String>>indexOf:startingAt:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18942
diff changeset
   999
                                INT m = (~0ULL/255 * (byteValue));
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1000
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1001
                                while (index <= last8) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1002
                                    unsigned INT v = *(unsigned INT *)(cp+index-1);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1003
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1004
                                    if (hasByteM8(v,m)) break;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1005
                                    index += 8;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1006
                                }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1007
                            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1008
#   endif
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1009
                            // the following loop checks four bytes at once
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1010
                            if (((index-1) & 0x3) == 0) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1011
                                int last4 = last-4;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1012
                                int m = (~0UL/255 * (byteValue));
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1013
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1014
                                while (index <= last4) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1015
                                    unsigned int v = *(unsigned int *)(cp+index-1);
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1016
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1017
                                    if (hasByteM(v,m)) break;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1018
                                    index += 4;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1019
                                }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1020
                            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1021
                            while (index <= last) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1022
                                if (cp[index-1] == byteValue) {
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1023
                                    RETURN ( __mkSmallInteger(index) );
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1024
                                }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1025
                                index++;
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1026
                            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1027
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1028
#  endif
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1029
# endif
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1030
                    }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1031
                }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1032
            }
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1033
            RETURN ( __mkSmallInteger(0) );
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1034
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1035
    }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1036
# undef V2
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1037
#endif /* not SCHTEAM */
370
claus
parents: 368
diff changeset
  1038
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1039
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1040
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1041
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1042
     'hello world' indexOf:$0 startingAt:1
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1043
     'hello world' indexOf:$l startingAt:1
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1044
     'hello world' indexOf:$l startingAt:5
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1045
     'hello world' indexOf:$d startingAt:5
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1046
     #[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1047
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1048
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1049
     '1234567890123456a' indexOf:$a
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1050
     '1234567890123456a' indexOf:$b
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1051
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1052
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1053
     s := '12345678901234b'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1054
     self assert:(s indexOf:$x) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1055
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1056
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1057
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1058
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1059
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1060
     self assert:(s indexOf:$0) == 10.
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1061
     self assert:(s indexOf:$b) == 15.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1062
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1063
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1064
     s := ''.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1065
     self assert:(s indexOf:$1) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1066
     s := '1'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1067
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1068
     self assert:(s indexOf:$2) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1069
     s := '12'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1070
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1071
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1072
     self assert:(s indexOf:$3) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1073
     s := '123'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1074
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1075
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1076
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1077
     self assert:(s indexOf:$4) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1078
     s := '1234'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1079
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1080
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1081
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1082
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1083
     self assert:(s indexOf:$5) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1084
     s := '12345'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1085
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1086
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1087
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1088
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1089
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1090
     self assert:(s indexOf:$6) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1091
     s := '123456'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1092
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1093
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1094
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1095
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1096
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1097
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1098
     self assert:(s indexOf:$7) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1099
     s := '1234567'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1100
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1101
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1102
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1103
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1104
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1105
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1106
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1107
     self assert:(s indexOf:$8) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1108
     s := '12345678'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1109
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1110
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1111
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1112
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1113
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1114
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1115
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1116
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1117
     self assert:(s indexOf:$9) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1118
     s := '123456789'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1119
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1120
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1121
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1122
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1123
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1124
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1125
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1126
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1127
     self assert:(s indexOf:$9) == 9.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1128
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1129
     self assert:(s indexOf:$0) == 0.
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1130
     self assert:(s indexOf:$b) == 0.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1131
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1132
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1133
     s := String new:1024.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1134
     s atAllPut:$a.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1135
     s at:512 put:(Character space).
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1136
     Time millisecondsToRun:[
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1137
        1000000 timesRepeat:[ s indexOf:(Character space) ]
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1138
     ]
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1139
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1140
     timing (ms):
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1141
        v1: 1763 normal
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1142
            2340 +unroll
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1143
            3308 memsrch !!
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1144
        v2: 1045
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1145
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1146
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
  1147
    "Modified: / 10-01-2012 / 17:09:34 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1148
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1149
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1150
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1151
    "return the index of the first occurrence of any character in aCollectionOfCharacters,
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1152
     in myself starting at start, anInteger or 0 if not found;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1153
     - reimplemented here for speed if aCollectionOfCharacters is a string."
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1154
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1155
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1156
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1157
    unsigned char *ccp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1158
    unsigned char *cp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1159
    INT index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1160
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1161
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1162
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1163
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1164
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1165
    if (__isSmallInteger(start)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  1166
     && __isStringLike(aCollectionOfCharacters)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1167
	matchP = __stringVal(aCollectionOfCharacters);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1168
	index = __intVal(start);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1169
	if (index > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1170
	    cp = __stringVal(self) + index - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1171
	    if ((cls = __qClass(self)) != String) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1172
		cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1173
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1174
	    len = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1175
	    if (index <= len) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1176
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1177
		if (matchP[0] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1178
		    /* matchSet is empty */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1179
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1180
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1181
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1182
		if (matchP[1] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1183
		    /* only a single character match */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1184
		    unsigned char m = matchP[0];
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1185
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1186
# ifdef FAST_MEMCHR
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1187
		    ccp = (unsigned char *) memchr(cp, m, len+1-index);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1188
		    if (ccp) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1189
			RETURN ( __mkSmallInteger((ccp - cp) + index + 1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1190
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1191
# else
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  1192
		    while ((c = *cp++) != '\0') {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1193
			if (c == m) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1194
			    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1195
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1196
			index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1197
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1198
# endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1199
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1200
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1201
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1202
		if (matchP[2] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1203
		    /* two character matches */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1204
		    unsigned char m1 = matchP[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1205
		    unsigned char m2 = matchP[1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1206
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  1207
		    while ((c = *cp++) != '\0') {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1208
			if ((c == m1) || (c == m2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1209
			    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1210
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1211
			index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1212
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1213
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1214
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1215
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1216
		min = max = matchP[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1217
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1218
		for (ccp = matchP+1; *ccp ; ccp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1219
		    unsigned char c = *ccp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1220
		    if (c < min) min = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1221
		    else if (c > max) max = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1222
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1223
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  1224
		while ((c = *cp++) != '\0') {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1225
		    if ((c >= min) && (c <= max)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1226
			for (ccp = matchP; *ccp ; ccp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1227
			    if (*ccp == c) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1228
				RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1229
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1230
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1231
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1232
		    index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1233
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1234
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1235
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1236
	}
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1237
    }
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1238
%}.
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1239
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1240
    "/ fallback: 1st argument not a string or error
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1241
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1242
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1243
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1244
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1245
     'hello world' indexOfAny:'eoa' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1246
     'hello world' indexOfAny:'eoa' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1247
     'hello world' indexOfAny:'AOE' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1248
     'hello world' indexOfAny:'o' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1249
     'hello world' indexOfAny:'o' startingAt:6
18972
57301b0d5ee1 Removed (wrong) prototype of memchr() in String.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18971
diff changeset
  1250
     'hello world' indexOfAny:'#$' startingAt:6
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1251
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1252
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1253
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1254
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1255
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1256
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1257
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1258
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1259
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1260
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1261
#ifndef NON_ASCII       /* i.e. not EBCDIC ;-) */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1262
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1263
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1264
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1265
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1266
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1267
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1268
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1269
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1270
	index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1271
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1272
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1273
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1274
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1275
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1276
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1277
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1278
	len -= numInstBytes;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1279
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1280
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1281
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1282
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1283
	c = cp[index - 1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1284
	if (c < ' ') {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1285
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1286
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1287
	index++;
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1288
    }
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1289
    RETURN ( __mkSmallInteger(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1290
#endif
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1291
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1292
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1293
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1294
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1295
     'hello world'             indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1296
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1297
     '1\' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1298
     '1\' withCRs indexOfControlCharacterStartingAt:2
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1299
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1300
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1301
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1302
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1303
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1304
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1305
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1306
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1307
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1308
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1309
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1310
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1311
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1312
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1313
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1314
	index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1315
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1316
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1317
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1318
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1319
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1320
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1321
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1322
	len -= numInstBytes;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1323
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1324
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1325
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1326
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1327
	c = cp[index - 1];
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1328
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1329
	if (c > ' ')
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1330
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1331
	if ((c != ' ') && (c != '\t') && (c != '\n')
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1332
	 && (c != '\r') && (c != '\f')) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1333
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1334
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1335
	index++;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1336
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1337
    RETURN ( __mkSmallInteger(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1338
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1339
    ^ super indexOfNonSeparatorStartingAt:start
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1340
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1341
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1342
     'hello world' indexOfNonWhiteSpaceStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1343
     'hello world' indexOfNonWhiteSpaceStartingAt:7
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1344
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1345
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1346
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1347
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1348
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1349
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1350
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1351
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1352
    REGISTER unsigned char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1353
    int len, index;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1354
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1355
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1356
    index = __intVal(start);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1357
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1358
	index = 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1359
    }
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1360
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1361
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1362
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1363
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1364
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1365
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1366
	len -= numInstBytes;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1367
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1368
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1369
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1370
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1371
	c = cp[index - 1];
329
claus
parents: 314
diff changeset
  1372
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1373
	if (c <= ' ')
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1374
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1375
	if ((c == ' ') || (c == '\t') || (c == '\n')
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1376
	 || (c == '\r') || (c == '\f')) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1377
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1378
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1379
	index++;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1380
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1381
    RETURN ( __mkSmallInteger(0) );
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1382
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1383
    ^ super indexOfSeparatorStartingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1384
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1385
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1386
     'hello world' indexOfSeparatorStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1387
     'hello world' indexOfSeparatorStartingAt:7
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1388
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1389
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1390
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1391
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1392
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1393
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1394
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1395
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1396
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1397
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1398
    REGISTER unsigned byteValue;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1399
    REGISTER INT count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1400
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1401
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1402
    if (__isCharacter(aCharacter)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1403
	limit = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1404
	count = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1405
	byteValue = __intVal(__characterVal(aCharacter));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1406
	if (byteValue <= 0xFF) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1407
	    cp = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1408
	    if ((cls = __qClass(self)) != String) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1409
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1410
		limit -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1411
		cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1412
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1413
	    /* loop unrolled and software-pipelined
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1414
	     * (gives 30-40% speedup on Intel-DUO using borland bcc55)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1415
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1416
	    while (limit >= 4) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1417
		register unsigned char c1, c2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1418
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1419
		c1 = cp[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1420
		limit -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1421
		c2 = cp[1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1422
		if (c1 == byteValue) count++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1423
		c1 = cp[2];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1424
		if (c2 == byteValue) count++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1425
		c2 = cp[3];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1426
		if (c1 == byteValue) count++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1427
		cp += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1428
		if (c2 == byteValue) count++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1429
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1430
	    while (limit > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1431
		register unsigned char c1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1432
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1433
		c1 = cp[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1434
		limit--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1435
		if (c1 == byteValue) count++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1436
		cp ++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1437
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1438
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1439
	RETURN ( __mkSmallInteger(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1440
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1441
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1442
    ^ super occurrencesOf:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1443
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1444
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1445
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1446
     'hello world' occurrencesOf:$w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1447
     'hello world' occurrencesOf:$l
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1448
     'hello world' occurrencesOf:$x
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1449
     'hello world' occurrencesOf:1
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1450
     Time millisecondsToRun:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1451
	1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ]
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1452
     ]. 219 203 156 203 204 204 219 172 187 187 141
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1453
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1454
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1455
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1456
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1457
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1458
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1459
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1460
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1461
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1462
     In contrast to ST-80, case differences are NOT ignored, thus
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1463
     'foo' < 'Foo' will return false.
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1464
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1465
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1466
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1467
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1468
    return context._RETURN( self.stringLtP(aString) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1469
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1470
#else
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1471
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1472
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1473
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1474
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1475
    if (__isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1476
	argIsString = __qIsStringLike(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1477
	if (argIsString || __qClass(aString) == __qClass(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1478
	    cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1479
	    len2 = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1480
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1481
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1482
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1483
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1484
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1485
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1486
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1487
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1488
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1489
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1490
	    cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1491
	    len1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1492
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1493
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1494
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1495
	    if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1496
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1497
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1498
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1499
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1500
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1501
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1502
	    if (len1 <= len2)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1503
		cmp = strncmp(cp1, cp2, len1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1504
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1505
		cmp = strncmp(cp1, cp2, len2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1506
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1507
	    if (cmp < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1508
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1509
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1510
	    if ((cmp == 0) && (len1 < len2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1511
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1512
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1513
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1514
	}
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1515
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1516
#endif
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1517
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1518
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1519
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1520
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1521
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1522
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1523
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1524
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1525
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1526
375
claus
parents: 370
diff changeset
  1527
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1528
#ifdef __SCHTEAM__
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1529
    if (aString == self) {
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1530
	return __c__._RETURN_true();
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1531
    }
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1532
    if (aString.isStringLike()) {
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1533
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False );
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1534
    }
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1535
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1536
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1537
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1538
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1539
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1540
    unsigned char *cp1, *cp2;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1541
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1542
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1543
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1544
    if (aString == self) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1545
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1546
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1547
    if (! __isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1548
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1549
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1550
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1551
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1552
    if (argIsString || __qClass(aString) == __qClass(self)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1553
	cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1554
	l2 = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1555
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1556
	 * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1557
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1558
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1559
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1560
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1561
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1562
	    l2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1563
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1564
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1565
	cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1566
	l1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1567
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1568
	 * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1569
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1570
	if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1571
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1572
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1573
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1574
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1575
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1576
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1577
	if (l1 != l2) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1578
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1579
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1580
# ifdef FAST_MEMCMP
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1581
	RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1582
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1583
	addrDelta = cp2 - cp1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1584
#  ifdef __UNROLL_LOOPS__
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1585
	while (l1 >= (sizeof(unsigned INT)*4)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1586
	    if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1587
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1588
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1589
	    if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1590
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1591
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1592
	    if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1593
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1594
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1595
	    if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1596
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1597
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1598
	    l1 -= (sizeof(unsigned INT) * 4);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1599
	    cp1 += (sizeof(unsigned INT) * 4);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1600
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1601
#  endif /* __UNROLL_LOOPS__ */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1602
	while (l1 >= sizeof(unsigned INT)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1603
	    if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1604
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1605
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1606
	    l1 -= sizeof(unsigned INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1607
	    cp1 += sizeof(unsigned INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1608
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1609
	if (l1 >= sizeof(unsigned short)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1610
	    if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1611
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1612
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1613
	    l1 -= sizeof(unsigned short);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1614
	    cp1 += sizeof(unsigned short);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1615
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1616
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1617
	    if (*cp1 != *(cp1+addrDelta)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1618
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1619
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1620
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1621
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1622
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1623
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1624
	RETURN (true);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1625
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1626
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1627
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1628
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1629
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1630
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1631
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1632
     'foo' = 'Foo'
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1633
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1634
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1635
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1636
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1637
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1638
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1639
     tEmpty := Time millisecondsToRun:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1640
	 1000000 timesRepeat:[]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1641
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1642
     tCmp := Time millisecondsToRun:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1643
	 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1644
     ].
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1645
     tCmp - tEmpty
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1646
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1647
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1648
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1649
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1650
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1651
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1652
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1653
     In contrast to ST-80, case differences are NOT ignored, thus
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1654
     'foo' > 'Foo' will return true.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1655
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1656
375
claus
parents: 370
diff changeset
  1657
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1658
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1659
    return context._RETURN( aString.stringLtP( self ) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1660
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1661
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1662
    int len1, len2, cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1663
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1664
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1665
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1666
    if (__isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1667
	argIsString = __qIsStringLike(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1668
	if (argIsString || __qClass(aString) == __qClass(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1669
	    cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1670
	    len2 = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1671
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1672
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1673
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1674
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1675
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1676
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1677
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1678
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1679
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1680
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1681
	    cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1682
	    len1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1683
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1684
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1685
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1686
	    if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1687
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1688
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1689
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1690
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1691
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1692
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1693
	    if (len1 <= len2)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1694
		cmp = strncmp(cp1, cp2, len1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1695
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1696
		cmp = strncmp(cp1, cp2, len2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1697
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1698
	    if (cmp > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1699
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1700
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1701
	    if ((cmp == 0) && (len1 > len2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1702
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1703
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1704
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1705
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1706
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1707
#endif /* not __SCHTEAM__ */
370
claus
parents: 368
diff changeset
  1708
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1709
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1710
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1711
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1712
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1713
    "Compare the receiver with the argument and return 1 if the receiver is
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1714
     greater, 0 if equal and -1 if less than the argument in a sorted list.
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1715
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1716
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1717
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1718
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1719
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1720
    int cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1721
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1722
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1723
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1724
    if (__isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1725
	argIsString = __qIsStringLike(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1726
	if (argIsString || __qClass(aString) == __qClass(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1727
	    cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1728
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1729
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1730
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1731
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1732
	    if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1733
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1734
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1735
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1736
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1737
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1738
	    cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1739
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1740
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1741
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1742
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1743
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1744
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1745
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1746
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1747
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1748
#ifdef HAS_STRCOLL
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1749
	    cmp = strcoll(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1750
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1751
	    cmp = strcmp(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1752
#endif
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1753
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1754
	    if (cmp > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1755
		RETURN ( __mkSmallInteger(1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1756
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1757
	    if (cmp < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1758
		RETURN ( __mkSmallInteger(-1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1759
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1760
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1761
	}
370
claus
parents: 368
diff changeset
  1762
    }
329
claus
parents: 314
diff changeset
  1763
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1764
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1765
     currently, this operation is only defined for strings, symbols
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1766
     and subclasses.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1767
    "
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1768
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1769
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1770
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1771
compareWith:aString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1772
    "Compare the receiver with the argument and return 1 if the receiver is
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1773
     greater, 0 if equal and -1 if less than the argument.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1774
     This comparison is based on the elements' codepoints -
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1775
     i.e. upper/lowercase & national characters are NOT treated specially.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1776
     'foo' compareWith: 'Foo' will return 1.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1777
     while 'foo' sameAs:'Foo' will return true"
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1778
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1779
%{  /* NOCONTEXT */
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1780
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1781
    int cmp;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1782
    unsigned char *cp1, *cp2;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1783
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1784
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1785
    if (__isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1786
	argIsString = __qIsStringLike(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1787
	if (argIsString || __qClass(aString) == __qClass(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1788
	    cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1789
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1790
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1791
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1792
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1793
	    if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1794
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1795
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1796
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1797
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1798
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1799
	    cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1800
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1801
	     * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1802
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1803
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1804
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1805
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1806
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1807
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1808
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1809
	    cmp = strcmp(cp1, cp2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1810
	    if (cmp > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1811
		RETURN ( __mkSmallInteger(1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1812
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1813
	    if (cmp < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1814
		RETURN ( __mkSmallInteger(-1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1815
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1816
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1817
	}
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1818
    }
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1819
%}.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1820
    "
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1821
     currently, this operation is only defined for strings, symbols
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1822
     and subclasses.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1823
    "
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1824
    ^ self primitiveFailed
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1825
!
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1826
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1827
hash
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1828
    "return an integer useful as a hash-key.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1829
     This default method uses whichever hash algorithm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1830
     used in the ST/X VM (which is actually fnv-1a)"
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1831
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1832
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1833
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1834
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1835
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1836
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1837
#else
18487
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1838
    /* Following code is inlined FNV1a hash. 
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1839
     * Inlined for speed (to avoid send).
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1840
     * DO NOT use __symbolHash() here as it 
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1841
     * does not handle characters with codepoint 0
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1842
     * properly - see
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1843
     * https://swing.fit.cvut.cz/projects/stx-jv/ticket/65
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1844
     */
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1845
    REGISTER unsigned int h;
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1846
    REGISTER unsigned char *cp;
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1847
    int l;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1848
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1849
    cp = __stringVal(self);
18487
8735bd9eee2f Use inlined FNV1a hash for String
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18470
diff changeset
  1850
    l = __stringSize(self);
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1851
    if (__qClass(self) == String) {
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1852
	cont:    
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1853
	h = 2166136261U;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1854
	while (l >= 4) {
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1855
	    l -= 4;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1856
	    h = (h ^ cp[0]) * 16777619;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1857
	    h = (h ^ cp[1]) * 16777619;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1858
	    h = (h ^ cp[2]) * 16777619;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1859
	    h = (h ^ cp[3]) * 16777619;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1860
	    cp += 4;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1861
    	}
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1862
    	while (l--) {
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1863
	    h = (h ^ *cp++) * 16777619;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1864
    	}
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1865
    	// make it a smallInteger
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1866
    	h = (h ^ (h >> 30)) & 0x3FFFFFFF;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1867
    	RETURN ( __mkSmallInteger(h));
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1868
    } else {        
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1869
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1870
	cp += n;
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1871
	goto cont;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1872
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1873
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1874
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1875
    ^ self primitiveFailed
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1876
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1877
    "
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1878
     'a' hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1879
     'ab' hash = 'ab' asUnicode16String hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1880
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1881
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1882
    "Created: / 26-12-2011 / 13:53:09 / cg"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1883
!
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1884
13880
Claus Gittinger <cg@exept.de>
parents: 13205
diff changeset
  1885
hash_dragonBook
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1886
    "return an integer useful as a hash-key.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1887
     This method implements the dragon-book algorithm (aho, ullman)."
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1888
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1889
%{  /* NOCONTEXT */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1890
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1891
    REGISTER unsigned g, val;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1892
    REGISTER unsigned char *cp, *cp0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1893
    int l;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1894
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1895
    cp = __stringVal(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1896
    l = __stringSize(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1897
    if (__qClass(self) != @global(String)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1898
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1899
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1900
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1901
	l -= n;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1902
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1903
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1904
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1905
     * this is the dragon-book algorithm
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1906
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1907
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1908
    val = 0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1909
    switch (l) {
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1910
    default:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1911
	for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1912
	    val = (val << 4) + *cp;
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  1913
	    if ((g = (val & 0xF0000000)) != 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1914
		val ^= g >> 24;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1915
		val ^= g;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1916
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1917
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1918
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1919
    case 6:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1920
	val = cp[5] << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1921
    case 5:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1922
	val = (val + cp[4]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1923
    case 4:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1924
	val = (val + cp[3]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1925
    case 3:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1926
	val = (val + cp[2]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1927
    case 2:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1928
	val = (val + cp[1]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1929
    case 1:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1930
	val = val + cp[0];
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1931
    case 0:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1932
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1933
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1934
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1935
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1936
     * multiply by large prime to spread values
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1937
     * This speeds up Set and Dictionary by a factor of 10!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1938
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1939
    val *= 31415821;
12763
e19933d3e188 changed:
Stefan Vogel <sv@exept.de>
parents: 12727
diff changeset
  1940
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1941
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1942
    ^ self primitiveFailed
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1943
!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1944
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1945
hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1946
    "return an integer useful as a hash-key.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1947
     This method uses the fnv-1a algorithm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1948
     (which is actually a pretty good one)."
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1949
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1950
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1951
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1952
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1953
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1954
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1955
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1956
    REGISTER unsigned int h;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1957
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1958
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1959
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1960
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1961
    l = __stringSize(self);
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1962
    if (__qClass(self) == String) {
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1963
	cont:    
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1964
	h = 2166136261U;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1965
	while (l >= 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1966
	l -= 4;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1967
	h = (h ^ cp[0]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1968
	h = (h ^ cp[1]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1969
	h = (h ^ cp[2]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1970
	h = (h ^ cp[3]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1971
	cp += 4;
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1972
    	}
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1973
    	while (l--) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  1974
	h = (h ^ *cp++) * 16777619;
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1975
    	}
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1976
    	// make it a smallInteger
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1977
    	h = (h ^ (h >> 30)) & 0x3FFFFFFF;
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1978
    	RETURN ( __mkSmallInteger(h));
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1979
    } else {        
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1980
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1981
	cp += n;
18488
cb7a21f38b77 Optimize for fast-path in String>hash, String>>hash_fnv1a and Symbol>>hash to avoid jumps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18487
diff changeset
  1982
	goto cont;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1983
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1984
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1985
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1986
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1987
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1988
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1989
     'a' hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1990
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1991
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1992
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1993
hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1994
    "return an integer useful as a hash-key.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1995
     This method uses the same algorithm as used in
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1996
     the java virtual machine (which is actually a bad one)."
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1997
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  1998
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  1999
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2000
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2001
    long h = me.hash_java();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2002
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2003
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2004
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2005
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2006
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2007
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2008
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2009
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2010
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2011
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2012
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2013
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2014
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2015
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2016
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2017
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2018
     * this is the jvm algorithm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2019
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2020
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2021
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2022
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2023
	val = ((val * 31) & 0xFFFFFFFF) + cp[0];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2024
	val = ((val * 31) & 0xFFFFFFFF) + cp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2025
	val = ((val * 31) & 0xFFFFFFFF) + cp[2];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2026
	val = ((val * 31) & 0xFFFFFFFF) + cp[3];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2027
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2028
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2029
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2030
	val = ((val * 31) & 0xFFFFFFFF) + *cp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2031
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2032
    RETURN ( __MKUINT(val));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2033
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2034
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2035
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2036
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2037
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2038
     'a' hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2039
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2040
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2041
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2042
hash_sdbm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2043
    "return an integer useful as a hash-key.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2044
     This method implements the sdbm algorithm."
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2045
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2046
%{  /* NOCONTEXT */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2047
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2048
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2049
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2050
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2051
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2052
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2053
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2054
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2055
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2056
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2057
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2058
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2059
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2060
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2061
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2062
     * this is the sdbm algorithm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2063
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2064
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2065
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2066
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2067
	val = ((val * 65599) & _MAX_INT) + cp[0];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2068
	val = ((val * 65599) & _MAX_INT) + cp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2069
	val = ((val * 65599) & _MAX_INT) + cp[2];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2070
	val = ((val * 65599) & _MAX_INT) + cp[3];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2071
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2072
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2073
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2074
	val = ((val * 65599) & _MAX_INT) + *cp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2075
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2076
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2077
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2078
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2079
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2080
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2081
     'a' hash
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2082
     'ab' hash = 'ab' asUnicode16String hash
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2083
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2084
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2085
    "Created: / 26-12-2011 / 13:53:09 / cg"
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2086
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2087
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2088
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2089
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2090
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2091
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2092
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2093
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2094
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2095
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2096
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2097
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2098
#ifdef __SCHTEAM__
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2099
    if (aString == self) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2100
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2101
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2102
    if (aString.isStringLike()) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2103
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True );
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2104
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2105
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2106
	return __c__._RETURN_true();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2107
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2108
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2109
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  2110
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2111
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  2112
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2113
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2114
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2115
    if (aString == self) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2116
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2118
    if (! __isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2119
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2120
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2121
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2122
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2123
    if (argIsString || __qClass(aString) == __qClass(self)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2124
	cp1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2125
	l1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2126
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2127
	 * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2128
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2129
	if (!__qIsStringLike(self)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2130
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2131
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2132
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2133
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2134
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2135
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2136
	cp2 = __stringVal(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2137
	l2 = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2138
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2139
	 * care for instances of subclasses ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2140
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2141
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2142
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2143
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2144
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2145
	    l2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2146
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2147
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2148
	if (l1 != l2) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2149
	    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2150
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2151
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2152
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2153
# ifdef __UNROLL_LOOPS__
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2154
	while (l1 >= (sizeof(unsigned INT)*4)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2155
	    if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2156
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2157
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2158
	    if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2159
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2160
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2161
	    if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2162
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2163
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2164
	    if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2165
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2166
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2167
	    l1 -= (sizeof(unsigned INT) * 4);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2168
	    cp1 += (sizeof(unsigned INT) * 4);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2169
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2170
# endif /* __UNROLL_LOOPS__ */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2171
	while (l1 >= sizeof(unsigned INT)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2172
	    if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2173
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2174
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2175
	    l1 -= sizeof(unsigned INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2176
	    cp1 += sizeof(unsigned INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2177
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2178
	if (l1 >= sizeof(unsigned short)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2179
	    if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2180
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2181
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2182
	    l1 -= sizeof(unsigned short);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2183
	    cp1 += sizeof(unsigned short);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2184
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2185
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2186
	    if (*cp1 != *(cp1+addrDelta)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2187
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2188
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2189
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2190
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2191
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2192
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2193
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2194
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2195
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2196
    ^ super ~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2197
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2198
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2199
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2200
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2201
asArrayOfSubstrings
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2202
    "Answer an array with all the substrings of the receiver separated by
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2203
     separator characters (space, cr, tab, linefeed, formfeed, etc).
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2204
     CG: This is ported Squeak code, and I am not sure if it is more efficient than
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2205
	 the inherited one... after all: who added it anyway ?"
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2206
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2207
    | substrings start end stop |
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2208
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2209
    substrings := OrderedCollection new.
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2210
    start := 1.
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2211
    stop := self size.
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2212
    [start <= stop] whileTrue: [
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2213
	(self at: start) isSeparator ifFalse: [
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2214
	    end := start + 1.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2215
	    [end <= stop and: [(self at: end) isSeparator not]]
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2216
		whileTrue: [end := end + 1].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2217
	    substrings add: (self copyFrom: start to: end - 1).
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2218
	    start := end - 1
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2219
	].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2220
	start := start + 1
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2221
    ].
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2222
    ^ substrings asArray
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2223
!
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2224
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2225
asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2226
    "if the receiver does not end with a 0-valued character, return a copy of it,
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2227
     with an additional 0-character. Otherwise return the receiver. This is sometimes
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2228
     needed when a string has to be passed to C, which needs 0-terminated strings.
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2229
     Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2230
     strings are not."
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2231
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2232
    ^ self
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2233
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2234
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2235
     'abc' asAsciiZ
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2236
     'abc' asWideString asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2237
    "
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2238
!
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2239
3281
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2240
asBoldText
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2241
    "return self as a bold text"
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2242
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2243
    ^Text string: self emphasis: #bold
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2244
!
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  2245
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2246
asByteArray
15938
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2247
    "return a new ByteArray with the receiver's elements.
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2248
     This redefined method is faster than Collection>>#asByteArray"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2249
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2250
    |bytes sz|
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2251
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2252
    sz := self size.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2253
    bytes := ByteArray new:sz .
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2254
    bytes replaceFrom:1 to:sz with:self startingAt:1.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2255
    ^ bytes
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2256
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2257
    "
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  2258
     'fooBar' asByteArray.
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2259
    "
14260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2261
    "Modified (comment): / 26-07-2012 / 22:55:26 / cg"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2262
!
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2263
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2264
asExternalBytes
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2265
    |bytes sz|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2266
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2267
    sz := self size.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2268
    bytes := ExternalBytes new:(sz + 1).
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2269
    bytes replaceFrom:1 to:sz with:self startingAt:1.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2270
    bytes at:(sz + 1) put:0.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2271
    ^ bytes
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2272
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2273
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2274
     |x|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2275
     x := 'fooBar' asExternalBytes.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2276
     x unprotectFromGC.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2277
     ObjectMemory garbageCollect
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2278
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2279
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2280
    "Modified: / 03-08-2006 / 14:45:32 / fm"
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2281
!
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2282
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2283
asExternalBytesUnprotected
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2284
    "Like asExternalBytes, but does not register the bytes so
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2285
     bytes are GARBAGE-COLLECTED!!"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2286
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2287
    |bytes sz|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2288
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2289
    sz := self size.
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2290
    bytes := ExternalBytes unprotectedNew:(sz + 1).
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2291
    bytes replaceFrom:1 to:sz with:self startingAt:1.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2292
    bytes at:(sz + 1) put:0.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2293
    ^ bytes
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2294
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2295
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2296
     |x|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2297
     x := 'fooBar' asExternalBytesUnprotected.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2298
     ObjectMemory garbageCollect
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2299
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2300
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2301
    "Created: / 05-06-2012 / 14:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2302
    "Modified: / 30-11-2013 / 11:41:40 / cg"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2303
!
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2304
12454
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2305
asImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2306
    "return a write-protected copy of myself"
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2307
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2308
    ^ self copy changeClassTo:ImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2309
!
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2310
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2311
asLowercase
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2312
    "a tuned version. Some apps call this very heavily"
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2313
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2314
%{  /* NOCONTEXT */
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18661
diff changeset
  2315
#if 0
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2316
#ifndef __SCHTEAM__
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2317
    REGISTER OBJ slf = self;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2318
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2319
    if (__qClass(slf) == String) {
18931
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2320
        char quickBuffer[256];
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2321
        int sz = __stringSize(slf);
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2322
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2323
        if (sz < (sizeof(quickBuffer)-1)) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2324
            REGISTER int i = 0;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2325
            int anyChange = 0;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2326
            REGISTER unsigned char *cp = __stringVal(slf);
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2327
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2328
            // fast advance
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2329
            // all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z)
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2330
            // or 0xC0 .. 0xDF. 
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2331
            // I.e. they have the 0x20 bit clear.
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2332
            // Thus, we can fast skip over lowercase, spaces and some puctuation,
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2333
            // if all bytes of a word have the x20 bit set.
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2334
            // 
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2335
#if __POINTER_SIZE__ == 8
18931
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2336
            for (; i<(sz-8); i+=8) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2337
                unsigned INT eightChars;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2338
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2339
                eightChars = *((unsigned INT *)(cp));
18932
ee6840c12f41 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18931
diff changeset
  2340
                if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) break;
18931
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2341
                *((unsigned INT *)(&quickBuffer[i])) = eightChars;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2342
            }
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2343
#endif
18931
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2344
            for (; i<(sz-4); i+=4) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2345
                unsigned int fourChars;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2346
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2347
                fourChars = *((unsigned int *)(cp));
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2348
                if ((fourChars & 0x20202020U) != 0x20202020U) break;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2349
                *((unsigned int *)(&quickBuffer[i])) = fourChars;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2350
            }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2351
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2352
            for (; i<sz; i++) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2353
                unsigned char ch = cp[i];
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2354
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2355
                quickBuffer[i] = ch;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2356
                if ((ch & 0x60) == 0x40) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2357
                    if (ch >= 'A') {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2358
                        if (ch <= 'Z') {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2359
                            quickBuffer[i] = ch - 'A' + 'a';
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2360
                            anyChange = 1;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2361
                        } else {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2362
                            // deal with national latin1 characters
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2363
                            if (ch >= 0xC0) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2364
                                if (ch <= 0xDE) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2365
                                    if (ch != 0xD7) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2366
                                        quickBuffer[i] = ch + 0x20;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2367
                                        anyChange = 1;
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2368
                                    }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2369
                                }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2370
                            }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2371
                        }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2372
                    }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2373
                }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2374
            }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2375
            quickBuffer[i] = '\0';
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2376
            if (! anyChange) {
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2377
                RETURN(slf);
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2378
            }
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2379
            RETURN (__MKSTRING_L(quickBuffer, i));
bb57d4309f62 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18909
diff changeset
  2380
        }
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2381
    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2382
#endif /* ! __SCHTEAM__ */
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18661
diff changeset
  2383
#endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2384
%}.
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2385
    ^ super asLowercase
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2386
!
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2387
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2388
asPackageId
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2389
    "given a package-string as receiver, return a packageId object.
14566
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2390
     packageIds hide the details of module/directory handling inside the path.
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2391
     See PackageId for the required format of those strings."
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  2392
14571
6e2375384861 class: String
Claus Gittinger <cg@exept.de>
parents: 14566
diff changeset
  2393
    ^ PackageId from: self
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2394
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2395
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2396
     'stx:libbasic' asPackageId
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2397
     'stx:goodies/net/ssl' asPackageId
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2398
     'stx:hello' asPackageId
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2399
    "
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2400
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2401
    "Created: / 18-08-2006 / 12:19:54 / cg"
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2402
!
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2403
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  2404
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2405
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2406
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2407
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2408
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2409
11287
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2410
asSingleByteStringIfPossible
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2411
    "I am a single-byte string"
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2412
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2413
    ^ self
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2414
!
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2415
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2416
asSingleByteStringReplaceInvalidWith:replacementCharacter
11883
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2417
    "return the receiver converted to a 'normal' string,
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2418
     with invalid characters replaced by replacementCharacter.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2419
     Can be used to convert from 16-bit strings to 8-bit strings
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2420
     and replace characters above code-255 with some replacement.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2421
     Dummy here, because I am already a single byte string."
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2422
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2423
    ^ self
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2424
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2425
    "Modified: / 07-08-2006 / 15:04:45 / fm"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2426
!
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2427
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2428
asSymbol
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2429
    "Return a unique symbol with the name taken from the receivers characters."
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2430
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2431
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2432
#ifdef __SCHTEAM__
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2433
    return context._RETURN( STSymbol._new(self.asString()) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2434
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2435
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2436
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2437
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2438
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2439
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2440
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2441
    if (cls != String) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2442
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2443
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2444
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2445
    if (newSymbol) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2446
	RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2447
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2448
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2449
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2450
    ^ ObjectMemory allocationFailureSignal raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2451
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2452
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2453
     'hello' asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2454
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2455
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2456
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2457
asSymbolIfInterned
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2458
    "If a symbol with the receivers characters is already known, return it. Otherwise, return nil.
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2459
     This can be used to query for an existing symbol and is the same as:
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2460
	self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2461
     but slightly faster, since the symbol lookup operation is only
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2462
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2463
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2464
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2465
#ifdef __SCHTEAM__
18622
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2466
    STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() );
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2467
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2468
    return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2469
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2470
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2471
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2472
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2473
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2474
    if (cls != String) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2475
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2476
    } else {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2477
	indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2478
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2479
    RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx));
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2480
#endif /* not __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2481
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2482
    ^ self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2483
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2484
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2485
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2486
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2487
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2488
17378
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2489
beImmutable
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2490
    "make myself write-protected"
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2491
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2492
    self changeClassTo:ImmutableString
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2493
!
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2494
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2495
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2496
    "return a string with the characters of the receiver where all tabulator characters
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2497
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2498
     Notice: if the receiver does not contain any tabs, it is returned unchanged;
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2499
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2500
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2501
     Rewritten for speed - because this is very heavily used when reading
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2502
     big files in the FileBrowser (and therefore speeds up fileReading considerably)."
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2503
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2504
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2505
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2506
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2507
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2508
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2509
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2510
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2511
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2512
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2513
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2514
     && __isSmallInteger(numSpaces)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2515
	n = __intVal(numSpaces);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2516
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2517
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2518
	 * for small strings (< 80), do it without a prescan ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2519
	 * the buffer is large enough to even convert a
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2520
	 * receiver consisting fully of tabs.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2521
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2522
	if (__stringSize(self) < 80) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2523
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2524
	    for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2525
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2526
		    any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2527
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2528
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2529
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2530
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2531
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2532
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2533
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2534
		    *dstP++ = c;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2535
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2536
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2537
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2538
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2539
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2540
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2541
	    if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2542
	    *dstP = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2543
	    RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2544
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2545
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2546
	 * for large strings, we compute the new size, allocate a new string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2547
	 * and expand it.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2548
	 *
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2549
	 * first, scan for size ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2550
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2551
	idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2552
	for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2553
	    if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2554
		any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2555
		while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2556
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2557
		    sz++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2558
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2559
		idx++; sz ++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2560
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2561
		sz++; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2562
		if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2563
		    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2564
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2565
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2566
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2567
	if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2568
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2569
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2570
	 * get the string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2571
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2572
	sz = OHDR_SIZE + sz + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2573
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2574
	if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2575
	    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2576
	    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2577
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2578
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2579
	     * expand
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2580
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2581
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2582
	    for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2583
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2584
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2585
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2586
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2587
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2588
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2589
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2590
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2591
		    *dstP++ = c; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2592
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2593
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2594
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2595
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2596
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2597
	    *dstP++ = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2598
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2599
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2600
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2601
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2602
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2603
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2604
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2605
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2606
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2607
, aString
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2608
    "return the concatenation of myself and the argument, aString as a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2609
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2610
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2611
%{
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2612
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2613
    if ( aString.isStringLike() && self.isStringLike() ) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2614
	STString me = self.asSTString();
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2615
	STString other = aString.asSTString();
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2616
	int myLength = me.characters.length;
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2617
	int otherLength = other.characters.length;
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2618
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2619
	char[] newChars = new char[myLength + otherLength];
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2620
	System.arraycopy(me.characters, 0, newChars, 0, myLength);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2621
	System.arraycopy(other.characters, 0, newChars, myLength, otherLength);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2622
	return context._RETURN( new STString( newChars ));
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2623
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2624
#else
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2625
    int l1, l2, sz;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2626
    OBJ newString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2627
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2628
    if (__isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2629
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2630
	 * can do it here if both are Strings/Symbols:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2631
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2632
	if (__qIsStringLike(self) && __qIsStringLike(aString)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2633
	    l1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2634
	    l2 = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2635
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2636
	    sz = OHDR_SIZE + l1 + l2 + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2637
	    __qNew(newString, sz);      /* OBJECT ALLOCATION */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2638
	    if (newString != nil) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2639
		char *cp1, *cp2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2640
		REGISTER unsigned char *dstp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2641
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2642
		__InstPtr(newString)->o_class = String;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2643
		__qSTORE(newString, String);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2644
		dstp = __stringVal(newString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2645
		cp1 = (char *) __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2646
		cp2 = (char *) __stringVal(aString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2647
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2648
# ifdef bcopy4
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2649
		/* knowing that allocation is 4-byte aligned and
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2650
		 * size rounded up to next 4-byte, the first copy
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2651
		 * can be done word-wise.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2652
		 * that speeds up size-10-string , size-10-string
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2653
		 * by 10% on a P5/200.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2654
		 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2655
		{
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2656
		    int nw = l1 >> 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2657
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2658
		    if (l1 & 3) nw++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2659
		    bcopy4(cp1, dstp, nw);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2660
		    dstp += l1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2661
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2662
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2663
#  ifdef FAST_MEMCPY
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2664
		memcpy(dstp, cp1, l1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2665
		dstp += l1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2666
#  else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2667
		while (l1 >= 4) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2668
		    *(int *)dstp = *(int *)cp1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2669
		    dstp += 4; cp1 += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2670
		    l1 -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2671
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2672
		while (l1--) *dstp++ = *cp1++;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2673
#  endif
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2674
# endif
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2675
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2676
# ifdef bcopy4
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2677
		if (((INT)dstp & 3) == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2678
		    int nw = l2 >> 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2679
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2680
		    if (l2 & 3) nw++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2681
		    bcopy4(cp2, dstp, nw);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2682
		    *(dstp + l2) = '\0';
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2683
		    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2684
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2685
# endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2686
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2687
# ifdef FAST_MEMCPY
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2688
		memcpy(dstp, cp2, l2+1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2689
		dstp[l2] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2690
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2691
		while (l2--) *dstp++ = *cp2++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2692
		*dstp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2693
# endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2694
		RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2695
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2696
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2697
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2698
#endif /* not SCHTEAM */
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2699
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2700
    ^ super , aString
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2701
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2702
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2703
     'hello' , 'world' asImmutableString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2704
     'hello' , #world
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2705
     #[0 0 0 1] asString, #[0 0 0 2 0] asString
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2706
    "
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2707
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2708
    "Modified: / 01-04-2012 / 13:19:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2709
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2710
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2711
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2712
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2713
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2714
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2715
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2716
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2717
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2718
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2719
    int len1, len2, len3, sz;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2720
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2721
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2722
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2723
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2724
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2725
    if (__qIsStringLike(self)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2726
	    && __isStringLike(string1)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2727
	    && __isStringLike(string2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2728
	len1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2729
	len2 = __stringSize(string1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2730
	len3 = __stringSize(string2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2731
	sz = OHDR_SIZE + len1 + len2 + len3 + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2732
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2733
	if (newString != nil) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2734
	    __InstPtr(newString)->o_class = String;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2735
	    __qSTORE(newString, String);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2736
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2737
#ifdef FAST_MEMCPY
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2738
	    memcpy(dstp, __stringVal(self), len1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2739
	    memcpy(dstp + len1, __stringVal(string1), len2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2740
	    memcpy(dstp + len1 + len2, __stringVal(string2), len3+1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2741
	    *(dstp + len1 + len2 + len3) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2742
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2743
	    srcp = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2744
	    while (len1--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2745
	    srcp = __stringVal(string1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2746
	    while (len2--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2747
	    srcp = __stringVal(string2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2748
	    while (len3--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2749
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2750
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2751
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2752
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2753
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2754
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2755
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2756
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2757
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2758
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2759
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2760
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2761
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2762
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2763
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2764
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2765
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2766
    int len1, len2, len3, len4, sz;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2767
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2768
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2769
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2770
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2771
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2772
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2773
     && __isStringLike(string1)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2774
     && __isStringLike(string2)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2775
     && __isStringLike(string3)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2776
	len1 = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2777
	len2 = __stringSize(string1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2778
	len3 = __stringSize(string2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2779
	len4 = __stringSize(string3);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2780
	sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2781
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2782
	if (newString != nil) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2783
	    __InstPtr(newString)->o_class = String;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2784
	    __qSTORE(newString, String);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2785
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2786
#ifdef FAST_MEMCPY
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2787
	    memcpy(dstp, __stringVal(self), len1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2788
	    memcpy(dstp + len1, __stringVal(string1), len2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2789
	    memcpy(dstp + len1 + len2, __stringVal(string2), len3);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2790
	    memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2791
	    *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2792
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2793
	    srcp = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2794
	    while (len1--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2795
	    srcp = __stringVal(string1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2796
	    while (len2--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2797
	    srcp = __stringVal(string2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2798
	    while (len3--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2799
	    srcp = __stringVal(string3);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2800
	    while (len4--) *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2801
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2802
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2803
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2804
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2805
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2806
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2807
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2808
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2809
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2810
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2811
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2812
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  2813
    (self class == String) ifTrue:[
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2814
	^ self copyFrom:1
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2815
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2816
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2817
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2818
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2819
copyFrom:start
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2820
    "return a new collection consisting of receivers elements from startIndex to the end of the collection.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2821
     This method will always return a string, even if the receiver
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2822
     is a subclass-instance. This might change if there is a need.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2823
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2824
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2825
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2826
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2827
#if !defined(FAST_MEMCPY)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2828
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2829
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2830
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2831
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2832
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2833
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2834
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2835
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2836
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2837
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2838
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2839
    if (__isSmallInteger(start)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2840
     && ((myClass==String) || (myClass==Symbol))) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2841
	len = __stringSize(self);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2842
	index1 = __intVal(start);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2843
	if (index1 > 0) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2844
	    if (index1 <= len) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2845
		count = len - index1 + 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2846
		sz = OHDR_SIZE + count + 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2847
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2848
		__PROTECT_CONTEXT__
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2849
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2850
		__UNPROTECT_CONTEXT__
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2851
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2852
		if (newString != nil) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2853
		    __InstPtr(newString)->o_class = String;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2854
		    __qSTORE(newString, String);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2855
		    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2856
#ifdef FAST_MEMCPY
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2857
		    memcpy(dstp, __stringVal(self) + index1 - 1, count);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2858
		    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2859
#else
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2860
		    srcp = __stringVal(self) + index1 - 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2861
		    while (count--) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2862
			*dstp++ = *srcp++;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2863
		    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2864
		    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2865
#endif
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2866
		    RETURN ( newString );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2867
		}
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2868
	    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2869
	}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2870
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2871
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2872
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2873
    "fall back in case of non-integer index or out-of-bound index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2874
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2875
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2876
    ^ super copyFrom:start
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2877
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2878
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2879
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2880
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2881
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2882
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2883
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2884
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2885
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2886
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2887
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2888
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2889
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2890
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2891
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2892
    OBJ myClass;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2893
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2894
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2895
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2896
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2897
    if (__bothSmallInteger(start, stop)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2898
     && ((myClass==String) || (myClass==Symbol))) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2899
	len = __stringSize(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2900
	index1 = __intVal(start);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2901
	index2 = __intVal(stop);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2902
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2903
	if ((index1 <= index2) && (index1 > 0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2904
	    if (index2 <= len) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2905
		count = index2 - index1 + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2906
		sz = OHDR_SIZE + count + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2907
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2908
		__PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2909
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2910
		__UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2911
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2912
		if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2913
		    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2914
		    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2915
		    dstp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2916
		    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2917
#ifdef bcopy4
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2918
		    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2919
			int nw = count >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2920
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2921
			if (count & 3) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2922
			    nw++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2923
			}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2924
			bcopy4(srcp, dstp, nw);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2925
			dstp[count] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2926
		    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2927
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2928
# ifdef FAST_MEMCPY
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2929
		    memcpy(dstp, srcp, count);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2930
		    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2931
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2932
		    while (count--) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2933
			*dstp++ = *srcp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2934
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2935
		    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2936
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2937
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2938
		    RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2939
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2940
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2941
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2942
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2943
	 * allow empty copy
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2944
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2945
	if (index1 > index2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2946
	    __PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2947
	    __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2948
	    __UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2949
	    if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2950
		__InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2951
		(__stringVal(newString))[0] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2952
		RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2953
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2954
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2955
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2956
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2957
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2958
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2959
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2960
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2961
    ^ super copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2962
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2963
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2964
copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2965
    "return a new string containing the receivers characters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2966
     and the single new character, aCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2967
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2968
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2969
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2970
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2971
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2972
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2973
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2974
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2975
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2976
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2977
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2978
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2979
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2980
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2981
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2982
    if (__isCharacter(aCharacter)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2983
	unsigned int cVal = __intVal(__characterVal(aCharacter));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2984
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2985
	if ((cVal <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2986
	 && ((myClass==String) || (myClass==Symbol))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2987
	    count = __stringSize(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2988
	    sz = OHDR_SIZE + count + 1 + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2989
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2990
	    __PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2991
	    __qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2992
	    __UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2993
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2994
	    if (newString) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2995
		__InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2996
		__qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2997
		dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2998
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2999
# ifdef bcopy4
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3000
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3001
		    int nw = count >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3002
		    char *srcp = (char *)__stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3003
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3004
		    if (count & 3) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3005
			nw++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3006
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3007
		    bcopy4(srcp, dstp, nw);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3008
		    dstp += count;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3009
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3010
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3011
#  ifdef FAST_MEMCPY
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3012
		memcpy(dstp, __stringVal(self), count);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3013
		dstp += count;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3014
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3015
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3016
		    REGISTER unsigned char *srcp;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3017
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3018
		    srcp = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3019
		    while ((*dstp = *srcp++) != '\0')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3020
			dstp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3021
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3022
#  endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3023
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3024
		*dstp++ = cVal;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3025
		*dstp = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3026
		RETURN (newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3027
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3028
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3029
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3030
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3031
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3032
    "fall back in case of non-character arg;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3033
     will eventually lead to an bad element signal raise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3034
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3035
    ^ super copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3036
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3037
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3038
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3039
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3040
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3041
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3042
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3043
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3044
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3045
    (self class == String) ifTrue:[
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3046
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3047
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3048
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3049
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3050
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3051
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  3052
    "return a deep copy of the receiver - reimplemented to be a bit faster"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3053
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3054
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3055
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3056
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3057
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3058
    (self class == String) ifTrue:[
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3059
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3060
    ].
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3061
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3062
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3063
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3064
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3065
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3066
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3067
    (self class == String) ifTrue:[
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3068
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3069
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3070
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3071
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3072
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3073
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3074
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3075
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3076
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3077
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3078
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3079
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3080
    (self class == String) ifTrue:[
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3081
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3082
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  3083
    ^ super simpleDeepCopy
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3084
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3085
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  3086
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3087
!String methodsFor:'encoding'!
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3088
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3089
utf8Encoded
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3090
    "Return my UTF-8 representation as a new String"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3091
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3092
    self containsNon7BitAscii ifTrue:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3093
	^ CharacterEncoderImplementations::ISO10646_to_UTF8 new encodeString:self
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3094
    ].
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3095
    "speed up common case"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3096
    ^ self.
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3097
!
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3098
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3099
utf8EncodedOn:aStream
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3100
    "write to aStream in utf8 encoding"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3101
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3102
    self containsNon7BitAscii ifTrue:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3103
	aStream nextPutAllUtf8:self.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3104
    ] ifFalse:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3105
	"speed up common case"
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3106
	aStream nextPutAll:self.
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3107
    ].
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3108
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3109
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3110
     String streamContents:[:w|
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3111
	'abcde1234' utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3112
     ].
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3113
     String streamContents:[:w|
18972
57301b0d5ee1 Removed (wrong) prototype of memchr() in String.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18971
diff changeset
  3114
	 'abcde' utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3115
     ].
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3116
     String streamContents:[:w|
18972
57301b0d5ee1 Removed (wrong) prototype of memchr() in String.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18971
diff changeset
  3117
	 'abcde' asUnicode16String utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3118
     ].
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3119
    "
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3120
! !
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3121
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  3122
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3123
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3124
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3125
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3126
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3127
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3128
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3129
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3130
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3131
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  3132
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3133
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3134
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3135
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3136
    if (__isCharacter(aCharacter) && __isString(self)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3137
	byteValue = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3138
	if ((unsigned)byteValue <= 0xFF) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3139
	    l = __stringSize(self);
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3140
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3141
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3142
	    if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3143
		memset(__stringVal(self), byteValue, l);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3144
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3145
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3146
	    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3147
		INT v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3148
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3149
		v = (byteValue << 8) | byteValue;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3150
		v = (v << 16) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3151
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3152
		dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3153
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3154
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3155
		if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3156
		    memset4(dst, v, l>>2);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3157
		    l = l & 3;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3158
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3159
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3160
#  ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3161
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3162
		    UINT64 v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3163
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3164
		    v64 = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3165
		    v64 = (v64 << 32) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3166
		    while (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3167
			((UINT64 *)dst)[0] = v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3168
			dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3169
			l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3170
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3171
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3172
#  else /* no UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3173
		while (l >= 16) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3174
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3175
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3176
		    ((int *)dst)[2] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3177
		    ((int *)dst)[3] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3178
		    dst += 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3179
		    l -= 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3180
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3181
		if (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3182
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3183
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3184
		    dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3185
		    l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3186
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3187
		if (l >= 4) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3188
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3189
		    dst += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3190
		    l -= 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3191
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3192
#   if 0
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3193
		if (l >= 2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3194
		    ((short *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3195
		    dst += 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3196
		    l -= 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3197
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3198
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3199
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3200
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3201
# endif /* FAST_MEMSET4 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3202
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3203
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3204
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3205
	     * remaining bytes
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3206
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3207
	    while (l-- > 0)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3208
		*dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3209
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3210
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3211
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3212
	    RETURN ( self );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3213
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3214
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3215
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3216
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3217
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3218
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3219
     (String new:10) atAllPut:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3220
     String new:10 withAll:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3221
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3222
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3223
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3224
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3225
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3226
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3227
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3228
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3229
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3230
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3231
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3232
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3233
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3234
    unsigned char c, cNext;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3235
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3236
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3237
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3238
     && __isString(self)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3239
	srcp = (unsigned char *)__stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3240
	oldVal = __intVal(__characterVal(oldCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3241
	newVal = __intVal(__characterVal(newCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3242
	if ((oldVal <= 0xFF)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3243
	 && (newVal <= 0xFF)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3244
	    cNext = *srcp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3245
	    while ((c = cNext) != '\0') {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3246
		cNext = srcp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3247
		if (c == oldVal)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3248
		    *srcp = newVal;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3249
		srcp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3250
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3251
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3252
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3253
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3254
%}.
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  3255
    newCharacter isCharacter ifFalse:[self halt:'please change the sender'].
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3256
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3257
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3258
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3259
     'helloWorld' copy replaceAll:$o with:$O
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3260
     'helloWorld' copy replaceAll:$d with:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3261
     'helloWorld' copy replaceAll:$h with:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3262
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3263
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3264
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3265
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3266
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3267
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  3268
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3269
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3270
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3271
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3272
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3273
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3274
    if ( aString.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3275
     && self.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3276
     && start.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3277
     && stop.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3278
     && repStart.isSmallInteger()) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3279
	STString me = self.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3280
	STString other = aString.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3281
	int _start = start.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3282
	int _stop = stop.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3283
	int _repStart = repStart.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3284
	int mySize = me.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3285
	int otherSize = other.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3286
	int count = _stop - _start + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3287
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3288
	if (_start >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3289
	 && _repStart >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3290
	 && _stop < mySize
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3291
	 && (_repStart + count) <= otherSize) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3292
	    if (count > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3293
		System.arraycopy(other.characters, _repStart, me.characters, _start, count);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3294
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3295
	    return context._RETURN(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3296
	}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3297
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3298
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3299
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3300
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3301
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3302
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3303
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3304
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3305
# ifndef NO_PRIM_STRING
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3306
    if (__isStringLike(aString)
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3307
     && __isString(self)
252
  3308
     && __bothSmallInteger(start, stop)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3309
	len = __stringSize(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3310
	index1 = __intVal(start);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3311
	index2 = __intVal(stop);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3312
	count = index2 - index1 + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3313
	if (count <= 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3314
	     RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3315
	}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3316
	if ((index2 <= len) && (index1 > 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3317
	    repLen = __stringSize(aString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3318
	    repIndex = __intVal(repStart);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3319
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3320
		srcp = __stringVal(aString) + repIndex - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3321
		dstp = __stringVal(self) + index1 - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3322
		if (aString == self) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3323
		    /* take care of overlapping copy */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3324
		    memmove(dstp, srcp, count);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3325
		    RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3326
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3327
#  ifdef bcopy4
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3328
		/* copy quadbytes if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3329
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3330
		 * no sizeof(int) here please -
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3331
		 * - bcopy4 (if defined) copies 4-bytes on ALL machines
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3332
		 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3333
		if ((count > 12)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3334
		 && (((unsigned INT)srcp & 3) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3335
		 && (((unsigned INT)dstp & 3) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3336
		    int n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3337
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3338
		    n = count >> 2;        /* make it quads */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3339
		    bcopy4(srcp, dstp, n);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3340
		    n <<= 2;               /* back to chars */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3341
		    dstp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3342
		    srcp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3343
		    count -= n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3344
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3345
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3346
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3347
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3348
#  else
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3349
#   ifdef FAST_MEMCPY
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3350
		memcpy(dstp, srcp, count);
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3351
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3352
		/* copy longs if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3353
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3354
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3355
		    while (count >= sizeof(INT)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3356
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3357
			dstp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3358
			srcp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3359
			count -= sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3360
		    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3361
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3362
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3363
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3364
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3365
#   endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3366
#  endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3367
		RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3368
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3369
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3370
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3371
# endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3372
#endif /* not SCHTEAM */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3373
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3374
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3375
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3376
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3377
withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3378
    "return a string containing the chars of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3379
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3380
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3381
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3382
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  3383
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3384
     endIndex   "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3385
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3386
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3387
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3388
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3389
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3390
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3391
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3392
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3393
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3394
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3395
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3396
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  3397
    if (__qClass(self) == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3398
	cp = cp0 = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3399
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3400
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3401
	 * find first non-whiteSpace from beginning
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3402
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3403
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3404
# ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3405
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3406
	    cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3407
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3408
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3409
	while (*((unsigned *)cp) == 0x20202020) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3410
	    cp += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3411
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3412
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3413
	while ((c = *cp)
329
claus
parents: 314
diff changeset
  3414
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3415
	 && (c <= ' ')
329
claus
parents: 314
diff changeset
  3416
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3417
	 && ((c == ' ') || (c == '\n') || (c == '\t')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3418
			|| (c == '\r') || (c == '\f'))
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3419
	) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3420
	    cp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3421
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3422
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3423
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3424
	 * find first non-whiteSpace from end
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3425
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3426
	ep = ep0 = cp0 + __stringSize(self) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3427
	while ((ep >= cp) && (*ep == ' ')) ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3428
	c = *ep;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3429
	while ((ep >= cp) &&
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3430
#ifndef NON_ASCII
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3431
	       (c <= ' ') &&
329
claus
parents: 314
diff changeset
  3432
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3433
	       ((c == ' ') || (c == '\n') || (c == '\t')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3434
			   || (c == '\r') || (c == '\f'))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3435
	    ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3436
	    c = *ep;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3437
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3438
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3439
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3440
	 * no whiteSpace ?
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3441
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3442
	if ((cp == cp0) && (ep == ep0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3443
	    RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3444
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3445
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3446
	startIndex = __mkSmallInteger(cp - cp0 + 1);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3447
	endIndex = __mkSmallInteger(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3448
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3449
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3450
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3451
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3452
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3453
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3454
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3455
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3456
     'hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3457
     '    hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3458
     '    hello ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3459
     '    hello  ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3460
     '    hello   ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3461
     '    hello    ' withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3462
     '        ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3463
    "
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3464
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3465
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3466
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3467
withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3468
    "return a string containing the characters of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3469
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3470
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3471
     Notice, this is different from String>>withoutSeparators."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3472
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3473
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3474
     endIndex   "{ Class: SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3475
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3476
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3477
    startIndex := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3478
%{
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3479
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3480
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3481
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3482
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3483
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3484
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3485
    if (__qClass(self) == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3486
	cp = cp0 = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3487
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3488
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3489
	 * find first non-blank from beginning
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3490
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3491
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3492
# ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3493
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3494
	    cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3495
	}
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3496
# endif /* UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3497
	while (*((unsigned *)cp) == 0x20202020) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3498
	    cp += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3499
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3500
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3501
	while (*cp == ' ') cp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3502
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3503
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3504
	 * find first non-blank from end
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3505
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3506
	ep = ep0 = cp0 + __stringSize(self) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3507
	while ((ep >= cp) && (*ep == ' ')) ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3508
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3509
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3510
	 * no blanks ?
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3511
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3512
	if ((cp == cp0) && (ep == ep0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3513
	    RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3514
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3515
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3516
	startIndex = __mkSmallInteger(cp - cp0 + 1);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3517
	endIndex = __mkSmallInteger(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3518
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3519
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3520
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3521
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3522
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3523
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3524
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3525
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3526
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3527
     '    hello' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3528
     '    hello ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3529
     '    hello  ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3530
     '    hello   ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3531
     '    hello    ' withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3532
     '        ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3533
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3534
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3535
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3536
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3537
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3538
displayString
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3539
    "return a string used when displaying the receiver in a view."
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3540
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3541
    ^ super displayString.
17539
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3542
"/    ^ self storeString.
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3543
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3544
    "
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3545
     'hello' -> 'hello'
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3546
    "
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3547
!
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3548
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3549
errorPrint
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3550
    "print the receiver on standard error, if the global Stderr is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3551
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3552
     the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3553
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3554
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3555
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3556
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3557
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3558
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3559
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3560
	if (self.isStringLike()) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3561
	    System.err.print(self.asString());
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3562
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3563
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3564
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3565
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3566
    if (@global(Stderr) == nil) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3567
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3568
	    console_fprintf(stderr, "%s" , __stringVal(self));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3569
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3570
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3571
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3572
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3573
#endif /* not SCHTEAM */
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3574
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3575
    super errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3576
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3577
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3578
      'hello world' asUnicode16String errorPrint
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3579
      (Character value:356) asString errorPrint
18972
57301b0d5ee1 Removed (wrong) prototype of memchr() in String.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18971
diff changeset
  3580
      'Bnnigheim' errorPrint
57301b0d5ee1 Removed (wrong) prototype of memchr() in String.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18971
diff changeset
  3581
      'Bnnigheim' asUnicodeString errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3582
    "
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3583
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3584
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3585
errorPrintCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3586
    "print the receiver on standard error, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3587
     if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3588
     which sends the string to the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3589
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3590
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3591
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3592
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3593
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3594
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3595
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3596
	if (self.isStringLike()) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3597
	    System.err.println(self.asString());
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3598
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3599
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3600
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3601
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3602
    if (@global(Stderr) == nil) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3603
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3604
	    console_fprintf(stderr, "%s\n" , __stringVal(self));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3605
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3606
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3607
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3608
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3609
#endif
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3610
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3611
    super errorPrintCR
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3612
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3613
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3614
print
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3615
    "print the receiver on standard output, if the global Stdout is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3616
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3617
     the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3618
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3619
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3620
     (but only, as long as Stdout is nil, which is set later after startup)."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3621
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3622
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3623
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3624
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3625
	System.out.print(self.toString());
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3626
	return context._RETURN(self);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3627
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3628
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3629
    if (@global(Stdout) == nil) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3630
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3631
	    console_fprintf(stdout, "%s" , __stringVal(self));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3632
	    console_fflush(stdout);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3633
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3634
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3635
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3636
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3637
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3638
    super print
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3639
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3640
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3641
printCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3642
    "print the receiver on standard output, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3643
     if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3644
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3645
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3646
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3647
     (but only, as long as Stdout is nil, which is set later after startup)."
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3648
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3649
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3650
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3651
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3652
	System.out.println(self.toString());
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3653
	return context._RETURN(self);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3654
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3655
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3656
    if (@global(Stdout) == nil) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3657
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3658
	    console_fprintf(stdout, "%s\n" , __stringVal(self));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3659
	    console_fflush(stdout);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3660
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3661
	}
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3662
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3663
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3664
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3665
    super printCR
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3666
!
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3667
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3668
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3669
    "non-standard but sometimes useful.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3670
     Return a printed representation of the receiver as specified by formatString,
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3671
     which is defined by printf.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3672
     This method is NONSTANDARD and may be removed without notice.
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3673
     WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3674
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3675
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3676
%{  /* STACK: 1000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3677
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3678
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3679
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3680
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3681
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3682
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3683
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3684
    OBJ s;
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3685
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3686
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3687
    if (__isStringLike(formatString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3688
	cp = (char *)__stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3689
	if (__qClass(self) != String) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3690
	    cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3691
	}
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3692
again:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3693
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3694
	 * actually only needed on sparc: since thisContext is
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3695
	 * in a global register, which gets destroyed by printf,
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3696
	 * manually save it here - very stupid ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3697
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3698
	__BEGIN_PROTECT_REGISTERS__
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3699
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3700
	len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3701
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3702
	__END_PROTECT_REGISTERS__
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3703
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3704
	if ((len < 0) || (len > bufsize)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3705
	    if (len < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3706
		bufsize = bufsize * 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3707
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3708
		bufsize = len + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3709
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3710
	    if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3711
		free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3712
	    buf = mallocbuf = malloc(bufsize);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3713
	    if (buf == NULL)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3714
		goto fail;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3715
	    goto again;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3716
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3717
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3718
	s = __MKSTRING_L(buf, len);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3719
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3720
	if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3721
	    free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3722
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3723
	if (s != nil) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3724
	    RETURN (s);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3725
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3726
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3727
fail:;
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3728
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3729
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3730
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3731
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3732
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3733
     'hello' printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3734
     (String new:900) printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3735
     'hello' printfPrintString:'%%10s -> %10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3736
     'hello' printfPrintString:'%%-10s -> %-10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3737
     'hello' printfPrintString:'%%900s -> %900s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3738
     'hello' printfPrintString:'%%-900s -> %-900s'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3739
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3740
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3741
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3742
storeOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3743
    "put the storeString of myself on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3744
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  3745
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3746
    (self includes:$') ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3747
	self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3748
    ] ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3749
	aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3750
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3751
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3752
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3753
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3754
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3755
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3756
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3757
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3758
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  3759
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3760
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3761
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3762
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3763
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3764
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3765
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3766
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3767
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3768
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3769
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  3770
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3771
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3772
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3773
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3774
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3775
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3776
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3777
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3778
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3779
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3780
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3781
			  - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3782
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3783
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3784
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3785
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3786
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3787
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3788
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3789
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3790
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3791
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3792
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3793
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3794
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3795
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3796
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3797
characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3798
    "answer the size in bits of my largest character (actually only 7 or 8)"
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3799
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3800
%{  /* NOCONTEXT */
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3801
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3802
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3803
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3804
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3805
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3806
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3807
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3808
#if __POINTER_SIZE__ == 8
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3809
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3810
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3811
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3812
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3813
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3814
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3815
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3816
#endif
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3817
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3818
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3819
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3820
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3821
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3822
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3823
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3824
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3825
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3826
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3827
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3828
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3829
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3830
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3831
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3832
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3833
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3834
    RETURN ( __mkSmallInteger(7) );
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3835
%}.
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3836
    ^ super characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3837
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3838
    "
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3839
     'hello world' characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3840
     'hello world' asUnicode16String characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3841
     ('hello world' , (Character value:16r88) asString) characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3842
    "
18587
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3843
!
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3844
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3845
containsNon7BitAscii
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3846
    "return true, if the underlying string contains 8BitCharacters (or widers)
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3847
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3848
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3849
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3850
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3851
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3852
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3853
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3854
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3855
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3856
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3857
#if __POINTER_SIZE__ == 8
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3858
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3859
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3860
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3861
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3862
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3863
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3864
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3865
#endif
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3866
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3867
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3868
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3869
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3870
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3871
	}
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3872
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3873
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3874
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3875
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3876
	}
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3877
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3878
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3879
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3880
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3881
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3882
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3883
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3884
%}.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3885
    ^ super containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3886
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3887
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3888
     'hello world' containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3889
     'hello world' asTwoByteString containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3890
     ('hello world' , (Character value:16r88) asString) containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3891
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3892
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3893
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3894
containsNon8BitElements
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3895
    "return true, if the underlying string contains elements larger than a single byte"
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3896
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3897
    ^ false.
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3898
!
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3899
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3900
isWideString
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3901
    ^ false
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3902
!
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3903
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3904
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3905
    "return true, if there is a symbol with same characters in the
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3906
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3907
     Can be used to check for existance of a symbol without creating one"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3908
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3909
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3910
#ifdef __SCHTEAM__
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  3911
    return context._RETURN( (STSymbol.asSymbolIfInterned(self.asSTString().asString()) != null) ? STObject.True : STObject.False );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3912
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3913
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3914
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3915
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3916
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3917
    if (cls != String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3918
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3919
    } else {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3920
	indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3921
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3922
    RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3923
#endif /* ! __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3924
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  3925
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3926
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3927
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3928
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3929
     'hello' knownAsSymbol
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3930
     'fooBarBaz' knownAsSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3931
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3932
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3933
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3934
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3935
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3936
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3937
     (which we can do here, since size is obviously not redefined in a subclass).
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3938
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3939
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3940
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3941
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  3942
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3943
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3944
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3945
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3946
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3947
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3948
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3949
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3950
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3951
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3952
			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3953
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3954
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3955
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3956
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3957
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3958
stringSpecies
15525
0a0baff63fd0 class: String
Stefan Vogel <sv@exept.de>
parents: 15440
diff changeset
  3959
    ^ self species
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3960
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3961
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3962
!String methodsFor:'sorting & reordering'!
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3963
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3964
reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3965
    "in-place reverse the characters of the string.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3966
     WARNING: this is a destructive operation, which modifies the receiver.
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3967
	      Please use reversed (with a d) for a functional version."
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3968
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3969
    "Q: is there a need to redefine it here ?"
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3970
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3971
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3972
#ifndef __SCHTEAM__
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3973
    REGISTER char c;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3974
    REGISTER unsigned char *hip, *lowp;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3975
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3976
    if (__isString(self)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3977
	lowp = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3978
	hip = lowp + __stringSize(self) - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3979
	while (lowp < hip) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3980
	    c = *lowp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3981
	    *lowp = *hip;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3982
	    *hip = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3983
	    lowp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3984
	    hip--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3985
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3986
	RETURN ( self );
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3987
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3988
    #endif
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3989
%}.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3990
    ^ super reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3991
! !
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3992
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  3993
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3994
!String methodsFor:'substring searching'!
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3995
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3996
indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
11347
7819f5148ca1 Boyer Moore algorithm for fast string search.
Claus Gittinger <cg@exept.de>
parents: 11346
diff changeset
  3997
    "redefined as primitive for maximum speed (BM)"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3998
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3999
    |notFound|
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4000
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  4001
%{  /* STACK:4000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4002
#ifndef __SCHTEAM__
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4003
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4004
     && __isStringLike(aSubString)
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4005
     && (caseSensitive == true)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4006
     && (__isSmallInteger(startIndex))
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4007
     && (__intVal(startIndex) > 0)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4008
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4009
	unsigned char *y = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4010
	unsigned char *x = __stringVal(aSubString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4011
	int m = __stringSize(aSubString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4012
	int n = __stringSize(self);
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4013
#       define MAX_PATTERN_SIZE 128
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4014
#       define XSIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4015
#       define ASIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4016
#       define MAX(a,b) (a>b ? a : b)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4017
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4018
	if (m == 0) {
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4019
#if 1
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4020
	    /* empty string does not match */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4021
	    RETURN(__mkSmallInteger(0));
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4022
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4023
	    /* empty string matches */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4024
	    RETURN(startIndex);
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4025
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4026
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4027
	if (m <= XSIZE) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4028
	    int i, j;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4029
	    static int lastPatternSize = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4030
	    static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 };
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4031
	    static int bmGs[XSIZE+1], bmBc[ASIZE];
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4032
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4033
#           define preBmBc(x, m, bmBc) {          \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4034
	       int i;                             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4035
						  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4036
	       for (i = 0; i < ASIZE; ++i)        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4037
		  bmBc[i] = m;                    \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4038
	       for (i = 0; i < m - 1; ++i)        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4039
		  bmBc[x[i]] = m - i - 1;         \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4040
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4041
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4042
#           define suffixes(x, m, suff) {                       \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4043
	       int f, g, i;                                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4044
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4045
	       suff[m - 1] = m;                                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4046
	       g = m - 1;                                       \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4047
	       for (i = m - 2; i >= 0; --i) {                   \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4048
		  if (i > g && suff[i + m - 1 - f] < i - g)     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4049
		     suff[i] = suff[i + m - 1 - f];             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4050
		  else {                                        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4051
		     if (i < g)                                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4052
			g = i;                                  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4053
		     f = i;                                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4054
		     while (g >= 0 && x[g] == x[g + m - 1 - f]) \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4055
			--g;                                    \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4056
		     suff[i] = f - g;                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4057
		  }                                             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4058
	       }                                                \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4059
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4060
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4061
#           define preBmGs(x, m, bmGs) {                        \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4062
	       int i, j, suff[XSIZE];                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4063
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4064
	       suffixes(x, m, suff);                            \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4065
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4066
	       for (i = 0; i < m; ++i)                          \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4067
		  bmGs[i] = m;                                  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4068
	       j = 0;                                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4069
	       for (i = m - 1; i >= 0; --i)                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4070
		  if (suff[i] == i + 1)                         \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4071
		     for (; j < m - 1 - i; ++j)                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4072
			if (bmGs[j] == m)                       \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4073
			   bmGs[j] = m - 1 - i;                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4074
	       for (i = 0; i <= m - 2; ++i)                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4075
		  bmGs[m - 1 - suff[i]] = m - 1 - i;            \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4076
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4077
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4078
	    /* tables only depend on pattern; so we can cache them in case the same string is searched again */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4079
	    if ((m == lastPatternSize)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4080
	     && (strcmp(lastPattern, x) == 0)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4081
		/* tables are still valid */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4082
		// printf("valid: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4083
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4084
		/* Preprocessing */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4085
		// printf("compute: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4086
		preBmGs(x, m, bmGs);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4087
		preBmBc(x, m, bmBc);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4088
		if (m <= MAX_PATTERN_SIZE) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4089
		    // printf("cache for: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4090
		    strcpy(lastPattern, x);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4091
		    lastPatternSize = m;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4092
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4093
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4094
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4095
	    /* Searching */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4096
	    j = __intVal(startIndex) - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4097
	    while (j <= n - m) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4098
	       for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4099
	       if (i < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4100
		  RETURN (__mkSmallInteger(j+1));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4101
		  j += bmGs[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4102
	       } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4103
		  int s1 = bmGs[i];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4104
		  int s2 = bmBc[y[i + j]] - m + 1 + i;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4105
		  j += MAX(s1, s2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4106
	       }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4107
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4108
	    notFound = true;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4109
	}
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4110
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4111
#endif /* ! __SCHTEAM__ */
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4112
%}.
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4113
    notFound == true ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4114
	^ exceptionValue value.
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4115
    ].
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4116
    ^ super indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4117
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4118
    "Modified: / 05-08-2012 / 12:27:31 / cg"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4119
! !
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4120
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4121
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4122
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4123
endsWith:aStringOrChar
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4124
    "return true, if the receiver ends with something, aStringOrChar.
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4125
     If aStringOrChar is an empty string, true is returned"
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4126
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4127
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4128
#ifndef __SCHTEAM__
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4129
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4130
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4131
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4132
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4133
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4134
    if (__isStringLike(slf) && __isStringLike(aStringOrChar)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4135
	len1 = __qSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4136
	len2 = __qSize(aStringOrChar);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4137
	if (len1 < len2) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4138
	    RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4139
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4140
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4141
	src1 = __stringVal(slf) + (len1 - len2);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4142
	src2 = __stringVal(aStringOrChar);
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4143
	while ((c = *src2++) != '\0') {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4144
	    if (c != *src1++) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4145
		RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4146
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4147
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4148
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4149
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4150
    if (__isCharacter(aStringOrChar)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4151
	int val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4152
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4153
	val = __intVal(__characterVal(aStringOrChar));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4154
	if ((unsigned)val <= 0xFF) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4155
	    len1 = __stringSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4156
	    if (len1 > 0) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4157
		RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4158
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4159
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4160
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4161
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4162
#endif /* ! __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4163
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4164
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4165
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4166
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4167
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4168
     'hello world' endsWith:'earth'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4169
     'hello world' endsWith:$d
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4170
     'hello world' endsWith:$e
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4171
     '' endsWith:$d
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4172
     'hello world' endsWith:#($r $l $d)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4173
     'hello world' endsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4174
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4175
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4176
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4177
isBlank
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4178
    "return true, if the receivers size is 0 or if it contains only spaces.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4179
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4180
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4181
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4182
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4183
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4184
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4185
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4186
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  4187
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4188
    if ((cls = __qClass(self)) != String)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4189
	src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4190
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4191
#  ifndef NON_ASCII
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4192
#   ifdef UINT64
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  4193
    while (*((UINT64 *)src) == 0x2020202020202020L) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4194
	src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4195
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4196
#   endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4197
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4198
    while (*((unsigned *)src) == 0x20202020) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4199
	src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4200
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4201
#  endif /* ascii */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4202
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4203
    while ((c = *src++) == ' ')
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4204
	;; /* just walking along */
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4205
    if (c != '\0') {
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4206
	RETURN ( false );
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4207
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4208
    RETURN ( true );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4209
# endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4210
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4211
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4212
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4213
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4214
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4215
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4216
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4217
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4218
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4219
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4220
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4221
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4222
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4223
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4224
	RETURN ( (__stringSize(self) == 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4225
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4226
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4227
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4228
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4229
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4230
10958
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4231
isLiteral
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4232
    "return true, if the receiver can be used as a literal constant in ST syntax
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4233
     (i.e. can be used in constant arrays)"
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4234
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4235
    ^ true
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4236
!
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4237
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4238
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4239
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4240
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4241
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  4242
%{  /* STACK: 2000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4243
#ifndef __SCHTEAM__
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4244
    /*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4245
     * this is very heavy used when correcting errors
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4246
     * (all symbols are searched for best match) - therefore it must be fast
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4247
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4248
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4249
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4250
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4251
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4252
    unsigned char *s1, *s2;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4253
    int v1, v2, v3;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4254
    INT m;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4255
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4256
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4257
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4258
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4259
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  4260
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4261
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4262
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4263
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  4264
    if (__qIsStringLike(self) && __isStringLike(aString)
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4265
	&& __bothSmallInteger(insrtWeight, caseWeight)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4266
	&& __bothSmallInteger(substWeight, deleteWeight)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4267
	&& __isSmallInteger(kbdTypoWeight)
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4268
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4269
	iW = __intVal(insrtWeight);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4270
	cW = __intVal(caseWeight);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4271
	sW = __intVal(substWeight);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4272
	kW = __intVal(kbdTypoWeight);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4273
	dW = __intVal(deleteWeight);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4274
	s1 = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4275
	s2 = __stringVal(aString);
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  4276
	l1 = __stringSize(self);
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  4277
	l2 = __stringSize(aString);
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4278
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4279
	sz = (l1 < l2) ? l2 : l1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4280
	rowDelta = sz + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4281
	if (sz <= FASTSIZE) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4282
	    data = fastData;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4283
	} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4284
	    /* add ifdef ALLOCA here ... */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4285
	    data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4286
	    if (! data) goto mallocFailed;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4287
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4288
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4289
	data[0] = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4290
	for (j=1, dp=data+1; j<=sz; j++, dp++)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4291
	    *dp = dp[-1] + iW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4292
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4293
	for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4294
	    *dp = dp[-rowDelta] + dW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4295
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4296
	for (i=0; i<l1; i++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4297
	    for (j=0; j<l2; j++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4298
		if (s1[i] == s2[j])
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4299
		    m = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4300
		else if (tolower(s1[i]) == tolower(s2[j]))
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4301
		    m = cW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4302
		else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j])))
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4303
		    m = kW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4304
		else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4305
		    m = sW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4306
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4307
		dp = data + ((i+1)*rowDelta) + j;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4308
		v2 = dp[0] + iW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4309
		v1 = dp[-rowDelta] + m;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4310
		v3 = dp[-rowDelta+1] + dW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4311
		if (v1 < v2) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4312
		    if (v1 < v3)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4313
			m = v1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4314
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4315
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4316
		} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4317
		    if (v2 < v3)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4318
			m = v2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4319
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4320
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4321
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4322
		dp[1] = m;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4323
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4324
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4325
	m = data[l1*rowDelta + l2];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4326
	if (sz > FASTSIZE)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4327
	    free(data);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4328
	RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4329
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4330
mallocFailed: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4331
#endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4332
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4333
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4334
    ^ super levenshteinTo:aString
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4335
			s:substWeight k:kbdTypoWeight c:caseWeight
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4336
			i:insrtWeight d:deleteWeight
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4337
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4338
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4339
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4340
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4341
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4342
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4343
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4344
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4345
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4346
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4347
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4348
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4349
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4350
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4351
    "return true if the receiver is not empty (i.e. if size ~~ 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4352
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4353
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4354
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4355
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4356
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4357
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4358
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4359
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4360
	RETURN ( (__stringSize(self) != 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4361
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4362
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4363
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4364
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4365
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4366
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4367
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  4368
    "return true, if the receiver starts with something, aStringOrChar.
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4369
     If the argument is empty, true is returned.
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4370
     Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:,
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4371
     which are both inconsistent w.r.t. an empty argument."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4372
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4373
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4374
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4375
    if (self.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4376
	if (aStringOrChar.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4377
	    java.lang.String me = self.asString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4378
	    java.lang.String other = aStringOrChar.asString();
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4379
	    return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4380
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4381
	if (aStringOrChar.isSTCharacter()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4382
	    char[] me = self.asSTString().characters;
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4383
	    char ch = aStringOrChar.charValue();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4384
	    return __c__._RETURN( ((me.length > 0)
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4385
				  && (me[0] == ch)) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4386
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4387
    }
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4388
#else
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4389
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4390
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4391
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4392
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4393
14217
d399ca31088f changed: #startsWith:
Stefan Vogel <sv@exept.de>
parents: 14201
diff changeset
  4394
    if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4395
	src1 = __stringVal(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4396
	src2 = __stringVal(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4397
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4398
	if (src1[0] != src2[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4399
	    if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4400
		RETURN (true);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4401
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4402
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4403
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4404
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4405
	len1 = __qSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4406
	len2 = __qSize(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4407
	if (len1 < len2) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4408
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4409
	}
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4410
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4411
# ifdef UINT64
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4412
	while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4413
	    if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4414
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4415
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4416
	    len2 -= sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4417
	    src1 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4418
	    src2 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4419
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4420
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4421
#  ifdef __UNROLL_LOOPS__
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4422
	while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4423
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4424
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4425
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4426
	    if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4427
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4428
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4429
	    if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4430
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4431
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4432
	    if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4433
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4434
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4435
	    len2 -= sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4436
	    src1 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4437
	    src2 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4438
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4439
#  endif /* __UNROLL_LOOPS__ */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4440
# endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  4441
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4442
	while (len2 > (OHDR_SIZE+sizeof(INT))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4443
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4444
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4445
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4446
	    len2 -= sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4447
	    src1 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4448
	    src2 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4449
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4450
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4451
	while ((c = *src2++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4452
	    if (c != *src1) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4453
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4454
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4455
	    src1++;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4456
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4457
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4458
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4459
    if (__isCharacter(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4460
	int val;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4461
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4462
	val = __intVal(__characterVal(aStringOrChar));
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4463
	if ((unsigned)val <= 0xFF) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4464
	    len1 = __stringSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4465
	    if (len1 > 0) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4466
		RETURN ( (__stringVal(slf)[0] == val) ? true : false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4467
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4468
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4469
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4470
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4471
#endif /* not __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4472
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4473
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4474
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4475
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4476
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4477
     'hello world' startsWith:'hella'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4478
     'hello world' startsWith:'hi'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4479
     'hello world' startsWith:$h
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4480
     'hello world' startsWith:$H
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4481
     'hello world' startsWith:(Character value:16rFF00)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4482
     'hello world' startsWith:60
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4483
     'hello world' startsWith:#($h $e $l)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4484
     'hello world' startsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4485
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4486
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4487
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4488
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4489
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4490
isSingleByteString
16773
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4491
    "returns true only for strings and immutable strings.
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4492
     Must replace foo isMemberOf:String and foo class == String"
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4493
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4494
    ^ true
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4495
!
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4496
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4497
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4498
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4499
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4500
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4501
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4502
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4503
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4504
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4505
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4506
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4507
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4508
version
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4509
    ^ '$Header$'
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4510
!
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4511
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4512
version_CVS
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4513
    ^ '$Header$'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4514
! !
18902
494a4d4a6155 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18700
diff changeset
  4515