String.st
author Claus Gittinger <cg@exept.de>
Sun, 08 May 2016 02:22:47 +0200
changeset 19748 44eae32d9fad
parent 19745 cf16402b6366
child 19759 9ff833d647f6
permissions -rw-r--r--
#TUNING by cg class: String added: #includesAny: changed:13 methods
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
19107
ad915b7ce4b3 win32 definition
Claus Gittinger <cg@exept.de>
parents: 18999
diff changeset
    48
#ifdef FAST_MEMCHR
ad915b7ce4b3 win32 definition
Claus Gittinger <cg@exept.de>
parents: 18999
diff changeset
    49
# if !defined(__osx__) && !defined(WIN32)
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    50
 char *memchr();
17573
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
    51
# endif
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    52
#endif
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    53
%}
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    54
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    55
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    56
!String primitiveFunctions!
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    57
%{
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    58
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
    59
static int
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    60
nextOnKeyboard(char1, char2)
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    61
{
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    62
    /* 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
    63
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    64
    static char *us_keys[] = { "1234567890-",
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    65
			    "*qwertyuiop",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    66
			    "**asdfghjkl:",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    67
			    "***zxcvbnm",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    68
			    0 };
10370
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    69
    static char *de_keys[] = { "1234567890-",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    70
			    "*qwertzuiop",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    71
			    "**asdfghjkl:",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    72
			    "***yxcvbnm",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    73
			    0 };
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    74
    char **keys = us_keys;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    75
    char **line1, **line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    76
    char *col1, *col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    77
    int diff;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    78
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    79
    for (line1 = keys; *line1 != 0; line1++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    80
	for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    81
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    82
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    83
    if (*col1 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    84
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    85
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    86
    for (line2 = keys; *line2 != 0; line2++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    87
	for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    88
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    89
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    90
    if (*col2 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    91
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    92
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    93
    diff = col1 - col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    94
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    95
	return(0);
8647
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
    diff = line1 - line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    98
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    99
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   100
    return(1);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   101
}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   102
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   103
%}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   104
! !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   105
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
!String class methodsFor:'documentation'!
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
copyright
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   111
	      All Rights Reserved
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
 This software is furnished under a license and may be used
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
 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
   115
 inclusion of the above copyright notice.   This software may not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
 be provided or otherwise made available to, or used by, any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
 other person.  No title to or ownership of the software is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
 hereby transferred.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   121
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
documentation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
    Strings are ByteArrays storing Characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
    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
   127
    there is always one 0-byte added at the end, which is not counted
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   128
    in the strings size, and is not accessible from the smalltalk level.
4800
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   129
    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
   130
    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
   131
    prevent a nonsense contents ...)
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   132
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   133
    You cannot add any instvars to String, since the run time system & compiler
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
    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
   135
    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
   136
    of String (the access functions defined here can handle this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
    A little warning though: not all smalltalk systems allow subclassing String,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   138
    so your program may become unportable if you do so.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   139
7895
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   140
    Strings have an implicit (assumed) encoding of iso8859-1.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   141
    For strings with other encodings, either keep the encoding separately,
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   142
    or use instances of encodedString.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   143
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   144
    [author:]
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   145
        Claus Gittinger
1310
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   146
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   147
    [see also:]
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   148
        Text StringCollection TwoByteString JISEncodedString
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   149
        Symbol
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   151
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   152
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
!String class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
basicNew:anInteger
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   156
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   157
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   158
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   159
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   160
     can be directly used as separator or for formatting."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   163
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   164
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   165
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
    OBJ newString;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   167
    REGISTER INT len, instsize;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
    REGISTER unsigned char *cp;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   169
    int nInstVars;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
252
   171
    if (__isSmallInteger(anInteger)) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   172
        len = __intVal(anInteger);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   173
        if (len >= 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   174
            instsize = OHDR_SIZE + len + 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   175
            if (self == String || self == ImmutableString) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   176
                if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   177
                    /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   178
                     * the most common case
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   179
                     */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   180
                    __qCheckedNew(newString, instsize);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   181
                    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   182
                    __qSTORE(newString, self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   183
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   184
                    cp = __stringVal(newString);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   185
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   186
# if defined(memset4)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   187
                    {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   188
                        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   189
                         * no sizeof(int) here please -
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   190
                         * - memset4 (if defined) fills 4-bytes on ALL machines
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   191
                         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   192
                        int l4 = len >> 2;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   193
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   194
                        if (len & 3) l4++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   195
                        memset4(cp, 0x20202020, l4);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   196
                        cp[len] = '\0';
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   197
                    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   198
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   199
#  ifdef FAST_MEMSET
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   200
                    memset(cp, ' ', len);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   201
                    cp[len] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   202
#  else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   203
                    for ( ; len >= 8; cp += 8, len -= 8) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   204
#   ifdef INT64
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   205
                        ((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   206
#   else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   207
                        ((int *)cp)[0] = 0x20202020;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   208
                        ((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   209
#   endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   210
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   211
                    while (len--)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   212
                        *cp++ = ' ';
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
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
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   217
                    RETURN (newString);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   218
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   219
                nInstVars = 0;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   220
            } else {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   221
                nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   222
                instsize += __OBJS2BYTES__(nInstVars);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   223
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   224
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   225
            __PROTECT_CONTEXT__;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   226
            __qNew(newString, instsize);        /* OBJECT ALLOCATION */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   227
            __UNPROTECT_CONTEXT__;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   228
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   229
            if (newString == nil) goto fail;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   230
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   231
            __InstPtr(newString)->o_class = self;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   232
            __qSTORE(newString, self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   233
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   234
            cp = __stringVal(newString);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   235
            if (nInstVars) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   236
                OBJ *op;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   237
                cp += __OBJS2BYTES__(nInstVars);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   238
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   239
                /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   240
                 * nil-out instvars
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   241
                 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   242
# if defined(memset4)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
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)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   246
                /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   247
                 * knowing that nil is 0
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   248
                 */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
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
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   251
                op = __InstPtr(newString)->i_instvars;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   252
                do {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   253
                    *op++ = nil;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   254
                } while (--nInstVars);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   255
#  endif  /* !FAST_MEMSET */
357
claus
parents: 347
diff changeset
   256
# endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   257
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   258
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   259
            /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   260
             * fill with spaces
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   261
             */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   262
# ifdef FAST_MEMSET
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   263
            memset(cp, ' ', len);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   264
            *(cp + len) = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   265
# else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   266
            while (len >= 8) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   267
#  ifdef INT64
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   268
                ((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   269
#  else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   270
                ((int *)cp)[0] = 0x20202020;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   271
                ((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   272
#  endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   273
                cp += 8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   274
                len -= 8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   275
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   276
            while (len--)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   277
                *cp++ = ' ';
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   278
            *cp = '\0';
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   279
# endif /* !FAST_MEMSET */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   280
            RETURN (newString);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   281
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   283
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   284
#endif /* not __SCHTEAM__ */
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   285
%}.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   286
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   287
     invalid argument, or out-of-memory:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   288
     use error handling in superclass
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   289
    "
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   290
    (anInteger < 0) ifTrue:[
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   291
        "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   292
         the argument is negative,
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   293
        "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   294
        self error:'bad (negative) argument to new:'.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   295
        ^ nil
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   296
    ].
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   297
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   298
    ^ (super basicNew:anInteger+1) atAllPut:(Character space)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   299
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
new:n
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   302
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   303
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   304
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   305
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   306
     can be directly used as separator or for formatting."
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   307
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    ^ self basicNew:n
347
claus
parents: 345
diff changeset
   309
!
claus
parents: 345
diff changeset
   310
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   311
readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   312
    "read & return the next String from the (character-)stream aStream;
claus
parents: 345
diff changeset
   313
     skipping all whitespace first; return the value of exceptionBlock,
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   314
     if no string can be read. The sequence of characters as read from the
347
claus
parents: 345
diff changeset
   315
     stream must be one as stored via storeOn: or storeString."
claus
parents: 345
diff changeset
   316
claus
parents: 345
diff changeset
   317
    "
claus
parents: 345
diff changeset
   318
     this method is not to be inherited
claus
parents: 345
diff changeset
   319
     (i.e. not ok for subclasses; Symbol, for example)
claus
parents: 345
diff changeset
   320
    "
claus
parents: 345
diff changeset
   321
    self ~~ String ifTrue:[
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
   322
	^ super readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   323
    ].
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   324
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   325
claus
parents: 345
diff changeset
   326
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   327
     String readFrom:('''hello world''' readStream)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   328
     String readFrom:('''hello '''' world''' readStream)
347
claus
parents: 345
diff changeset
   329
     String readFrom:('1 ''hello'' ' readStream)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   330
     String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
3376
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   331
    "
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   332
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   333
    "Modified: / 05-07-2006 / 16:41:29 / cg"
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   334
    "Modified: / 07-08-2006 / 15:03:09 / fm"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   337
uninitializedNew:anInteger
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   338
    "return a new string with anInteger characters but undefined contents.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   339
     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
   340
     used as a stream buffer."
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   341
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   342
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   343
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   344
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   345
#else
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   346
    OBJ newString;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   347
    REGISTER int len;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   348
    REGISTER unsigned char *cp;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   349
    REGISTER OBJ *op;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   350
    int nInstVars, instsize;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   351
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   352
    if (__isSmallInteger(anInteger)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   353
	len = __intVal(anInteger);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   354
	if (len >= 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   355
	    instsize = OHDR_SIZE + len + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   356
	    if (self == String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   357
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   358
		    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   359
		     * the most common case
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   360
		     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   361
		    __qCheckedNew(newString, instsize);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   362
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   363
		    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   364
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   365
		    cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   366
		    cp[len] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   367
		    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   368
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   369
		nInstVars = 0;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   370
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   371
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   372
		instsize += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   373
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   374
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   375
	    __PROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   376
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   377
	    __UNPROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   378
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   379
	    if (newString == nil) goto fail;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   380
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   381
	    __InstPtr(newString)->o_class = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   382
	    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   383
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   384
	    if (nInstVars) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   385
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   386
		 * nil-out instvars
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   387
		 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   388
# if defined(memset4)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   389
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   390
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   391
#  if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   392
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   393
		 * knowing that nil is 0
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   394
		 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   395
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   396
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   397
		op = __InstPtr(newString)->i_instvars;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   398
		do {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   399
		    *op++ = nil;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   400
		} while (--nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   401
#  endif
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   402
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   403
		cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   404
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   405
		cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   406
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   407
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   408
	    *(cp + len) = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   409
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   410
	}
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   411
    }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   412
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   413
#endif /* not __SCHTEAM__ */
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   414
%}.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   415
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   416
     invalid argument, or out-of-memory:
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   417
     use error handling in superclass
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   418
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   419
    (anInteger < 0) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   420
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   421
	 the argument is negative,
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   422
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   423
	self error:'bad (negative) argument to new:'.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   424
	^ nil
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   425
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   426
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   427
    ^ self basicNew:anInteger
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   428
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   429
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   430
     String uninitializedNew:100
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   431
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
8438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   434
!String class methodsFor:'Compatibility-Dolphin'!
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   435
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   436
lineDelimiter
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   437
    "Dolphin compatibility: answer CR LF"
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   439
    ^ self crlf
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
7302
13a053c255bf category
Claus Gittinger <cg@exept.de>
parents: 7283
diff changeset
   442
!String class methodsFor:'Compatibility-Squeak'!
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   443
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   444
cr
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   445
    "return a string consisting of the cr-Character"
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   446
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   447
    "/ ATTENTION: you get a NL (for compatibility) here!!
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   448
    "/ please use String return  / String lf
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   449
    self halt:'please make it explicit, if a return or a linefeed is wanted.'.
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   450
    "/ for now.
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   451
    "/ will be changed, when the historic UNIX baggage is removed
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   452
    "/ and all cr's are really returns (instead of nl's).
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   453
     
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   454
    ^ self lf
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   455
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   456
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   457
crlf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   458
    "return a string consisting of the cr-lf Characters"
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 isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   461
	CRLF := String
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   462
		    with:Character return
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   463
		    with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   464
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   465
    ^ CRLF
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   466
!
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
lf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   469
    "return a string consisting of the lf Character"
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 isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   472
	LF := String with:Character linefeed
7282
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
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   475
!
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   476
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   477
return
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   478
    "return a string consisting of the cr-Character"
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   479
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   480
    CR isNil ifTrue:[
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   481
        CR := String with:Character return
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   482
    ].
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   483
    ^ CR
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   484
!
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   485
12344
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   486
stringHash:aString initialHash:speciesHash
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   487
    "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
   488
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   489
    | stringSize hash low |
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   490
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   491
    stringSize := aString size.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   492
    hash := speciesHash bitAnd: 16rFFFFFFF.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   493
    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
   494
	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
   495
	"Begin hashMultiply"
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   496
	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
   497
	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
   498
    ].
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   499
    ^ hash.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   500
!
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   501
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   502
tab
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   503
    "return a string consisting of the tab-Character"
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   504
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   505
    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
   506
	TAB := String with:Character tab
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   507
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   508
    ^ TAB
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   509
! !
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   510
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   511
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   512
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   513
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   514
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   515
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   516
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   517
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   518
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   519
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   520
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   521
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   523
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   524
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   527
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   528
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   529
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
   531
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   532
!String methodsFor:'Compatibility-VW5.4'!
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   533
17649
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   534
asByteString
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   535
    ^ self asSingleByteString
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   536
!
053e0bc361ad class: String
Claus Gittinger <cg@exept.de>
parents: 17643
diff changeset
   537
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   538
asGUID
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   539
    "return self as a GUID (or UUID if not present)"
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   540
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   541
    GUID notNil ifTrue:[ ^ GUID fromString:self ].
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   542
    ^ self asUUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   543
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   544
    "
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   545
     '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asGUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   546
    "
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   547
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   548
    "Modified: / 12-01-2011 / 12:33:58 / cg"
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   549
! !
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   550
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   551
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   552
329
claus
parents: 314
diff changeset
   553
at:index
claus
parents: 314
diff changeset
   554
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   555
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   556
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   557
     This method is the same as at:."
claus
parents: 314
diff changeset
   558
claus
parents: 314
diff changeset
   559
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   560
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   561
    if (index.isSmallInteger()) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   562
	int idx1Based = context.stArg(0).intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   563
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   564
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   565
#else
329
claus
parents: 314
diff changeset
   566
    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
   567
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   568
claus
parents: 314
diff changeset
   569
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   570
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   571
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   572
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   573
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   574
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   575
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   576
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   577
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   578
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   579
	}
329
claus
parents: 314
diff changeset
   580
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   581
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   582
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   583
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   584
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   585
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   586
329
claus
parents: 314
diff changeset
   587
at:index put:aCharacter
claus
parents: 314
diff changeset
   588
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   589
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   590
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   591
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   592
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   593
claus
parents: 314
diff changeset
   594
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   595
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   596
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   597
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   598
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   599
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   600
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   601
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   602
#else
329
claus
parents: 314
diff changeset
   603
    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
   604
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   605
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   606
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   607
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   608
    if (__isString(slf)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   609
	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
   610
	    value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   611
	    if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   612
	     && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   613
		indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   614
		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   615
		    __stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   616
		    RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   617
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   618
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   619
	}
329
claus
parents: 314
diff changeset
   620
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   621
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   622
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   623
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   624
!
claus
parents: 314
diff changeset
   625
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   631
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   632
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   633
	int idx1Based = index.intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   634
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   635
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   636
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
    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
   638
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   639
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   640
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   641
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   642
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   643
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   644
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   645
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   646
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   647
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   648
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   649
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   650
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   652
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   653
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   655
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   656
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   657
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   658
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   659
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   660
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   661
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   662
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   663
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   664
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   665
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   666
     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
   667
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   668
a27a279701f8 Initial revision
claus
parents:
diff changeset
   669
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   670
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   671
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   672
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   673
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   674
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   675
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   676
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   677
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   678
    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
   679
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   680
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   681
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   682
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   683
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   684
    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
   685
	value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   686
	if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   687
	 && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   688
	    cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   689
	    indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   690
	    if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   691
		if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   692
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   693
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   694
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   695
		__stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   696
		RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   697
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   698
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   699
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   700
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   701
#endif /* not __SCHTEAM__ */
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   702
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   703
    (aCharacter isMemberOf:Character) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   704
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   705
	 tried to store something which is not a character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   706
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   707
	^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   708
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   709
    (aCharacter codePoint between:1 and:255) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   710
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   711
	 tried to store a multibyte character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   712
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   713
	^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   714
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   715
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   716
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   717
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   718
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   719
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   720
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   721
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   722
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   723
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   724
    super basicAt:index put:aCharacter codePoint.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   725
    ^ aCharacter
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   726
!
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   727
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   728
first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   729
    "return the first character.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   730
     Reimplemented here for speed"
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   731
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   732
%{  /* NOCONTEXT */
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
    REGISTER int indx;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   735
    REGISTER OBJ slf, cls;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   736
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   737
    slf = self;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   738
    cls = __qClass(slf);
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   739
    indx = 0;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   740
    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
   741
	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
   742
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   743
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   744
    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
   745
	RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   746
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   747
badIndex: ;
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
    ^ super first
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
    "
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   752
     'abc' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   753
     '' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   754
    "
2
claus
parents: 1
diff changeset
   755
! !
claus
parents: 1
diff changeset
   756
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   757
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   758
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   759
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   760
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   761
    "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
   762
     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
   763
19744
f64dd57ad912 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19742
diff changeset
   764
    ^ self indexOf:aCharacter startingAt:1.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   765
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   766
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   767
     'hello world' identityIndexOf:(Character space)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   768
     '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
   769
     'hello world' identityIndexOf:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   770
     #[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
   771
     #[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
   772
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   773
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   774
    "Modified: / 10-01-2012 / 17:07:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   775
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
13923
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   777
identityIndexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   778
    "return the index of the first occurrences of the argument, aCharacter
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   779
     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
   780
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   781
    ^ self indexOf:aCharacter startingAt:index
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
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   784
     'hello world' identityIndexOf:(Character space)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   785
     'hello world' identityIndexOf:$d
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   786
     'hello world' identityIndexOf:1
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   787
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   788
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   789
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   790
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   791
    "Created: / 10-01-2012 / 17:10:54 / cg"
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
10
claus
parents: 5
diff changeset
   794
includesAny:aCollection
claus
parents: 5
diff changeset
   795
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   796
     argument, aCollection.
17573
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   797
     - redefined for speed if the argument is a String; especially optimized,
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   798
     if the searched collection has less than 6 characters."
10
claus
parents: 5
diff changeset
   799
claus
parents: 5
diff changeset
   800
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   801
claus
parents: 5
diff changeset
   802
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   803
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   804
    OBJ cls;
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   805
    int index, last;
10
claus
parents: 5
diff changeset
   806
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
   807
    if (__isStringLike(aCollection)) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   808
        matchP = __stringVal(aCollection);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   809
        last = __stringSize(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   810
        cp = __stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   811
        if ((cls = __qClass(self)) != String) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   812
            int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   813
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   814
            cp += numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   815
            last -= numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   816
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   817
        index = 0;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   818
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   819
        switch (__stringSize(aCollection)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   820
            case 5:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   821
                /* five character search */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   822
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   823
                    unsigned char c1 = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   824
                    unsigned char c2 = matchP[1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   825
                    unsigned char c3 = matchP[2];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   826
                    unsigned char c4 = matchP[3];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   827
                    unsigned char c5 = matchP[4];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   828
                    unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   829
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   830
                    while (index < last) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   831
                        ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   832
                        if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   833
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   834
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   835
                        index++;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   836
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   837
                    RETURN (false);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   838
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   839
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   840
            case 4:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   841
                /* four character search */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   842
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   843
                    unsigned char c1 = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   844
                    unsigned char c2 = matchP[1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   845
                    unsigned char c3 = matchP[2];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   846
                    unsigned char c4 = matchP[3];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   847
                    unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   848
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   849
                    while (index < last) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   850
                        ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   851
                        if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   852
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   853
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   854
                        index++;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   855
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   856
                    RETURN (false);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   857
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   858
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   859
            case 3:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   860
                /* three character search */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   861
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   862
                    unsigned char c1 = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   863
                    unsigned char c2 = matchP[1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   864
                    unsigned char c3 = matchP[2];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   865
                    unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   866
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   867
                    while (index < last) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   868
                        ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   869
                        if ((ch == c1) || (ch == c2) || (ch == c3)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   870
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   871
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   872
                        index++;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   873
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   874
                    RETURN (false);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   875
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   876
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   877
            case 2:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   878
                /* two character search */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   879
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   880
#if 0
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   881
                    // this is roughly 10% slower (on OSX/64bit clang')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   882
                    if (last < 2000) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   883
                        if (strchr(cp, matchP[0])) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   884
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   885
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   886
                        if (strchr(cp, matchP[1])) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   887
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   888
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   889
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   890
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   891
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   892
#if 1
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   893
                    // this is 30 %faster !
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   894
#                   define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   895
#                   define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   896
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   897
                    unsigned char c1 = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   898
                    unsigned char c2 = matchP[1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   899
                    int last4 = last-4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   900
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   901
                    int m1 = (~0UL/255 * (c1));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   902
                    int m2 = (~0UL/255 * (c2));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   903
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   904
                    while (index < last4) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   905
                        unsigned int v = *(unsigned int *)(cp+index);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   906
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   907
                        if (hasByteM(v,m1)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   908
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   909
                        }    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   910
                        if (hasByteM(v,m2)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   911
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   912
                        }    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   913
                        index += 4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   914
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   915
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   916
#                   undef hasZeroByte
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   917
#                   undef hasByteM
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   918
#else
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   919
                    while (index < last4) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   920
                        unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   921
                        int any;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   922
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   923
                        ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   924
                        any = ((ch == c1) || (ch == c2));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   925
                        ch = cp[index+1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   926
                        any |= ((ch == c1) || (ch == c2));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   927
                        ch = cp[index+2];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   928
                        any |= ((ch == c1) || (ch == c2));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   929
                        ch = cp[index+3];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   930
                        any |= ((ch == c1) || (ch == c2));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   931
                        if (any) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   932
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   933
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   934
                        index += 4;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   935
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   936
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   937
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   938
                    while (index < last) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   939
                        unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   940
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   941
                        ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   942
                        if ((ch == c1) || (ch == c2)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   943
                            RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   944
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   945
                        index++;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   946
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   947
                    RETURN (false);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   948
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   949
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   950
            case 1:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   951
                /* single character search */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   952
                if (strchr(cp, matchP[0])) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   953
                    RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   954
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   955
                RETURN ( false );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   956
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   957
            case 0:
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   958
                RETURN ( false );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   959
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   960
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   961
        {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   962
            unsigned char ch;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   963
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   964
            while (index < last) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   965
                ch = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   966
                if (strchr(matchP, ch)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   967
                    RETURN ( true );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   968
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   969
                index++;    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   970
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   971
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   972
        RETURN ( false );
10
claus
parents: 5
diff changeset
   973
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   974
%}.
10
claus
parents: 5
diff changeset
   975
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   976
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   977
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   978
     'hello world' includesAny:'abcd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   979
     'hello world' includesAny:'xyz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   980
     'hello world' includesAny:'xz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   981
     'hello world' includesAny:'od'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   982
     'hello world' includesAny:'xd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   983
     'hello world' includesAny:'dx'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   984
     'hello world' includesAny:(Array with:$a with:$b with:$d)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   985
     'hello world' includesAny:(Array with:$x with:$y)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   986
     'hello world' includesAny:(Array with:1 with:2)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   987
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   988
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   989
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   990
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   991
        1000000 timesRepeat:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   992
            s includesAny:'12'   
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   993
        ]    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   994
     ].540 680 550 850 890 850
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   995
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   996
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   997
     s := String new:2000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   998
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   999
        1000000 timesRepeat:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1000
            s includesAny:'12'   
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1001
        ]    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1002
     ]. 1030 1060 1650 1690
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1003
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1004
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1005
     s := 'hello world'.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1006
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1007
        1000000 timesRepeat:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1008
            s includesAny:'12'   
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1009
        ]    
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1010
     ].70 60  
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1011
    "
10
claus
parents: 5
diff changeset
  1012
!
claus
parents: 5
diff changeset
  1013
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1014
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1015
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1016
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1017
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1018
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1019
%{  /* NOCONTEXT */
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1020
#ifdef __SCHTEAM__
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1021
    if (start.isSmallInteger()
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1022
     && aCharacter.isSTCharacter()) {
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1023
        int idx1Based = start.intValue();   // st index is 1 based
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1024
        int jIdx = self.asString().indexOf(aCharacter.charValue(), idx1Based-1);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1025
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1026
        return context._RETURN( jIdx+1 );    // st index is 1 based
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1027
    }
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1028
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1029
#else
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1030
# if defined(__BORLANDC__) || defined(__VISUALC__)
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1031
#  undef __UNROLL_LOOPS__
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1032
#  undef FAST_MEMCHR
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1033
#  define V2
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1034
# endif
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1035
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1036
    REGISTER unsigned char *cp;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1037
    REGISTER INT index;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1038
    REGISTER unsigned byteValue;
8924
eb2dd7dd459f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8923
diff changeset
  1039
    int last;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1040
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1041
252
  1042
    if (__isSmallInteger(start)) {
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1043
        index = __intVal(start);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1044
        if (index > 0) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1045
            if (__isCharacter(aCharacter)) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1046
                byteValue = __intVal(__characterVal(aCharacter));
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1047
                if (byteValue <= 0xFF) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1048
                    last = __stringSize(self);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1049
                    cp = __stringVal(self);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1050
                    if ((cls = __qClass(self)) != String) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1051
                        int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1052
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1053
                        cp += numInstBytes;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1054
                        last -= numInstBytes;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1055
                    }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1056
                    if (index <= last) {
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1057
# ifdef FAST_MEMCHR
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1058
                        REGISTER unsigned char *ncp;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1059
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1060
                        ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1061
                        if (ncp) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1062
                            RETURN ( __mkSmallInteger(ncp - cp + 1) );
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1063
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1064
# else
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1065
#  ifdef __UNROLL_LOOPS__
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1066
                        {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1067
                            int last3 = last-3;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1068
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1069
                            for (; index <= last3; index += 4) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1070
                                if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1071
                                if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1072
                                if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1073
                                if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1074
                            }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1075
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1076
#  endif
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1077
#  ifdef V1
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1078
                        for (; index <= last; index++) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1079
                            if (cp[index-1] == byteValue) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1080
                                RETURN ( __mkSmallInteger(index) );
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1081
                            }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1082
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1083
#  endif
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1084
#  ifdef V2
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1085
                        {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1086
                            // see bit twiddling hacks
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1087
#                           define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1088
#                           define hasByteM(v,m)   hasZeroByte( (v) ^ m)
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1089
#   if __POINTER_SIZE__ == 8
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1090
#                           define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1091
#                           define hasByteM8(v,m)   hasZeroByte8( (v) ^ m)
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1092
                            // the following loop checks eight bytes at once
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1093
                            if (((index-1) & 0x7) == 0) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1094
                                int last8 = last-8;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1095
                                INT m = (~0ULL/255 * (byteValue));
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1096
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1097
                                while (index <= last8) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1098
                                    unsigned INT v = *(unsigned INT *)(cp+index-1);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1099
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1100
                                    if (hasByteM8(v,m)) break;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1101
                                    index += 8;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1102
                                }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1103
                            }
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1104
#   endif
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1105
                            // the following loop checks four bytes at once
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1106
                            if (((index-1) & 0x3) == 0) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1107
                                int last4 = last-4;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1108
                                int m = (~0UL/255 * (byteValue));
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1109
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1110
                                while (index <= last4) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1111
                                    unsigned int v = *(unsigned int *)(cp+index-1);
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1112
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1113
                                    if (hasByteM(v,m)) break;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1114
                                    index += 4;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1115
                                }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1116
                            }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1117
                            while (index <= last) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1118
                                if (cp[index-1] == byteValue) {
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1119
                                    RETURN ( __mkSmallInteger(index) );
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1120
                                }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1121
                                index++;
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1122
                            }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1123
                        }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1124
#  endif
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1125
# endif
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1126
                    }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1127
                }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1128
            }
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1129
            RETURN ( __mkSmallInteger(0) );
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1130
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1131
    }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1132
# undef V2
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1133
#endif /* not SCHTEAM */
370
claus
parents: 368
diff changeset
  1134
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1135
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1136
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1137
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1138
     '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
  1139
     '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
  1140
     '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
  1141
     '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
  1142
     #[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
  1143
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1144
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1145
     '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
  1146
     '1234567890123456a' indexOf:$b
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1147
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1148
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1149
     s := '12345678901234b'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1150
     self assert:(s indexOf:$x) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1151
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1152
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1153
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1154
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1155
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1156
     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
  1157
     self assert:(s indexOf:$b) == 15.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1158
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1159
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1160
     s := ''.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1161
     self assert:(s indexOf:$1) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1162
     s := '1'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1163
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1164
     self assert:(s indexOf:$2) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1165
     s := '12'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1166
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1167
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1168
     self assert:(s indexOf:$3) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1169
     s := '123'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1170
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1171
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1172
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1173
     self assert:(s indexOf:$4) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1174
     s := '1234'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1175
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1176
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1177
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1178
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1179
     self assert:(s indexOf:$5) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1180
     s := '12345'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1181
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1182
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1183
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1184
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1185
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1186
     self assert:(s indexOf:$6) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1187
     s := '123456'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1188
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1189
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1190
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1191
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1192
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1193
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1194
     self assert:(s indexOf:$7) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1195
     s := '1234567'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1196
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1197
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1198
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1199
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1200
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1201
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1202
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1203
     self assert:(s indexOf:$8) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1204
     s := '12345678'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1205
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1206
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1207
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1208
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1209
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1210
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1211
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1212
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1213
     self assert:(s indexOf:$9) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1214
     s := '123456789'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1215
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1216
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1217
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1218
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1219
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1220
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1221
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1222
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1223
     self assert:(s indexOf:$9) == 9.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1224
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1225
     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
  1226
     self assert:(s indexOf:$b) == 0.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1227
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1228
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1229
     s := String new:1024.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1230
     s atAllPut:$a.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1231
     s at:512 put:(Character space).
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1232
     Time millisecondsToRun:[
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1233
        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
  1234
     ]
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1235
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1236
     timing (ms):
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1237
            bcc                 OSX(2007 powerbook)
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1238
        v1: 1763 normal
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1239
            2340 +unroll
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1240
            3308 memsrch !!       90
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1241
        v2: 1045                150
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1242
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1243
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
  1244
    "Modified: / 10-01-2012 / 17:09:34 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1245
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1246
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1247
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1248
    "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
  1249
     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
  1250
     - 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
  1251
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1252
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1253
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1254
    unsigned char *ccp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1255
    unsigned char *cp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1256
    INT index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1257
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1258
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1259
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1260
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1261
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1262
    if (__isSmallInteger(start)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  1263
     && __isStringLike(aCollectionOfCharacters)) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1264
        matchP = __stringVal(aCollectionOfCharacters);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1265
        index = __intVal(start);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1266
        if (index > 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1267
            cp = __stringVal(self) + index - 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1268
            if ((cls = __qClass(self)) != String) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1269
                cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1270
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1271
            len = __stringSize(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1272
            if (index <= len) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1273
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1274
                if (matchP[0] == 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1275
                    /* matchSet is empty */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1276
                    RETURN ( __mkSmallInteger(0) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1277
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1278
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1279
                if (matchP[1] == 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1280
                    /* only a single character match */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1281
                    unsigned char m = matchP[0];
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1282
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1283
# ifdef FAST_MEMCHR
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1284
                    ccp = (unsigned char *) memchr(cp, m, len+1-index);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1285
                    if (ccp) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1286
                        RETURN ( __mkSmallInteger((ccp - cp) + index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1287
                    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1288
# else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1289
                    while ((c = *cp++) != '\0') {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1290
                        if (c == m) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1291
                            RETURN ( __mkSmallInteger(index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1292
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1293
                        index++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1294
                    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1295
# endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1296
                    RETURN ( __mkSmallInteger(0) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1297
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1298
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1299
                if (matchP[2] == 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1300
                    /* two character matches */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1301
                    unsigned char m1 = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1302
                    unsigned char m2 = matchP[1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1303
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1304
                    while ((c = *cp++) != '\0') {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1305
                        if ((c == m1) || (c == m2)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1306
                            RETURN ( __mkSmallInteger(index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1307
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1308
                        index++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1309
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1310
                    RETURN ( __mkSmallInteger(0) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1311
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1312
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1313
                min = max = matchP[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1314
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1315
                for (ccp = matchP+1; *ccp ; ccp++) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1316
                    unsigned char c = *ccp;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1317
                    if (c < min) min = c;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1318
                    else if (c > max) max = c;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1319
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1320
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1321
                while ((c = *cp++) != '\0') {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1322
                    if ((c >= min) && (c <= max)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1323
                        for (ccp = matchP; *ccp ; ccp++) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1324
                            if (*ccp == c) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1325
                                RETURN ( __mkSmallInteger(index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1326
                            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1327
                        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1328
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1329
                    index++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1330
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1331
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1332
            RETURN ( __mkSmallInteger(0) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1333
        }
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1334
    }
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1335
%}.
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1336
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1337
    "/ 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
  1338
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1339
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1340
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1341
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1342
     'hello world' indexOfAny:'eoa' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1343
     'hello world' indexOfAny:'eoa' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1344
     'hello world' indexOfAny:'AOE' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1345
     'hello world' indexOfAny:'o' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1346
     'hello world' indexOfAny:'o' startingAt:6
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  1347
     'hello world§' indexOfAny:'#§$' startingAt:6
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1348
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1349
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1350
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1351
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1352
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1353
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1354
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1355
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1356
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1357
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1358
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1359
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1360
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1361
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1362
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1363
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1364
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1365
    if (index <= 0) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1366
        index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1367
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1368
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1369
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1370
    if ((cls = __qClass(self)) != String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1371
        int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1372
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1373
        cp += numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1374
        len -= numInstBytes;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1375
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1376
    while (index <= len) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1377
        REGISTER unsigned char c;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1378
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1379
        c = cp[index - 1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1380
        if (c < ' ') {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1381
            RETURN ( __mkSmallInteger(index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1382
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1383
        index++;
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1384
    }
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1385
    RETURN ( __mkSmallInteger(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1386
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1387
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1388
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1389
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1390
     'hello world'             indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1391
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1392
     '1\' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1393
     '1\' withCRs indexOfControlCharacterStartingAt:2
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1394
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1395
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1396
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1397
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1398
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1399
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1400
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1401
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1402
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1403
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1404
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1405
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1406
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1407
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1408
    if (index <= 0) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1409
        index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1410
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1411
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1412
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1413
    if ((cls = __qClass(self)) != String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1414
        int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1415
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1416
        cp += numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1417
        len -= numInstBytes;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1418
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1419
    while (index <= len) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1420
        REGISTER unsigned char c;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1421
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1422
        c = cp[index - 1];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1423
        if (c > ' ') {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1424
            if ((c != ' ') && (c != '\t') && (c != '\n')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1425
             && (c != '\r') && (c != '\f')) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1426
                RETURN ( __mkSmallInteger(index) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1427
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1428
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1429
        index++;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1430
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1431
    RETURN ( __mkSmallInteger(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1432
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1433
    ^ super indexOfNonSeparatorStartingAt:start
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1434
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1435
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1436
     'hello world' indexOfNonWhiteSpaceStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1437
     'hello world' indexOfNonWhiteSpaceStartingAt:7
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1438
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1439
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1440
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1441
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1442
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1443
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1444
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1445
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1446
    if (__isSmallInteger(start)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1447
        REGISTER unsigned char *cp;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1448
        int len, index;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1449
        OBJ cls;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1450
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1451
        index = __intVal(start)-1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1452
        // is this a good idea?
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1453
        if (index < 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1454
            index = 0;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1455
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1456
        len = __stringSize(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1457
        cp = __stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1458
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1459
        // care for subclasses of string
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1460
        if ((cls = __qClass(self)) != String) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1461
            int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1462
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1463
            cp += numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1464
            len -= numInstBytes;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1465
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1466
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1467
        // these pre-loops do fast skip over non-separators
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1468
        // (anything above 0x32)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1469
#if __POINTER_SIZE__ == 8
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1470
        if ((index & 7) == 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1471
            int len8 = len-8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1472
            while (index < len8) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1473
                REGISTER unsigned INT eightChars;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1474
                REGISTER unsigned INT eightCharsMasked;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1475
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1476
                eightChars = ((unsigned INT *)(cp+index))[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1477
                eightCharsMasked = eightChars & 0xE0E0E0E0E0E0E0E0ULL;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1478
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1479
                // any control char?
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1480
                // (these are 0..31 and also the space);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1481
                // so we need two compares.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1482
#               define hasZeroByte(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1483
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1484
#               define maskSpace       (~0UL/255 * (32))
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1485
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1486
                if (hasByteM(eightChars, maskSpace)) break;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1487
                if (hasZeroByte(eightCharsMasked)) break;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1488
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1489
#               undef hasZeroByte 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1490
#               undef hasByteM   
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1491
#               undef maskSpace       
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1492
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1493
                index += 8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1494
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1495
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1496
#endif /* POINTER_SIZE == 8*/
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1497
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1498
        if ((index & 3) == 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1499
            int len4 = len-4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1500
            while (index < len4) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1501
                REGISTER unsigned int fourChars;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1502
                REGISTER unsigned int fourCharsMasked;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1503
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1504
                fourChars = ((unsigned int *)(cp+index))[0];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1505
                fourCharsMasked = fourChars & 0xE0E0E0E0UL;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1506
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1507
                // any control char?
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1508
                // (these are 0..31 and also the space);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1509
                // so we need two compares.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1510
#               define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1511
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1512
#               define maskSpace       (~0UL/255 * (32))
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1513
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1514
                if (hasByteM(fourChars, maskSpace)) break;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1515
                if (hasZeroByte(fourCharsMasked)) break;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1516
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1517
#               undef hasZeroByte 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1518
#               undef hasByteM   
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1519
#               undef maskSpace       
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1520
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1521
                index += 4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1522
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1523
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1524
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1525
        while (index < len) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1526
            REGISTER unsigned char c;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1527
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1528
            c = cp[index];
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1529
            if (c <= ' ') { 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1530
                if ((c == ' ') || (c == '\t') || (c == '\n')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1531
                 || (c == '\r') || (c == '\f')) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1532
                    RETURN ( __mkSmallInteger(index+1) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1533
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1534
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1535
            index++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1536
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1537
        RETURN ( __mkSmallInteger(0) );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1538
    }    
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1539
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1540
    ^ super indexOfSeparatorStartingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1541
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1542
    " 123456789012
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1543
     'hello world ' indexOfSeparatorStartingAt:1 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1544
     'hello world ' indexOfSeparatorStartingAt:3 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1545
     'hello world ' indexOfSeparatorStartingAt:7 -> 12
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1546
     'hello world' indexOfSeparatorStartingAt:7  -> 0
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1547
     'helloworld' indexOfSeparatorStartingAt:1   -> 0
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1548
    "
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1549
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1550
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1551
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1552
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1553
     self assert:(s indexOfSeparatorStartingAt:1) == 0.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1554
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1555
         1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1556
     ]
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1557
     original (char-wise):760 760 750 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1558
     with 4-byte at a time: 640 650 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1559
     with 8-byte at a time: 300 290 320
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1560
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1561
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1562
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1563
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1564
     s at:400 put:(Character return).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1565
     self assert:(s indexOfSeparatorStartingAt:1) == 400.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1566
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1567
         1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1568
     ]        
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1569
     original (char-wise):340 350 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1570
     with 4-byte at a time: 310 290 280
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1571
     with 8-byte at a time: 150 140 140
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1572
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1573
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1574
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1575
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1576
     s at:999 put:(Character space).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1577
     self assert:(s indexOfSeparatorStartingAt:1) == 999.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1578
     Time millisecondsToRun:[
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1579
         1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1580
     ]        
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1581
     original (char-wise): 750 750 790 
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1582
     with 4-byte at a time: 640 640 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1583
     with 8-byte at a time: 280 290 300
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1584
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1585
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1586
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1587
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1588
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1589
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1590
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1591
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1592
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1593
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1594
    REGISTER unsigned byteValue;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1595
    REGISTER INT count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1596
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1597
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1598
    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
  1599
	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
  1600
	count = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1601
	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
  1602
	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
  1603
	    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
  1604
	    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
  1605
		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
  1606
		limit -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1607
		cp += n;
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
	    /* 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
  1610
	     * (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
  1611
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1612
	    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
  1613
		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
  1614
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1615
		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
  1616
		limit -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1617
		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
  1618
		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
  1619
		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
  1620
		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
  1621
		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
  1622
		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
  1623
		cp += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1624
		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
  1625
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1626
	    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
  1627
		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
  1628
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1629
		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
  1630
		limit--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1631
		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
  1632
		cp ++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1633
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1634
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1635
	RETURN ( __mkSmallInteger(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1636
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1637
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1638
    ^ super occurrencesOf:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1639
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1640
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1641
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1642
     'hello world' occurrencesOf:$w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1643
     'hello world' occurrencesOf:$l
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1644
     'hello world' occurrencesOf:$x
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1645
     'hello world' occurrencesOf:1
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1646
     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
  1647
	1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ]
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1648
     ]. 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
  1649
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1650
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1651
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1652
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1653
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1654
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1655
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1656
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1657
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1658
     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
  1659
     'foo' < 'Foo' will return false.
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1660
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1661
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1662
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1663
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1664
    return context._RETURN( self.stringLtP(aString) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1665
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1666
#else
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1667
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1668
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1669
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1670
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1671
    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
  1672
	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
  1673
	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
  1674
	    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
  1675
	    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
  1676
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1677
	     * 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
  1678
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1679
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1680
		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
  1681
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1682
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1683
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1684
	    }
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
	    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
  1687
	    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
  1688
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1689
	     * 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
  1690
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1691
	    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
  1692
		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
  1693
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1694
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1695
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1696
	    }
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 (len1 <= len2)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1699
		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
  1700
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1701
		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
  1702
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1703
	    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
  1704
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1705
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1706
	    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
  1707
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1708
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1709
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1710
	}
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1711
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1712
#endif
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1713
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1714
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1715
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1716
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1717
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1718
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1719
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1720
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1721
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1722
375
claus
parents: 370
diff changeset
  1723
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1724
#ifdef __SCHTEAM__
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1725
    if (aString == self) {
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1726
	return __c__._RETURN_true();
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1727
    }
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1728
    if (aString.isStringLike()) {
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1729
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False );
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1730
    }
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1731
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1732
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1733
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1734
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1735
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1736
    unsigned char *cp1, *cp2;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1737
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1738
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1739
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1740
    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
  1741
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1742
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1743
    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
  1744
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1745
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1746
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1747
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1748
    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
  1749
	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
  1750
	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
  1751
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1752
	 * 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
  1753
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1754
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1755
	    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
  1756
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1757
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1758
	    l2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1761
	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
  1762
	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
  1763
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1764
	 * 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
  1765
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1766
	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
  1767
	    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
  1768
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1769
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1770
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1771
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1772
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1773
	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
  1774
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1775
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1776
# 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
  1777
	RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1778
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1779
	addrDelta = cp2 - cp1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1780
#  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
  1781
	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
  1782
	    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
  1783
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1784
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1785
	    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
  1786
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1787
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1788
	    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
  1789
		RETURN (false);
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
	    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
  1792
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1793
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1794
	    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
  1795
	    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
  1796
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1797
#  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
  1798
	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
  1799
	    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
  1800
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1801
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1802
	    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
  1803
	    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
  1804
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1805
	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
  1806
	    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
  1807
		RETURN (false);
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
	    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
  1810
	    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
  1811
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1812
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1813
	    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
  1814
		RETURN (false);
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
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1817
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1818
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1819
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1820
	RETURN (true);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1821
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1822
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1823
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1824
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1825
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1826
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1827
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1828
     'foo' = 'Foo'
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1829
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1830
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1831
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1832
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1833
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1834
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1835
     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
  1836
	 1000000 timesRepeat:[]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1837
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1838
     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
  1839
	 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1840
     ].
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1841
     tCmp - tEmpty
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1842
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1843
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1844
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1845
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1846
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1847
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1848
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1849
     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
  1850
     'foo' > 'Foo' will return true.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1851
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1852
375
claus
parents: 370
diff changeset
  1853
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1854
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1855
    return context._RETURN( aString.stringLtP( self ) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1856
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1857
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1858
    int len1, len2, cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1859
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1860
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1861
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1862
    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
  1863
	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
  1864
	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
  1865
	    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
  1866
	    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
  1867
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1868
	     * 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
  1869
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1870
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1871
		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
  1872
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1873
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1874
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1875
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1876
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1877
	    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
  1878
	    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
  1879
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1880
	     * 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
  1881
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1882
	    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
  1883
		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
  1884
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1885
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1886
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1887
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1888
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1889
	    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
  1890
		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
  1891
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1892
		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
  1893
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1894
	    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
  1895
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1896
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1897
	    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
  1898
		RETURN ( true );
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
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1901
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1902
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1903
#endif /* not __SCHTEAM__ */
370
claus
parents: 368
diff changeset
  1904
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1905
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1906
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1907
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1908
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1909
    "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
  1910
     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
  1911
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1912
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1913
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1914
    ^ self compareWith:aString collating:true
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1915
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1916
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1917
     'hallo' compareWith:'hällo'
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1918
     'hbllo' compareWith:'hällo'
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1919
     
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1920
     'hallo' compareCollatingWith:'hällo'
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1921
     'hbllo' compareCollatingWith:'hällo'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1922
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1923
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1924
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1925
compareWith:aString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1926
    "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
  1927
     greater, 0 if equal and -1 if less than the argument.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1928
     This comparison is based on the elements' codepoints -
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1929
     i.e. upper/lowercase & national characters are NOT treated specially.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1930
     'foo' compareWith: 'Foo' will return 1.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1931
     while 'foo' sameAs:'Foo' will return true"
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1932
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1933
    ^ self compareWith:aString collating:false
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1934
!
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1935
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1936
compareWith:aString collating:collatingBoolean
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1937
    "Compare the receiver with the argument and return 1 if the receiver is
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1938
     greater, 0 if equal and -1 if less than the argument.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1939
     If the collatingBoolean is true, the comparison will be based on the
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1940
     current setting of LC_COLLATE in the locale (which is set in the shell environment);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1941
     otherwise, it will be a simple string-compare.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1942
     This comparison is based on the elements' codepoints -
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1943
     i.e. upper/lowercase & national characters are NOT treated specially.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1944
     'foo' compareWith: 'Foo' will return 1.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1945
     while 'foo' sameAs:'Foo' will return true"
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1946
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1947
%{  /* NOCONTEXT */
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1948
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1949
    int cmp;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1950
    unsigned char *cp1, *cp2;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1951
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1952
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1953
    if (__isNonNilObject(aString)) {
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1954
        argIsString = __qIsStringLike(aString);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1955
        if (argIsString || __qClass(aString) == __qClass(self)) {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1956
            //
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1957
            // care for instances of subclasses ...
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1958
            //
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1959
            cp1 = __stringVal(self);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1960
            if (!__qIsStringLike(self)) {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1961
                int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1962
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1963
                cp1 += n;
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1964
            }
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1965
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1966
            //
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1967
            // care for instances of subclasses ...
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1968
            //
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1969
            cp2 = __stringVal(aString);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1970
            if (!argIsString) {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1971
                int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1972
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1973
                cp2 += n;
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1974
            }
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1975
            if (collatingBoolean == true) {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1976
#ifdef HAS_STRCOLL
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1977
                cmp = strcoll(cp1, cp2);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1978
#else
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1979
                // bail out, to give programmer a chance to do it in Smalltalk (inherited)
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1980
                goto getOutOfHere;
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1981
#endif            
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1982
            } else {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1983
                cmp = strcmp(cp1, cp2);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1984
            }    
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1985
            {
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1986
                // int signum = (cmp>0) ? 1 : ((cmp<0) ? -1 : 0);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1987
                int signum = (cmp > 0) - (cmp < 0);
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1988
                RETURN( __mkSmallInteger( signum ) );
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1989
            }    
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1990
        }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1991
    }
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1992
getOutOfHere: ;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1993
%}.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1994
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1995
     currently, this operation is only defined for strings, symbols and subclasses.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1996
     allow for an implementation in Smalltalk
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1997
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1998
    ^ super compareWith:aString collating:collatingBoolean
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1999
!
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2000
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2001
hash
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2002
    "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
  2003
     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
  2004
     used in the ST/X VM (which is actually fnv-1a)"
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2005
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2006
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2007
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2008
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2009
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2010
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2011
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2012
    extern unsigned int __symbolHash(char *);
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2013
    unsigned char *cp = __stringVal(self);
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2014
    unsigned int h;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2015
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2016
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2017
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2018
    }
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2019
    h = __symbolHash(cp);
16891
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2020
    // make sure, it fits into a smallInt
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2021
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2022
    RETURN(__mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2023
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2024
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2025
    ^ self primitiveFailed
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2026
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2027
    "
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2028
     'a' hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2029
     'ab' hash = 'ab' asUnicode16String hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2030
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2031
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2032
    "Created: / 26-12-2011 / 13:53:09 / cg"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2033
!
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2034
13880
Claus Gittinger <cg@exept.de>
parents: 13205
diff changeset
  2035
hash_dragonBook
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2036
    "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
  2037
     This method implements the dragon-book algorithm (aho, ullman)."
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2038
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2039
%{  /* NOCONTEXT */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2040
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2041
    REGISTER unsigned g, val;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2042
    REGISTER unsigned char *cp, *cp0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2043
    int l;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2044
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2045
    cp = __stringVal(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2046
    l = __stringSize(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2047
    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
  2048
	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
  2049
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2050
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2051
	l -= n;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2052
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2053
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2054
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2055
     * this is the dragon-book algorithm
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2056
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2057
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2058
    val = 0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2059
    switch (l) {
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2060
    default:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2061
	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
  2062
	    val = (val << 4) + *cp;
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  2063
	    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
  2064
		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
  2065
		val ^= g;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2066
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2067
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2068
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2069
    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
  2070
	val = cp[5] << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2071
    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
  2072
	val = (val + cp[4]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2073
    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
  2074
	val = (val + cp[3]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2075
    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
  2076
	val = (val + cp[2]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2077
    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
  2078
	val = (val + cp[1]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2079
    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
  2080
	val = val + cp[0];
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2081
    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
  2082
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2083
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2084
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2085
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2086
     * multiply by large prime to spread values
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2087
     * This speeds up Set and Dictionary by a factor of 10!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2088
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2089
    val *= 31415821;
12763
e19933d3e188 changed:
Stefan Vogel <sv@exept.de>
parents: 12727
diff changeset
  2090
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2091
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2092
    ^ self primitiveFailed
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2093
!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2094
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2095
hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2096
    "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
  2097
     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
  2098
     (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
  2099
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2100
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2101
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2102
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2103
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2104
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2105
#else
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2106
    REGISTER unsigned int h  = 2166136261u;
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2107
    REGISTER unsigned char *cp = __stringVal(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2108
    INT l  = __stringSize(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2109
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2110
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2111
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2112
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2113
	cp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2114
	l -= n;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2115
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2116
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2117
    while (l >= 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2118
	l -= 4;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2119
	h = (h ^ cp[0]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2120
	h = (h ^ cp[1]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2121
	h = (h ^ cp[2]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2122
	h = (h ^ cp[3]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2123
	cp += 4;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2124
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2125
    while (l--) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2126
	h = (h ^ *cp++) * 16777619;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2127
    }
16900
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2128
    // make it a smallInteger
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2129
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2130
    RETURN ( __mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2131
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2132
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2133
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2134
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2135
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2136
     'a' hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2137
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2138
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2139
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2140
hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2141
    "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
  2142
     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
  2143
     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
  2144
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2145
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2146
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2147
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2148
    long h = me.hash_java();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2149
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2150
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2151
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2152
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2153
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2154
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2155
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2156
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2157
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2158
	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
  2159
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2160
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2161
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2162
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2163
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2164
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2165
     * 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
  2166
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2167
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2168
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2169
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2170
	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
  2171
	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
  2172
	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
  2173
	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
  2174
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2175
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2176
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2177
	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
  2178
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2179
    RETURN ( __MKUINT(val));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2180
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2181
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2182
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2183
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2184
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2185
     'a' hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2186
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2187
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2188
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2189
hash_sdbm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2190
    "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
  2191
     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
  2192
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2193
%{  /* NOCONTEXT */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2194
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2195
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2196
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2197
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2198
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2199
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2200
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2201
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2202
	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
  2203
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2204
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2205
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2206
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2207
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2208
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2209
     * 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
  2210
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2211
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2212
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2213
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2214
	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
  2215
	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
  2216
	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
  2217
	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
  2218
	cp += 4;
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
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2221
	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
  2222
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2223
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2224
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2225
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2226
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2227
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2228
     'a' hash
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2229
     '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
  2230
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2231
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2232
    "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
  2233
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2234
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2235
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2236
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2237
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2238
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2239
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2240
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2241
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2242
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2243
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2244
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2245
#ifdef __SCHTEAM__
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2246
    if (aString == self) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2247
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2248
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2249
    if (aString.isStringLike()) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2250
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True );
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2251
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2252
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2253
	return __c__._RETURN_true();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2254
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2255
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2256
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  2257
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2258
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  2259
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2260
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2261
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2262
    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
  2263
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2264
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2265
    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
  2266
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2267
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2268
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2269
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2270
    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
  2271
	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
  2272
	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
  2273
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2274
	 * 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
  2275
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2276
	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
  2277
	    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
  2278
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2279
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2280
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2281
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2282
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2283
	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
  2284
	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
  2285
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2286
	 * 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
  2287
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2288
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2289
	    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
  2290
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2291
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2292
	    l2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2293
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2294
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2295
	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
  2296
	    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2297
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2298
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2299
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2300
# 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
  2301
	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
  2302
	    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
  2303
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2304
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2305
	    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
  2306
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2307
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2308
	    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
  2309
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2310
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2311
	    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
  2312
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2313
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2314
	    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
  2315
	    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
  2316
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2317
# 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
  2318
	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
  2319
	    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
  2320
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2321
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2322
	    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
  2323
	    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
  2324
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2325
	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
  2326
	    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
  2327
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2328
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2329
	    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
  2330
	    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
  2331
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2332
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2333
	    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
  2334
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2335
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2336
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2337
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2338
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2339
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2340
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2341
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2342
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2343
    ^ super ~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2344
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2345
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2346
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2347
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2348
asArrayOfSubstrings
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2349
    "Answer an array with all the substrings of the receiver separated by
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2350
     separator characters (space, cr, tab, linefeed, formfeed, etc).
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2351
     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
  2352
	 the inherited one... after all: who added it anyway ?"
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2353
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2354
    | substrings start end stop |
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2355
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2356
    substrings := OrderedCollection new.
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2357
    start := 1.
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2358
    stop := self size.
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2359
    [start <= stop] whileTrue: [
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2360
	(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
  2361
	    end := start + 1.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2362
	    [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
  2363
		whileTrue: [end := end + 1].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2364
	    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
  2365
	    start := end - 1
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2366
	].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2367
	start := start + 1
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2368
    ].
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2369
    ^ substrings asArray
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2370
!
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2371
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2372
asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2373
    "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
  2374
     with an additional 0-character. Otherwise return the receiver. This is sometimes
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2375
     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
  2376
     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
  2377
     strings are not."
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2378
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2379
    ^ self
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2380
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2381
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2382
     'abc' asAsciiZ
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2383
     'abc' asWideString asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2384
    "
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2385
!
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2386
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2387
asByteArray
15938
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2388
    "return a new ByteArray with the receiver's elements.
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2389
     This redefined method is faster than Collection>>#asByteArray"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2390
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2391
    |bytes sz|
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2392
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2393
    sz := self size.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2394
    bytes := ByteArray new:sz .
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2395
    bytes replaceFrom:1 to:sz with:self startingAt:1.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2396
    ^ bytes
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2397
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2398
    "
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  2399
     'fooBar' asByteArray.
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2400
    "
14260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2401
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2402
    "Modified (comment): / 26-07-2012 / 22:55:26 / cg"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2403
!
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2404
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2405
asExternalBytes
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2406
    "return a 0-terminated externalBytes collection containing
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2407
     my characters. 
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2408
     The returned collection is save from being garbage collected;
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2409
     i.t. it can be handed to a C-function, and must 
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2410
     (either there or here) be freed explicitly or unprotectedFromGC"
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2411
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2412
    ^ (ExternalBytes new:(self size + 1))
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2413
        replaceNullTerminatedFromString:self
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2414
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2415
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2416
     |x|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2417
     x := 'fooBar' asExternalBytes.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2418
     x unprotectFromGC.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2419
     ObjectMemory garbageCollect
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2420
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2421
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2422
    "Modified: / 03-08-2006 / 14:45:32 / fm"
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2423
!
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2424
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2425
asExternalBytesUnprotected
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2426
    "Like asExternalBytes, but does not register the bytes so
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2427
     bytes are GARBAGE-COLLECTED!!"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2428
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2429
    ^ (ExternalBytes unprotectedNew:(self size + 1))
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2430
        replaceNullTerminatedFromString:self
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2431
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2432
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2433
     |x|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2434
     x := 'fooBar' asExternalBytesUnprotected.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2435
     ObjectMemory garbageCollect
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2436
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2437
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2438
    "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
  2439
    "Modified: / 30-11-2013 / 11:41:40 / cg"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2440
!
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2441
12454
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2442
asImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2443
    "return a write-protected copy of myself"
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2444
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2445
    ^ self copy changeClassTo:ImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2446
!
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2447
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2448
asLowercase
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2449
    "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
  2450
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2451
%{  /* NOCONTEXT */
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18661
diff changeset
  2452
#if 0
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2453
#ifndef __SCHTEAM__
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2454
    REGISTER OBJ slf = self;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2455
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2456
    if (__qClass(slf) == String) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2457
	char quickBuffer[256];
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2458
	int sz = __stringSize(slf);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2459
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2460
	if (sz < (sizeof(quickBuffer)-1)) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2461
	    REGISTER int i = 0;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2462
	    int anyChange = 0;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2463
	    REGISTER unsigned char *cp = __stringVal(slf);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2464
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2465
	    // fast advance
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2466
	    // all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z)
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2467
	    // or 0xC0 .. 0xDF.
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2468
	    // I.e. they have the 0x20 bit clear.
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2469
	    // Thus, we can fast skip over lowercase, spaces and some puctuation,
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2470
	    // if all bytes of a word have the x20 bit set.
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2471
	    //
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2472
#if __POINTER_SIZE__ == 8
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2473
	    for (; i<(sz-8); i+=8) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2474
		unsigned INT eightChars;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2475
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2476
		eightChars = *((unsigned INT *)(cp));
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2477
		if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) break;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2478
		*((unsigned INT *)(&quickBuffer[i])) = eightChars;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2479
	    }
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2480
#endif
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2481
	    for (; i<(sz-4); i+=4) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2482
		unsigned int fourChars;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2483
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2484
		fourChars = *((unsigned int *)(cp));
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2485
		if ((fourChars & 0x20202020U) != 0x20202020U) break;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2486
		*((unsigned int *)(&quickBuffer[i])) = fourChars;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2487
	    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2488
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2489
	    for (; i<sz; i++) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2490
		unsigned char ch = cp[i];
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2491
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2492
		quickBuffer[i] = ch;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2493
		if ((ch & 0x60) == 0x40) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2494
		    if (ch >= 'A') {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2495
			if (ch <= 'Z') {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2496
			    quickBuffer[i] = ch - 'A' + 'a';
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2497
			    anyChange = 1;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2498
			} else {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2499
			    // deal with national latin1 characters
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2500
			    if (ch >= 0xC0) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2501
				if (ch <= 0xDE) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2502
				    if (ch != 0xD7) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2503
					quickBuffer[i] = ch + 0x20;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2504
					anyChange = 1;
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2505
				    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2506
				}
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2507
			    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2508
			}
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2509
		    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2510
		}
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2511
	    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2512
	    quickBuffer[i] = '\0';
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2513
	    if (! anyChange) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2514
		RETURN(slf);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2515
	    }
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2516
	    RETURN (__MKSTRING_L(quickBuffer, i));
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  2517
	}
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2518
    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2519
#endif /* ! __SCHTEAM__ */
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18661
diff changeset
  2520
#endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2521
%}.
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2522
    ^ super asLowercase
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2523
!
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2524
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2525
asPackageId
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2526
    "given a package-string as receiver, return a packageId object.
14566
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2527
     packageIds hide the details of module/directory handling inside the path.
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2528
     See PackageId for the required format of those strings."
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  2529
14571
6e2375384861 class: String
Claus Gittinger <cg@exept.de>
parents: 14566
diff changeset
  2530
    ^ PackageId from: self
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2531
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2532
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2533
     '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
  2534
     '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
  2535
     'stx:hello' asPackageId
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2536
    "
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2537
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2538
    "Created: / 18-08-2006 / 12:19:54 / cg"
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2539
!
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2540
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  2541
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2542
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2543
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2544
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2545
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2546
11287
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2547
asSingleByteStringIfPossible
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2548
    "I am a single-byte string"
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2549
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2550
    ^ self
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2551
!
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2552
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2553
asSingleByteStringReplaceInvalidWith:replacementCharacter
11883
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2554
    "return the receiver converted to a 'normal' string,
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2555
     with invalid characters replaced by replacementCharacter.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2556
     Can be used to convert from 16-bit strings to 8-bit strings
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2557
     and replace characters above code-255 with some replacement.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2558
     Dummy here, because I am already a single byte string."
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2559
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2560
    ^ self
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2561
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2562
    "Modified: / 07-08-2006 / 15:04:45 / fm"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2563
!
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2564
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2565
asSymbol
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2566
    "Return a unique symbol with the name taken from the receiver's characters."
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2567
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2568
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2569
#ifdef __SCHTEAM__
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2570
    return context._RETURN( STSymbol._new(self.asString()) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2571
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2572
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2573
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2574
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2575
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2576
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2577
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2578
    if (cls != String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2579
        cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2580
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2581
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2582
    if (newSymbol) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2583
        RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2584
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2585
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2586
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2587
    ^ ObjectMemory allocationFailureSignal raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2588
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2589
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2590
     'hello' asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2591
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2592
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2593
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2594
asSymbolIfInterned
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2595
    "If a symbol with the receiver's characters is already known, return it. Otherwise, return nil.
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2596
     This can be used to query for an existing symbol and is the same as:
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2597
        self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2598
     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
  2599
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2600
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2601
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2602
#ifdef __SCHTEAM__
18622
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2603
    STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() );
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2604
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2605
    return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2606
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2607
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2608
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2609
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2610
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2611
    if (cls != String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2612
        indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2613
    } else {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2614
        indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2615
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2616
    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
  2617
#endif /* not __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2618
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2619
    ^ self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2620
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2621
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2622
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2623
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2624
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2625
17378
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2626
beImmutable
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2627
    "make myself write-protected"
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2628
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2629
    self changeClassTo:ImmutableString
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2630
!
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2631
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2632
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2633
    "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
  2634
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2635
     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
  2636
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2637
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2638
     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
  2639
     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
  2640
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2641
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2642
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2643
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2644
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2645
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2646
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2647
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2648
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2649
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2650
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2651
     && __isSmallInteger(numSpaces)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2652
	n = __intVal(numSpaces);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2653
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2654
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2655
	 * for small strings (< 80), do it without a prescan ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2656
	 * the buffer is large enough to even convert a
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2657
	 * receiver consisting fully of tabs.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2658
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2659
	if (__stringSize(self) < 80) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2660
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2661
	    for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2662
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2663
		    any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2664
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2665
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2666
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2667
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2668
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2669
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2670
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2671
		    *dstP++ = c;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2672
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2673
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2674
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2675
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2676
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2677
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2678
	    if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2679
	    *dstP = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2680
	    RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2681
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2682
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2683
	 * for large strings, we compute the new size, allocate a new string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2684
	 * and expand it.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2685
	 *
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2686
	 * first, scan for size ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2687
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2688
	idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2689
	for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2690
	    if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2691
		any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2692
		while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2693
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2694
		    sz++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2695
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2696
		idx++; sz ++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2697
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2698
		sz++; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2699
		if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2700
		    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2701
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2702
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2703
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2704
	if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2705
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2706
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2707
	 * get the string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2708
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2709
	sz = OHDR_SIZE + sz + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2710
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2711
	if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2712
	    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2713
	    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2714
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2715
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2716
	     * expand
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2717
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2718
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2719
	    for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2720
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2721
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2722
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2723
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2724
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2725
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2726
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2727
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2728
		    *dstP++ = c; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2729
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2730
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2731
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2732
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2733
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2734
	    *dstP++ = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2735
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2736
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2737
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2738
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2739
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2740
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2741
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2742
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2743
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2744
, aString
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2745
    "return the concatenation of myself and the argument, aString as a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2746
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2747
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2748
%{
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2749
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2750
    if ( aString.isStringLike() && self.isStringLike() ) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2751
	STString me = self.asSTString();
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2752
	STString other = aString.asSTString();
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2753
	int myLength = me.characters.length;
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2754
	int otherLength = other.characters.length;
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2755
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2756
	char[] newChars = new char[myLength + otherLength];
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2757
	System.arraycopy(me.characters, 0, newChars, 0, myLength);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2758
	System.arraycopy(other.characters, 0, newChars, myLength, otherLength);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2759
	return context._RETURN( new STString( newChars ));
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2760
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2761
#else
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2762
    int l1, l2, sz;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2763
    OBJ newString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2764
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2765
    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
  2766
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2767
	 * 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
  2768
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2769
	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
  2770
	    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
  2771
	    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
  2772
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2773
	    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
  2774
	    __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
  2775
	    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
  2776
		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
  2777
		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
  2778
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2779
		__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
  2780
		__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
  2781
		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
  2782
		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
  2783
		cp2 = (char *) __stringVal(aString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2784
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2785
# 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
  2786
		/* 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
  2787
		 * 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
  2788
		 * 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
  2789
		 * 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
  2790
		 * 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
  2791
		 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2792
		{
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2793
		    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
  2794
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2795
		    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
  2796
		    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
  2797
		    dstp += l1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2798
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2799
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2800
#  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
  2801
		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
  2802
		dstp += l1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2803
#  else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2804
		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
  2805
		    *(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
  2806
		    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
  2807
		    l1 -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2808
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2809
		while (l1--) *dstp++ = *cp1++;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2810
#  endif
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2811
# endif
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2812
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2813
# 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
  2814
		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
  2815
		    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
  2816
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2817
		    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
  2818
		    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
  2819
		    *(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
  2820
		    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2821
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2822
# endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2823
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2824
# 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
  2825
		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
  2826
		dstp[l2] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2827
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2828
		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
  2829
		*dstp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2830
# endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2831
		RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2832
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2833
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2834
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2835
#endif /* not SCHTEAM */
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2836
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2837
    ^ super , aString
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2838
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2839
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2840
     'hello' , 'world' asImmutableString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2841
     'hello' , #world
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2842
     #[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
  2843
    "
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2844
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2845
    "Modified: / 01-04-2012 / 13:19:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2846
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2847
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2848
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2849
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2850
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2851
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2852
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2853
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2854
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2855
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2856
    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
  2857
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2858
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2859
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2860
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2861
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2862
    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
  2863
	    && __isStringLike(string1)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2864
	    && __isStringLike(string2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2865
	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
  2866
	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
  2867
	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
  2868
	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
  2869
	__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
  2870
	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
  2871
	    __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
  2872
	    __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
  2873
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2874
#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
  2875
	    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
  2876
	    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
  2877
	    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
  2878
	    *(dstp + len1 + len2 + len3) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2879
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2880
	    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
  2881
	    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
  2882
	    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
  2883
	    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
  2884
	    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
  2885
	    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
  2886
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2887
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2888
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2889
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2890
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2891
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2892
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2893
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2894
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2895
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2896
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2897
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2898
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2899
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2900
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2901
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2902
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2903
    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
  2904
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2905
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2906
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2907
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2908
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2909
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2910
     && __isStringLike(string1)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2911
     && __isStringLike(string2)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2912
     && __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
  2913
	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
  2914
	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
  2915
	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
  2916
	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
  2917
	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
  2918
	__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
  2919
	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
  2920
	    __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
  2921
	    __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
  2922
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2923
#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
  2924
	    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
  2925
	    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
  2926
	    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
  2927
	    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
  2928
	    *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2929
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2930
	    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
  2931
	    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
  2932
	    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
  2933
	    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
  2934
	    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
  2935
	    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
  2936
	    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
  2937
	    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
  2938
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2939
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2940
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2941
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2942
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2943
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2944
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2945
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2946
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2947
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2948
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2949
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  2950
    (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
  2951
	^ self copyFrom:1
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2952
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2953
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2954
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2955
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2956
copyFrom:start
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2957
    "return a new collection consisting of receiver's elements from startIndex to the end of the collection.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2958
     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
  2959
     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
  2960
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2961
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2962
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2963
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2964
#if !defined(FAST_MEMCPY)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2965
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2966
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2967
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2968
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2969
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2970
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2971
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2972
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2973
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2974
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2975
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2976
    if (__isSmallInteger(start)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2977
     && ((myClass==String) || (myClass==Symbol))) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2978
        len = __stringSize(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2979
        index1 = __intVal(start);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2980
        if (index1 > 0) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2981
            if (index1 <= len) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2982
                count = len - index1 + 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2983
                sz = OHDR_SIZE + count + 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2984
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2985
                __PROTECT_CONTEXT__
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2986
                __qNew(newString, sz);  /* OBJECT ALLOCATION */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2987
                __UNPROTECT_CONTEXT__
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2988
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2989
                if (newString != nil) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2990
                    __InstPtr(newString)->o_class = String;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2991
                    __qSTORE(newString, String);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2992
                    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2993
#ifdef FAST_MEMCPY
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2994
                    memcpy(dstp, __stringVal(self) + index1 - 1, count);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2995
                    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2996
#else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2997
                    srcp = __stringVal(self) + index1 - 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2998
                    while (count--) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2999
                        *dstp++ = *srcp++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3000
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3001
                    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3002
#endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3003
                    RETURN ( newString );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3004
                }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3005
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3006
        }
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3007
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3008
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3009
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3010
    "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
  3011
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3012
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3013
    ^ super copyFrom:start
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3014
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3015
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3016
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3017
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3018
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3019
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3020
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3021
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3022
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3023
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3024
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3025
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3026
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3027
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3028
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3029
    OBJ myClass;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3030
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3031
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3032
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3033
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3034
    if (__bothSmallInteger(start, stop)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3035
     && ((myClass==String) || (myClass==Symbol))) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3036
	len = __stringSize(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3037
	index1 = __intVal(start);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3038
	index2 = __intVal(stop);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3039
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3040
	if ((index1 <= index2) && (index1 > 0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3041
	    if (index2 <= len) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3042
		count = index2 - index1 + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3043
		sz = OHDR_SIZE + count + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3044
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3045
		__PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3046
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3047
		__UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3048
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3049
		if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3050
		    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3051
		    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3052
		    dstp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3053
		    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3054
#ifdef bcopy4
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3055
		    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3056
			int nw = count >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3057
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3058
			if (count & 3) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3059
			    nw++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3060
			}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3061
			bcopy4(srcp, dstp, nw);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3062
			dstp[count] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3063
		    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3064
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3065
# ifdef FAST_MEMCPY
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3066
		    memcpy(dstp, srcp, count);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3067
		    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3068
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3069
		    while (count--) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3070
			*dstp++ = *srcp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3071
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3072
		    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3073
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3074
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3075
		    RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3076
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3077
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3078
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3079
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3080
	 * allow empty copy
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3081
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3082
	if (index1 > index2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3083
	    __PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3084
	    __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3085
	    __UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3086
	    if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3087
		__InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3088
		(__stringVal(newString))[0] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3089
		RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3090
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3091
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3092
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3093
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3094
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3095
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3096
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3097
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3098
    ^ super copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3099
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3100
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3101
copyWith:aCharacter
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3102
    "return a new string containing the receiver's characters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3103
     and the single new character, aCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3104
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3105
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3106
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3107
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3108
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3109
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3110
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3111
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3112
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3113
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3114
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3115
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3116
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3117
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3118
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3119
    if (__isCharacter(aCharacter)) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3120
        unsigned int cVal = __intVal(__characterVal(aCharacter));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3121
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3122
        if ((cVal <= 0xFF)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3123
         && ((myClass==String) || (myClass==Symbol))) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3124
            count = __stringSize(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3125
            sz = OHDR_SIZE + count + 1 + 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3126
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3127
            __PROTECT_CONTEXT__
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3128
            __qNew(newString, sz);  /* OBJECT ALLOCATION */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3129
            __UNPROTECT_CONTEXT__
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3130
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3131
            if (newString) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3132
                __InstPtr(newString)->o_class = String;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3133
                __qSTORE(newString, String);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3134
                dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3135
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3136
# ifdef bcopy4
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3137
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3138
                    int nw = count >> 2;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3139
                    char *srcp = (char *)__stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3140
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3141
                    if (count & 3) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3142
                        nw++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3143
                    }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3144
                    bcopy4(srcp, dstp, nw);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3145
                    dstp += count;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3146
                }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3147
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3148
#  ifdef FAST_MEMCPY
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3149
                memcpy(dstp, __stringVal(self), count);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3150
                dstp += count;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3151
#  else
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3152
                {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3153
                    REGISTER unsigned char *srcp;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3154
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3155
                    srcp = __stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3156
                    while ((*dstp = *srcp++) != '\0')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3157
                        dstp++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3158
                }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3159
#  endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3160
# endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3161
                *dstp++ = cVal;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3162
                *dstp = '\0';
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3163
                RETURN (newString );
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3164
            }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3165
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3166
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3167
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3168
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3169
    "fall back in case of non-character arg;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3170
     will eventually lead to an bad element signal raise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3171
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3172
    ^ super copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3173
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3174
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3175
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3176
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3177
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3178
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3179
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3180
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3181
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3182
    (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
  3183
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3184
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3185
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3186
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3187
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3188
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  3189
    "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
  3190
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3191
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3192
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3193
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3194
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3195
    (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
  3196
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3197
    ].
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3198
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3199
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3200
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3201
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3202
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3203
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3204
    (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
  3205
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3206
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3207
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3208
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3209
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3210
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3211
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3212
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3213
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3214
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3215
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3216
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3217
    (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
  3218
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3219
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  3220
    ^ super simpleDeepCopy
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
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  3223
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3224
!String methodsFor:'encoding'!
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3225
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3226
utf8Encoded
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3227
    "Return my UTF-8 representation as a new String"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3228
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3229
    self containsNon7BitAscii ifTrue:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3230
	^ CharacterEncoderImplementations::ISO10646_to_UTF8 new encodeString:self
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3231
    ].
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3232
    "speed up common case"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3233
    ^ self.
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3234
!
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3235
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3236
utf8EncodedOn:aStream
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3237
    "write to aStream in utf8 encoding"
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3238
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3239
    self containsNon7BitAscii ifTrue:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3240
	aStream nextPutAllUtf8:self.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3241
    ] ifFalse:[
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3242
	"speed up common case"
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3243
	aStream nextPutAll:self.
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3244
    ].
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3245
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3246
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3247
     String streamContents:[:w|
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3248
	'abcde1234' utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3249
     ].
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3250
     String streamContents:[:w|
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3251
	 'abcdeäöüß' utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3252
     ].
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3253
     String streamContents:[:w|
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3254
	 'abcdeäöüß' asUnicode16String utf8EncodedOn:w
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3255
     ].
17626
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3256
    "
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3257
! !
07cb8b1641f9 class: String
Stefan Vogel <sv@exept.de>
parents: 17573
diff changeset
  3258
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  3259
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3260
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3261
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3262
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3263
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3264
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3265
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3266
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3267
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3268
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  3269
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3270
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3271
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3272
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3273
    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
  3274
	byteValue = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3275
	if ((unsigned)byteValue <= 0xFF) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3276
	    l = __stringSize(self);
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3277
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3278
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3279
	    if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3280
		memset(__stringVal(self), byteValue, l);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3281
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3282
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3283
	    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3284
		INT v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3285
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3286
		v = (byteValue << 8) | byteValue;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3287
		v = (v << 16) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3288
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3289
		dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3290
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3291
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3292
		if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3293
		    memset4(dst, v, l>>2);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3294
		    l = l & 3;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3295
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3296
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3297
#  ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3298
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3299
		    UINT64 v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3300
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3301
		    v64 = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3302
		    v64 = (v64 << 32) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3303
		    while (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3304
			((UINT64 *)dst)[0] = v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3305
			dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3306
			l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3307
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3308
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3309
#  else /* no UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3310
		while (l >= 16) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3311
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3312
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3313
		    ((int *)dst)[2] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3314
		    ((int *)dst)[3] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3315
		    dst += 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3316
		    l -= 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3317
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3318
		if (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3319
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3320
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3321
		    dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3322
		    l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3323
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3324
		if (l >= 4) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3325
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3326
		    dst += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3327
		    l -= 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3328
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3329
#   if 0
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3330
		if (l >= 2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3331
		    ((short *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3332
		    dst += 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3333
		    l -= 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3334
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3335
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3336
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3337
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3338
# endif /* FAST_MEMSET4 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3339
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3340
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3341
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3342
	     * remaining bytes
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3343
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3344
	    while (l-- > 0)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3345
		*dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3346
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3347
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3348
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3349
	    RETURN ( self );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3350
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3351
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3352
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3353
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3354
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3355
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3356
     (String new:10) atAllPut:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3357
     String new:10 withAll:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3358
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3359
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3360
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3361
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3362
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3363
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3364
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3365
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3366
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3367
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3368
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3369
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3370
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3371
    unsigned char c, cNext;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3372
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3373
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3374
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3375
     && __isString(self)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3376
	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
  3377
	oldVal = __intVal(__characterVal(oldCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3378
	newVal = __intVal(__characterVal(newCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3379
	if ((oldVal <= 0xFF)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3380
	 && (newVal <= 0xFF)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3381
	    cNext = *srcp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3382
	    while ((c = cNext) != '\0') {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3383
		cNext = srcp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3384
		if (c == oldVal)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3385
		    *srcp = newVal;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3386
		srcp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3387
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3388
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3389
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3390
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3391
%}.
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  3392
    newCharacter isCharacter ifFalse:[self halt:'please change the sender'].
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3393
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3394
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3395
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3396
     'helloWorld' copy replaceAll:$o with:$O
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3397
     'helloWorld' copy replaceAll:$d with:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3398
     'helloWorld' copy replaceAll:$h with:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3399
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3400
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3401
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3402
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3403
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3404
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  3405
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3406
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3407
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3408
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3409
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3410
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3411
    if ( aString.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3412
     && self.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3413
     && start.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3414
     && stop.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3415
     && repStart.isSmallInteger()) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3416
	STString me = self.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3417
	STString other = aString.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3418
	int _start = start.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3419
	int _stop = stop.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3420
	int _repStart = repStart.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3421
	int mySize = me.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3422
	int otherSize = other.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3423
	int count = _stop - _start + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3424
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3425
	if (_start >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3426
	 && _repStart >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3427
	 && _stop < mySize
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3428
	 && (_repStart + count) <= otherSize) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3429
	    if (count > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3430
		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
  3431
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3432
	    return context._RETURN(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3433
	}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3434
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3435
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3436
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3437
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3438
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3439
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3440
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3441
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3442
# ifndef NO_PRIM_STRING
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3443
    if (__isStringLike(aString)
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3444
     && __isString(self)
252
  3445
     && __bothSmallInteger(start, stop)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3446
	len = __stringSize(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3447
	index1 = __intVal(start);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3448
	index2 = __intVal(stop);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3449
	count = index2 - index1 + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3450
	if (count <= 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3451
	     RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3452
	}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3453
	if ((index2 <= len) && (index1 > 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3454
	    repLen = __stringSize(aString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3455
	    repIndex = __intVal(repStart);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3456
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3457
		srcp = __stringVal(aString) + repIndex - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3458
		dstp = __stringVal(self) + index1 - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3459
		if (aString == self) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3460
		    /* take care of overlapping copy */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3461
		    memmove(dstp, srcp, count);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3462
		    RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3463
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3464
#  ifdef bcopy4
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3465
		/* copy quadbytes if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3466
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3467
		 * no sizeof(int) here please -
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3468
		 * - 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
  3469
		 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3470
		if ((count > 12)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3471
		 && (((unsigned INT)srcp & 3) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3472
		 && (((unsigned INT)dstp & 3) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3473
		    int n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3474
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3475
		    n = count >> 2;        /* make it quads */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3476
		    bcopy4(srcp, dstp, n);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3477
		    n <<= 2;               /* back to chars */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3478
		    dstp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3479
		    srcp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3480
		    count -= n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3481
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3482
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3483
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3484
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3485
#  else
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3486
#   ifdef FAST_MEMCPY
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3487
		memcpy(dstp, srcp, count);
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3488
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3489
		/* copy longs if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3490
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3491
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3492
		    while (count >= sizeof(INT)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3493
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3494
			dstp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3495
			srcp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3496
			count -= sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3497
		    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3498
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3499
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3500
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3501
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3502
#   endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3503
#  endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3504
		RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3505
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3506
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3507
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3508
# endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3509
#endif /* not SCHTEAM */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3510
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3511
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3512
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3513
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3514
withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3515
    "return a string containing the chars of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3516
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3517
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3518
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3519
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  3520
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3521
     endIndex   "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3522
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3523
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3524
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3525
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3526
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3527
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3528
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3529
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3530
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3531
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3532
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3533
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  3534
    if (__qClass(self) == String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3535
        cp = cp0 = __stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3536
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3537
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3538
         * find first non-whiteSpace from beginning
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3539
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3540
#ifdef UINT64
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3541
        while (*((UINT64 *)cp) == 0x2020202020202020L) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3542
            cp += 8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3543
        }
329
claus
parents: 314
diff changeset
  3544
#endif
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3545
        while (*((unsigned *)cp) == 0x20202020) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3546
            cp += 4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3547
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3548
        while ((c = *cp)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3549
         && (c <= ' ')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3550
         && ((c == ' ') || (c == '\n') || (c == '\t')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3551
                        || (c == '\r') || (c == '\f'))
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3552
        ) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3553
            cp++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3554
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3555
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3556
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3557
         * find first non-whiteSpace from end
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3558
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3559
        ep = ep0 = cp0 + __stringSize(self) - 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3560
        while ((ep >= cp) && (*ep == ' ')) ep--;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3561
        c = *ep;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3562
        while ((ep >= cp) &&
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3563
               (c <= ' ') &&
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3564
               ((c == ' ') || (c == '\n') || (c == '\t')
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3565
                           || (c == '\r') || (c == '\f'))) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3566
            ep--;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3567
            c = *ep;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3568
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3569
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3570
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3571
         * no whiteSpace ?
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3572
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3573
        if ((cp == cp0) && (ep == ep0)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3574
            RETURN(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3575
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3576
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3577
        startIndex = __mkSmallInteger(cp - cp0 + 1);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3578
        endIndex = __mkSmallInteger(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3579
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3580
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3581
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3582
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3583
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3584
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3585
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3586
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3587
     'hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3588
     '    hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3589
     '    hello ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3590
     '    hello  ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3591
     '    hello   ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3592
     '    hello    ' withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3593
     '        ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3594
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3595
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3596
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3597
withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3598
    "return a string containing the characters of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3599
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3600
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3601
     Notice, this is different from String>>withoutSeparators."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3602
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3603
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3604
     endIndex   "{ Class: SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3605
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3606
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3607
    startIndex := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3608
%{
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3609
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3610
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3611
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3612
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3613
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3614
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3615
    if (__qClass(self) == String) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3616
        cp = cp0 = __stringVal(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3617
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3618
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3619
         * find first non-blank from beginning
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3620
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3621
#ifdef UINT64
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3622
        while (*((UINT64 *)cp) == 0x2020202020202020L) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3623
            cp += 8;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3624
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3625
#endif /* UINT64 */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3626
        while (*((unsigned *)cp) == 0x20202020) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3627
            cp += 4;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3628
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3629
        while (*cp == ' ') cp++;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3630
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3631
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3632
         * find first non-blank from end
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3633
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3634
        ep = ep0 = cp0 + __stringSize(self) - 1;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3635
        while ((ep >= cp) && (*ep == ' ')) ep--;
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3636
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3637
        /*
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3638
         * no blanks ?
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3639
         */
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3640
        if ((cp == cp0) && (ep == ep0)) {
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3641
            RETURN(self);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3642
        }
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3643
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3644
        startIndex = __mkSmallInteger(cp - cp0 + 1);
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3645
        endIndex = __mkSmallInteger(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3646
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3647
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3648
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3649
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3650
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3651
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3652
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3653
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3654
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3655
     '    hello' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3656
     '    hello ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3657
     '    hello  ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3658
     '    hello   ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3659
     '    hello    ' withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3660
     '        ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3661
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3662
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3663
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3664
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3665
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3666
displayString
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3667
    "return a string used when displaying the receiver in a view."
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3668
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3669
    ^ super displayString.
17539
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3670
"/    ^ self storeString.
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3671
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3672
    "
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3673
     'hello' -> 'hello'
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3674
    "
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3675
!
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3676
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3677
errorPrint
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3678
    "print the receiver on standard error, if the global Stderr is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3679
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3680
     the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3681
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3682
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3683
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3684
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3685
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3686
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3687
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3688
	if (self.isStringLike()) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3689
	    org.exept.stj.STSystem.err.print(self.asString());
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3690
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3691
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3692
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3693
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3694
    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
  3695
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3696
	    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
  3697
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3698
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3699
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3700
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3701
#endif /* not SCHTEAM */
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3702
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3703
    super errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3704
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3705
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3706
      'hello world' asUnicode16String errorPrint
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3707
      (Character value:356) asString errorPrint
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3708
      'Bönnigheim' errorPrint
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3709
      'Bönnigheim' asUnicodeString errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3710
    "
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3711
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3712
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3713
errorPrintCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3714
    "print the receiver on standard error, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3715
     if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3716
     which sends the string to the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3717
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3718
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3719
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3720
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3721
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3722
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3723
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3724
	if (self.isStringLike()) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3725
	    org.exept.stj.STSystem.err.println(self.asString());
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3726
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3727
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3728
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3729
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3730
    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
  3731
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3732
	    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
  3733
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3734
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3735
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3736
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3737
#endif
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3738
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3739
    super errorPrintCR
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3740
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3741
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3742
print
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3743
    "print the receiver on standard output, if the global Stdout is nil;
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3744
     otherwise, fall back to the inherited print, 
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3745
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3746
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3747
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3748
     (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
  3749
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3750
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3751
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3752
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3753
        org.exept.stj.STSystem.out.print(self.toString());
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3754
        return context._RETURN(self);
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3755
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3756
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3757
    if (@global(Stdout) == nil) {
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3758
        if (__qIsStringLike(self)) {
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3759
            console_fprintf(stdout, "%s" , __stringVal(self));
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3760
            console_fflush(stdout);
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3761
            RETURN (self);
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3762
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3763
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3764
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3765
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3766
    super print
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3767
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3768
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3769
printCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3770
    "print the receiver on standard output, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3771
     if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3772
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3773
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3774
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3775
     (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
  3776
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3777
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3778
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3779
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3780
	org.exept.stj.STSystem.out.println(self.toString());
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3781
	return context._RETURN(self);
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3782
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3783
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3784
    if (@global(Stdout) == nil) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3785
	if (__qIsStringLike(self)) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3786
	    console_fprintf(stdout, "%s\n" , __stringVal(self));
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3787
	    console_fflush(stdout);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3788
	    RETURN (self);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3789
	}
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3790
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3791
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3792
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3793
    super printCR
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3794
!
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3795
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3796
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3797
    "non-standard but sometimes useful.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3798
     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
  3799
     which is defined by printf.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3800
     This method is NONSTANDARD and may be removed without notice.
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3801
     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
  3802
     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
  3803
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3804
%{  /* STACK: 1000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3805
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3806
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3807
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3808
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3809
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3810
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3811
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3812
    OBJ s;
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3813
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3814
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3815
    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
  3816
	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
  3817
	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
  3818
	    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
  3819
	}
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3820
again:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3821
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3822
	 * 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
  3823
	 * 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
  3824
	 * 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
  3825
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3826
	__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
  3827
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3828
	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
  3829
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3830
	__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
  3831
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3832
	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
  3833
	    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
  3834
		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
  3835
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3836
		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
  3837
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3838
	    if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3839
		free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3840
	    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
  3841
	    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
  3842
		goto fail;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3843
	    goto again;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3844
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3845
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3846
	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
  3847
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3848
	if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3849
	    free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3850
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3851
	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
  3852
	    RETURN (s);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3853
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3854
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3855
fail:;
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3856
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3857
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3858
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3859
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3860
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3861
     'hello' printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3862
     (String new:900) printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3863
     'hello' printfPrintString:'%%10s -> %10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3864
     'hello' printfPrintString:'%%-10s -> %-10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3865
     'hello' printfPrintString:'%%900s -> %900s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3866
     'hello' printfPrintString:'%%-900s -> %-900s'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3867
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3868
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3869
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3870
storeOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3871
    "put the storeString of myself on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3872
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  3873
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3874
    (self includes:$') ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3875
	self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3876
    ] ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3877
	aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3878
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3879
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3880
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3881
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3882
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3883
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3884
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3885
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3886
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  3887
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3888
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3889
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3890
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3891
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3892
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3893
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3894
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3895
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3896
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3897
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  3898
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3899
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3900
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3901
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3902
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3903
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3904
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3905
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3906
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3907
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3908
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3909
			  - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3910
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3911
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3912
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3913
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3914
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3915
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3916
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3917
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3918
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3919
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3920
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3921
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3922
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3923
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3924
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3925
characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3926
    "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
  3927
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3928
%{  /* NOCONTEXT */
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3929
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3930
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3931
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3932
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3933
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3934
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3935
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3936
#if __POINTER_SIZE__ == 8
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3937
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3938
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3939
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3940
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3941
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3942
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3943
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3944
#endif
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3945
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3946
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3947
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3948
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3949
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3950
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3951
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3952
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3953
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3954
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3955
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3956
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3957
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3958
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3959
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3960
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3961
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3962
    RETURN ( __mkSmallInteger(7) );
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3963
%}.
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3964
    ^ super characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3965
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3966
    "
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3967
     'hello world' characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3968
     'hello world' asUnicode16String characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3969
     ('hello world' , (Character value:16r88) asString) characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3970
    "
18587
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3971
!
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3972
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3973
containsNon7BitAscii
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3974
    "return true, if the underlying string contains 8BitCharacters (or widers)
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3975
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3976
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3977
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3978
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3979
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3980
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3981
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3982
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3983
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3984
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3985
#if __POINTER_SIZE__ == 8
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3986
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3987
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3988
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3989
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3990
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3991
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3992
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3993
#endif
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3994
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3995
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3996
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3997
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3998
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3999
	}
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4000
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4001
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4002
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4003
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4004
	}
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  4005
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4006
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4007
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4008
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4009
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4010
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4011
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4012
%}.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4013
    ^ super containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4014
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4015
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4016
     'hello world' containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4017
     'hello world' asTwoByteString containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4018
     ('hello world' , (Character value:16r88) asString) containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4019
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4020
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4021
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4022
containsNon8BitElements
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4023
    "return true, if the underlying string contains elements larger than a single byte"
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4024
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4025
    ^ false.
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4026
!
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4027
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4028
isWideString
19579
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4029
    "true if I require more than one byte per character"
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4030
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4031
    ^ false
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4032
!
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4033
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4034
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4035
    "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
  4036
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4037
     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
  4038
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4039
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4040
#ifdef __SCHTEAM__
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4041
    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
  4042
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4043
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4044
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4045
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4046
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4047
    if (cls != String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4048
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4049
    } else {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4050
	indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4051
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4052
    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
  4053
#endif /* ! __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4054
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  4055
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4056
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4057
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4058
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4059
     'hello' knownAsSymbol
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4060
     'fooBarBaz' knownAsSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4061
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4062
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4063
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4064
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4065
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4066
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4067
     (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
  4068
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4069
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4070
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4071
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  4072
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4073
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4074
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4075
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4076
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4077
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4078
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4079
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4080
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4081
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4082
			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4083
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4084
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4085
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4086
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4087
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4088
stringSpecies
15525
0a0baff63fd0 class: String
Stefan Vogel <sv@exept.de>
parents: 15440
diff changeset
  4089
    ^ self species
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4090
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4091
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4092
!String methodsFor:'sorting & reordering'!
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4093
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4094
reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4095
    "in-place reverse the characters of the string.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4096
     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
  4097
	      Please use reversed (with a d) for a functional version."
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4098
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4099
    "Q: is there a need to redefine it here ?"
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4100
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4101
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4102
#ifndef __SCHTEAM__
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4103
    REGISTER char c;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4104
    REGISTER unsigned char *hip, *lowp;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4105
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4106
    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
  4107
	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
  4108
	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
  4109
	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
  4110
	    c = *lowp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4111
	    *lowp = *hip;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4112
	    *hip = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4113
	    lowp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4114
	    hip--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4115
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4116
	RETURN ( self );
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4117
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4118
    #endif
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4119
%}.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4120
    ^ super reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4121
! !
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  4122
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4123
!String methodsFor:'substring searching'!
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4124
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4125
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
  4126
    "redefined as primitive for maximum speed (BM)"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4127
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4128
    |notFound|
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4129
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  4130
%{  /* STACK:4000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4131
#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
  4132
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4133
     && __isStringLike(aSubString)
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4134
     && (caseSensitive == true)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4135
     && (__isSmallInteger(startIndex))
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4136
     && (__intVal(startIndex) > 0)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4137
    ) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4138
        unsigned char *y = __stringVal(self);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4139
        unsigned char *x = __stringVal(aSubString);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4140
        int m = __stringSize(aSubString);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4141
        int n = __stringSize(self);
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4142
#       define MAX_PATTERN_SIZE 128
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4143
#       define XSIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4144
#       define ASIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4145
#       define MAX(a,b) (a>b ? a : b)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4146
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4147
        if (m == 0) {
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4148
#if 1
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4149
            /* empty string does not match */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4150
            RETURN(__mkSmallInteger(0));
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4151
#else
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4152
            /* empty string matches */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4153
            RETURN(startIndex);
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4154
#endif
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4155
        }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4156
        if (m <= XSIZE) {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4157
            int i, j;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4158
            static int lastPatternSize = 0;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4159
            static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 };
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4160
            static int bmGs[XSIZE+1], bmBc[ASIZE];
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4161
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4162
#           define preBmBc(x, m, bmBc) {          \
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4163
               int i;                             \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4164
                                                  \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4165
               for (i = 0; i < ASIZE; ++i)        \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4166
                  bmBc[i] = m;                    \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4167
               for (i = 0; i < m - 1; ++i)        \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4168
                  bmBc[x[i]] = m - i - 1;         \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4169
            }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4170
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4171
#           define suffixes(x, m, suff) {                       \
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4172
               int f, g, i;                                     \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4173
                                                                \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4174
               suff[m - 1] = m;                                 \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4175
               g = m - 1;                                       \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4176
               for (i = m - 2; i >= 0; --i) {                   \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4177
                  if (i > g && suff[i + m - 1 - f] < i - g)     \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4178
                     suff[i] = suff[i + m - 1 - f];             \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4179
                  else {                                        \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4180
                     if (i < g)                                 \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4181
                        g = i;                                  \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4182
                     f = i;                                     \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4183
                     while (g >= 0 && x[g] == x[g + m - 1 - f]) \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4184
                        --g;                                    \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4185
                     suff[i] = f - g;                           \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4186
                  }                                             \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4187
               }                                                \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4188
            }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4189
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4190
#           define preBmGs(x, m, bmGs) {                        \
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4191
               int i, j, suff[XSIZE];                           \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4192
                                                                \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4193
               suffixes(x, m, suff);                            \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4194
                                                                \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4195
               for (i = 0; i < m; ++i)                          \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4196
                  bmGs[i] = m;                                  \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4197
               j = 0;                                           \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4198
               for (i = m - 1; i >= 0; --i)                     \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4199
                  if (suff[i] == i + 1)                         \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4200
                     for (; j < m - 1 - i; ++j)                 \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4201
                        if (bmGs[j] == m)                       \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4202
                           bmGs[j] = m - 1 - i;                 \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4203
               for (i = 0; i <= m - 2; ++i)                     \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4204
                  bmGs[m - 1 - suff[i]] = m - 1 - i;            \
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4205
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4206
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4207
            /* tables only depend on pattern; so we can cache them in case the same string is searched again */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4208
            if ((m == lastPatternSize)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4209
             && (strcmp(lastPattern, x) == 0)) {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4210
                /* tables are still valid */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4211
                // printf("valid: \"%s\"\n", lastPattern);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4212
            } else {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4213
                /* Preprocessing */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4214
                // printf("compute: \"%s\"\n", lastPattern);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4215
                preBmGs(x, m, bmGs);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4216
                preBmBc(x, m, bmBc);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4217
                if (m <= MAX_PATTERN_SIZE) {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4218
                    // printf("cache for: \"%s\"\n", lastPattern);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4219
                    strcpy(lastPattern, x);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4220
                    lastPatternSize = m;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4221
                }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4222
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4223
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4224
            /* Searching */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4225
            j = __intVal(startIndex) - 1;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4226
            while (j <= n - m) {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4227
               for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4228
               if (i < 0) {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4229
                  RETURN (__mkSmallInteger(j+1));
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4230
                  j += bmGs[0];
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4231
               } else {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4232
                  int s1 = bmGs[i];
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4233
                  int s2 = bmBc[y[i + j]] - m + 1 + i;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4234
                  j += MAX(s1, s2);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4235
               }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4236
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4237
            notFound = true;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4238
        }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4239
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4240
#endif /* ! __SCHTEAM__ */
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4241
%}.
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4242
    notFound == true ifTrue:[
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4243
        ^ exceptionValue value.
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4244
    ].
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4245
    ^ self slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4246
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4247
    "Modified: / 05-08-2012 / 12:27:31 / cg"
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4248
!
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4249
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4250
slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4251
    "naive search fallback (non-BM).
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4252
     Use this for short searchStrings (<= 2)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4253
     or for caseSensitive searches"
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4254
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4255
    |notFound|
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4256
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4257
%{
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4258
#ifndef __SCHTEAM__
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4259
    if (__qIsStringLike(self)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4260
     && __isStringLike(aSubString)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4261
     && (__isSmallInteger(startIndex))
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4262
     && (__intVal(startIndex) > 0)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4263
    ) {
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4264
        unsigned char *c_pSelf = __stringVal(self);
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4265
        unsigned char *c_substring = __stringVal(aSubString);
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4266
        unsigned char *c_pSelfI, *c_pSelfMax;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4267
        int c_lenSelf = __stringSize(self);
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4268
        int c_lenSubstring = __stringSize(aSubString);
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4269
        int c_idx0Max = c_lenSelf - c_lenSubstring;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4270
        unsigned char c_first;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4271
        unsigned char c_ucFirst;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4272
        unsigned char c_lcFirst;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4273
        unsigned char c_oppositeCaseFirst;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4274
        int i;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4275
        
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4276
        if (c_lenSubstring == 0) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4277
#if 1
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4278
            /* empty string does not match */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4279
            notFound = true;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4280
            goto getOutOfHere;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4281
#else
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4282
            /* empty string matches */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4283
            RETURN(startIndex);
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4284
#endif
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4285
        }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4286
        
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4287
        // searched string's length > string
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4288
        if (c_idx0Max < 0) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4289
            notFound = true;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4290
            goto getOutOfHere;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4291
        }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4292
        
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4293
        c_first = c_lcFirst = c_substring[0];
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4294
        if (((c_first >= 'A') && (c_first <= 'Z'))
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4295
         || ((c_first >= 0xC0) && (c_first <= 0xDE))) {
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4296
            c_ucFirst = c_first;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4297
            c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a';
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4298
        } else {
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4299
            if (((c_first >= 'a') && (c_first <= 'z'))
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4300
             || ((c_first >= 0xE0) && (c_first <= 0xFE))) {
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4301
                c_lcFirst = c_first;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4302
                c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A';
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4303
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4304
        }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4305
        
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4306
        // idx:
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4307
        // 0123456789
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4308
        
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4309
        // 1234567890 - lenSelf = 10
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4310
        // abc        - lenSubstring = 3
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4311
        //            - idx0Max = 7 (last legal startIndex)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4312
        
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4313
        i = __intVal(startIndex) - 1;
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4314
        c_pSelfI = c_pSelf + i;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4315
        c_pSelfMax = c_pSelf + c_idx0Max;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4316
        
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4317
        for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4318
            int j;
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4319
            unsigned char c_selfChar;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4320
            
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4321
            // find the first char
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4322
            c_selfChar = c_pSelfI[0];
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4323
            if (c_selfChar != c_first) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4324
                if (caseSensitive == true) continue;
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4325
                if (c_selfChar != c_oppositeCaseFirst) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4326
searchNext: ;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4327
                    continue;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4328
                }    
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4329
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4330
            
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4331
            // first char matches
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4332
            // compare rest
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4333
            for (j=1; j<c_lenSubstring; j++) {
19742
3625237bc6d7 signed compare bug
Claus Gittinger <cg@exept.de>
parents: 19741
diff changeset
  4334
                unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4335
                
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4336
                c_subChar = c_substring[j];
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4337
                c_selfChar = c_pSelfI[j];
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4338
                
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4339
                if (c_selfChar == c_subChar) continue;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4340
                if (caseSensitive == true) goto searchNext;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4341
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4342
                c_lcSubChar = c_subChar;
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4343
                if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z'))
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4344
                 || ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) {
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4345
                    c_lcSubChar = c_subChar - 'A' + 'a';
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4346
                    if (c_selfChar != c_lcSubChar) goto searchNext;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4347
                } else {
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4348
                    if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z'))
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4349
                     || ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) {
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4350
                        c_ucSubChar = c_subChar - 'a' + 'A';
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4351
                        if (c_selfChar != c_ucSubChar) goto searchNext;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4352
                    } else {
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4353
                        goto searchNext;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4354
                    }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4355
                }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4356
            }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4357
            // if we arrive here, we have a match at i
19733
Claus Gittinger <cg@exept.de>
parents: 19715
diff changeset
  4358
            RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) );
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4359
        }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4360
        notFound = true;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4361
    }
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4362
    
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4363
    getOutOfHere: ;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4364
#endif /* ! __SCHTEAM__ */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4365
%}.
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4366
    "/ arrive here if either not found, or invalid arguments
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4367
    notFound == true ifTrue:[
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4368
        ^ exceptionValue value.
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4369
    ].
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4370
    ^ 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
  4371
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4372
    "
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4373
     'abcdefg' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4374
     'abcdefg' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4375
     'abcdefg' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4376
     'abcabcg' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4377
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4378
     'ABCDEFG' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4379
     'ABCDEFG' slowIndexOfSubCollection:'Abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4380
     'ABCDEFG' slowIndexOfSubCollection:'aBC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4381
     'ABCDEFG' slowIndexOfSubCollection:'ABC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4382
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4383
     'ABCDEFG' slowIndexOfSubCollection:'a' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4384
     'ABCDEFG' slowIndexOfSubCollection:'A' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4385
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4386
     'ABCDEFG' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4387
     'ABCDEFG' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4388
     'ABCABCG' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4389
     
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4390
     '1234567890' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4391
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4392
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4393
     '1234567890' slowIndexOfSubCollection:'234' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4394
     '1234567890' slowIndexOfSubCollection:'345' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4395
     '1231231231' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4396
     '1231231231' slowIndexOfSubCollection:'123' startingAt:2 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4397
     '1231231231' slowIndexOfSubCollection:'123' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4398
     '1231231231' slowIndexOfSubCollection:'123' startingAt:4 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4399
     '1231231231' slowIndexOfSubCollection:'123' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4400
     '1231231231' slowIndexOfSubCollection:'123' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4401
     '1231231231' slowIndexOfSubCollection:'123' startingAt:7 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4402
     '1231231231' slowIndexOfSubCollection:'123' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4403
     '1231231231' slowIndexOfSubCollection:'123' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4404
     '1231231231' slowIndexOfSubCollection:'123' startingAt:10 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4405
     '1231231231' slowIndexOfSubCollection:'123' startingAt:11 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4406
     '1231231231' slowIndexOfSubCollection:'231' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4407
     '1231231231' slowIndexOfSubCollection:'231' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4408
     '1231231231' slowIndexOfSubCollection:'231' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4409
     '1231231231' slowIndexOfSubCollection:'231' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4410
     '1231231231' slowIndexOfSubCollection:'231' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4411
     '1231231231' slowIndexOfSubCollection:'231' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4412
     '1231231231' slowIndexOfSubCollection:'2310' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4413
     '1231231231' slowIndexOfSubCollection:'2310' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4414
    " 
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4415
! !
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4416
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4417
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4418
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4419
endsWith:aStringOrChar
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4420
    "return true, if the receiver ends with something, aStringOrChar.
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4421
     If aStringOrChar is an empty string, true is returned"
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4422
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4423
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4424
#ifndef __SCHTEAM__
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4425
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4426
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4427
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4428
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4429
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4430
    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
  4431
	len1 = __qSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4432
	len2 = __qSize(aStringOrChar);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4433
	if (len1 < len2) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4434
	    RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4435
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4436
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4437
	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
  4438
	src2 = __stringVal(aStringOrChar);
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4439
	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
  4440
	    if (c != *src1++) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4441
		RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4442
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4443
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4444
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4445
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4446
    if (__isCharacter(aStringOrChar)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4447
	int val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4448
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4449
	val = __intVal(__characterVal(aStringOrChar));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4450
	if ((unsigned)val <= 0xFF) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4451
	    len1 = __stringSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4452
	    if (len1 > 0) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4453
		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
  4454
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4455
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4456
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4457
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4458
#endif /* ! __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4459
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4460
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4461
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4462
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4463
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4464
     'hello world' endsWith:'earth'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4465
     'hello world' endsWith:$d
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4466
     'hello world' endsWith:$e
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4467
     '' endsWith:$d
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4468
     'hello world' endsWith:#($r $l $d)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4469
     'hello world' endsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4470
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4471
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4472
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4473
isBlank
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4474
    "return true, if the receiver's size is 0 or if it contains only spaces.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4475
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4476
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4477
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4478
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4479
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4480
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4481
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4482
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  4483
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4484
    if ((cls = __qClass(self)) != String)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4485
        src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4486
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4487
# ifdef UINT64
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  4488
    while (*((UINT64 *)src) == 0x2020202020202020L) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4489
        src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4490
    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4491
# endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4492
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4493
    while (*((unsigned *)src) == 0x20202020) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4494
        src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4495
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4496
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4497
    while ((c = *src++) == ' ')
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4498
        ;; /* just walking along */
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4499
    if (c != '\0') {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4500
        RETURN ( false );
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4501
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4502
    RETURN ( true );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4503
# endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4504
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4505
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4506
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4507
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4508
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4509
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4510
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4511
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4512
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4513
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4514
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4515
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4516
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4517
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4518
	RETURN ( (__stringSize(self) == 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4519
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4520
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4521
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4522
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4523
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4524
10958
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4525
isLiteral
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4526
    "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
  4527
     (i.e. can be used in constant arrays)"
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4528
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4529
    ^ true
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4530
!
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4531
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4532
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
  4533
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4534
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4535
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  4536
%{  /* STACK: 2000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4537
#ifndef __SCHTEAM__
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4538
    /*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4539
     * this is very heavy used when correcting errors
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4540
     * (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
  4541
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4542
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4543
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4544
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4545
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4546
    unsigned char *s1, *s2;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4547
    int v1, v2, v3;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4548
    INT m;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4549
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4550
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4551
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4552
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4553
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  4554
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4555
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4556
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4557
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  4558
    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
  4559
	&& __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
  4560
	&& __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
  4561
	&& __isSmallInteger(kbdTypoWeight)
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4562
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4563
	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
  4564
	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
  4565
	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
  4566
	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
  4567
	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
  4568
	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
  4569
	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
  4570
	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
  4571
	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
  4572
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4573
	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
  4574
	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
  4575
	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
  4576
	    data = fastData;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4577
	} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4578
	    /* 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
  4579
	    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
  4580
	    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
  4581
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4582
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4583
	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
  4584
	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
  4585
	    *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
  4586
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4587
	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
  4588
	    *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
  4589
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4590
	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
  4591
	    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
  4592
		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
  4593
		    m = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4594
		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
  4595
		    m = cW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4596
		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
  4597
		    m = kW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4598
		else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4599
		    m = sW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4600
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4601
		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
  4602
		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
  4603
		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
  4604
		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
  4605
		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
  4606
		    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
  4607
			m = v1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4608
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4609
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4610
		} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4611
		    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
  4612
			m = v2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4613
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4614
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4615
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4616
		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
  4617
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4618
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4619
	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
  4620
	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
  4621
	    free(data);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4622
	RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4623
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4624
mallocFailed: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4625
#endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4626
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4627
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4628
    ^ 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
  4629
			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
  4630
			i:insrtWeight d:deleteWeight
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4631
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4632
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4633
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4634
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4635
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4636
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4637
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4638
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4639
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4640
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4641
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4642
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4643
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4644
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4645
    "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
  4646
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4647
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4648
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4649
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4650
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4651
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4652
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4653
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4654
	RETURN ( (__stringSize(self) != 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4655
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4656
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4657
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4658
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4659
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4660
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4661
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  4662
    "return true, if the receiver starts with something, aStringOrChar.
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4663
     If the argument is empty, true is returned.
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4664
     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
  4665
     which are both inconsistent w.r.t. an empty argument."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4666
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4667
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4668
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4669
    if (self.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4670
	if (aStringOrChar.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4671
	    java.lang.String me = self.asString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4672
	    java.lang.String other = aStringOrChar.asString();
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4673
	    return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4674
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4675
	if (aStringOrChar.isSTCharacter()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4676
	    char[] me = self.asSTString().characters;
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4677
	    char ch = aStringOrChar.charValue();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4678
	    return __c__._RETURN( ((me.length > 0)
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4679
				  && (me[0] == ch)) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4680
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4681
    }
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4682
#else
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4683
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4684
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4685
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4686
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4687
14217
d399ca31088f changed: #startsWith:
Stefan Vogel <sv@exept.de>
parents: 14201
diff changeset
  4688
    if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4689
	src1 = __stringVal(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4690
	src2 = __stringVal(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4691
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4692
	if (src1[0] != src2[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4693
	    if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4694
		RETURN (true);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4695
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4696
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4697
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4698
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4699
	len1 = __qSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4700
	len2 = __qSize(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4701
	if (len1 < len2) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4702
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4703
	}
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4704
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4705
# ifdef UINT64
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4706
	while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4707
	    if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4708
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4709
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4710
	    len2 -= sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4711
	    src1 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4712
	    src2 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4713
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4714
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4715
#  ifdef __UNROLL_LOOPS__
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4716
	while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4717
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4718
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4719
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4720
	    if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4721
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4722
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4723
	    if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4724
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4725
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4726
	    if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4727
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4728
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4729
	    len2 -= sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4730
	    src1 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4731
	    src2 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4732
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4733
#  endif /* __UNROLL_LOOPS__ */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4734
# endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  4735
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4736
	while (len2 > (OHDR_SIZE+sizeof(INT))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4737
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4738
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4739
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4740
	    len2 -= sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4741
	    src1 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4742
	    src2 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4743
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4744
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4745
	while ((c = *src2++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4746
	    if (c != *src1) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4747
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4748
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4749
	    src1++;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4750
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4751
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4752
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4753
    if (__isCharacter(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4754
	int val;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4755
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4756
	val = __intVal(__characterVal(aStringOrChar));
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4757
	if ((unsigned)val <= 0xFF) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4758
	    len1 = __stringSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4759
	    if (len1 > 0) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4760
		RETURN ( (__stringVal(slf)[0] == val) ? true : false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4761
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4762
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4763
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4764
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4765
#endif /* not __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4766
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4767
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4768
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4769
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4770
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4771
     'hello world' startsWith:'hella'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4772
     'hello world' startsWith:'hi'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4773
     'hello world' startsWith:$h
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4774
     'hello world' startsWith:$H
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4775
     'hello world' startsWith:(Character value:16rFF00)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4776
     'hello world' startsWith:60
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4777
     'hello world' startsWith:#($h $e $l)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4778
     'hello world' startsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4779
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4780
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4781
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4782
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4783
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4784
isSingleByteString
16773
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4785
    "returns true only for strings and immutable strings.
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4786
     Must replace foo isMemberOf:String and foo class == String"
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4787
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4788
    ^ true
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4789
!
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4790
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4791
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4792
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4793
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4794
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4795
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4796
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4797
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4798
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4799
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4800
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4801
version
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4802
    ^ '$Header$'
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4803
!
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4804
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4805
version_CVS
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4806
    ^ '$Header$'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4807
! !
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  4808