String.st
author Claus Gittinger <cg@exept.de>
Wed, 14 Sep 2016 08:54:18 +0200
changeset 20384 78b74ac7c891
parent 20272 9d04254b1c19
child 20398 8cb53f870d39
child 20483 4d7cd83a4cb6
permissions -rw-r--r--
#TUNING by cg class: String added: #includes:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
     1
"{ Encoding: utf8 }"
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    14
"{ Package: 'stx:libbasic' }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    15
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
    16
"{ NameSpace: Smalltalk }"
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
    17
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    18
CharacterArray variableByteSubclass:#String
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    19
	instanceVariableNames:''
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
    20
	classVariableNames:'CRLF CR LF TAB'
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    21
	poolDictionaries:''
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    22
	category:'Collections-Text'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    25
!String primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
%{
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
    27
3809
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    28
#include <stdio.h>
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    29
#define _STDIO_H_INCLUDED_
14752
201d3e649814 include stdlib.h to define malloc() prototypes
Stefan Vogel <sv@exept.de>
parents: 14664
diff changeset
    30
#include <stdlib.h>
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
#include <ctype.h>
359
claus
parents: 357
diff changeset
    32
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    33
#ifdef LINUX
359
claus
parents: 357
diff changeset
    34
# define __STRINGDEFS__
claus
parents: 357
diff changeset
    35
# include <linuxIntern.h>
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    36
#endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    37
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    38
#ifdef __osx__
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    39
# include <string.h>
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    40
# include <stdlib.h>
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    41
#endif
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
    42
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
    43
#ifdef __MINGW__
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
    44
# include <string.h>
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
    45
# include <stdlib.h>
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
    46
#endif
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
    47
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    48
/*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    49
 * old st/x creates strings with spaces in it;
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    50
 * new st/x will fill it with zeros (for st-80 compatibility)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    51
 * the define below sets old behavior.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    52
 */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    53
#define INITIALIZE_WITH_SPACE
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    54
19107
ad915b7ce4b3 win32 definition
Claus Gittinger <cg@exept.de>
parents: 18999
diff changeset
    55
#ifdef FAST_MEMCHR
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
    56
// # if !defined(__osx__) && !defined(__win32__)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
    57
// extern void *memchr();
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
    58
// # endif
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    59
#endif
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    60
%}
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    61
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    62
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    63
!String primitiveFunctions!
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    64
%{
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    65
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
    66
static int
19878
a7d162406bde *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19877
diff changeset
    67
nextOnKeyboard(int char1, int char2)
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    68
{
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    69
    /* 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
    70
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    71
    static char *us_keys[] = { "1234567890-",
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    72
			    "*qwertyuiop",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    73
			    "**asdfghjkl:",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    74
			    "***zxcvbnm",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    75
			    0 };
10370
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    76
    static char *de_keys[] = { "1234567890-",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    77
			    "*qwertzuiop",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    78
			    "**asdfghjkl:",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    79
			    "***yxcvbnm",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    80
			    0 };
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    81
    char **keys = us_keys;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    82
    char **line1, **line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    83
    char *col1, *col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    84
    int diff;
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 (line1 = keys; *line1 != 0; line1++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    87
	for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
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 (*col1 == 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
    for (line2 = keys; *line2 != 0; line2++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    94
	for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    95
	    continue;
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
    if (*col2 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    98
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    99
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   100
    diff = col1 - col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   101
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   102
	return(0);
8647
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
    diff = line1 - line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   105
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   106
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   107
    return(1);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   108
}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   109
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   110
%}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   111
! !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
   112
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
!String class methodsFor:'documentation'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
copyright
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   118
	      All Rights Reserved
608
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
 This software is furnished under a license and may be used
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
 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
   122
 inclusion of the above copyright notice.   This software may not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
 be provided or otherwise made available to, or used by, any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
 other person.  No title to or ownership of the software is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
 hereby transferred.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   128
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
documentation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   131
    Strings are ByteArrays storing Characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
19910
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   133
    Strings are kind of kludgy: to allow for easy handling by C functions,
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
    there is always one 0-byte added at the end, which is not counted
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   135
    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
   136
    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
   137
    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
   138
    prevent a nonsense contents ...)
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   139
19305
459c58e9baed #DOCUMENTATION
mawalch
parents: 19188
diff changeset
   140
    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
   141
    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
   142
    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
   143
    of String (the access functions defined here can handle this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   144
    A little warning though: not all smalltalk systems allow subclassing String,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
    so your program may become unportable if you do so.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   146
20003
7867360500a7 #OTHER by mawalch
mawalch
parents: 19910
diff changeset
   147
    Strings have an implicit (assumed) encoding of ISO-8859-1.
7895
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   148
    For strings with other encodings, either keep the encoding separately,
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   149
    or use instances of encodedString.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   150
19910
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   151
    Be careful when using the 0-byte in a String. This is not prohibited, but 
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   152
    the implementations of some String methods use C functions and may
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   153
    therefore yield unexpected results (e.g. compareWith:collating:) when
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   154
    processing a String containing the 0-byte.
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   155
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   156
    [author:]
19910
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   157
        Claus Gittinger
1310
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   158
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   159
    [see also:]
19910
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   160
        Text StringCollection TwoByteString JISEncodedString
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
   161
        Symbol
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   163
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   164
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
!String class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
basicNew:anInteger
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   168
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   169
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   170
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   171
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   172
     can be directly used as separator or for formatting."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   175
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   176
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   177
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
    OBJ newString;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   179
    REGISTER INT len, instsize;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
    REGISTER unsigned char *cp;
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
   181
    int nInstVars;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
252
   183
    if (__isSmallInteger(anInteger)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   184
	len = __intVal(anInteger);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   185
	if (len >= 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   186
	    instsize = OHDR_SIZE + len + 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   187
	    if (self == String || self == ImmutableString) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   188
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   189
		    /*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   190
		     * the most common case
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   191
		     */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   192
		    __qCheckedNew(newString, instsize);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   193
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   194
		    __qSTORE(newString, self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   195
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   196
		    cp = __stringVal(newString);
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   197
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   198
# if defined(memset4)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   199
		    {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   200
			/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   201
			 * no sizeof(int) here please -
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   202
			 * - memset4 (if defined) fills 4-bytes on ALL machines
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   203
			 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   204
			int l4 = len >> 2;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   205
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   206
			if (len & 3) l4++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   207
			memset4(cp, 0x20202020, l4);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   208
			cp[len] = '\0';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   209
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   210
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   211
#  ifdef FAST_MEMSET
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   212
		    memset(cp, ' ', len);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   213
		    cp[len] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   214
#  else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   215
		    for ( ; len >= 8; cp += 8, len -= 8) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   216
#   ifdef INT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   217
			((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   218
#   else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   219
			((int *)cp)[0] = 0x20202020;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   220
			((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   221
#   endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   222
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   223
		    while (len--)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   224
			*cp++ = ' ';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   225
		    *cp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   226
#  endif /* not FAST_MEMSET */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   227
# endif /* not memset4 */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   228
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   229
		    RETURN (newString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   230
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   231
		nInstVars = 0;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   232
	    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   233
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   234
		instsize += __OBJS2BYTES__(nInstVars);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   235
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   236
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   237
	    __PROTECT_CONTEXT__;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   238
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   239
	    __UNPROTECT_CONTEXT__;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   240
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   241
	    if (newString == nil) goto fail;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   242
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   243
	    __InstPtr(newString)->o_class = self;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   244
	    __qSTORE(newString, self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   245
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   246
	    cp = __stringVal(newString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   247
	    if (nInstVars) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   248
		OBJ *op;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   249
		cp += __OBJS2BYTES__(nInstVars);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   250
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   251
		/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   252
		 * nil-out instvars
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   253
		 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   254
# if defined(memset4)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   255
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   256
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   257
#  if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   258
		/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   259
		 * knowing that nil is 0
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   260
		 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   261
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   262
#  else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   263
		op = __InstPtr(newString)->i_instvars;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   264
		do {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   265
		    *op++ = nil;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   266
		} while (--nInstVars);
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   267
#  endif  /* !FAST_MEMSET */
357
claus
parents: 347
diff changeset
   268
# endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   269
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   270
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   271
	    /*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   272
	     * fill with spaces
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   273
	     */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   274
# ifdef FAST_MEMSET
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   275
	    memset(cp, ' ', len);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   276
	    *(cp + len) = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   277
# else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   278
	    while (len >= 8) {
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   279
#  ifdef INT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   280
		((INT64 *)cp)[0] = 0x2020202020202020L;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   281
#  else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   282
		((int *)cp)[0] = 0x20202020;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   283
		((int *)cp)[1] = 0x20202020;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   284
#  endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   285
		cp += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   286
		len -= 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   287
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   288
	    while (len--)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   289
		*cp++ = ' ';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   290
	    *cp = '\0';
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   291
# endif /* !FAST_MEMSET */
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   292
	    RETURN (newString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   293
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   295
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   296
#endif /* not __SCHTEAM__ */
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   297
%}.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   298
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   299
     invalid argument, or out-of-memory:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   300
     use error handling in superclass
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   301
    "
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   302
    (anInteger < 0) ifTrue:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   303
	"
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   304
	 the argument is negative,
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   305
	"
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   306
	self error:'bad (negative) argument to new:'.
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   307
	^ nil
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   308
    ].
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   309
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   310
    ^ (super basicNew:anInteger+1) atAllPut:(Character space)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   311
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   312
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
new:n
20193
c24ef271e741 #OTHER by mawalch
mawalch
parents: 20162
diff changeset
   314
    "return a new empty string with n characters.
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   315
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   316
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   317
     This makes much more sense, in that a freshly created string
20272
9d04254b1c19 #DOCUMENTATION by mawalch
mawalch
parents: 20193
diff changeset
   318
     can be directly used as separator or for formatting.
9d04254b1c19 #DOCUMENTATION by mawalch
mawalch
parents: 20193
diff changeset
   319
9d04254b1c19 #DOCUMENTATION by mawalch
mawalch
parents: 20193
diff changeset
   320
     Redefined here with exactly the same code as in Behavior for
9d04254b1c19 #DOCUMENTATION by mawalch
mawalch
parents: 20193
diff changeset
   321
     better performance. "
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   322
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    ^ self basicNew:n
347
claus
parents: 345
diff changeset
   324
!
claus
parents: 345
diff changeset
   325
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   326
readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   327
    "read & return the next String from the (character-)stream aStream;
claus
parents: 345
diff changeset
   328
     skipping all whitespace first; return the value of exceptionBlock,
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   329
     if no string can be read. The sequence of characters as read from the
347
claus
parents: 345
diff changeset
   330
     stream must be one as stored via storeOn: or storeString."
claus
parents: 345
diff changeset
   331
claus
parents: 345
diff changeset
   332
    "
claus
parents: 345
diff changeset
   333
     this method is not to be inherited
claus
parents: 345
diff changeset
   334
     (i.e. not ok for subclasses; Symbol, for example)
claus
parents: 345
diff changeset
   335
    "
claus
parents: 345
diff changeset
   336
    self ~~ String ifTrue:[
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
   337
	^ super readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   338
    ].
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   339
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   340
claus
parents: 345
diff changeset
   341
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   342
     String readFrom:('''hello world''' readStream)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   343
     String readFrom:('''hello '''' world''' readStream)
347
claus
parents: 345
diff changeset
   344
     String readFrom:('1 ''hello'' ' readStream)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   345
     String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
3376
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   346
    "
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   347
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   348
    "Modified: / 05-07-2006 / 16:41:29 / cg"
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   349
    "Modified: / 07-08-2006 / 15:03:09 / fm"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   352
uninitializedNew:anInteger
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   353
    "return a new string with anInteger characters but undefined contents.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   354
     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
   355
     used as a stream buffer."
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   356
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   357
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   358
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   359
    return context._RETURN( self.basicNew( anInteger.intValue() ));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   360
#else
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   361
    OBJ newString;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   362
    REGISTER int len;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   363
    REGISTER unsigned char *cp;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   364
    REGISTER OBJ *op;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   365
    int nInstVars, instsize;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   366
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   367
    if (__isSmallInteger(anInteger)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   368
	len = __intVal(anInteger);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   369
	if (len >= 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   370
	    instsize = OHDR_SIZE + len + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   371
	    if (self == String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   372
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   373
		    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   374
		     * the most common case
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   375
		     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   376
		    __qCheckedNew(newString, instsize);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   377
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   378
		    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   379
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   380
		    cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   381
		    cp[len] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   382
		    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   383
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   384
		nInstVars = 0;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   385
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   386
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   387
		instsize += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   388
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   389
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   390
	    __PROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   391
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   392
	    __UNPROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   393
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   394
	    if (newString == nil) goto fail;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   395
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   396
	    __InstPtr(newString)->o_class = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   397
	    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   398
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   399
	    if (nInstVars) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   400
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   401
		 * nil-out instvars
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   402
		 */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   403
# if defined(memset4)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   404
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   405
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   406
#  if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   407
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   408
		 * knowing that nil is 0
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   409
		 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   410
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   411
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   412
		op = __InstPtr(newString)->i_instvars;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   413
		do {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   414
		    *op++ = nil;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   415
		} while (--nInstVars);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
   416
#  endif
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   417
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   418
		cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   419
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   420
		cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   421
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   422
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   423
	    *(cp + len) = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   424
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   425
	}
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   426
    }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   427
fail: ;;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   428
#endif /* not __SCHTEAM__ */
7684
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
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   431
     invalid argument, or out-of-memory:
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   432
     use error handling in superclass
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   433
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   434
    (anInteger < 0) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   435
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   436
	 the argument is negative,
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   437
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   438
	self error:'bad (negative) argument to new:'.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   439
	^ nil
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   440
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
    ^ self basicNew:anInteger
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   443
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   444
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   445
     String uninitializedNew:100
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   446
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
8438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   449
!String class methodsFor:'Compatibility-Dolphin'!
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   450
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   451
lineDelimiter
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   452
    "Dolphin compatibility: answer CR LF"
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   453
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   454
    ^ self crlf
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   455
! !
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   456
7302
13a053c255bf category
Claus Gittinger <cg@exept.de>
parents: 7283
diff changeset
   457
!String class methodsFor:'Compatibility-Squeak'!
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   458
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   459
cr
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   460
    "return a string consisting of the cr-Character"
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   461
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   462
    "/ ATTENTION: you get a NL (for compatibility) here!!
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   463
    "/ please use String return  / String lf
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   464
    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
   465
    "/ for now.
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   466
    "/ will be changed, when the historic UNIX baggage is removed
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   467
    "/ and all cr's are really returns (instead of nl's).
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   468
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   469
    ^ self lf
7282
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
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   472
crlf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   473
    "return a string consisting of the cr-lf Characters"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   474
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   475
    CRLF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   476
	CRLF := String
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   477
		    with:Character return
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   478
		    with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   479
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   480
    ^ CRLF
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   481
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   482
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   483
lf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   484
    "return a string consisting of the lf Character"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   485
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   486
    LF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   487
	LF := String with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   488
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   489
    ^ LF
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   490
!
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   491
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   492
return
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   493
    "return a string consisting of the cr-Character"
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   494
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   495
    CR isNil ifTrue:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   496
	CR := String with:Character return
19503
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   497
    ].
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   498
    ^ CR
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   499
!
f923e67431d8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19383
diff changeset
   500
12344
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   501
stringHash:aString initialHash:speciesHash
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   502
    "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
   503
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   504
    | stringSize hash low |
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   505
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   506
    stringSize := aString size.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   507
    hash := speciesHash bitAnd: 16rFFFFFFF.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   508
    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
   509
	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
   510
	"Begin hashMultiply"
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   511
	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
   512
	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
   513
    ].
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   514
    ^ hash.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   515
!
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   516
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   517
tab
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   518
    "return a string consisting of the tab-Character"
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   519
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   520
    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
   521
	TAB := String with:Character tab
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   522
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   523
    ^ TAB
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   524
! !
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   525
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   526
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   527
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   529
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   530
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   531
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   532
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   533
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   534
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   535
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   536
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   538
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   539
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   541
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   542
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   543
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   544
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
   546
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
329
claus
parents: 314
diff changeset
   549
at:index
claus
parents: 314
diff changeset
   550
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   551
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   552
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   553
     This method is the same as at:."
claus
parents: 314
diff changeset
   554
claus
parents: 314
diff changeset
   555
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   556
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   557
    if (index.isSmallInteger()) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   558
	int idx1Based = context.stArg(0).intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   559
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   560
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   561
#else
329
claus
parents: 314
diff changeset
   562
    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
   563
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   564
claus
parents: 314
diff changeset
   565
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   566
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   567
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   568
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   569
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   570
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   571
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   572
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   573
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   574
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   575
	}
329
claus
parents: 314
diff changeset
   576
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   577
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   578
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   579
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   580
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   581
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
329
claus
parents: 314
diff changeset
   583
at:index put:aCharacter
claus
parents: 314
diff changeset
   584
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   585
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   586
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   587
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   588
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   589
claus
parents: 314
diff changeset
   590
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   591
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   592
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   593
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   594
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   595
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   596
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   597
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   598
#else
329
claus
parents: 314
diff changeset
   599
    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
   600
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   601
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   602
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   603
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   604
    if (__isString(slf)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   605
	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
   606
	    value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   607
	    if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   608
	     && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   609
		indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   610
		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   611
		    __stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   612
		    RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   613
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   614
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   615
	}
329
claus
parents: 314
diff changeset
   616
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   617
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   618
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   619
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   620
!
claus
parents: 314
diff changeset
   621
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   627
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   628
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   629
	int idx1Based = index.intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   630
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   631
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   632
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   633
    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
   634
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   637
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   638
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   639
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   640
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   641
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   642
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   643
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   644
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   645
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   646
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   647
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   648
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   649
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   650
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   651
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   652
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   653
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   654
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   655
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   656
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   657
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   658
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   661
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   662
     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
   663
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   664
a27a279701f8 Initial revision
claus
parents:
diff changeset
   665
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   666
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   667
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   668
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   669
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   670
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   671
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   672
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   673
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   674
    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
   675
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   676
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   677
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   678
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   679
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   680
    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
   681
	value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   682
	if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   683
	 && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   684
	    cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   685
	    indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   686
	    if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   687
		if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   688
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   689
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   690
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   691
		__stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   692
		RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   693
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   694
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   695
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   696
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   697
#endif /* not __SCHTEAM__ */
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   698
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   699
    (aCharacter isMemberOf:Character) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   700
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   701
	 tried to store something which is not a character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   702
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   703
	^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   704
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   705
    (aCharacter codePoint between:1 and:255) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   706
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   707
	 tried to store a multibyte character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   708
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   709
	^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   710
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   711
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   712
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   713
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   714
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   715
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   716
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   717
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   718
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   719
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   720
    super basicAt:index put:aCharacter codePoint.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   721
    ^ aCharacter
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   722
!
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   723
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   724
first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   725
    "return the first character.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   726
     Reimplemented here for speed"
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
%{  /* NOCONTEXT */
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   729
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   730
    REGISTER int indx;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   731
    REGISTER OBJ slf, cls;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   732
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   733
    slf = self;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   734
    cls = __qClass(slf);
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   735
    indx = 0;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   736
    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
   737
	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
   738
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   739
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   740
    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
   741
	RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   742
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   743
badIndex: ;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   744
%}.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   745
    ^ super first
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
    "
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   748
     'abc' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   749
     '' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   750
    "
2
claus
parents: 1
diff changeset
   751
! !
claus
parents: 1
diff changeset
   752
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   753
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   754
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   756
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   757
    "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
   758
     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
   759
19744
f64dd57ad912 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19742
diff changeset
   760
    ^ self indexOf:aCharacter startingAt:1.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   761
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   762
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   763
     'hello world' identityIndexOf:(Character space)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   764
     '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
   765
     'hello world' identityIndexOf:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   766
     #[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
   767
     #[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
   768
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   769
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   770
    "Modified: / 10-01-2012 / 17:07:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   772
13923
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   773
identityIndexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   774
    "return the index of the first occurrences of the argument, aCharacter
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   775
     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
   776
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   777
    ^ self indexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   778
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   779
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   780
     'hello world' identityIndexOf:(Character space)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   781
     'hello world' identityIndexOf:$d
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   782
     'hello world' identityIndexOf:1
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   783
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   784
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   785
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   786
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   787
    "Created: / 10-01-2012 / 17:10:54 / cg"
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   788
!
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   789
20384
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   790
includes:aCharacter
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   791
    "return true, if the receiver includes aCharacter.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   792
     - redefined here for speed"
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   793
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   794
%{  /* NOCONTEXT */
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   795
#ifdef FAST_MEMCHR
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   796
    REGISTER unsigned char *cp;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   797
    REGISTER unsigned byteValue;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   798
    int last;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   799
    OBJ cls;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   800
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   801
    if (__isCharacter(aCharacter)) {
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   802
        byteValue = __intVal(__characterVal(aCharacter));
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   803
        if (byteValue <= 0xFF) {            
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   804
            last = __stringSize(self);
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   805
            cp = __stringVal(self);
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   806
            if ((cls = __qClass(self)) != String) {
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   807
                int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   808
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   809
                cp += numInstBytes;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   810
                last -= numInstBytes;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   811
            }
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   812
            cp = (unsigned char *) memchr(cp, byteValue, last);
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   813
            RETURN ( (cp == NULL) ? false : true );
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   814
        }
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   815
        RETURN (false);
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   816
    }
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   817
#endif
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   818
%}.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   819
    ^ (self indexOf:aCharacter startingAt:1) ~~ 0
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   820
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   821
    "
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   822
     'hello world' includes:$l
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   823
     'hello world' includes:$W
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   824
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   825
     |s|
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   826
     s := String new:1024.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   827
     s atAllPut:$a.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   828
     s at:512 put:(Character space).
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   829
     Time millisecondsToRun:[
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   830
        1000000 timesRepeat:[ s includes:(Character space) ]
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   831
     ]
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   832
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   833
     timing (ms):
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   834
            bcc                 OSX(2007 powerbook)
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   835
                                 110    
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   836
    "
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   837
!
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   838
10
claus
parents: 5
diff changeset
   839
includesAny:aCollection
claus
parents: 5
diff changeset
   840
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   841
     argument, aCollection.
17573
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   842
     - redefined for speed if the argument is a String; especially optimized,
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   843
     if the searched collection has less than 6 characters."
10
claus
parents: 5
diff changeset
   844
claus
parents: 5
diff changeset
   845
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   846
claus
parents: 5
diff changeset
   847
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   848
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   849
    OBJ cls;
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   850
    int index, last;
10
claus
parents: 5
diff changeset
   851
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
   852
    if (__isStringLike(aCollection)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   853
	matchP = __stringVal(aCollection);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   854
	last = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   855
	cp = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   856
	if ((cls = __qClass(self)) != String) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   857
	    int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   858
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   859
	    cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   860
	    last -= numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   861
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   862
	index = 0;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   863
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   864
	switch (__stringSize(aCollection)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   865
	    case 5:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   866
		/* five character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   867
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   868
		    unsigned char c1 = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   869
		    unsigned char c2 = matchP[1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   870
		    unsigned char c3 = matchP[2];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   871
		    unsigned char c4 = matchP[3];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   872
		    unsigned char c5 = matchP[4];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   873
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   874
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   875
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   876
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   877
			if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   878
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   879
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   880
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   881
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   882
		    RETURN (false);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   883
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   884
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   885
	    case 4:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   886
		/* four character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   887
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   888
		    unsigned char c1 = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   889
		    unsigned char c2 = matchP[1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   890
		    unsigned char c3 = matchP[2];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   891
		    unsigned char c4 = matchP[3];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   892
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   893
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   894
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   895
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   896
			if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   897
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   898
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   899
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   900
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   901
		    RETURN (false);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   902
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   903
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   904
	    case 3:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   905
		/* three character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   906
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   907
		    unsigned char c1 = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   908
		    unsigned char c2 = matchP[1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   909
		    unsigned char c3 = matchP[2];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   910
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   911
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   912
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   913
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   914
			if ((ch == c1) || (ch == c2) || (ch == c3)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   915
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   916
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   917
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   918
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   919
		    RETURN (false);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   920
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   921
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   922
	    case 2:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   923
		/* two character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   924
		{
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   925
#if 0
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   926
		    // this is roughly 10% slower (on OSX/64bit clang')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   927
		    if (last < 2000) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   928
			if (strchr(cp, matchP[0])) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   929
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   930
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   931
			if (strchr(cp, matchP[1])) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   932
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   933
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   934
		    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   935
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   936
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   937
#if 1
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   938
		    // this is 30 %faster !
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   939
#                   define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   940
#                   define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   941
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   942
		    unsigned char c1 = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   943
		    unsigned char c2 = matchP[1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   944
		    int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   945
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   946
		    int m1 = (~0UL/255 * (c1));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   947
		    int m2 = (~0UL/255 * (c2));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   948
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   949
		    while (index < last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   950
			unsigned int v = *(unsigned int *)(cp+index);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   951
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   952
			if (hasByteM(v,m1)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   953
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   954
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   955
			if (hasByteM(v,m2)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   956
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   957
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   958
			index += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   959
		    }
19748
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
#                   undef hasZeroByte
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   962
#                   undef hasByteM
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   963
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   964
		    while (index < last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   965
			unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   966
			int any;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   967
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   968
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   969
			any = ((ch == c1) || (ch == c2));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   970
			ch = cp[index+1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   971
			any |= ((ch == c1) || (ch == c2));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   972
			ch = cp[index+2];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   973
			any |= ((ch == c1) || (ch == c2));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   974
			ch = cp[index+3];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   975
			any |= ((ch == c1) || (ch == c2));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   976
			if (any) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   977
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   978
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   979
			index += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   980
		    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   981
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   982
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   983
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   984
			unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   985
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   986
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   987
			if ((ch == c1) || (ch == c2)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   988
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   989
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   990
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   991
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   992
		    RETURN (false);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   993
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   994
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   995
	    case 1:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   996
		/* single character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   997
		if (strchr(cp, matchP[0])) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   998
		    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   999
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1000
		RETURN ( false );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1001
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1002
	    case 0:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1003
		RETURN ( false );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1004
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1005
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1006
	{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1007
	    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1008
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1009
	    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1010
		ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1011
		if (strchr(matchP, ch)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1012
		    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1013
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1014
		index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1015
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1016
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1017
	RETURN ( false );
10
claus
parents: 5
diff changeset
  1018
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1019
%}.
10
claus
parents: 5
diff changeset
  1020
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1021
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1022
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1023
     'hello world' includesAny:'abcd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1024
     'hello world' includesAny:'xyz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1025
     'hello world' includesAny:'xz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1026
     'hello world' includesAny:'od'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1027
     'hello world' includesAny:'xd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1028
     'hello world' includesAny:'dx'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1029
     'hello world' includesAny:(Array with:$a with:$b with:$d)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1030
     'hello world' includesAny:(Array with:$x with:$y)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1031
     'hello world' includesAny:(Array with:1 with:2)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1032
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1033
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1034
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1035
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1036
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1037
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1038
	]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1039
     ].540 680 550 850 890 850
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1040
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1041
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1042
     s := String new:2000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1043
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1044
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1045
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1046
	]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1047
     ]. 1030 1060 1650 1690
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1048
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1049
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1050
     s := 'hello world'.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1051
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1052
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1053
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1054
	]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1055
     ].70 60
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1056
    "
10
claus
parents: 5
diff changeset
  1057
!
claus
parents: 5
diff changeset
  1058
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1059
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1060
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1061
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1062
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1064
%{  /* NOCONTEXT */
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1065
#ifdef __SCHTEAM__
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1066
    if (start.isSmallInteger()
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1067
     && aCharacter.isSTCharacter()) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1068
	int idx1Based = start.intValue();   // st index is 1 based
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1069
	int jIdx = self.asString().indexOf(aCharacter.charValue(), idx1Based-1);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1070
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1071
	return context._RETURN( jIdx+1 );    // st index is 1 based
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1072
    }
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1073
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1074
#else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1075
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1076
# if defined(__BORLANDC__) || defined(__VISUALC__)
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1077
#  undef __UNROLL_LOOPS__
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1078
#  undef FAST_MEMCHR
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1079
#  define V2
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1080
# endif
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1081
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1082
    REGISTER unsigned char *cp;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1083
    REGISTER INT index;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1084
    REGISTER unsigned byteValue;
8924
eb2dd7dd459f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8923
diff changeset
  1085
    int last;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1086
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1087
252
  1088
    if (__isSmallInteger(start)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1089
	index = __intVal(start);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1090
	if (index > 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1091
	    if (__isCharacter(aCharacter)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1092
		byteValue = __intVal(__characterVal(aCharacter));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1093
		if (byteValue <= 0xFF) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1094
		    last = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1095
		    cp = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1096
		    if ((cls = __qClass(self)) != String) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1097
			int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1098
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1099
			cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1100
			last -= numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1101
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1102
		    if (index <= last) {
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1103
# ifdef FAST_MEMCHR
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1104
			REGISTER unsigned char *ncp;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1105
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1106
			ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1107
			if (ncp) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1108
			    RETURN ( __mkSmallInteger(ncp - cp + 1) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1109
			}
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1110
# else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1111
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1112
#  ifdef V2
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1113
			{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1114
			    // see bit twiddling hacks
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1115
#                           define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1116
#                           define hasByteM(v,m)   hasZeroByte( (v) ^ m)
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1117
#   if __POINTER_SIZE__ == 8
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1118
#                           define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1119
#                           define hasByteM8(v,m)   hasZeroByte8( (v) ^ m)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1120
			    // the following loop checks eight bytes at once
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1121
			    if (((index-1) & 0x7) == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1122
				int last8 = last-8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1123
				INT m = (~0ULL/255 * (byteValue));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1124
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1125
				while (index <= last8) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1126
				    unsigned INT v = *(unsigned INT *)(cp+index-1);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1127
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1128
				    if (hasByteM8(v,m)) break;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1129
				    index += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1130
				}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1131
			    }
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1132
#   endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1133
			    // the following loop checks four bytes at once
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1134
			    if (((index-1) & 0x3) == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1135
				int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1136
				int m = (~0UL/255 * (byteValue));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1137
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1138
				while (index <= last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1139
				    unsigned int v = *(unsigned int *)(cp+index-1);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1140
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1141
				    if (hasByteM(v,m)) break;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1142
				    index += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1143
				}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1144
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1145
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1146
#  else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1147
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1148
#   ifdef __UNROLL_LOOPS__
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1149
			{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1150
			    int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1151
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1152
			    for (; index <= last4; index += 4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1153
				if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1154
				if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1155
				if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1156
				if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1157
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1158
			}
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1159
#   endif
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1160
#  endif /* V2 */
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1161
			while (index <= last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1162
			    if (cp[index-1] == byteValue) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1163
				RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1164
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1165
			    index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1166
			}
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1167
# endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1168
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1169
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1170
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1171
	    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1172
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1173
    }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1174
# undef V2
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1175
#endif /* not SCHTEAM */
370
claus
parents: 368
diff changeset
  1176
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1177
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1178
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1179
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1180
     '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
  1181
     '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
  1182
     '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
  1183
     '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
  1184
     #[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
  1185
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1186
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1187
     '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
  1188
     '1234567890123456a' indexOf:$b
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1189
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1190
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1191
     s := '12345678901234b'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1192
     self assert:(s indexOf:$x) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1193
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1194
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1195
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1196
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1197
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1198
     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
  1199
     self assert:(s indexOf:$b) == 15.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1200
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1201
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1202
     s := ''.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1203
     self assert:(s indexOf:$1) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1204
     s := '1'.
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) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1207
     s := '12'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1208
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1209
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1210
     self assert:(s indexOf:$3) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1211
     s := '123'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1212
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1213
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1214
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1215
     self assert:(s indexOf:$4) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1216
     s := '1234'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1217
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1218
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1219
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1220
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1221
     self assert:(s indexOf:$5) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1222
     s := '12345'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1223
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1224
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1225
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1226
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1227
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1228
     self assert:(s indexOf:$6) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1229
     s := '123456'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1230
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1231
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1232
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1233
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1234
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1235
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1236
     self assert:(s indexOf:$7) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1237
     s := '1234567'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1238
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1239
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1240
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1241
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1242
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1243
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1244
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1245
     self assert:(s indexOf:$8) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1246
     s := '12345678'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1247
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1248
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1249
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1250
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1251
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1252
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1253
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1254
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1255
     self assert:(s indexOf:$9) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1256
     s := '123456789'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1257
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1258
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1259
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1260
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1261
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1262
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1263
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1264
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1265
     self assert:(s indexOf:$9) == 9.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1266
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1267
     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
  1268
     self assert:(s indexOf:$b) == 0.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1269
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1270
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1271
     s := String new:1024.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1272
     s atAllPut:$a.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1273
     s at:512 put:(Character space).
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1274
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1275
	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
  1276
     ]
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1277
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1278
     timing (ms):
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1279
	    bcc                 OSX(2007 powerbook)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1280
	v1: 1763 normal
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1281
	    2340 +unroll
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1282
	    3308 memsrch !!       90
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1283
	v2: 1045                150
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1284
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1285
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
  1286
    "Modified: / 10-01-2012 / 17:09:34 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1287
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1288
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1289
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1290
    "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
  1291
     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
  1292
     - 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
  1293
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1294
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1295
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1296
    unsigned char *ccp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1297
    unsigned char *cp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1298
    INT index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1299
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1300
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1301
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1302
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1303
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1304
    if (__isSmallInteger(start)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  1305
     && __isStringLike(aCollectionOfCharacters)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1306
	matchP = __stringVal(aCollectionOfCharacters);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1307
	index = __intVal(start);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1308
	if (index > 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1309
	    cp = __stringVal(self) + index - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1310
	    if ((cls = __qClass(self)) != String) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1311
		cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1312
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1313
	    len = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1314
	    if (index <= len) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1315
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1316
		if (matchP[0] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1317
		    /* matchSet is empty */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1318
		    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1319
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1320
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1321
		if (matchP[1] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1322
		    /* only a single character match */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1323
		    unsigned char m = matchP[0];
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1324
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1325
# ifdef FAST_MEMCHR
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1326
		    ccp = (unsigned char *) memchr(cp, m, len+1-index);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1327
		    if (ccp) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1328
			RETURN ( __mkSmallInteger((ccp - cp) + index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1329
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1330
# else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1331
		    while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1332
			if (c == m) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1333
			    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1334
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1335
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1336
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1337
# endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1338
		    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1339
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1340
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1341
		if (matchP[2] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1342
		    /* two character matches */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1343
		    unsigned char m1 = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1344
		    unsigned char m2 = matchP[1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1345
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1346
		    while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1347
			if ((c == m1) || (c == m2)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1348
			    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1349
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1350
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1351
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1352
		    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1353
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1354
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1355
		min = max = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1356
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1357
		for (ccp = matchP+1; *ccp ; ccp++) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1358
		    unsigned char c = *ccp;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1359
		    if (c < min) min = c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1360
		    else if (c > max) max = c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1361
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1362
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1363
		while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1364
		    if ((c >= min) && (c <= max)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1365
			for (ccp = matchP; *ccp ; ccp++) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1366
			    if (*ccp == c) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1367
				RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1368
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1369
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1370
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1371
		    index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1372
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1373
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1374
	    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1375
	}
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1376
    }
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1377
%}.
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1378
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1379
    "/ 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
  1380
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1381
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1382
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1383
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1384
     'hello world' indexOfAny:'eoa' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1385
     'hello world' indexOfAny:'eoa' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1386
     'hello world' indexOfAny:'AOE' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1387
     'hello world' indexOfAny:'o' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1388
     'hello world' indexOfAny:'o' startingAt:6
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1389
     'hello world§' indexOfAny:'#§$' startingAt:6
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1390
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1391
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1392
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1393
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1394
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1395
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1396
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1397
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1398
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1399
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1400
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1401
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1402
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1403
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1404
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1405
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1406
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1407
    if (index <= 0) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1408
	index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1409
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1410
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1411
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1412
    if ((cls = __qClass(self)) != String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1413
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1414
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1415
	cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1416
	len -= numInstBytes;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1417
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1418
    while (index <= len) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1419
	REGISTER unsigned char c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1420
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1421
	c = cp[index - 1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1422
	if (c < ' ') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1423
	    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1424
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1425
	index++;
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1426
    }
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1427
    RETURN ( __mkSmallInteger(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1428
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1429
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1430
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1431
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1432
     'hello world'             indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1433
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1434
     '1\' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1435
     '1\' withCRs indexOfControlCharacterStartingAt:2
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1436
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1437
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1438
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1439
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1440
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1441
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1442
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1443
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1444
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1445
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1446
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1447
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1448
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1449
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1450
    if (index <= 0) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1451
	index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1452
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1453
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1454
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1455
    if ((cls = __qClass(self)) != String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1456
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1457
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1458
	cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1459
	len -= numInstBytes;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1460
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1461
    while (index <= len) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1462
	REGISTER unsigned char c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1463
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1464
	c = cp[index - 1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1465
	if (c > ' ') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1466
	    if ((c != ' ') && (c != '\t') && (c != '\n')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1467
	     && (c != '\r') && (c != '\f')) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1468
		RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1469
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1470
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1471
	index++;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1472
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1473
    RETURN ( __mkSmallInteger(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1474
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1475
    ^ super indexOfNonSeparatorStartingAt:start
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1476
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1477
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1478
     'hello world' indexOfNonWhiteSpaceStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1479
     'hello world' indexOfNonWhiteSpaceStartingAt:7
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1480
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1481
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1482
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1483
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1484
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1485
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1486
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1487
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1488
    if (__isSmallInteger(start)) {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1489
	REGISTER unsigned char *cp;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1490
	int len, index;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1491
	OBJ cls;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1492
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1493
	index = __intVal(start)-1;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1494
	// is this a good idea?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1495
	if (index < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1496
	    index = 0;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1497
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1498
	len = __stringSize(self);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1499
	cp = __stringVal(self);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1500
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1501
	// care for subclasses of string
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1502
	if ((cls = __qClass(self)) != String) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1503
	    int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1504
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1505
	    cp += numInstBytes;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1506
	    len -= numInstBytes;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1507
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1508
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1509
	// these pre-loops do fast skip over non-separators
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1510
	// (anything above 0x32)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1511
#if __POINTER_SIZE__ == 8
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1512
	if ((index & 7) == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1513
	    int len8 = len-8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1514
	    while (index < len8) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1515
		REGISTER unsigned INT eightChars;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1516
		REGISTER unsigned INT eightCharsMasked;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1517
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1518
		eightChars = ((unsigned INT *)(cp+index))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1519
		eightCharsMasked = eightChars & 0xE0E0E0E0E0E0E0E0ULL;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1520
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1521
		// any control char?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1522
		// (these are 0..31 and also the space);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1523
		// so we need two compares.
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1524
#               define hasZeroByte(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1525
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
19790
d99c007f4c5b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19773
diff changeset
  1526
#               define maskSpace       (~0ULL/255 * (32))
d99c007f4c5b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19773
diff changeset
  1527
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1528
		if (hasByteM(eightChars, maskSpace)) break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1529
		if (hasZeroByte(eightCharsMasked)) break;
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1530
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1531
#               undef hasZeroByte
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1532
#               undef hasByteM
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1533
#               undef maskSpace
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1534
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1535
		index += 8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1536
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1537
	}
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1538
#endif /* POINTER_SIZE == 8*/
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1539
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1540
	if ((index & 3) == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1541
	    int len4 = len-4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1542
	    while (index < len4) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1543
		REGISTER unsigned int fourChars;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1544
		REGISTER unsigned int fourCharsMasked;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1545
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1546
		fourChars = ((unsigned int *)(cp+index))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1547
		fourCharsMasked = fourChars & 0xE0E0E0E0UL;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1548
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1549
		// any control char?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1550
		// (these are 0..31 and also the space);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1551
		// so we need two compares.
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1552
#               define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1553
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1554
#               define maskSpace       (~0UL/255 * (32))
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1555
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1556
		if (hasByteM(fourChars, maskSpace)) break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1557
		if (hasZeroByte(fourCharsMasked)) break;
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1558
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1559
#               undef hasZeroByte
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1560
#               undef hasByteM
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1561
#               undef maskSpace
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1562
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1563
		index += 4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1564
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1565
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1566
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1567
	while (index < len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1568
	    REGISTER unsigned char c;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1569
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1570
	    c = cp[index];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1571
	    if (c <= ' ') {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1572
		if ((c == ' ') || (c == '\t') || (c == '\n')
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1573
		 || (c == '\r') || (c == '\f')) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1574
		    RETURN ( __mkSmallInteger(index+1) );
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1575
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1576
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1577
	    index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1578
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1579
	RETURN ( __mkSmallInteger(0) );
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1580
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1581
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1582
    ^ super indexOfSeparatorStartingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1583
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1584
    " 123456789012
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1585
     'hello world ' indexOfSeparatorStartingAt:1 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1586
     'hello world ' indexOfSeparatorStartingAt:3 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1587
     'hello world ' indexOfSeparatorStartingAt:7 -> 12
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1588
     'hello world' indexOfSeparatorStartingAt:7  -> 0
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1589
     'helloworld' indexOfSeparatorStartingAt:1   -> 0
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1590
    "
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1591
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1592
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1593
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1594
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1595
     self assert:(s indexOfSeparatorStartingAt:1) == 0.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1596
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1597
	 1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1598
     ]
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1599
     original (char-wise):760 760 750
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1600
     with 4-byte at a time: 640 650 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1601
     with 8-byte at a time: 300 290 320
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1602
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1603
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1604
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1605
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1606
     s at:400 put:(Character return).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1607
     self assert:(s indexOfSeparatorStartingAt:1) == 400.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1608
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1609
	 1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1610
     ]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1611
     original (char-wise):340 350
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1612
     with 4-byte at a time: 310 290 280
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1613
     with 8-byte at a time: 150 140 140
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1614
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1615
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1616
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1617
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1618
     s at:999 put:(Character space).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1619
     self assert:(s indexOfSeparatorStartingAt:1) == 999.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1620
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1621
	 1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1622
     ]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1623
     original (char-wise): 750 750 790
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1624
     with 4-byte at a time: 640 640 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1625
     with 8-byte at a time: 280 290 300
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1626
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1627
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1628
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1629
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1630
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1631
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1632
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1633
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1634
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1635
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1636
    REGISTER unsigned byteValue;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1637
    REGISTER INT count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1638
    OBJ cls;
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
    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
  1641
	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
  1642
	count = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1643
	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
  1644
	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
  1645
	    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
  1646
	    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
  1647
		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
  1648
		limit -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1649
		cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1650
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1651
	    /* 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
  1652
	     * (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
  1653
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1654
	    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
  1655
		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
  1656
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1657
		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
  1658
		limit -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1659
		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
  1660
		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
  1661
		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
  1662
		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
  1663
		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
  1664
		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
  1665
		cp += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1666
		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
  1667
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1668
	    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
  1669
		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
  1670
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1671
		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
  1672
		limit--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1673
		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
  1674
		cp ++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1675
	    }
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
	RETURN ( __mkSmallInteger(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1678
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1679
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1680
    ^ super occurrencesOf:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1681
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1682
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1683
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1684
     'hello world' occurrencesOf:$w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1685
     'hello world' occurrencesOf:$l
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1686
     'hello world' occurrencesOf:$x
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1687
     'hello world' occurrencesOf:1
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1688
     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
  1689
	1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ]
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1690
     ]. 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
  1691
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1692
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1693
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1694
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1695
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1696
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1697
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1698
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1699
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1700
     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
  1701
     'foo' < 'Foo' will return false.
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1702
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1703
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1704
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1705
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1706
    return context._RETURN( self.stringLtP(aString) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1707
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1708
#else
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1709
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1710
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1711
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1712
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1713
    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
  1714
	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
  1715
	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
  1716
	    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
  1717
	    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
  1718
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1719
	     * 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
  1720
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1721
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1722
		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
  1723
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1724
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1725
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1726
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1727
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1728
	    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
  1729
	    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
  1730
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1731
	     * 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
  1732
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1733
	    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
  1734
		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
  1735
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1736
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1737
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1738
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1739
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1740
	    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
  1741
		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
  1742
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1743
		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
  1744
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1745
	    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
  1746
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1747
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1748
	    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
  1749
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1750
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1751
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1752
	}
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1753
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1754
#endif
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1755
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1756
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1757
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1758
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1759
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1760
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1761
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1762
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1763
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1764
375
claus
parents: 370
diff changeset
  1765
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1766
#ifdef __SCHTEAM__
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1767
    if (aString == self) {
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1768
	return __c__._RETURN_true();
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1769
    }
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1770
    if (aString.isStringLike()) {
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1771
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False );
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1772
    }
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1773
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1774
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1775
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1776
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1777
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1778
    unsigned char *cp1, *cp2;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1779
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1780
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1781
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1782
    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
  1783
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1784
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1785
    if (! __isNonNilObject(aString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1786
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1787
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1788
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1789
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1790
    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
  1791
	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
  1792
	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
  1793
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1794
	 * 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
  1795
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1796
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1797
	    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
  1798
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1799
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1800
	    l2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1803
	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
  1804
	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
  1805
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1806
	 * 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
  1807
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1808
	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
  1809
	    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
  1810
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1811
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1812
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1813
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1814
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1815
	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
  1816
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1817
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1818
# 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
  1819
	RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1820
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1821
	addrDelta = cp2 - cp1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1822
#  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
  1823
	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
  1824
	    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
  1825
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1826
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1827
	    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
  1828
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1829
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1830
	    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
  1831
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1832
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1833
	    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
  1834
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1835
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1836
	    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
  1837
	    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
  1838
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1839
#  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
  1840
	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
  1841
	    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
  1842
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1843
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1844
	    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
  1845
	    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
  1846
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1847
	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
  1848
	    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
  1849
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1850
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1851
	    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
  1852
	    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
  1853
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1854
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1855
	    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
  1856
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1857
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1858
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1859
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1860
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1861
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1862
	RETURN (true);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1863
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1864
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1865
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1866
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1867
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1868
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1869
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1870
     'foo' = 'Foo'
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1871
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1872
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1873
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1874
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1875
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1876
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1877
     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
  1878
	 1000000 timesRepeat:[]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1879
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1880
     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
  1881
	 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1882
     ].
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1883
     tCmp - tEmpty
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1884
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1885
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1886
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1887
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1888
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1889
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1890
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1891
     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
  1892
     'foo' > 'Foo' will return true.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1893
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1894
375
claus
parents: 370
diff changeset
  1895
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1896
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1897
    return context._RETURN( aString.stringLtP( self ) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1898
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1899
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1900
    int len1, len2, cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1901
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1902
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1903
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1904
    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
  1905
	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
  1906
	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
  1907
	    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
  1908
	    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
  1909
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1910
	     * 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
  1911
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1912
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1913
		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
  1914
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1915
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1916
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1917
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1918
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1919
	    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
  1920
	    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
  1921
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1922
	     * 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
  1923
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1924
	    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
  1925
		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
  1926
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1927
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1928
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1929
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1930
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1931
	    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
  1932
		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
  1933
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1934
		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
  1935
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1936
	    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
  1937
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1938
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1939
	    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
  1940
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1941
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1942
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1943
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1944
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1945
#endif /* not __SCHTEAM__ */
370
claus
parents: 368
diff changeset
  1946
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1947
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1948
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1949
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1950
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1951
    "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
  1952
     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
  1953
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1954
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1955
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1956
    ^ self compareWith:aString collating:true
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1957
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1958
    "
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1959
     'hallo' compareWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1960
     'hbllo' compareWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1961
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1962
     'hallo' compareCollatingWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1963
     'hbllo' compareCollatingWith:'hällo'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1964
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1965
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1966
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1967
compareWith:aString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1968
    "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
  1969
     greater, 0 if equal and -1 if less than the argument.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1970
     This comparison is based on the elements' codepoints -
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1971
     i.e. upper/lowercase & national characters are NOT treated specially.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1972
     'foo' compareWith: 'Foo' will return 1.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1973
     while 'foo' sameAs:'Foo' will return true"
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1974
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1975
    ^ self compareWith:aString collating:false
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1976
!
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1977
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1978
compareWith:aString collating:collatingBoolean
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1979
    "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
  1980
     greater, 0 if equal and -1 if less than the argument.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1981
     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
  1982
     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
  1983
     otherwise, it will be a simple string-compare.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1984
     This comparison is based on the elements' codepoints -
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1985
     i.e. upper/lowercase & national characters are NOT treated specially.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1986
     'foo' compareWith: 'Foo' will return 1.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1987
     while 'foo' sameAs:'Foo' will return true"
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1988
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1989
%{  /* NOCONTEXT */
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1990
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1991
    int cmp;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1992
    unsigned char *cp1, *cp2;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1993
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1994
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1995
    if (__isNonNilObject(aString)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1996
	argIsString = __qIsStringLike(aString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1997
	if (argIsString || __qClass(aString) == __qClass(self)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1998
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1999
	    // care for instances of subclasses ...
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2000
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2001
	    cp1 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2002
	    if (!__qIsStringLike(self)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2003
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2004
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2005
		cp1 += n;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2006
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2007
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2008
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2009
	    // care for instances of subclasses ...
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2010
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2011
	    cp2 = __stringVal(aString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2012
	    if (!argIsString) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2013
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2014
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2015
		cp2 += n;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2016
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2017
	    if (collatingBoolean == true) {
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2018
#ifdef HAS_STRCOLL
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2019
		cmp = strcoll(cp1, cp2);
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2020
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2021
		// bail out, to give programmer a chance to do it in Smalltalk (inherited)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2022
		goto getOutOfHere;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2023
#endif
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2024
	    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2025
		cmp = strcmp(cp1, cp2);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2026
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2027
	    {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2028
		// int signum = (cmp>0) ? 1 : ((cmp<0) ? -1 : 0);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2029
		int signum = (cmp > 0) - (cmp < 0);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2030
		RETURN( __mkSmallInteger( signum ) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2031
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2032
	}
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2033
    }
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2034
getOutOfHere: ;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2035
%}.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2036
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2037
     currently, this operation is only defined for strings, symbols and subclasses.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2038
     allow for an implementation in Smalltalk
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2039
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2040
    ^ super compareWith:aString collating:collatingBoolean
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2041
!
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2042
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2043
hash
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2044
    "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
  2045
     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
  2046
     used in the ST/X VM (which is actually fnv-1a)"
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2047
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2048
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2049
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2050
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2051
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2052
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2053
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2054
    extern unsigned int __symbolHash(char *);
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2055
    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
  2056
    unsigned int h;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2057
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2058
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2059
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2060
    }
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2061
    h = __symbolHash(cp);
16891
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2062
    // make sure, it fits into a smallInt
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2063
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2064
    RETURN(__mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2065
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2066
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2067
    ^ self primitiveFailed
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2068
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2069
    "
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2070
     'a' hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2071
     'ab' hash = 'ab' asUnicode16String hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2072
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2073
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2074
    "Created: / 26-12-2011 / 13:53:09 / cg"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2075
!
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2076
13880
Claus Gittinger <cg@exept.de>
parents: 13205
diff changeset
  2077
hash_dragonBook
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2078
    "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
  2079
     This method implements the dragon-book algorithm (aho, ullman)."
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2080
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2081
%{  /* NOCONTEXT */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2082
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2083
    REGISTER unsigned g, val;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2084
    REGISTER unsigned char *cp, *cp0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2085
    int l;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2086
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2087
    cp = __stringVal(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2088
    l = __stringSize(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2089
    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
  2090
	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
  2091
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2092
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2093
	l -= n;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2094
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2095
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2096
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2097
     * this is the dragon-book algorithm
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2098
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2099
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2100
    val = 0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2101
    switch (l) {
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2102
    default:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2103
	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
  2104
	    val = (val << 4) + *cp;
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  2105
	    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
  2106
		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
  2107
		val ^= g;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2108
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2109
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2110
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2111
    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
  2112
	val = cp[5] << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2113
    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
  2114
	val = (val + cp[4]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2115
    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
  2116
	val = (val + cp[3]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2117
    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
  2118
	val = (val + cp[2]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2119
    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
  2120
	val = (val + cp[1]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2121
    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
  2122
	val = val + cp[0];
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2123
    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
  2124
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2125
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2126
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2127
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2128
     * multiply by large prime to spread values
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2129
     * This speeds up Set and Dictionary by a factor of 10!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2130
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2131
    val *= 31415821;
12763
e19933d3e188 changed:
Stefan Vogel <sv@exept.de>
parents: 12727
diff changeset
  2132
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2133
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2134
    ^ self primitiveFailed
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2135
!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2136
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2137
hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2138
    "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
  2139
     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
  2140
     (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
  2141
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2142
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2143
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2144
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2145
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2146
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2147
#else
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2148
    REGISTER unsigned int h  = 2166136261u;
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2149
    REGISTER unsigned char *cp = __stringVal(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2150
    INT l  = __stringSize(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2151
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2152
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2153
	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
  2154
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2155
	cp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2156
	l -= n;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2157
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2158
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2159
    while (l >= 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2160
	l -= 4;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2161
	h = (h ^ cp[0]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2162
	h = (h ^ cp[1]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2163
	h = (h ^ cp[2]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2164
	h = (h ^ cp[3]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2165
	cp += 4;
16889
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
    while (l--) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2168
	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
  2169
    }
16900
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2170
    // make it a smallInteger
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2171
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2172
    RETURN ( __mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2173
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2174
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2175
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2176
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2177
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2178
     'a' hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2179
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2180
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2181
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2182
hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2183
    "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
  2184
     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
  2185
     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
  2186
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2187
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2188
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2189
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2190
    long h = me.hash_java();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2191
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2192
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2193
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2194
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2195
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2196
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2197
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2198
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2199
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2200
	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
  2201
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2202
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2203
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2204
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2205
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
     * 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
  2208
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2209
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2210
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2211
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2212
	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
  2213
	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
  2214
	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
  2215
	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
  2216
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2217
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2218
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2219
	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
  2220
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2221
    RETURN ( __MKUINT(val));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2222
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2223
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2224
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2225
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
     'a' hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2228
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2229
!
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
hash_sdbm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2232
    "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
  2233
     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
  2234
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2235
%{  /* NOCONTEXT */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2236
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2237
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2238
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2239
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2240
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2241
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2242
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2243
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2244
	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
  2245
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2246
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2247
	l -= n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2248
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2249
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2250
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2251
     * 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
  2252
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2253
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2254
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2255
	l -= 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2256
	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
  2257
	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
  2258
	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
  2259
	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
  2260
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2261
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2262
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2263
	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
  2264
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2265
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2266
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2267
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2268
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2269
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2270
     'a' hash
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2271
     '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
  2272
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2273
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2274
    "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
  2275
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2276
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2277
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2278
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2279
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2280
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2281
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2282
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2283
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2284
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2285
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2286
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2287
#ifdef __SCHTEAM__
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2288
    if (aString == self) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2289
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2290
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2291
    if (aString.isStringLike()) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2292
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True );
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2293
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2294
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2295
	return __c__._RETURN_true();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2296
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2297
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2298
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  2299
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2300
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  2301
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2302
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2303
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2304
    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
  2305
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2306
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2307
    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
  2308
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2309
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2310
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2311
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2312
    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
  2313
	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
  2314
	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
  2315
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2316
	 * 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
  2317
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2318
	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
  2319
	    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
  2320
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2321
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2322
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2323
	}
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
	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
  2326
	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
  2327
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2328
	 * 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
  2329
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2330
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2331
	    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
  2332
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2333
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2334
	    l2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2337
	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
  2338
	    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2339
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2340
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2341
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2342
# 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
  2343
	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
  2344
	    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
  2345
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2346
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2347
	    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
  2348
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2349
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2350
	    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
  2351
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2352
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2353
	    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
  2354
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2355
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2356
	    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
  2357
	    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
  2358
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2359
# 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
  2360
	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
  2361
	    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
  2362
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2363
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2364
	    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
  2365
	    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
  2366
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2367
	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
  2368
	    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
  2369
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2370
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2371
	    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
  2372
	    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
  2373
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2374
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2375
	    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
  2376
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2377
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2378
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2379
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2380
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2381
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2382
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2383
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2384
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2385
    ^ super ~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2386
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2387
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2388
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2389
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2390
asArrayOfSubstrings
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2391
    "Answer an array with all the substrings of the receiver separated by
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2392
     separator characters (space, cr, tab, linefeed, formfeed, etc).
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2393
     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
  2394
	 the inherited one... after all: who added it anyway ?"
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2395
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2396
    | substrings start end stop |
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2397
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2398
    substrings := OrderedCollection new.
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2399
    start := 1.
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2400
    stop := self size.
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  2401
    [start <= stop] whileTrue: [
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2402
	(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
  2403
	    end := start + 1.
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2404
	    [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
  2405
		whileTrue: [end := end + 1].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2406
	    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
  2407
	    start := end - 1
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2408
	].
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2409
	start := start + 1
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2410
    ].
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  2411
    ^ substrings asArray
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2412
!
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2413
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2414
asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2415
    "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
  2416
     with an additional 0-character. Otherwise return the receiver. This is sometimes
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2417
     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
  2418
     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
  2419
     strings are not."
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2420
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2421
    ^ self
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2422
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2423
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2424
     'abc' asAsciiZ
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2425
     'abc' asWideString asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2426
    "
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2427
!
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2428
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2429
asByteArray
15938
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2430
    "return a new ByteArray with the receiver's elements.
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2431
     This redefined method is faster than Collection>>#asByteArray"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2432
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2433
    |bytes sz|
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2434
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2435
    sz := self size.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2436
    bytes := ByteArray new:sz .
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2437
    bytes replaceFrom:1 to:sz with:self startingAt:1.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2438
    ^ bytes
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2439
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2440
    "
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  2441
     'fooBar' asByteArray.
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2442
    "
14260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2443
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2444
    "Modified (comment): / 26-07-2012 / 22:55:26 / cg"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2445
!
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2446
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2447
asExternalBytes
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2448
    "return a 0-terminated externalBytes collection containing
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2449
     my characters.
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2450
     The returned collection is save from being garbage collected;
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2451
     i.t. it can be handed to a C-function, and must
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2452
     (either there or here) be freed explicitly or unprotectedFromGC"
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2453
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2454
    ^ (ExternalBytes new:(self size + 1))
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2455
	replaceNullTerminatedFromString:self
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2456
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2457
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2458
     |x|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2459
     x := 'fooBar' asExternalBytes.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2460
     x unprotectFromGC.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2461
     ObjectMemory garbageCollect
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2462
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2463
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2464
    "Modified: / 03-08-2006 / 14:45:32 / fm"
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2465
!
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2466
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2467
asExternalBytesUnprotected
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2468
    "Like asExternalBytes, but does not register the bytes so
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2469
     bytes are GARBAGE-COLLECTED!!"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2470
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2471
    ^ (ExternalBytes unprotectedNew:(self size + 1))
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2472
	replaceNullTerminatedFromString:self
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2473
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2474
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2475
     |x|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2476
     x := 'fooBar' asExternalBytesUnprotected.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2477
     ObjectMemory garbageCollect
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2478
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2479
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2480
    "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
  2481
    "Modified: / 30-11-2013 / 11:41:40 / cg"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2482
!
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2483
12454
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2484
asImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2485
    "return a write-protected copy of myself"
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2486
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2487
    ^ self copy changeClassTo:ImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2488
!
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2489
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2490
asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2491
    "a tuned version for Strings with size < 255. Some apps call this very heavily.
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2492
     We can do this for 8-bit strings, since the mapping is well known and lowercase chars 
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2493
     fit in one byte also."
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2494
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2495
%{  /* NOCONTEXT */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2496
#ifndef __SCHTEAM__
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2497
    REGISTER OBJ slf = self;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2498
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2499
    if (__isStringLike(slf)) {
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2500
        char quickBuffer[256];
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2501
        int sz = __stringSize(slf);
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2502
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2503
        if (sz < (sizeof(quickBuffer)-1)) {
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2504
            REGISTER int i = 0;
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2505
            int anyChange = 0;
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2506
            REGISTER unsigned char *cp = __stringVal(slf);
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2507
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2508
            // fast advance
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2509
            // all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z)
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2510
            // or 0xC0 .. 0xDF.
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2511
            // I.e. they have the 0x20 bit clear.
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2512
            // Thus, we can fast skip over lowercase, spaces and some punctuation,
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2513
            // if all bytes of a word have the x20 bit set.
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2514
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2515
#if __POINTER_SIZE__ == 8
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2516
            for (; i < (sz-8); i += 8) {
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2517
                unsigned INT eightChars = *(unsigned INT *)(cp+i);
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2518
                if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) goto convert;
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2519
                *(unsigned INT *)(quickBuffer+i) = eightChars;
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2520
            }
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2521
#endif
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2522
            for (; i < (sz-4); i += 4) {
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2523
                unsigned int fourChars = *(unsigned int *)(cp+i);
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2524
                if ((fourChars & 0x20202020U) != 0x20202020U) break;
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2525
                *(unsigned int *)(quickBuffer+i) = fourChars;
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2526
            }
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2527
convert:
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2528
            for (; i<sz; i++) {
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2529
                unsigned char ch = cp[i];
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2530
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2531
                quickBuffer[i] = ch;
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2532
                if ((ch & 0x60) == 0x40) {
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2533
                    if (ch >= 'A' && ch <= 'Z') {
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2534
                        quickBuffer[i] = ch - 'A' + 'a';
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2535
                        anyChange = 1;
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2536
                    } else {
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2537
                        // deal with national latin1 characters
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2538
                        if (ch >= 0xC0 && ch <= 0xDE && ch != 0xD7) {
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2539
                            quickBuffer[i] = ch + 0x20;
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2540
                            anyChange = 1;
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2541
                        }
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2542
                    }
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2543
                }
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2544
            }
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2545
            if (! anyChange) {
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2546
                RETURN(slf);
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2547
            }
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2548
            quickBuffer[i] = '\0';
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2549
            RETURN (__MKSTRING_L(quickBuffer, i));
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2550
        }
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2551
    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2552
#endif /* ! __SCHTEAM__ */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2553
%}.
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2554
    ^ super asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2555
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2556
    "
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2557
        'Hello WORLD' asLowercase
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2558
        (String new:300) asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2559
    "
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2560
!
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2561
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2562
asPackageId
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2563
    "given a package-string as receiver, return a packageId object.
14566
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2564
     packageIds hide the details of module/directory handling inside the path.
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2565
     See PackageId for the required format of those strings."
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  2566
14571
6e2375384861 class: String
Claus Gittinger <cg@exept.de>
parents: 14566
diff changeset
  2567
    ^ PackageId from: self
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2568
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2569
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2570
     '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
  2571
     '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
  2572
     'stx:hello' asPackageId
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2573
    "
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2575
    "Created: / 18-08-2006 / 12:19:54 / cg"
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2576
!
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2577
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  2578
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2579
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2580
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2581
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2582
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2583
11287
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2584
asSingleByteStringIfPossible
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2585
    "I am a single-byte string"
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2586
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2587
    ^ self
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2588
!
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2589
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2590
asSingleByteStringReplaceInvalidWith:replacementCharacter
11883
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2591
    "return the receiver converted to a 'normal' string,
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2592
     with invalid characters replaced by replacementCharacter.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2593
     Can be used to convert from 16-bit strings to 8-bit strings
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2594
     and replace characters above code-255 with some replacement.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2595
     Dummy here, because I am already a single byte string."
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2596
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2597
    ^ self
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2598
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2599
    "Modified: / 07-08-2006 / 15:04:45 / fm"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2600
!
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2601
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2602
asSymbol
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2603
    "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
  2604
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2605
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2606
#ifdef __SCHTEAM__
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2607
    return context._RETURN( STSymbol._new(self.asString()) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2608
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2609
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2610
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2611
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2612
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2613
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2614
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2615
    if (cls != String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2616
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2617
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2618
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2619
    if (newSymbol) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2620
	RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2621
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2622
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2623
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2624
    ^ ObjectMemory allocationFailureSignal raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2625
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2626
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2627
     'hello' asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2628
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2629
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2630
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2631
asSymbolIfInterned
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2632
    "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
  2633
     This can be used to query for an existing symbol and is the same as:
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2634
        self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2635
     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
  2636
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2637
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2638
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2639
#ifdef __SCHTEAM__
18622
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2640
    STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() );
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2641
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2642
    return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2643
#else
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2644
    OBJ cls = __qClass(self);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2645
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2646
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2647
    if (cls != String && cls != ImmutableString) {
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2648
        indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2649
    } else {
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2650
        indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2651
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2652
    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
  2653
#endif /* not __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2654
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2655
    ^ self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2656
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2657
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2658
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2659
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2660
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2661
17378
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2662
beImmutable
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2663
    "make myself write-protected"
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2664
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2665
    self changeClassTo:ImmutableString
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2666
!
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2667
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2668
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2669
    "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
  2670
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2671
     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
  2672
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2673
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2674
     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
  2675
     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
  2676
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2677
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2678
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2679
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2680
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2681
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2682
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2683
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2684
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2685
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2686
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2687
     && __isSmallInteger(numSpaces)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2688
	n = __intVal(numSpaces);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2689
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2690
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2691
	 * for small strings (< 80), do it without a prescan ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2692
	 * the buffer is large enough to even convert a
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2693
	 * receiver consisting fully of tabs.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2694
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2695
	if (__stringSize(self) < 80) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2696
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2697
	    for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2698
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2699
		    any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2700
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2701
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2702
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2703
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2704
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2705
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2706
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2707
		    *dstP++ = c;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2708
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2709
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2710
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2711
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2712
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2713
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2714
	    if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2715
	    *dstP = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2716
	    RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2717
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2718
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2719
	 * for large strings, we compute the new size, allocate a new string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2720
	 * and expand it.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2721
	 *
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2722
	 * first, scan for size ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2723
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2724
	idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2725
	for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2726
	    if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2727
		any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2728
		while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2729
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2730
		    sz++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2731
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2732
		idx++; sz ++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2733
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2734
		sz++; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2735
		if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2736
		    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2737
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2738
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2739
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2740
	if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2741
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2742
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2743
	 * get the string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2744
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2745
	sz = OHDR_SIZE + sz + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2746
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2747
	if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2748
	    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2749
	    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2750
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2751
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2752
	     * expand
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2753
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2754
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2755
	    for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2756
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2757
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2758
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2759
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2760
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2761
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2762
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2763
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2764
		    *dstP++ = c; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2765
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2766
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2767
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2768
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2769
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2770
	    *dstP++ = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2771
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2772
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2773
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2774
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2775
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2776
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2777
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2778
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2779
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2780
, aStringOrCharacter
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2781
    "return the concatenation of myself and the argument, aStringOrCharacter as a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2782
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2783
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2784
%{
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2785
#ifdef __SCHTEAM__
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2786
    if ( aStringOrCharacter.isStringLike() && self.isStringLike() ) {
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2787
        STString me = self.asSTString();
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2788
        STString other = aStringOrCharacter.asSTString();
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2789
        int myLength = me.characters.length;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2790
        int otherLength = other.characters.length;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2791
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2792
        char[] newChars = new char[myLength + otherLength];
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2793
        System.arraycopy(me.characters, 0, newChars, 0, myLength);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2794
        System.arraycopy(other.characters, 0, newChars, myLength, otherLength);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2795
        return context._RETURN( new STString( newChars ));
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2796
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2797
#else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2798
    /*
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2799
     * can do it here if both are Strings/Symbols:
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2800
     */
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2801
    if (__qIsStringLike(self)) {
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2802
        char *cp1 = (char *) __stringVal(self);
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2803
        int l1 = __stringSize(self);
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2804
        int l2;
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2805
        char *cp2 = 0;
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2806
        int sz;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2807
        OBJ newString;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2808
        char character;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2809
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2810
        if (__isCharacter(aStringOrCharacter)) {
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2811
            if (__intVal(__characterVal(aStringOrCharacter)) <= 0 || __intVal(__characterVal(aStringOrCharacter)) > 255)
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2812
                goto out;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2813
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2814
            character = __intVal(__characterVal(aStringOrCharacter));
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2815
            l2 = 1;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2816
            cp2 = &character;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2817
        } else if (__isStringLike(aStringOrCharacter)) {
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2818
            l2 = __stringSize(aStringOrCharacter);
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2819
        } else
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2820
            goto out;
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2821
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2822
        sz = OHDR_SIZE + l1 + l2 + 1;
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2823
        __qNew(newString, sz);      /* OBJECT ALLOCATION */
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2824
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2825
        cp1 = (char *) __stringVal(self);
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2826
        if (cp2 == 0) 
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2827
            cp2 = (char *) __stringVal(aStringOrCharacter);
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2828
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2829
        if (newString != nil) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2830
            REGISTER unsigned char *dstp;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2831
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2832
            __InstPtr(newString)->o_class = String;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2833
            __qSTORE(newString, String);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2834
            dstp = __stringVal(newString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2835
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2836
# if defined(bcopy4)
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2837
            /* knowing that allocation is 4-byte aligned and
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2838
             * size rounded up to next 4-byte, the first copy
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2839
             * can be done word-wise.
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2840
             * that speeds up size-10-string , size-10-string
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2841
             * by 10% on a P5/200.
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2842
             */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2843
            {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2844
                int nw = l1 >> 2;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2845
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2846
                if (l1 & 3) nw++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2847
                bcopy4(cp1, dstp, nw);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2848
                dstp += l1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2849
            }
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2850
# elif defined(FAST_MEMCPY)
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2851
            memcpy(dstp, cp1, l1);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2852
            dstp += l1;
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2853
# else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2854
            while (l1 >= 4) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2855
                *(int *)dstp = *(int *)cp1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2856
                dstp += 4; cp1 += 4;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2857
                l1 -= 4;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2858
            }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2859
            while (l1--) *dstp++ = *cp1++;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2860
# endif
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2861
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2862
# ifdef bcopy4
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2863
            if (((INT)dstp & 3) == 0) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2864
                int nw = l2 >> 2;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2865
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2866
                if (l2 & 3) nw++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2867
                bcopy4(cp2, dstp, nw);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2868
                *(dstp + l2) = '\0';
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2869
                RETURN ( newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2870
            }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2871
# endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2872
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2873
# ifdef FAST_MEMCPY
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2874
            memcpy(dstp, cp2, l2+1);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2875
            dstp[l2] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2876
# else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2877
            while (l2--) *dstp++ = *cp2++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2878
            *dstp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2879
# endif
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2880
            RETURN ( newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2881
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2882
    }
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2883
out:;
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2884
#endif /* not SCHTEAM */
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2885
%}.
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2886
    ^ super , aStringOrCharacter
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2887
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2888
    "
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2889
     'hello' , ' world' asImmutableString
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2890
     'hello ' , #world
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2891
     'hello ' , $w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2892
     #[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
  2893
    "
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2894
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2895
    "Modified: / 01-04-2012 / 13:19:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2896
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2897
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2898
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2899
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2900
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2901
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2902
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2903
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2904
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2905
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2906
    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
  2907
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2908
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2909
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2910
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2911
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2912
    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
  2913
	    && __isStringLike(string1)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2914
	    && __isStringLike(string2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2915
	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
  2916
	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
  2917
	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
  2918
	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
  2919
	__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
  2920
	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
  2921
	    __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
  2922
	    __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
  2923
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2924
#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
  2925
	    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
  2926
	    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
  2927
	    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
  2928
	    *(dstp + len1 + len2 + len3) = '\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
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2937
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2938
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2939
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2940
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2941
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2942
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2943
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2944
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2945
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2946
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2947
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2948
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2949
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2950
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2951
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2952
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2953
    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
  2954
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2955
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2956
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2957
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2958
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2959
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2960
     && __isStringLike(string1)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2961
     && __isStringLike(string2)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2962
     && __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
  2963
	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
  2964
	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
  2965
	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
  2966
	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
  2967
	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
  2968
	__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
  2969
	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
  2970
	    __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
  2971
	    __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
  2972
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2973
#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
  2974
	    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
  2975
	    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
  2976
	    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
  2977
	    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
  2978
	    *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2979
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2980
	    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
  2981
	    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
  2982
	    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
  2983
	    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
  2984
	    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
  2985
	    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
  2986
	    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
  2987
	    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
  2988
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2989
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2990
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2991
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2992
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2993
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2994
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2995
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2996
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2997
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2998
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2999
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3000
    (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
  3001
	^ self copyFrom:1
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3002
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3003
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3004
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3005
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3006
copyFrom:start
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3007
    "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
  3008
     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
  3009
     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
  3010
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3011
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3012
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3013
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3014
#if !defined(FAST_MEMCPY)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3015
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3016
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3017
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3018
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3019
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3020
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3021
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3022
#ifndef NO_PRIM_STRING
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3023
    if (__isSmallInteger(start) && __qIsStringLike(self)) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3024
        len = __stringSize(self);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3025
        index1 = __intVal(start);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3026
        if (index1 > 0) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3027
            if (index1 <= len) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3028
                count = len - index1 + 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3029
                sz = OHDR_SIZE + count + 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3030
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3031
                __PROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3032
                __qNew(newString, sz);  /* OBJECT ALLOCATION */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3033
                __UNPROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3034
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3035
                if (newString != nil) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3036
                    __InstPtr(newString)->o_class = String;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3037
                    __qSTORE(newString, String);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3038
                    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3039
#ifdef FAST_MEMCPY
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3040
                    memcpy(dstp, __stringVal(self) + index1 - 1, count);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3041
                    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3042
#else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3043
                    srcp = __stringVal(self) + index1 - 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3044
                    while (count--) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3045
                        *dstp++ = *srcp++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3046
                    }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3047
                    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3048
#endif
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3049
                    RETURN ( newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3050
                }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3051
            }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3052
        }
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3053
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3054
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3055
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3056
    "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
  3057
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3058
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3059
    ^ super copyFrom:start
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3060
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3061
    "
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3062
        '12345' copyFrom:3
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3063
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3064
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3065
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3066
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3067
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3068
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3069
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3070
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3071
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3072
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3073
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3074
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3075
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3076
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3077
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3078
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3079
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3080
#ifndef NO_PRIM_STRING
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3081
    if (__bothSmallInteger(start, stop) && __qIsStringLike(self)) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3082
        len = __stringSize(self);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3083
        index1 = __intVal(start);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3084
        index2 = __intVal(stop);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3085
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3086
        if ((index1 <= index2) && (index1 > 0)) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3087
            if (index2 <= len) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3088
                count = index2 - index1 + 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3089
                sz = OHDR_SIZE + count + 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3090
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3091
                __PROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3092
                __qNew(newString, sz);  /* OBJECT ALLOCATION */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3093
                __UNPROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3094
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3095
                if (newString != nil) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3096
                    __InstPtr(newString)->o_class = String;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3097
                    __qSTORE(newString, String);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3098
                    dstp = __stringVal(newString);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3099
                    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3100
#ifdef bcopy4
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3101
                    {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3102
                        int nw = count >> 2;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3103
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3104
                        if (count & 3) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3105
                            nw++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3106
                        }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3107
                        bcopy4(srcp, dstp, nw);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3108
                        dstp[count] = '\0';
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3109
                    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3110
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3111
# ifdef FAST_MEMCPY
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3112
                    memcpy(dstp, srcp, count);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3113
                    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3114
# else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3115
                    while (count--) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3116
                        *dstp++ = *srcp++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3117
                    }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3118
                    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3119
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3120
#endif
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3121
                    RETURN ( newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3122
                }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3123
            }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3124
        }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3125
        /*
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3126
         * allow empty copy
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3127
         */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3128
        if (index1 > index2) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3129
            __PROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3130
            __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3131
            __UNPROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3132
            if (newString != nil) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3133
                __InstPtr(newString)->o_class = String;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3134
                (__stringVal(newString))[0] = '\0';
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3135
                RETURN ( newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3136
            }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3137
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3138
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3139
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3140
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3141
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3142
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3143
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3144
    ^ super copyFrom:start to:stop
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3145
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3146
    "
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3147
        '12345678' copyFrom:3 to:7
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3148
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3149
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3150
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3151
copyWith:aCharacter
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3152
    "return a new string containing the receiver's characters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3153
     and the single new character, aCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3154
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3155
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3156
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3157
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3158
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3159
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3160
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3161
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3162
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3163
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3164
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3165
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3166
    if (__isCharacter(aCharacter)) {
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3167
        unsigned int cVal = __intVal(__characterVal(aCharacter));
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3168
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3169
        if ((cVal <= 0xFF) && __qIsStringLike(self)) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3170
            count = __stringSize(self);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3171
            sz = OHDR_SIZE + count + 1 + 1;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3172
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3173
            __PROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3174
            __qNew(newString, sz);  /* OBJECT ALLOCATION */
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3175
            __UNPROTECT_CONTEXT__
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3176
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3177
            if (newString) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3178
                __InstPtr(newString)->o_class = String;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3179
                __qSTORE(newString, String);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3180
                dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3181
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3182
# ifdef bcopy4
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3183
                {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3184
                    int nw = count >> 2;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3185
                    char *srcp = (char *)__stringVal(self);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3186
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3187
                    if (count & 3) {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3188
                        nw++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3189
                    }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3190
                    bcopy4(srcp, dstp, nw);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3191
                    dstp += count;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3192
                }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3193
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3194
#  ifdef FAST_MEMCPY
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3195
                memcpy(dstp, __stringVal(self), count);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3196
                dstp += count;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3197
#  else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3198
                {
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3199
                    REGISTER unsigned char *srcp;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3200
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3201
                    srcp = __stringVal(self);
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3202
                    while ((*dstp = *srcp++) != '\0')
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3203
                        dstp++;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3204
                }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3205
#  endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3206
# endif
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3207
                *dstp++ = cVal;
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3208
                *dstp = '\0';
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3209
                RETURN (newString );
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3210
            }
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3211
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3212
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3213
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3214
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3215
    "fall back in case of non-character arg;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3216
     will eventually lead to an bad element signal raise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3217
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3218
    ^ super copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3219
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3220
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3221
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3222
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3223
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3224
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3225
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3226
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3227
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3228
    (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
  3229
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3230
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3231
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3232
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3233
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3234
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  3235
    "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
  3236
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3237
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3238
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3239
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3240
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3241
    (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
  3242
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3243
    ].
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3244
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3245
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3246
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3247
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3248
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3249
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3250
    (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
  3251
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3252
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3253
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3254
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3255
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3256
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3257
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3258
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3259
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3260
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3261
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3262
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3263
    (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
  3264
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3265
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  3266
    ^ super simpleDeepCopy
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3267
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3268
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  3269
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  3270
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3271
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3272
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3273
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3274
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3275
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3276
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3277
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3278
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3279
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  3280
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3281
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3282
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3283
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3284
    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
  3285
	byteValue = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3286
	if ((unsigned)byteValue <= 0xFF) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3287
	    l = __stringSize(self);
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3288
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3289
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3290
	    if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3291
		memset(__stringVal(self), byteValue, l);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3292
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3293
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3294
	    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3295
		INT v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3296
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3297
		v = (byteValue << 8) | byteValue;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3298
		v = (v << 16) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3299
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3300
		dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3301
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3302
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3303
		if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3304
		    memset4(dst, v, l>>2);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3305
		    l = l & 3;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3306
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3307
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3308
#  ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3309
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3310
		    UINT64 v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3311
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3312
		    v64 = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3313
		    v64 = (v64 << 32) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3314
		    while (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3315
			((UINT64 *)dst)[0] = v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3316
			dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3317
			l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3318
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3319
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3320
#  else /* no UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3321
		while (l >= 16) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3322
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3323
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3324
		    ((int *)dst)[2] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3325
		    ((int *)dst)[3] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3326
		    dst += 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3327
		    l -= 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3328
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3329
		if (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3330
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3331
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3332
		    dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3333
		    l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3334
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3335
		if (l >= 4) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3336
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3337
		    dst += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3338
		    l -= 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3339
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3340
#   if 0
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3341
		if (l >= 2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3342
		    ((short *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3343
		    dst += 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3344
		    l -= 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3345
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3346
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3347
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3348
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3349
# endif /* FAST_MEMSET4 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3350
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3351
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3352
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3353
	     * remaining bytes
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3354
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3355
	    while (l-- > 0)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3356
		*dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3357
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3358
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3359
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3360
	    RETURN ( self );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3361
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3362
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3363
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3364
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3365
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3366
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3367
     (String new:10) atAllPut:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3368
     String new:10 withAll:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3369
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3370
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3371
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3372
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3373
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3374
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3375
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3376
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3377
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3378
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3379
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3380
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3381
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3382
    unsigned char c, cNext;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3383
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3384
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3385
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3386
     && __isString(self)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3387
	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
  3388
	oldVal = __intVal(__characterVal(oldCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3389
	newVal = __intVal(__characterVal(newCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3390
	if ((oldVal <= 0xFF)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3391
	 && (newVal <= 0xFF)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3392
	    cNext = *srcp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3393
	    while ((c = cNext) != '\0') {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3394
		cNext = srcp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3395
		if (c == oldVal)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3396
		    *srcp = newVal;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3397
		srcp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3398
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3399
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3400
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3401
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3402
%}.
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  3403
    newCharacter isCharacter ifFalse:[self halt:'please change the sender'].
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3404
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3405
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3406
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3407
     'helloWorld' copy replaceAll:$o with:$O
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3408
     'helloWorld' copy replaceAll:$d with:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3409
     'helloWorld' copy replaceAll:$h with:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3410
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3411
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3412
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3413
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3414
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3415
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  3416
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3417
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3418
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3419
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3420
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3421
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3422
    if ( aString.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3423
     && self.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3424
     && start.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3425
     && stop.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3426
     && repStart.isSmallInteger()) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3427
	STString me = self.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3428
	STString other = aString.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3429
	int _start = start.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3430
	int _stop = stop.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3431
	int _repStart = repStart.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3432
	int mySize = me.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3433
	int otherSize = other.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3434
	int count = _stop - _start + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3435
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3436
	if (_start >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3437
	 && _repStart >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3438
	 && _stop < mySize
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3439
	 && (_repStart + count) <= otherSize) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3440
	    if (count > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3441
		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
  3442
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3443
	    return context._RETURN(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3444
	}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3445
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3446
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3447
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3448
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3449
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3450
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3451
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3452
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3453
# ifndef NO_PRIM_STRING
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3454
    if (__isStringLike(aString)
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3455
     && __isString(self)
252
  3456
     && __bothSmallInteger(start, stop)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3457
	len = __stringSize(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3458
	index1 = __intVal(start);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3459
	index2 = __intVal(stop);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3460
	count = index2 - index1 + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3461
	if (count <= 0) {
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
	}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3464
	if ((index2 <= len) && (index1 > 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3465
	    repLen = __stringSize(aString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3466
	    repIndex = __intVal(repStart);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3467
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3468
		srcp = __stringVal(aString) + repIndex - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3469
		dstp = __stringVal(self) + index1 - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3470
		if (aString == self) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3471
		    /* take care of overlapping copy */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3472
		    memmove(dstp, srcp, count);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3473
		    RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3474
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3475
#  ifdef bcopy4
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3476
		/* copy quadbytes if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3477
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3478
		 * no sizeof(int) here please -
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3479
		 * - 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
  3480
		 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3481
		if ((count > 12)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3482
		 && (((unsigned INT)srcp & 3) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3483
		 && (((unsigned INT)dstp & 3) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3484
		    int n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3485
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3486
		    n = count >> 2;        /* make it quads */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3487
		    bcopy4(srcp, dstp, n);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3488
		    n <<= 2;               /* back to chars */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3489
		    dstp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3490
		    srcp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3491
		    count -= n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3492
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3493
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3494
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3495
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3496
#  else
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3497
#   ifdef FAST_MEMCPY
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3498
		memcpy(dstp, srcp, count);
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3499
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3500
		/* copy longs if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3501
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3502
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3503
		    while (count >= sizeof(INT)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3504
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3505
			dstp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3506
			srcp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3507
			count -= sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3508
		    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3509
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3510
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3511
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3512
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3513
#   endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3514
#  endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3515
		RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3516
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3517
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3518
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3519
# endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3520
#endif /* not SCHTEAM */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3521
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3522
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3523
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3524
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3525
withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3526
    "return a string containing the chars of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3527
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3528
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3529
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3530
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  3531
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3532
     endIndex   "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3533
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3534
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3535
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3536
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3537
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3538
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3539
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3540
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3541
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3542
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3543
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3544
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  3545
    if (__qClass(self) == String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3546
	cp = cp0 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3547
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3548
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3549
	 * find first non-whiteSpace from beginning
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3550
	 */
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3551
#ifdef UINT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3552
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3553
	    cp += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3554
	}
329
claus
parents: 314
diff changeset
  3555
#endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3556
	while (*((unsigned *)cp) == 0x20202020) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3557
	    cp += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3558
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3559
	while ((c = *cp)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3560
	 && (c <= ' ')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3561
	 && ((c == ' ') || (c == '\n') || (c == '\t')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3562
			|| (c == '\r') || (c == '\f'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3563
	) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3564
	    cp++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3565
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3566
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3567
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3568
	 * find first non-whiteSpace from end
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3569
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3570
	ep = ep0 = cp0 + __stringSize(self) - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3571
	while ((ep >= cp) && (*ep == ' ')) ep--;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3572
	c = *ep;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3573
	while ((ep >= cp) &&
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3574
	       (c <= ' ') &&
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3575
	       ((c == ' ') || (c == '\n') || (c == '\t')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3576
			   || (c == '\r') || (c == '\f'))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3577
	    ep--;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3578
	    c = *ep;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3579
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3580
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3581
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3582
	 * no whiteSpace ?
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3583
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3584
	if ((cp == cp0) && (ep == ep0)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3585
	    RETURN(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3586
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3587
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3588
	startIndex = __mkSmallInteger(cp - cp0 + 1);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3589
	endIndex = __mkSmallInteger(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3590
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3591
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3592
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3593
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3594
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3595
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3596
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3597
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3598
     'hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3599
     '    hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3600
     '    hello ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3601
     '    hello  ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3602
     '    hello   ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3603
     '    hello    ' withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3604
     '        ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3605
    "
608
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3608
withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3609
    "return a string containing the characters of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3610
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3611
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3612
     Notice, this is different from String>>withoutSeparators."
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
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3615
     endIndex   "{ Class: SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3616
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3617
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3618
    startIndex := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3619
%{
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3620
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3621
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3622
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3623
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3624
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3625
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3626
    if (__qClass(self) == String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3627
	cp = cp0 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3628
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3629
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3630
	 * find first non-blank from beginning
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3631
	 */
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3632
#ifdef UINT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3633
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3634
	    cp += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3635
	}
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3636
#endif /* UINT64 */
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3637
	while (*((unsigned *)cp) == 0x20202020) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3638
	    cp += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3639
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3640
	while (*cp == ' ') cp++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3641
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3642
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3643
	 * find first non-blank from end
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3644
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3645
	ep = ep0 = cp0 + __stringSize(self) - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3646
	while ((ep >= cp) && (*ep == ' ')) ep--;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3647
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3648
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3649
	 * no blanks ?
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3650
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3651
	if ((cp == cp0) && (ep == ep0)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3652
	    RETURN(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3653
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3654
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3655
	startIndex = __mkSmallInteger(cp - cp0 + 1);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3656
	endIndex = __mkSmallInteger(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3657
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3658
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3659
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3660
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3661
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3662
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3663
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3664
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3665
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3666
     '    hello' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3667
     '    hello ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3668
     '    hello  ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3669
     '    hello   ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3670
     '    hello    ' withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3671
     '        ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3672
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3673
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3674
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3675
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3676
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3677
displayString
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3678
    "return a string used when displaying the receiver in a view."
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3679
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3680
    ^ super displayString.
17539
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3681
"/    ^ self storeString.
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3682
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3683
    "
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3684
     'hello' -> 'hello'
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3685
    "
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3686
!
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3687
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3688
errorPrint
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3689
    "print the receiver on standard error, if the global Stderr is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3690
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3691
     the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3692
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3693
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3694
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3695
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3696
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3697
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3698
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3699
	if (self.isStringLike()) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3700
	    org.exept.stj.STSystem.err.print(self.asString());
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3701
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3702
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3703
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3704
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3705
    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
  3706
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3707
	    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
  3708
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3709
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3710
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3711
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3712
#endif /* not SCHTEAM */
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3713
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3714
    super errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3715
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3716
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3717
      'hello world' asUnicode16String errorPrint
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3718
      (Character value:356) asString errorPrint
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  3719
      'Bönnigheim' errorPrint
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  3720
      'Bönnigheim' asUnicodeString errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3721
    "
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3722
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3723
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3724
errorPrintCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3725
    "print the receiver on standard error, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3726
     if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3727
     which sends the string to the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3728
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3729
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3730
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3731
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3732
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3733
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3734
    if (@global(Stderr) == STObject.Nil) {
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3735
	if (self.isStringLike()) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3736
	    org.exept.stj.STSystem.err.println(self.asString());
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3737
	    return context._RETURN(self);
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3738
	}
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3739
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3740
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3741
    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
  3742
	if (__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3743
	    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
  3744
	    console_fflush(stderr);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3745
	    RETURN (self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3746
	}
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3747
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3748
#endif
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3749
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3750
    super errorPrintCR
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3751
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3752
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3753
print
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3754
    "print the receiver on standard output, if the global Stdout is nil;
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3755
     otherwise, fall back to the inherited print,
19383
4ef397143f9d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19305
diff changeset
  3756
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3757
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3758
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3759
     (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
  3760
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3761
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3762
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3763
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3764
	org.exept.stj.STSystem.out.print(self.toString());
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3765
	return context._RETURN(self);
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3766
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3767
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3768
    if (@global(Stdout) == nil) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3769
	if (__qIsStringLike(self)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3770
	    console_fprintf(stdout, "%s" , __stringVal(self));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3771
	    console_fflush(stdout);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3772
	    RETURN (self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3773
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3774
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3775
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3776
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3777
    super print
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3778
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3779
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3780
printCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3781
    "print the receiver on standard output, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3782
     if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3783
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3784
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3785
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3786
     (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
  3787
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3788
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3789
#ifdef __SCHTEAM__
18668
b8be71e850e1 schteam
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  3790
    if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3791
	org.exept.stj.STSystem.out.println(self.toString());
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3792
	return context._RETURN(self);
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3793
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3794
#else
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3795
    if (@global(Stdout) == nil) {
18999
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3796
	if (__qIsStringLike(self)) {
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3797
	    console_fprintf(stdout, "%s\n" , __stringVal(self));
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3798
	    console_fflush(stdout);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3799
	    RETURN (self);
52150e74c109 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18998
diff changeset
  3800
	}
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3801
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3802
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3803
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3804
    super printCR
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3805
!
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3806
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3807
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3808
    "non-standard but sometimes useful.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3809
     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
  3810
     which is defined by printf.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3811
     This method is NONSTANDARD and may be removed without notice.
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3812
     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
  3813
     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
  3814
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3815
%{  /* STACK: 1000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3816
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3817
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3818
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3819
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3820
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3821
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3822
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3823
    OBJ s;
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3824
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3825
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3826
    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
  3827
	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
  3828
	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
  3829
	    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
  3830
	}
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3831
again:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3832
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3833
	 * 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
  3834
	 * 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
  3835
	 * 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
  3836
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3837
	__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
  3838
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3839
	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
  3840
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3841
	__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
  3842
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3843
	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
  3844
	    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
  3845
		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
  3846
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3847
		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
  3848
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3849
	    if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3850
		free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3851
	    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
  3852
	    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
  3853
		goto fail;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3854
	    goto again;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3855
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3856
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3857
	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
  3858
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3859
	if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3860
	    free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3861
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3862
	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
  3863
	    RETURN (s);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3864
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3865
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3866
fail:;
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3867
#endif
608
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
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3870
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3871
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3872
     'hello' printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3873
     (String new:900) printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3874
     'hello' printfPrintString:'%%10s -> %10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3875
     'hello' printfPrintString:'%%-10s -> %-10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3876
     'hello' printfPrintString:'%%900s -> %900s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3877
     'hello' printfPrintString:'%%-900s -> %-900s'
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
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3880
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3881
storeOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3882
    "put the storeString of myself on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3883
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  3884
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3885
    (self includes:$') ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3886
	self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3887
    ] ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3888
	aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3889
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3890
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3891
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3892
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3893
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3894
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3895
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3896
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3897
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  3898
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3899
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3900
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3901
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3902
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3903
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3904
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3905
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3906
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3907
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3908
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  3909
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3910
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3911
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3912
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3913
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3914
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3915
    if (cls == String) {
20068
b1cba7634463 #DOCUMENTATION by mawalch
mawalch
parents: 20033
diff changeset
  3916
        RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3917
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3918
    RETURN ( __mkSmallInteger(__stringSize(slf)
20068
b1cba7634463 #DOCUMENTATION by mawalch
mawalch
parents: 20033
diff changeset
  3919
                          - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3920
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3921
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3922
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3923
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3924
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3925
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3926
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3927
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3928
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3929
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3930
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3931
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3932
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3933
19759
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3934
bytesPerCharacter
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3935
    "return the number of bytes each character has.
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3936
     Here, 1 is returned (storing single byte characters)."
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3937
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3938
    ^ 1
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3939
!
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  3940
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3941
characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3942
    "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
  3943
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3944
%{  /* NOCONTEXT */
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3945
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3946
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3947
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3948
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3949
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3950
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
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
#if __POINTER_SIZE__ == 8
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3953
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3954
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3955
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3956
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3957
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3958
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3959
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3960
#endif
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3961
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3962
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3963
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3964
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3965
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3966
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3967
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3968
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3969
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3970
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3971
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3972
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3973
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3974
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3975
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3976
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3977
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3978
    RETURN ( __mkSmallInteger(7) );
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3979
%}.
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3980
    ^ super characterSize
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
    "
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3983
     'hello world' characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3984
     'hello world' asUnicode16String characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3985
     ('hello world' , (Character value:16r88) asString) characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3986
    "
18587
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3987
!
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  3988
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3989
containsNon7BitAscii
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3990
    "return true, if the underlying string contains 8BitCharacters (or widers)
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3991
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3992
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3993
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3994
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3995
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3996
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3997
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  3998
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3999
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4000
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  4001
#if __POINTER_SIZE__ == 8
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4002
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4003
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4004
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4005
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4006
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4007
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4008
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  4009
#endif
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4010
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4011
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4012
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4013
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4014
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4015
	}
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4016
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4017
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4018
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4019
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4020
	}
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  4021
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4022
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4023
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4024
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4025
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4026
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4027
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4028
%}.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4029
    ^ super containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4030
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4031
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4032
     'hello world' containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4033
     'hello world' asTwoByteString containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4034
     ('hello world' , (Character value:16r88) asString) containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4035
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4036
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4037
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4038
containsNon8BitElements
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4039
    "return true, if the underlying string contains elements larger than a single byte"
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4040
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4041
    ^ false.
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4042
!
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4043
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4044
isWideString
19579
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4045
    "true if I require more than one byte per character"
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4046
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4047
    ^ false
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4048
!
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4049
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4050
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4051
    "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
  4052
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4053
     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
  4054
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4055
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4056
#ifdef __SCHTEAM__
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4057
    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
  4058
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4059
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4060
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4061
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4062
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4063
    if (cls != String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4064
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4065
    } else {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4066
	indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4067
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4068
    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
  4069
#endif /* ! __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4070
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  4071
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4072
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4073
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4074
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4075
     'hello' knownAsSymbol
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4076
     'fooBarBaz' knownAsSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4077
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4078
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4079
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4080
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4081
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4082
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4083
     (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
  4084
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4085
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4086
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4087
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  4088
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4089
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4090
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4091
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4092
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4093
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4094
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4095
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4096
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4097
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4098
			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4099
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4100
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4101
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4102
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4103
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4104
stringSpecies
15525
0a0baff63fd0 class: String
Stefan Vogel <sv@exept.de>
parents: 15440
diff changeset
  4105
    ^ self species
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4106
!
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4107
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4108
utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4109
    "return the number of charcters needed when this string is
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4110
     decoded from UTF-8."
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4111
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4112
%{  /* NOCONTEXT */
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4113
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4114
    unsigned char *cp = __stringVal(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4115
    unsigned char *last = cp + __stringSize(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4116
    int max = 1;
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4117
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4118
    if (!__isStringLike(self)) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4119
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4120
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4121
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4122
    for ( ; cp < last; cp++) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4123
	unsigned char mask = *cp & 0xF0;
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4124
	if (mask != 0) {
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4125
	    if ((mask & 0xE0 )== 0xC0) {  if (max < 2) max = 2; }
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4126
	    else if (mask == 0xE0) { if (max < 3) max = 3; }
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4127
	    else if (mask == 0xF0) { max = 4; break;}
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4128
	}
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4129
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4130
    RETURN (__mkSmallInteger(max));
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4131
%}.
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4132
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4133
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4134
     'hello world' utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4135
     'ä' utf8Encoded utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4136
     'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4137
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4138
!
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4139
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4140
utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4141
    "return the number of charcters needed when this string is
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4142
     decoded from UTF-8."
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4143
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4144
%{  /* NOCONTEXT */
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4145
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4146
    unsigned char *cp = __stringVal(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4147
    unsigned char *last = cp + __stringSize(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4148
    unsigned INT len = 0;
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4149
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4150
    if (!__isStringLike(self)) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4151
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4152
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4153
    // count the number of start-bytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4154
    for ( ; cp < last; cp++) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4155
	if ((*cp & 0xC0) != 0x80) len++;
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4156
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4157
    RETURN (__mkSmallInteger(len));
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4158
%}.
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4159
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4160
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4161
     'hello world' utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4162
     'ä' utf8Encoded utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4163
     'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4164
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4165
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4166
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4167
!String methodsFor:'sorting & reordering'!
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4168
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4169
reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4170
    "in-place reverse the characters of the string.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4171
     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
  4172
	      Please use reversed (with a d) for a functional version."
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4173
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4174
    "Q: is there a need to redefine it here ?"
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4175
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4176
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4177
#ifndef __SCHTEAM__
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4178
    REGISTER char c;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4179
    REGISTER unsigned char *hip, *lowp;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4180
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4181
    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
  4182
	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
  4183
	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
  4184
	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
  4185
	    c = *lowp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4186
	    *lowp = *hip;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4187
	    *hip = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4188
	    lowp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4189
	    hip--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4190
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4191
	RETURN ( self );
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4192
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4193
    #endif
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4194
%}.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4195
    ^ super reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4196
! !
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  4197
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4198
!String methodsFor:'substring searching'!
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4199
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4200
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
  4201
    "redefined as primitive for maximum speed (BM)"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4202
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4203
    |notFound|
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4204
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  4205
%{  /* STACK:4000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4206
#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
  4207
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4208
     && __isStringLike(aSubString)
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4209
     && (caseSensitive == true)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4210
     && (__isSmallInteger(startIndex))
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4211
     && (__intVal(startIndex) > 0)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4212
    ) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4213
	unsigned char *y = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4214
	unsigned char *x = __stringVal(aSubString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4215
	int m = __stringSize(aSubString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4216
	int n = __stringSize(self);
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4217
#       define MAX_PATTERN_SIZE 128
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4218
#       define XSIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4219
#       define ASIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4220
#       define MAX(a,b) (a>b ? a : b)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4221
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4222
	if (m == 0) {
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4223
#if 1
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4224
	    /* empty string does not match */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4225
	    RETURN(__mkSmallInteger(0));
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4226
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4227
	    /* empty string matches */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4228
	    RETURN(startIndex);
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4229
#endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4230
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4231
	if (m <= XSIZE) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4232
	    int i, j;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4233
	    static int lastPatternSize = 0;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4234
	    static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 };
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4235
	    static int bmGs[XSIZE+1], bmBc[ASIZE];
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4236
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4237
#           define preBmBc(x, m, bmBc) {          \
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4238
	       int i;                             \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4239
						  \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4240
	       for (i = 0; i < ASIZE; ++i)        \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4241
		  bmBc[i] = m;                    \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4242
	       for (i = 0; i < m - 1; ++i)        \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4243
		  bmBc[x[i]] = m - i - 1;         \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4244
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4245
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4246
#           define suffixes(x, m, suff) {                       \
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4247
	       int f, g, i;                                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4248
								\
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4249
	       suff[m - 1] = m;                                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4250
	       g = m - 1;                                       \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4251
	       for (i = m - 2; i >= 0; --i) {                   \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4252
		  if (i > g && suff[i + m - 1 - f] < i - g)     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4253
		     suff[i] = suff[i + m - 1 - f];             \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4254
		  else {                                        \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4255
		     if (i < g)                                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4256
			g = i;                                  \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4257
		     f = i;                                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4258
		     while (g >= 0 && x[g] == x[g + m - 1 - f]) \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4259
			--g;                                    \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4260
		     suff[i] = f - g;                           \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4261
		  }                                             \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4262
	       }                                                \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4263
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4264
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4265
#           define preBmGs(x, m, bmGs) {                        \
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4266
	       int i, j, suff[XSIZE];                           \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4267
								\
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4268
	       suffixes(x, m, suff);                            \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4269
								\
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4270
	       for (i = 0; i < m; ++i)                          \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4271
		  bmGs[i] = m;                                  \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4272
	       j = 0;                                           \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4273
	       for (i = m - 1; i >= 0; --i)                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4274
		  if (suff[i] == i + 1)                         \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4275
		     for (; j < m - 1 - i; ++j)                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4276
			if (bmGs[j] == m)                       \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4277
			   bmGs[j] = m - 1 - i;                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4278
	       for (i = 0; i <= m - 2; ++i)                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4279
		  bmGs[m - 1 - suff[i]] = m - 1 - i;            \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4280
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4281
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4282
	    /* tables only depend on pattern; so we can cache them in case the same string is searched again */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4283
	    if ((m == lastPatternSize)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4284
	     && (strcmp(lastPattern, x) == 0)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4285
		/* tables are still valid */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4286
		// printf("valid: \"%s\"\n", lastPattern);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4287
	    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4288
		/* Preprocessing */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4289
		// printf("compute: \"%s\"\n", lastPattern);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4290
		preBmGs(x, m, bmGs);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4291
		preBmBc(x, m, bmBc);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4292
		if (m <= MAX_PATTERN_SIZE) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4293
		    // printf("cache for: \"%s\"\n", lastPattern);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4294
		    strcpy(lastPattern, x);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4295
		    lastPatternSize = m;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4296
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4297
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4298
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4299
	    /* Searching */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4300
	    j = __intVal(startIndex) - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4301
	    while (j <= n - m) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4302
	       for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4303
	       if (i < 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4304
		  RETURN (__mkSmallInteger(j+1));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4305
		  j += bmGs[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4306
	       } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4307
		  int s1 = bmGs[i];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4308
		  int s2 = bmBc[y[i + j]] - m + 1 + i;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4309
		  j += MAX(s1, s2);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4310
	       }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4311
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4312
	    notFound = true;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4313
	}
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4314
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4315
#endif /* ! __SCHTEAM__ */
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4316
%}.
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4317
    notFound == true ifTrue:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4318
	^ exceptionValue value.
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4319
    ].
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4320
    ^ self slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4321
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4322
    "Modified: / 05-08-2012 / 12:27:31 / cg"
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4323
!
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4324
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4325
slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4326
    "naive search fallback (non-BM).
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4327
     Use this for short searchStrings (<= 2)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4328
     or for caseSensitive searches"
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
    |notFound|
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4331
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4332
%{
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4333
#ifndef __SCHTEAM__
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4334
    if (__qIsStringLike(self)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4335
     && __isStringLike(aSubString)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4336
     && (__isSmallInteger(startIndex))
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4337
     && (__intVal(startIndex) > 0)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4338
    ) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4339
	unsigned char *c_pSelf = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4340
	unsigned char *c_substring = __stringVal(aSubString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4341
	unsigned char *c_pSelfI, *c_pSelfMax;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4342
	int c_lenSelf = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4343
	int c_lenSubstring = __stringSize(aSubString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4344
	int c_idx0Max = c_lenSelf - c_lenSubstring;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4345
	unsigned char c_first;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4346
	unsigned char c_ucFirst;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4347
	unsigned char c_lcFirst;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4348
	unsigned char c_oppositeCaseFirst;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4349
	int i;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4350
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4351
	if (c_lenSubstring == 0) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4352
#if 1
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4353
	    /* empty string does not match */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4354
	    notFound = true;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4355
	    goto getOutOfHere;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4356
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4357
	    /* empty string matches */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4358
	    RETURN(startIndex);
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4359
#endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4360
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4361
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4362
	// searched string's length > string
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4363
	if (c_idx0Max < 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4364
	    notFound = true;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4365
	    goto getOutOfHere;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4366
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4367
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4368
	c_first = c_lcFirst = c_substring[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4369
	if (((c_first >= 'A') && (c_first <= 'Z'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4370
	 || ((c_first >= 0xC0) && (c_first <= 0xDE))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4371
	    c_ucFirst = c_first;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4372
	    c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4373
	} else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4374
	    if (((c_first >= 'a') && (c_first <= 'z'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4375
	     || ((c_first >= 0xE0) && (c_first <= 0xFE))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4376
		c_lcFirst = c_first;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4377
		c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4378
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4379
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4380
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4381
	// idx:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4382
	// 0123456789
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4383
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4384
	// 1234567890 - lenSelf = 10
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4385
	// abc        - lenSubstring = 3
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4386
	//            - idx0Max = 7 (last legal startIndex)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4387
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4388
	i = __intVal(startIndex) - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4389
	c_pSelfI = c_pSelf + i;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4390
	c_pSelfMax = c_pSelf + c_idx0Max;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4391
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4392
	for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4393
	    int j;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4394
	    unsigned char c_selfChar;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4395
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4396
	    // find the first char
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4397
	    c_selfChar = c_pSelfI[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4398
	    if (c_selfChar != c_first) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4399
		if (caseSensitive == true) continue;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4400
		if (c_selfChar != c_oppositeCaseFirst) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4401
searchNext: ;
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4402
		    continue;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4403
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4404
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4405
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4406
	    // first char matches
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4407
	    // compare rest
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4408
	    for (j=1; j<c_lenSubstring; j++) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4409
		unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4410
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4411
		c_subChar = c_substring[j];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4412
		c_selfChar = c_pSelfI[j];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4413
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4414
		if (c_selfChar == c_subChar) continue;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4415
		if (caseSensitive == true) goto searchNext;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4416
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4417
		c_lcSubChar = c_subChar;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4418
		if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4419
		 || ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4420
		    c_lcSubChar = c_subChar - 'A' + 'a';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4421
		    if (c_selfChar != c_lcSubChar) goto searchNext;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4422
		} else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4423
		    if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4424
		     || ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4425
			c_ucSubChar = c_subChar - 'a' + 'A';
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4426
			if (c_selfChar != c_ucSubChar) goto searchNext;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4427
		    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4428
			goto searchNext;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4429
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4430
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4431
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4432
	    // if we arrive here, we have a match at i
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4433
	    RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4434
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4435
	notFound = true;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4436
    }
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4437
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4438
    getOutOfHere: ;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4439
#endif /* ! __SCHTEAM__ */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4440
%}.
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4441
    "/ arrive here if either not found, or invalid arguments
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4442
    notFound == true ifTrue:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4443
	^ exceptionValue value.
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4444
    ].
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4445
    ^ 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
  4446
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4447
    "
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4448
     'abcdefg' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4449
     'abcdefg' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4450
     'abcdefg' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4451
     'abcabcg' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4452
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4453
     'ABCDEFG' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4454
     'ABCDEFG' slowIndexOfSubCollection:'Abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4455
     'ABCDEFG' slowIndexOfSubCollection:'aBC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4456
     'ABCDEFG' slowIndexOfSubCollection:'ABC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4457
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4458
     'ABCDEFG' slowIndexOfSubCollection:'a' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4459
     'ABCDEFG' slowIndexOfSubCollection:'A' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4460
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4461
     'ABCDEFG' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4462
     'ABCDEFG' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4463
     'ABCABCG' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4464
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4465
     '1234567890' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4466
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4467
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4468
     '1234567890' slowIndexOfSubCollection:'234' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4469
     '1234567890' slowIndexOfSubCollection:'345' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4470
     '1231231231' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4471
     '1231231231' slowIndexOfSubCollection:'123' startingAt:2 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4472
     '1231231231' slowIndexOfSubCollection:'123' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4473
     '1231231231' slowIndexOfSubCollection:'123' startingAt:4 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4474
     '1231231231' slowIndexOfSubCollection:'123' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4475
     '1231231231' slowIndexOfSubCollection:'123' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4476
     '1231231231' slowIndexOfSubCollection:'123' startingAt:7 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4477
     '1231231231' slowIndexOfSubCollection:'123' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4478
     '1231231231' slowIndexOfSubCollection:'123' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4479
     '1231231231' slowIndexOfSubCollection:'123' startingAt:10 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4480
     '1231231231' slowIndexOfSubCollection:'123' startingAt:11 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4481
     '1231231231' slowIndexOfSubCollection:'231' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4482
     '1231231231' slowIndexOfSubCollection:'231' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4483
     '1231231231' slowIndexOfSubCollection:'231' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4484
     '1231231231' slowIndexOfSubCollection:'231' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4485
     '1231231231' slowIndexOfSubCollection:'231' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4486
     '1231231231' slowIndexOfSubCollection:'231' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4487
     '1231231231' slowIndexOfSubCollection:'2310' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4488
     '1231231231' slowIndexOfSubCollection:'2310' startingAt:8 ifAbsent:nil caseSensitive:true
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4489
    "
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4490
! !
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4491
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4492
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4493
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4494
endsWith:aStringOrChar
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4495
    "return true, if the receiver ends with something, aStringOrChar.
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4496
     If aStringOrChar is an empty string, true is returned"
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4497
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4498
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4499
#ifndef __SCHTEAM__
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4500
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4501
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4502
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4503
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4504
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4505
    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
  4506
	len1 = __qSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4507
	len2 = __qSize(aStringOrChar);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4508
	if (len1 < len2) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4509
	    RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4510
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4511
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4512
	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
  4513
	src2 = __stringVal(aStringOrChar);
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4514
	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
  4515
	    if (c != *src1++) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4516
		RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4517
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4518
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4519
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4520
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4521
    if (__isCharacter(aStringOrChar)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4522
	int val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4523
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4524
	val = __intVal(__characterVal(aStringOrChar));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4525
	if ((unsigned)val <= 0xFF) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4526
	    len1 = __stringSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4527
	    if (len1 > 0) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4528
		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
  4529
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4530
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4531
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4532
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4533
#endif /* ! __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4534
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4535
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4536
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4537
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4538
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4539
     'hello world' endsWith:'earth'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4540
     'hello world' endsWith:$d
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4541
     'hello world' endsWith:$e
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4542
     '' endsWith:$d
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4543
     'hello world' endsWith:#($r $l $d)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4544
     'hello world' endsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4545
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4546
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4547
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4548
isBlank
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4549
    "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
  4550
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4551
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4552
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4553
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4554
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4555
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4556
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4557
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  4558
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4559
    if ((cls = __qClass(self)) != String)
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4560
	src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4561
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4562
# ifdef UINT64
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  4563
    while (*((UINT64 *)src) == 0x2020202020202020L) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4564
	src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4565
    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4566
# endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4567
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4568
    while (*((unsigned *)src) == 0x20202020) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4569
	src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4570
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4571
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4572
    while ((c = *src++) == ' ')
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4573
	;; /* just walking along */
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4574
    if (c != '\0') {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4575
	RETURN ( false );
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4576
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4577
    RETURN ( true );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4578
# endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4579
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4580
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4581
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4582
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4583
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4584
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4585
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4586
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4587
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4588
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4589
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4590
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4591
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4592
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4593
	RETURN ( (__stringSize(self) == 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4594
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4595
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4596
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4597
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4598
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4599
10958
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4600
isLiteral
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4601
    "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
  4602
     (i.e. can be used in constant arrays)"
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4603
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4604
    ^ true
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4605
!
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4606
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4607
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
  4608
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4609
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4610
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  4611
%{  /* STACK: 2000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4612
#ifndef __SCHTEAM__
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4613
    /*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4614
     * this is very heavy used when correcting errors
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4615
     * (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
  4616
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4617
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4618
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4619
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4620
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4621
    unsigned char *s1, *s2;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4622
    int v1, v2, v3;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4623
    INT m;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4624
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4625
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4626
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4627
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4628
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  4629
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4630
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4631
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4632
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  4633
    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
  4634
	&& __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
  4635
	&& __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
  4636
	&& __isSmallInteger(kbdTypoWeight)
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4637
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4638
	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
  4639
	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
  4640
	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
  4641
	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
  4642
	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
  4643
	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
  4644
	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
  4645
	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
  4646
	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
  4647
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4648
	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
  4649
	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
  4650
	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
  4651
	    data = fastData;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4652
	} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4653
	    /* 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
  4654
	    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
  4655
	    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
  4656
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4657
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4658
	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
  4659
	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
  4660
	    *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
  4661
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4662
	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
  4663
	    *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
  4664
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4665
	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
  4666
	    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
  4667
		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
  4668
		    m = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4669
		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
  4670
		    m = cW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4671
		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
  4672
		    m = kW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4673
		else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4674
		    m = sW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4675
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4676
		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
  4677
		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
  4678
		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
  4679
		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
  4680
		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
  4681
		    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
  4682
			m = v1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4683
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4684
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4685
		} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4686
		    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
  4687
			m = v2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4688
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4689
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4690
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4691
		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
  4692
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4693
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4694
	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
  4695
	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
  4696
	    free(data);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4697
	RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4698
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4699
mallocFailed: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4700
#endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4701
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4702
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4703
    ^ 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
  4704
			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
  4705
			i:insrtWeight d:deleteWeight
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4706
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4707
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4708
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4709
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4710
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4711
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4712
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4713
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4714
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4715
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4716
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4717
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4718
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4719
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4720
    "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
  4721
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4722
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4723
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4724
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4725
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4726
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4727
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4728
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4729
	RETURN ( (__stringSize(self) != 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4730
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4731
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4732
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4733
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4734
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4735
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4736
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  4737
    "return true, if the receiver starts with something, aStringOrChar.
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4738
     If the argument is empty, true is returned.
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4739
     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
  4740
     which are both inconsistent w.r.t. an empty argument."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4741
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4742
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4743
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4744
    if (self.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4745
	if (aStringOrChar.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4746
	    java.lang.String me = self.asString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4747
	    java.lang.String other = aStringOrChar.asString();
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4748
	    return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4749
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4750
	if (aStringOrChar.isSTCharacter()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4751
	    char[] me = self.asSTString().characters;
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4752
	    char ch = aStringOrChar.charValue();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4753
	    return __c__._RETURN( ((me.length > 0)
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4754
				  && (me[0] == ch)) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4755
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4756
    }
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4757
#else
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4758
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4759
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4760
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4761
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4762
14217
d399ca31088f changed: #startsWith:
Stefan Vogel <sv@exept.de>
parents: 14201
diff changeset
  4763
    if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4764
	src1 = __stringVal(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4765
	src2 = __stringVal(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4766
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4767
	if (src1[0] != src2[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4768
	    if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4769
		RETURN (true);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4770
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4771
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4772
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4773
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4774
	len1 = __qSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4775
	len2 = __qSize(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4776
	if (len1 < len2) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4777
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4778
	}
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4779
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4780
# ifdef UINT64
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4781
	while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4782
	    if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4783
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4784
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4785
	    len2 -= sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4786
	    src1 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4787
	    src2 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4788
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4789
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4790
#  ifdef __UNROLL_LOOPS__
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4791
	while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4792
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4793
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4794
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4795
	    if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4796
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4797
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4798
	    if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4799
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4800
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4801
	    if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4802
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4803
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4804
	    len2 -= sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4805
	    src1 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4806
	    src2 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4807
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4808
#  endif /* __UNROLL_LOOPS__ */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4809
# endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  4810
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4811
	while (len2 > (OHDR_SIZE+sizeof(INT))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4812
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4813
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4814
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4815
	    len2 -= sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4816
	    src1 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4817
	    src2 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4818
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4819
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4820
	while ((c = *src2++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4821
	    if (c != *src1) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4822
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4823
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4824
	    src1++;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4825
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4826
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4827
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4828
    if (__isCharacter(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4829
	int val;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4830
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4831
	val = __intVal(__characterVal(aStringOrChar));
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4832
	if ((unsigned)val <= 0xFF) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4833
	    len1 = __stringSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4834
	    if (len1 > 0) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4835
		RETURN ( (__stringVal(slf)[0] == val) ? true : false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4836
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4837
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4838
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4839
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4840
#endif /* not __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4841
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4842
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4843
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4844
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4845
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4846
     'hello world' startsWith:'hella'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4847
     'hello world' startsWith:'hi'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4848
     'hello world' startsWith:$h
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4849
     'hello world' startsWith:$H
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4850
     'hello world' startsWith:(Character value:16rFF00)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4851
     'hello world' startsWith:60
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4852
     'hello world' startsWith:#($h $e $l)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4853
     'hello world' startsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4854
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4855
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4856
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4857
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4858
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4859
isSingleByteString
16773
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4860
    "returns true only for strings and immutable strings.
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4861
     Must replace foo isMemberOf:String and foo class == String"
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4862
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4863
    ^ true
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4864
!
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4865
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4866
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4867
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4868
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4869
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4870
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4871
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4872
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4873
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4874
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4875
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4876
version
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4877
    ^ '$Header$'
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4878
!
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4879
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  4880
version_CVS
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4881
    ^ '$Header$'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4882
! !
19910
723e42b5ad3d #DOCUMENTATION by mawalch
mawalch
parents: 19878
diff changeset
  4883