String.st
author Stefan Vogel <sv@exept.de>
Wed, 11 Jan 2017 11:25:28 +0100
changeset 21226 568b192939c7
parent 20879 e0a981ba5487
child 21024 8734987eb5c7
child 21376 c0ba4a6db200
permissions -rw-r--r--
#REFACTORING by stefan class: OSProcess comment/format in: #setupShufflerForOutput: changed: #startProcess
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
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   151
    Be careful when using the 0-byte in a String. This is not prohibited, but
19910
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:]
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
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:]
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   160
	Text StringCollection TwoByteString JISEncodedString
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
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
20879
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
   527
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   530
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   531
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   532
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   533
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   534
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   535
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   536
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   537
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   539
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   540
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   541
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   542
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   543
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   544
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
   547
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   549
329
claus
parents: 314
diff changeset
   550
at:index
claus
parents: 314
diff changeset
   551
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   552
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   553
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   554
     This method is the same as at:."
claus
parents: 314
diff changeset
   555
claus
parents: 314
diff changeset
   556
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   557
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   558
    if (index.isSmallInteger()) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   559
	int idx1Based = context.stArg(0).intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   560
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   561
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   562
#else
329
claus
parents: 314
diff changeset
   563
    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
   564
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   565
claus
parents: 314
diff changeset
   566
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   567
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   568
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   569
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   570
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   571
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   572
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   573
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   574
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   575
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   576
	}
329
claus
parents: 314
diff changeset
   577
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   578
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   579
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   580
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   581
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   583
329
claus
parents: 314
diff changeset
   584
at:index put:aCharacter
claus
parents: 314
diff changeset
   585
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   586
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   587
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   588
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   589
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   590
claus
parents: 314
diff changeset
   591
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   592
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   593
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   594
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   595
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   596
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   597
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   598
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   599
#else
329
claus
parents: 314
diff changeset
   600
    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
   601
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   602
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   603
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   604
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   605
    if (__isString(slf)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   606
	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
   607
	    value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   608
	    if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   609
	     && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   610
		indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   611
		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   612
		    __stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   613
		    RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   614
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   615
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   616
	}
329
claus
parents: 314
diff changeset
   617
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   618
#endif /* ! __SCHTEAM__ */
329
claus
parents: 314
diff changeset
   619
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   620
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   621
!
claus
parents: 314
diff changeset
   622
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   628
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   629
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   630
	int idx1Based = index.intValue();   // st index is 1 based
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   631
	return context._RETURN( self.basicAt( idx1Based ));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   632
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   633
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
    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
   635
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   638
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   639
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   640
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   641
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   642
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   643
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   644
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   645
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   646
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   647
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   648
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   649
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   650
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   652
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   653
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   654
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   655
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   656
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   657
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   658
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   660
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   661
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   662
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   663
     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
   664
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   665
a27a279701f8 Initial revision
claus
parents:
diff changeset
   666
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   667
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   668
    if (index.isSmallInteger()) {
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   669
	int idx1Based = index.intValue();   // st index is 1 based
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
   670
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   671
	self.basicAt_put(idx1Based, aCharacter );
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
   672
	return context._RETURN( aCharacter );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   673
    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
   674
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   675
    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
   676
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   677
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   678
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   679
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   680
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   681
    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
   682
	value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   683
	if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   684
	 && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   685
	    cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   686
	    indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   687
	    if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   688
		if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   689
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   690
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   691
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   692
		__stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   693
		RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   694
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   695
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   696
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   697
badIndex: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   698
#endif /* not __SCHTEAM__ */
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   699
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   700
    (aCharacter isMemberOf:Character) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   701
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   702
	 tried to store something which is not a character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   703
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   704
	^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   705
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   706
    (aCharacter codePoint between:1 and:255) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   707
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   708
	 tried to store a multibyte character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   709
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   710
	^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   711
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   712
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   713
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   714
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   715
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   716
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   717
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   718
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   719
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   720
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   721
    super basicAt:index put:aCharacter codePoint.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   722
    ^ aCharacter
12716
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
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   725
first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   726
    "return the first character.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   727
     Reimplemented here for speed"
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   728
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   729
%{  /* NOCONTEXT */
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   730
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   731
    REGISTER int indx;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   732
    REGISTER OBJ slf, cls;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   733
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   734
    slf = self;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   735
    cls = __qClass(slf);
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   736
    indx = 0;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   737
    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
   738
	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
   739
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   740
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   741
    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
   742
	RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   743
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   744
badIndex: ;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   745
%}.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   746
    ^ super first
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
    "
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   749
     'abc' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   750
     '' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   751
    "
2
claus
parents: 1
diff changeset
   752
! !
claus
parents: 1
diff changeset
   753
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   754
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   755
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   756
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   757
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   758
    "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
   759
     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
   760
19744
f64dd57ad912 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19742
diff changeset
   761
    ^ self indexOf:aCharacter startingAt:1.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   762
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   763
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   764
     'hello world' identityIndexOf:(Character space)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   765
     '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
   766
     'hello world' identityIndexOf: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:1)
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   768
     #[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
   769
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   770
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   771
    "Modified: / 10-01-2012 / 17:07:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   772
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   773
13923
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   774
identityIndexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   775
    "return the index of the first occurrences of the argument, aCharacter
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   776
     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
   777
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   778
    ^ self indexOf:aCharacter startingAt:index
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
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   781
     'hello world' identityIndexOf:(Character space)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   782
     'hello world' identityIndexOf:$d
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   783
     'hello world' identityIndexOf:1
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   784
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   785
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
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
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   788
    "Created: / 10-01-2012 / 17:10:54 / cg"
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   789
!
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   790
20384
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   791
includes:aCharacter
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   792
    "return true, if the receiver includes aCharacter.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   793
     - redefined here for speed"
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   794
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   795
%{  /* NOCONTEXT */
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   796
#ifdef FAST_MEMCHR
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   797
    REGISTER unsigned char *cp;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   798
    REGISTER unsigned byteValue;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   799
    int last;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   800
    OBJ cls;
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   801
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   802
    if (__isCharacter(aCharacter)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   803
	byteValue = __intVal(__characterVal(aCharacter));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   804
	if (byteValue <= 0xFF) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   805
	    last = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   806
	    cp = __stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   807
	    if ((cls = __qClass(self)) != String) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   808
		int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   809
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   810
		cp += numInstBytes;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   811
		last -= numInstBytes;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   812
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   813
	    cp = (unsigned char *) memchr(cp, byteValue, last);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   814
	    RETURN ( (cp == NULL) ? false : true );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   815
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   816
	RETURN (false);
20384
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   817
    }
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   818
#endif
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   819
%}.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   820
    ^ (self indexOf:aCharacter startingAt:1) ~~ 0
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
    "
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   823
     'hello world' includes:$l
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   824
     'hello world' includes:$W
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   825
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   826
     |s|
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   827
     s := String new:1024.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   828
     s atAllPut:$a.
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   829
     s at:512 put:(Character space).
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   830
     Time millisecondsToRun:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   831
	1000000 timesRepeat:[ s includes:(Character space) ]
20384
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
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   834
     timing (ms):
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   835
	    bcc                 OSX(2007 powerbook)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
   836
				 110
20384
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
!
78b74ac7c891 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20272
diff changeset
   839
10
claus
parents: 5
diff changeset
   840
includesAny:aCollection
claus
parents: 5
diff changeset
   841
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   842
     argument, aCollection.
17573
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   843
     - redefined for speed if the argument is a String; especially optimized,
1579f53dd422 class: String
Claus Gittinger <cg@exept.de>
parents: 17539
diff changeset
   844
     if the searched collection has less than 6 characters."
10
claus
parents: 5
diff changeset
   845
claus
parents: 5
diff changeset
   846
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   847
claus
parents: 5
diff changeset
   848
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   849
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   850
    OBJ cls;
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   851
    int index, last;
10
claus
parents: 5
diff changeset
   852
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
   853
    if (__isStringLike(aCollection)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   854
	matchP = __stringVal(aCollection);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   855
	last = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   856
	cp = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   857
	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
   858
	    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
   859
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   860
	    cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   861
	    last -= numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   862
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   863
	index = 0;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   864
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   865
	switch (__stringSize(aCollection)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   866
	    case 5:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   867
		/* five character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   868
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   869
		    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
   870
		    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
   871
		    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
   872
		    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
   873
		    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
   874
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   875
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   876
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   877
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   878
			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
   879
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   880
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   881
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   882
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   883
		    RETURN (false);
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   886
	    case 4:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   887
		/* four character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   888
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   889
		    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
   890
		    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
   891
		    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
   892
		    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
   893
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   894
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   895
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   896
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   897
			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
   898
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   899
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   900
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   901
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   902
		    RETURN (false);
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   905
	    case 3:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   906
		/* three character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   907
		{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   908
		    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
   909
		    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
   910
		    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
   911
		    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   912
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   913
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   914
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   915
			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
   916
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   917
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   918
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   919
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   920
		    RETURN (false);
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   923
	    case 2:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   924
		/* two character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   925
		{
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   926
#if 0
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   927
		    // 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
   928
		    if (last < 2000) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   929
			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
   930
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   931
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   932
			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
   933
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   934
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   935
		    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   936
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   937
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   938
#if 1
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   939
		    // this is 30 %faster !
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   940
#                   define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   941
#                   define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   942
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   943
		    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
   944
		    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
   945
		    int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   946
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   947
		    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
   948
		    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
   949
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   950
		    while (index < last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   951
			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
   952
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   953
			if (hasByteM(v,m1)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   954
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   955
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   956
			if (hasByteM(v,m2)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   957
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   958
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   959
			index += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   960
		    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   961
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   962
#                   undef hasZeroByte
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   963
#                   undef hasByteM
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   964
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   965
		    while (index < last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   966
			unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   967
			int any;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   968
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   969
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   970
			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
   971
			ch = cp[index+1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   972
			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
   973
			ch = cp[index+2];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   974
			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
   975
			ch = cp[index+3];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   976
			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
   977
			if (any) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   978
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   979
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   980
			index += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   981
		    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   982
#endif
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
   983
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   984
		    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   985
			unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   986
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   987
			ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   988
			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
   989
			    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   990
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   991
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   992
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   993
		    RETURN (false);
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   996
	    case 1:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   997
		/* single character search */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
   998
		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
   999
		    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1000
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1001
		RETURN ( false );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1002
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1003
	    case 0:
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1004
		RETURN ( false );
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
	{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1008
	    unsigned char ch;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1009
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1010
	    while (index < last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1011
		ch = cp[index];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1012
		if (strchr(matchP, ch)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1013
		    RETURN ( true );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1014
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1015
		index++;
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
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1018
	RETURN ( false );
10
claus
parents: 5
diff changeset
  1019
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1020
%}.
10
claus
parents: 5
diff changeset
  1021
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1022
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1023
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1024
     'hello world' includesAny:'abcd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1025
     'hello world' includesAny:'xyz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1026
     'hello world' includesAny:'xz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1027
     'hello world' includesAny:'od'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1028
     'hello world' includesAny:'xd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1029
     'hello world' includesAny:'dx'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1030
     'hello world' includesAny:(Array with:$a with:$b with:$d)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1031
     'hello world' includesAny:(Array with:$x with:$y)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1032
     'hello world' includesAny:(Array with:1 with:2)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1033
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1034
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1035
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1036
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1037
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1038
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1039
	]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1040
     ].540 680 550 850 890 850
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1041
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1042
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1043
     s := String new:2000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1044
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1045
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1046
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1047
	]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1048
     ]. 1030 1060 1650 1690
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1049
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1050
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1051
     s := 'hello world'.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1052
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1053
	1000000 timesRepeat:[
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1054
	    s includesAny:'12'
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1055
	]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1056
     ].70 60
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1057
    "
10
claus
parents: 5
diff changeset
  1058
!
claus
parents: 5
diff changeset
  1059
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1060
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1061
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1062
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1064
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1065
%{  /* NOCONTEXT */
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1066
#ifdef __SCHTEAM__
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1067
    if (start.isSmallInteger()
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1068
     && aCharacter.isSTCharacter()) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1069
	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
  1070
	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
  1071
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1072
	return context._RETURN( jIdx+1 );    // st index is 1 based
18306
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
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1075
#else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1076
19745
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1077
# if defined(__BORLANDC__) || defined(__VISUALC__)
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1078
#  undef __UNROLL_LOOPS__
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1079
#  undef FAST_MEMCHR
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1080
#  define V2
cf16402b6366 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19744
diff changeset
  1081
# endif
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1082
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1083
    REGISTER unsigned char *cp;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1084
    REGISTER INT index;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1085
    REGISTER unsigned byteValue;
8924
eb2dd7dd459f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8923
diff changeset
  1086
    int last;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1087
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1088
252
  1089
    if (__isSmallInteger(start)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1090
	index = __intVal(start);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1091
	if (index > 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1092
	    if (__isCharacter(aCharacter)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1093
		byteValue = __intVal(__characterVal(aCharacter));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1094
		if (byteValue <= 0xFF) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1095
		    last = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1096
		    cp = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1097
		    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
  1098
			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
  1099
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1100
			cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1101
			last -= numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1102
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1103
		    if (index <= last) {
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1104
# ifdef FAST_MEMCHR
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1105
			REGISTER unsigned char *ncp;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1106
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1107
			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
  1108
			if (ncp) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1109
			    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
  1110
			}
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1111
# else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1112
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1113
#  ifdef V2
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1114
			{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1115
			    // see bit twiddling hacks
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1116
#                           define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1117
#                           define hasByteM(v,m)   hasZeroByte( (v) ^ m)
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1118
#   if __POINTER_SIZE__ == 8
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1119
#                           define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1120
#                           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
  1121
			    // 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
  1122
			    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
  1123
				int last8 = last-8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1124
				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
  1125
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1126
				while (index <= last8) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1127
				    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
  1128
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1129
				    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
  1130
				    index += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1131
				}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1132
			    }
18909
b77b871e2795 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18902
diff changeset
  1133
#   endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1134
			    // 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
  1135
			    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
  1136
				int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1137
				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
  1138
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1139
				while (index <= last4) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1140
				    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
  1141
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1142
				    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
  1143
				    index += 4;
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
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1147
#  else
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1148
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1149
#   ifdef __UNROLL_LOOPS__
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1150
			{
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1151
			    int last4 = last-4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1152
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1153
			    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
  1154
				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
  1155
				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
  1156
				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
  1157
				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
  1158
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1159
			}
19772
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1160
#   endif
9dad3602ce7d ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents: 19759
diff changeset
  1161
#  endif /* V2 */
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1162
			while (index <= last) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1163
			    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
  1164
				RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1165
			    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1166
			    index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1167
			}
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1168
# endif
19773
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
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1172
	    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1173
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1174
    }
18306
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1175
# undef V2
efb1f01b24e2 comment only
Claus Gittinger <cg@exept.de>
parents: 18286
diff changeset
  1176
#endif /* not SCHTEAM */
370
claus
parents: 368
diff changeset
  1177
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1178
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1179
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1180
    "
15262
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:$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
  1182
     '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
  1183
     '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
  1184
     '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
  1185
     #[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
  1186
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1187
15262
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:$a
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1189
     '1234567890123456a' indexOf:$b
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1190
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1191
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1192
     s := '12345678901234b'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1193
     self assert:(s indexOf:$x) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1194
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1195
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1196
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1197
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1198
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1199
     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
  1200
     self assert:(s indexOf:$b) == 15.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1201
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1202
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1203
     s := ''.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1204
     self assert:(s indexOf:$1) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1205
     s := '1'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1206
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1207
     self assert:(s indexOf:$2) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1208
     s := '12'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1209
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1210
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1211
     self assert:(s indexOf:$3) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1212
     s := '123'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1213
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1214
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1215
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1216
     self assert:(s indexOf:$4) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1217
     s := '1234'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1218
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1219
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1220
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1221
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1222
     self assert:(s indexOf:$5) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1223
     s := '12345'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1224
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1225
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1226
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1227
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1228
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1229
     self assert:(s indexOf:$6) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1230
     s := '123456'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1231
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1232
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1233
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1234
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1235
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1236
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1237
     self assert:(s indexOf:$7) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1238
     s := '1234567'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1239
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1240
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1241
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1242
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1243
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1244
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1245
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1246
     self assert:(s indexOf:$8) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1247
     s := '12345678'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1248
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1249
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1250
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1251
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1252
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1253
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1254
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1255
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1256
     self assert:(s indexOf:$9) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1257
     s := '123456789'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1258
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1259
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1260
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1261
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1262
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1263
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1264
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1265
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1266
     self assert:(s indexOf:$9) == 9.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1267
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1268
     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
  1269
     self assert:(s indexOf:$b) == 0.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1270
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1271
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1272
     s := String new:1024.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1273
     s atAllPut:$a.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1274
     s at:512 put:(Character space).
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1275
     Time millisecondsToRun:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1276
	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
  1277
     ]
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1278
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1279
     timing (ms):
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1280
	    bcc                 OSX(2007 powerbook)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1281
	v1: 1763 normal
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1282
	    2340 +unroll
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1283
	    3308 memsrch !!       90
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1284
	v2: 1045                150
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1285
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1286
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
  1287
    "Modified: / 10-01-2012 / 17:09:34 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1288
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1289
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1290
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1291
    "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
  1292
     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
  1293
     - 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
  1294
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1295
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1296
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1297
    unsigned char *ccp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1298
    unsigned char *cp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1299
    INT index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1300
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1301
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1302
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1303
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1304
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1305
    if (__isSmallInteger(start)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  1306
     && __isStringLike(aCollectionOfCharacters)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1307
	matchP = __stringVal(aCollectionOfCharacters);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1308
	index = __intVal(start);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1309
	if (index > 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1310
	    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
  1311
	    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
  1312
		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
  1313
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1314
	    len = __stringSize(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1315
	    if (index <= len) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1316
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1317
		if (matchP[0] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1318
		    /* matchSet is empty */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1319
		    RETURN ( __mkSmallInteger(0) );
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1322
		if (matchP[1] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1323
		    /* 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
  1324
		    unsigned char m = matchP[0];
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1325
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1326
# ifdef FAST_MEMCHR
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1327
		    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
  1328
		    if (ccp) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1329
			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
  1330
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1331
# else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1332
		    while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1333
			if (c == m) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1334
			    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1335
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1336
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1337
		    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1338
# endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1339
		    RETURN ( __mkSmallInteger(0) );
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1342
		if (matchP[2] == 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1343
		    /* two character matches */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1344
		    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
  1345
		    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
  1346
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1347
		    while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1348
			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
  1349
			    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1350
			}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1351
			index++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1352
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1353
		    RETURN ( __mkSmallInteger(0) );
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
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1356
		min = max = matchP[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1357
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1358
		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
  1359
		    unsigned char c = *ccp;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1360
		    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
  1361
		    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
  1362
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1363
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1364
		while ((c = *cp++) != '\0') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1365
		    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
  1366
			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
  1367
			    if (*ccp == c) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1368
				RETURN ( __mkSmallInteger(index) );
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
		    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1372
		    index++;
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
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1375
	    RETURN ( __mkSmallInteger(0) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1376
	}
516
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
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1380
    "/ 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
  1381
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1382
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1383
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1384
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1385
     'hello world' indexOfAny:'eoa' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1386
     'hello world' indexOfAny:'eoa' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1387
     'hello world' indexOfAny:'AOE' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1388
     'hello world' indexOfAny:'o' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1389
     'hello world' indexOfAny:'o' startingAt:6
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1390
     'hello world§' indexOfAny:'#§$' startingAt:6
516
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
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1393
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1394
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1395
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1396
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1397
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1398
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1399
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1400
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1401
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1402
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1403
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1404
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1405
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1406
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1407
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1408
    if (index <= 0) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1409
	index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1410
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1411
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1412
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1413
    if ((cls = __qClass(self)) != String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1414
	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
  1415
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1416
	cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1417
	len -= numInstBytes;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1418
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1419
    while (index <= len) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1420
	REGISTER unsigned char c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1421
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1422
	c = cp[index - 1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1423
	if (c < ' ') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1424
	    RETURN ( __mkSmallInteger(index) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1425
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1426
	index++;
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1427
    }
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1428
    RETURN ( __mkSmallInteger(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1429
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1430
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1431
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1432
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1433
     'hello world'             indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1434
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1435
     '1\' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1436
     '1\' withCRs indexOfControlCharacterStartingAt:2
3668
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
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1439
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1440
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1441
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1442
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1443
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1444
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1445
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1446
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1447
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1448
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1449
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1450
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1451
    if (index <= 0) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1452
	index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1453
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1454
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1455
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1456
    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
  1457
	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
  1458
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1459
	cp += numInstBytes;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1460
	len -= numInstBytes;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1461
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1462
    while (index <= len) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1463
	REGISTER unsigned char c;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1464
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1465
	c = cp[index - 1];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1466
	if (c > ' ') {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1467
	    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
  1468
	     && (c != '\r') && (c != '\f')) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1469
		RETURN ( __mkSmallInteger(index) );
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
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1472
	index++;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1473
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1474
    RETURN ( __mkSmallInteger(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1475
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1476
    ^ super indexOfNonSeparatorStartingAt:start
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1477
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1478
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1479
     'hello world' indexOfNonWhiteSpaceStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1480
     'hello world' indexOfNonWhiteSpaceStartingAt:7
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1481
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1482
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1483
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1484
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1485
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1486
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1487
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1488
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1489
    if (__isSmallInteger(start)) {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1490
	REGISTER unsigned char *cp;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1491
	int len, index;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1492
	OBJ cls;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1493
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1494
	index = __intVal(start)-1;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1495
	// is this a good idea?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1496
	if (index < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1497
	    index = 0;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1498
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1499
	len = __stringSize(self);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1500
	cp = __stringVal(self);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1501
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1502
	// care for subclasses of string
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1503
	if ((cls = __qClass(self)) != String) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1504
	    int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1505
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1506
	    cp += numInstBytes;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1507
	    len -= numInstBytes;
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
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1510
	// these pre-loops do fast skip over non-separators
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1511
	// (anything above 0x32)
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1512
#if __POINTER_SIZE__ == 8
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1513
	if ((index & 7) == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1514
	    int len8 = len-8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1515
	    while (index < len8) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1516
		REGISTER unsigned INT eightChars;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1517
		REGISTER unsigned INT eightCharsMasked;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1518
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1519
		eightChars = ((unsigned INT *)(cp+index))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1520
		eightCharsMasked = eightChars & 0xE0E0E0E0E0E0E0E0ULL;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1521
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1522
		// any control char?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1523
		// (these are 0..31 and also the space);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1524
		// so we need two compares.
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1525
#               define hasZeroByte(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1526
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
19790
d99c007f4c5b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19773
diff changeset
  1527
#               define maskSpace       (~0ULL/255 * (32))
d99c007f4c5b #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19773
diff changeset
  1528
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1529
		if (hasByteM(eightChars, maskSpace)) break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1530
		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
  1531
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1532
#               undef hasZeroByte
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1533
#               undef hasByteM
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1534
#               undef maskSpace
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1535
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1536
		index += 8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1537
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1538
	}
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1539
#endif /* POINTER_SIZE == 8*/
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1540
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1541
	if ((index & 3) == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1542
	    int len4 = len-4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1543
	    while (index < len4) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1544
		REGISTER unsigned int fourChars;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1545
		REGISTER unsigned int fourCharsMasked;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1546
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1547
		fourChars = ((unsigned int *)(cp+index))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1548
		fourCharsMasked = fourChars & 0xE0E0E0E0UL;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1549
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1550
		// any control char?
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1551
		// (these are 0..31 and also the space);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1552
		// so we need two compares.
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1553
#               define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1554
#               define hasByteM(v,m)   hasZeroByte( (v) ^ m)
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1555
#               define maskSpace       (~0UL/255 * (32))
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1556
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1557
		if (hasByteM(fourChars, maskSpace)) break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1558
		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
  1559
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1560
#               undef hasZeroByte
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1561
#               undef hasByteM
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1562
#               undef maskSpace
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1563
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1564
		index += 4;
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
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1568
	while (index < len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1569
	    REGISTER unsigned char c;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1570
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1571
	    c = cp[index];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1572
	    if (c <= ' ') {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1573
		if ((c == ' ') || (c == '\t') || (c == '\n')
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1574
		 || (c == '\r') || (c == '\f')) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1575
		    RETURN ( __mkSmallInteger(index+1) );
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
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1578
	    index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1579
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1580
	RETURN ( __mkSmallInteger(0) );
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1581
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1582
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1583
    ^ super indexOfSeparatorStartingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1584
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1585
    " 123456789012
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1586
     'hello world ' indexOfSeparatorStartingAt:1 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1587
     'hello world ' indexOfSeparatorStartingAt:3 -> 6
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1588
     'hello world ' indexOfSeparatorStartingAt:7 -> 12
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1589
     'hello world' indexOfSeparatorStartingAt:7  -> 0
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1590
     'helloworld' indexOfSeparatorStartingAt:1   -> 0
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1591
    "
19748
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
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1594
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1595
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1596
     self assert:(s indexOfSeparatorStartingAt:1) == 0.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1597
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1598
	 1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ]
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1599
     ]
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1600
     original (char-wise):760 760 750
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1601
     with 4-byte at a time: 640 650 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1602
     with 8-byte at a time: 300 290 320
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
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1605
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1606
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1607
     s at:400 put:(Character return).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1608
     self assert:(s indexOfSeparatorStartingAt:1) == 400.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1609
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1610
	 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
  1611
     ]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1612
     original (char-wise):340 350
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1613
     with 4-byte at a time: 310 290 280
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1614
     with 8-byte at a time: 150 140 140
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
    "
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1617
     |s|
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1618
     s := String new:1000 withAll:$a.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1619
     s at:999 put:(Character space).
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1620
     self assert:(s indexOfSeparatorStartingAt:1) == 999.
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1621
     Time millisecondsToRun:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19839
diff changeset
  1622
	 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
  1623
     ]
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1624
     original (char-wise): 750 750 790
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1625
     with 4-byte at a time: 640 640 620
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  1626
     with 8-byte at a time: 280 290 300
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1627
    "
608
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1630
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1631
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1632
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1633
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1634
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1635
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1636
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1637
    REGISTER unsigned byteValue;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1638
    REGISTER INT count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1639
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1640
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1641
    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
  1642
	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
  1643
	count = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1644
	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
  1645
	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
  1646
	    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
  1647
	    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
  1648
		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
  1649
		limit -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1650
		cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1651
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1652
	    /* 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
  1653
	     * (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
  1654
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1655
	    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
  1656
		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
  1657
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1658
		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
  1659
		limit -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1660
		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
  1661
		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
  1662
		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
  1663
		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
  1664
		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
  1665
		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
  1666
		cp += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1667
		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
  1668
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1669
	    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
  1670
		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
  1671
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1672
		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
  1673
		limit--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1674
		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
  1675
		cp ++;
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
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1678
	RETURN ( __mkSmallInteger(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1679
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1680
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1681
    ^ super occurrencesOf:aCharacter
608
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1684
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1685
     'hello world' occurrencesOf:$w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1686
     'hello world' occurrencesOf:$l
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1687
     'hello world' occurrencesOf:$x
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1688
     'hello world' occurrencesOf:1
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1689
     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
  1690
	1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ]
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1691
     ]. 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
  1692
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1693
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1694
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1695
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1696
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1697
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1698
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1699
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1700
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1701
     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
  1702
     'foo' < 'Foo' will return false.
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1703
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1704
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1705
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1706
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1707
    return context._RETURN( self.stringLtP(aString) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1708
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1709
#else
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1710
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1711
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1712
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1713
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1714
    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
  1715
	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
  1716
	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
  1717
	    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
  1718
	    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
  1719
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1720
	     * 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
  1721
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1722
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1723
		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
  1724
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1725
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1726
		len2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1729
	    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
  1730
	    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
  1731
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1732
	     * 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
  1733
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1734
	    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
  1735
		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
  1736
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1737
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1738
		len1 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1741
	    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
  1742
		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
  1743
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1744
		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
  1745
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1746
	    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
  1747
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1748
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1749
	    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
  1750
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1751
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1752
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1753
	}
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1754
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1755
#endif
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1756
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1757
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1758
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1759
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1760
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1761
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1762
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1763
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1764
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1765
375
claus
parents: 370
diff changeset
  1766
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1767
#ifdef __SCHTEAM__
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1768
    if (aString == self) {
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1769
	return __c__._RETURN_true();
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1770
    }
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1771
    if (aString.isStringLike()) {
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1772
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False );
18347
03b047d52f22 comments only
Claus Gittinger <cg@exept.de>
parents: 18343
diff changeset
  1773
    }
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1774
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1775
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  1776
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1777
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1778
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1779
    unsigned char *cp1, *cp2;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1780
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1781
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1782
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1783
    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
  1784
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1785
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1786
    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
  1787
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1788
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1789
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1790
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1791
    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
  1792
	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
  1793
	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
  1794
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1795
	 * 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
  1796
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1797
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1798
	    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
  1799
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1800
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1801
	    l2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1804
	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
  1805
	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
  1806
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1807
	 * 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
  1808
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1809
	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
  1810
	    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
  1811
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1812
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1813
	    l1 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1816
	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
  1817
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1818
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1819
# 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
  1820
	RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1821
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1822
	addrDelta = cp2 - cp1;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1823
#  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
  1824
	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
  1825
	    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
  1826
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1827
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1828
	    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
  1829
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1830
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1831
	    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
  1832
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1833
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1834
	    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
  1835
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1836
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1837
	    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
  1838
	    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
  1839
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1840
#  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
  1841
	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
  1842
	    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
  1843
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1844
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1845
	    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
  1846
	    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
  1847
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1848
	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
  1849
	    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
  1850
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1851
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1852
	    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
  1853
	    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
  1854
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1855
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1856
	    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
  1857
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1858
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1859
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1860
	    cp1++;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1863
	RETURN (true);
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1864
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1865
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1866
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1867
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1868
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1869
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1870
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1871
     'foo' = 'Foo'
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1872
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1873
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1874
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1875
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1876
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1877
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1878
     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
  1879
	 1000000 timesRepeat:[]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1880
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1881
     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
  1882
	 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1883
     ].
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1884
     tCmp - tEmpty
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1885
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1886
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1887
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1888
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1889
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1890
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1891
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1892
     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
  1893
     'foo' > 'Foo' will return true.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1894
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1895
375
claus
parents: 370
diff changeset
  1896
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1897
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18233
diff changeset
  1898
    return context._RETURN( aString.stringLtP( self ) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1899
    /* NOTREACHED */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  1900
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1901
    int len1, len2, cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1902
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1903
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1904
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1905
    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
  1906
	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
  1907
	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
  1908
	    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
  1909
	    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
  1910
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1911
	     * 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
  1912
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1913
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1914
		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
  1915
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1916
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1917
		len2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1920
	    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
  1921
	    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
  1922
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1923
	     * 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
  1924
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1925
	    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
  1926
		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
  1927
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1928
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1929
		len1 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1932
	    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
  1933
		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
  1934
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1935
		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
  1936
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1937
	    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
  1938
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1939
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1940
	    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
  1941
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1942
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1943
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1944
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1945
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1946
#endif /* not __SCHTEAM__ */
370
claus
parents: 368
diff changeset
  1947
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1948
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1949
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1950
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1951
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1952
    "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
  1953
     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
  1954
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1955
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1956
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1957
    ^ self compareWith:aString collating:true
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1958
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1959
    "
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1960
     'hallo' compareWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1961
     'hbllo' compareWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1962
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1963
     'hallo' compareCollatingWith:'hällo'
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  1964
     'hbllo' compareCollatingWith:'hällo'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1965
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1966
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1967
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1968
compareWith:aString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1969
    "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
  1970
     greater, 0 if equal and -1 if less than the argument.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1971
     This comparison is based on the elements' codepoints -
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1972
     i.e. upper/lowercase & national characters are NOT treated specially.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1973
     'foo' compareWith: 'Foo' will return 1.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1974
     while 'foo' sameAs:'Foo' will return true"
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1975
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1976
    ^ self compareWith:aString collating:false
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
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1979
compareWith:aString collating:collatingBoolean
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1980
    "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
  1981
     greater, 0 if equal and -1 if less than the argument.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1982
     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
  1983
     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
  1984
     otherwise, it will be a simple string-compare.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1985
     This comparison is based on the elements' codepoints -
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1986
     i.e. upper/lowercase & national characters are NOT treated specially.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1987
     'foo' compareWith: 'Foo' will return 1.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1988
     while 'foo' sameAs:'Foo' will return true"
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  1989
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1990
%{  /* NOCONTEXT */
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1991
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1992
    int cmp;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1993
    unsigned char *cp1, *cp2;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1994
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1995
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1996
    if (__isNonNilObject(aString)) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1997
	argIsString = __qIsStringLike(aString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  1998
	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
  1999
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2000
	    // 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
  2001
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2002
	    cp1 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2003
	    if (!__qIsStringLike(self)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2004
		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
  2005
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2006
		cp1 += n;
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
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2010
	    // 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
  2011
	    //
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2012
	    cp2 = __stringVal(aString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2013
	    if (!argIsString) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2014
		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
  2015
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2016
		cp2 += n;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2017
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2018
	    if (collatingBoolean == true) {
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2019
#ifdef HAS_STRCOLL
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2020
		cmp = strcoll(cp1, cp2);
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2021
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2022
		// 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
  2023
		goto getOutOfHere;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2024
#endif
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2025
	    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2026
		cmp = strcmp(cp1, cp2);
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
	    {
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) ? 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
  2030
		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
  2031
		RETURN( __mkSmallInteger( signum ) );
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2032
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2033
	}
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2034
    }
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2035
getOutOfHere: ;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2036
%}.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2037
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2038
     currently, this operation is only defined for strings, symbols and subclasses.
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2039
     allow for an implementation in Smalltalk
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2040
    "
19741
aa6012bec09c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19733
diff changeset
  2041
    ^ super compareWith:aString collating:collatingBoolean
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2042
!
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2043
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2044
hash
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2045
    "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
  2046
     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
  2047
     used in the ST/X VM (which is actually fnv-1a)"
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2048
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2049
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2050
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2051
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2052
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2053
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2054
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2055
    extern unsigned int __symbolHash(char *);
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2056
    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
  2057
    unsigned int h;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2058
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2059
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2060
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2061
    }
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2062
    h = __symbolHash(cp);
16891
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2063
    // make sure, it fits into a smallInt
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2064
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16889
diff changeset
  2065
    RETURN(__mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2066
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2067
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2068
    ^ self primitiveFailed
14653
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
    "
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2071
     'a' hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2072
     'ab' hash = 'ab' asUnicode16String hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2073
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2074
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2075
    "Created: / 26-12-2011 / 13:53:09 / cg"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2076
!
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  2077
13880
Claus Gittinger <cg@exept.de>
parents: 13205
diff changeset
  2078
hash_dragonBook
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2079
    "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
  2080
     This method implements the dragon-book algorithm (aho, ullman)."
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2081
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2082
%{  /* NOCONTEXT */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2083
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2084
    REGISTER unsigned g, val;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2085
    REGISTER unsigned char *cp, *cp0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2086
    int l;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2087
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2088
    cp = __stringVal(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2089
    l = __stringSize(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2090
    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
  2091
	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
  2092
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2093
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2094
	l -= n;
10697
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
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2098
     * this is the dragon-book algorithm
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
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2101
    val = 0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2102
    switch (l) {
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2103
    default:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2104
	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
  2105
	    val = (val << 4) + *cp;
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  2106
	    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
  2107
		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
  2108
		val ^= g;
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
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2111
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2112
    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
  2113
	val = cp[5] << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2114
    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
  2115
	val = (val + cp[4]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2116
    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
  2117
	val = (val + cp[3]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2118
    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
  2119
	val = (val + cp[2]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2120
    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
  2121
	val = (val + cp[1]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2122
    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
  2123
	val = val + cp[0];
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2124
    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
  2125
	break;
10697
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
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2129
     * multiply by large prime to spread values
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2130
     * This speeds up Set and Dictionary by a factor of 10!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2131
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2132
    val *= 31415821;
12763
e19933d3e188 changed:
Stefan Vogel <sv@exept.de>
parents: 12727
diff changeset
  2133
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2134
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2135
    ^ self primitiveFailed
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2136
!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  2137
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2138
hash_fnv1a
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2139
    "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
  2140
     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
  2141
     (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
  2142
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2143
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2144
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2145
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2146
    long h = me.hash_fnv1a();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2147
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2148
#else
18581
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2149
    REGISTER unsigned int h  = 2166136261u;
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2150
    REGISTER unsigned char *cp = __stringVal(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2151
    INT l  = __stringSize(self);
8c350282248e class: String
Stefan Vogel <sv@exept.de>
parents: 18578
diff changeset
  2152
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2153
    if (!__qIsStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2154
	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
  2155
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2156
	cp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2157
	l -= n;
16889
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
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2160
    while (l >= 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2161
	l -= 4;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2162
	h = (h ^ cp[0]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2163
	h = (h ^ cp[1]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2164
	h = (h ^ cp[2]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2165
	h = (h ^ cp[3]) * 16777619;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2166
	cp += 4;
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2167
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2168
    while (l--) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2169
	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
  2170
    }
16900
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2171
    // make it a smallInteger
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2172
    h = (h ^ (h >> 30)) & 0x3FFFFFFF;
04c111f73292 make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
  2173
    RETURN ( __mkSmallInteger(h));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2174
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2175
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2176
    ^ self primitiveFailed
16889
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
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2179
     'a' hash_fnv1a
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
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2183
hash_java
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2184
    "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
  2185
     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
  2186
     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
  2187
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2188
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2189
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2190
    STString me = self.asSTString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2191
    long h = me.hash_java();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2192
    return __c__._RETURN(STInteger._new(h));
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2193
#else
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2194
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2195
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2196
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2197
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2198
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2199
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2200
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2201
	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
  2202
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2203
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2204
	l -= n;
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
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2208
     * 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
  2209
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2210
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2211
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2212
	l -= 4;
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[0];
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[1];
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[2];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2216
	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
  2217
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2218
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2219
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2220
	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
  2221
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2222
    RETURN ( __MKUINT(val));
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  2223
#endif /* not SCHTEAM */
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2224
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2225
    ^ self primitiveFailed
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2226
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2227
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2228
     'a' hash_java
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
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2232
hash_sdbm
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2233
    "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
  2234
     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
  2235
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2236
%{  /* NOCONTEXT */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2237
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2238
    REGISTER unsigned INT val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2239
    REGISTER unsigned char *cp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2240
    int l;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2241
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2242
    cp = __stringVal(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2243
    l = __stringSize(self);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2244
    if (!__qIsStringLike(self)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2245
	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
  2246
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2247
	cp += n;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2248
	l -= n;
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
    /*
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2252
     * 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
  2253
     */
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2254
    val = 0;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2255
    while (l >= 4) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2256
	l -= 4;
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[0];
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[1];
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[2];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2260
	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
  2261
	cp += 4;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2262
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2263
    while (l--) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2264
	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
  2265
    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2266
    RETURN ( __mkSmallInteger(val & _MAX_INT));
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2267
%}.
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2268
    ^ self primitiveFailed
16889
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
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2271
     'a' hash
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2272
     '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
  2273
    "
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2274
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2275
    "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
  2276
!
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  2277
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2278
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2279
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2280
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2281
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2282
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2283
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2284
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2285
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2286
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2287
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2288
#ifdef __SCHTEAM__
18700
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2289
    if (aString == self) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2290
	return __c__._RETURN_false();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2291
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2292
    if (aString.isStringLike()) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2293
	return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True );
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2294
    }
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2295
    if (aString == STObject.Nil) {
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2296
	return __c__._RETURN_true();
3aa1dc3b3fdb steam stuff
Claus Gittinger <cg@exept.de>
parents: 18668
diff changeset
  2297
    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2298
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2299
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  2300
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2301
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  2302
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2303
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2304
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2305
    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
  2306
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2307
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2308
    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
  2309
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2310
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2311
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2312
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2313
    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
  2314
	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
  2315
	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
  2316
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2317
	 * 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
  2318
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2319
	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
  2320
	    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
  2321
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2322
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2323
	    l1 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2326
	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
  2327
	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
  2328
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2329
	 * 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
  2330
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2331
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2332
	    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
  2333
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2334
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2335
	    l2 -= n;
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2338
	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
  2339
	    RETURN ( true );
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
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2342
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2343
# 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
  2344
	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
  2345
	    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
  2346
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2347
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2348
	    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
  2349
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2350
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2351
	    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
  2352
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2353
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2354
	    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
  2355
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2356
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2357
	    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
  2358
	    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
  2359
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  2360
# 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
  2361
	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
  2362
	    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
  2363
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2364
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2365
	    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
  2366
	    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
  2367
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2368
	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
  2369
	    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
  2370
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2371
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2372
	    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
  2373
	    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
  2374
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2375
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2376
	    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
  2377
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2378
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2379
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2380
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2381
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2382
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2383
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2384
#endif /* not __SCHTEAM__ */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2385
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2386
    ^ super ~= aString
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2389
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2390
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2391
asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2392
    "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
  2393
     with an additional 0-character. Otherwise return the receiver. This is sometimes
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2394
     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
  2395
     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
  2396
     strings are not."
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2397
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2398
    ^ self
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2399
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2400
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2401
     'abc' asAsciiZ
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2402
     'abc' asWideString asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2403
    "
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2404
!
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  2405
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2406
asByteArray
15938
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2407
    "return a new ByteArray with the receiver's elements.
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  2408
     This redefined method is faster than Collection>>#asByteArray"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2409
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2410
    |bytes sz|
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2411
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2412
    sz := self size.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2413
    bytes := ByteArray new:sz .
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2414
    bytes replaceFrom:1 to:sz with:self startingAt:1.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2415
    ^ bytes
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2416
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2417
    "
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  2418
     'fooBar' asByteArray.
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2419
    "
14260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2420
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  2421
    "Modified (comment): / 26-07-2012 / 22:55:26 / cg"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2422
!
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  2423
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2424
asExternalBytes
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2425
    "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
  2426
     my characters.
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2427
     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
  2428
     i.t. it can be handed to a C-function, and must
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2429
     (either there or here) be freed explicitly or unprotectedFromGC"
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2430
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2431
    ^ (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
  2432
	replaceNullTerminatedFromString:self
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2433
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2434
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2435
     |x|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2436
     x := 'fooBar' asExternalBytes.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2437
     x unprotectFromGC.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2438
     ObjectMemory garbageCollect
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2439
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2440
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2441
    "Modified: / 03-08-2006 / 14:45:32 / fm"
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2442
!
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  2443
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2444
asExternalBytesUnprotected
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2445
    "Like asExternalBytes, but does not register the bytes so
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  2446
     bytes are GARBAGE-COLLECTED!!"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2447
19170
5f3211d65f0b #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19107
diff changeset
  2448
    ^ (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
  2449
	replaceNullTerminatedFromString:self
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2450
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2451
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2452
     |x|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2453
     x := 'fooBar' asExternalBytesUnprotected.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2454
     ObjectMemory garbageCollect
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2455
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2456
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2457
    "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
  2458
    "Modified: / 30-11-2013 / 11:41:40 / cg"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2459
!
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  2460
12454
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2461
asImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2462
    "return a write-protected copy of myself"
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2463
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2464
    ^ self copy changeClassTo:ImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2465
!
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  2466
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2467
asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2468
    "a tuned version for Strings with size < 255. Some apps call this very heavily.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2469
     We can do this for 8-bit strings, since the mapping is well known and lowercase chars
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2470
     fit in one byte also."
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2471
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2472
%{  /* NOCONTEXT */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2473
#ifndef __SCHTEAM__
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2474
    REGISTER OBJ slf = self;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2475
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2476
    if (__isStringLike(slf)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2477
	char quickBuffer[256];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2478
	int sz = __stringSize(slf);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2479
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2480
	if (sz < (sizeof(quickBuffer)-1)) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2481
	    REGISTER int i = 0;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2482
	    int anyChange = 0;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2483
	    REGISTER unsigned char *cp = __stringVal(slf);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2484
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2485
	    // fast advance
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2486
	    // all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2487
	    // or 0xC0 .. 0xDF.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2488
	    // I.e. they have the 0x20 bit clear.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2489
	    // Thus, we can fast skip over lowercase, spaces and some punctuation,
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2490
	    // 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
  2491
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2492
#if __POINTER_SIZE__ == 8
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2493
	    for (; i < (sz-8); i += 8) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2494
		unsigned INT eightChars = *(unsigned INT *)(cp+i);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2495
		if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) goto convert;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2496
		*(unsigned INT *)(quickBuffer+i) = eightChars;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2497
	    }
18661
ca8456883410 even faster asLowercase
Claus Gittinger <cg@exept.de>
parents: 18660
diff changeset
  2498
#endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2499
	    for (; i < (sz-4); i += 4) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2500
		unsigned int fourChars = *(unsigned int *)(cp+i);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2501
		if ((fourChars & 0x20202020U) != 0x20202020U) break;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2502
		*(unsigned int *)(quickBuffer+i) = fourChars;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2503
	    }
20126
8341bd725f11 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20109
diff changeset
  2504
convert:
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2505
	    for (; i<sz; i++) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2506
		unsigned char ch = cp[i];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2507
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2508
		quickBuffer[i] = ch;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2509
		if ((ch & 0x60) == 0x40) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2510
		    if (ch >= 'A' && ch <= 'Z') {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2511
			quickBuffer[i] = ch - 'A' + 'a';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2512
			anyChange = 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2513
		    } else {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2514
			// deal with national latin1 characters
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2515
			if (ch >= 0xC0 && ch <= 0xDE && ch != 0xD7) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2516
			    quickBuffer[i] = ch + 0x20;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2517
			    anyChange = 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2518
			}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2519
		    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2520
		}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2521
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2522
	    if (! anyChange) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2523
		RETURN(slf);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2524
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2525
	    quickBuffer[i] = '\0';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2526
	    RETURN (__MKSTRING_L(quickBuffer, i));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2527
	}
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2528
    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2529
#endif /* ! __SCHTEAM__ */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2530
%}.
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2531
    ^ super asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2532
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2533
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2534
	'Hello WORLD' asLowercase
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2535
	(String new:300) asLowercase
20109
27a6eda44c02 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20107
diff changeset
  2536
    "
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2537
!
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  2538
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2539
asPackageId
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2540
    "given a package-string as receiver, return a packageId object.
14566
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2541
     packageIds hide the details of module/directory handling inside the path.
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2542
     See PackageId for the required format of those strings."
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  2543
14571
6e2375384861 class: String
Claus Gittinger <cg@exept.de>
parents: 14566
diff changeset
  2544
    ^ PackageId from: self
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2545
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2546
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2547
     '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
  2548
     '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
  2549
     'stx:hello' asPackageId
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2550
    "
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2551
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2552
    "Created: / 18-08-2006 / 12:19:54 / cg"
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2553
!
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2554
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  2555
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2556
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2557
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2558
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2559
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2560
11287
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2561
asSingleByteStringIfPossible
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2562
    "I am a single-byte string"
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2563
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2564
    ^ self
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2565
!
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2566
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2567
asSingleByteStringReplaceInvalidWith:replacementCharacter
11883
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2568
    "return the receiver converted to a 'normal' string,
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2569
     with invalid characters replaced by replacementCharacter.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2570
     Can be used to convert from 16-bit strings to 8-bit strings
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2571
     and replace characters above code-255 with some replacement.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2572
     Dummy here, because I am already a single byte string."
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2573
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2574
    ^ self
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2575
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2576
    "Modified: / 07-08-2006 / 15:04:45 / fm"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2577
!
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2578
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2579
asSymbol
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2580
    "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
  2581
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2582
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2583
#ifdef __SCHTEAM__
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2584
    return context._RETURN( STSymbol._new(self.asString()) );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2585
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2586
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2587
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2588
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2589
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2590
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2591
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2592
    if (cls != String) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2593
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2594
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2595
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2596
    if (newSymbol) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  2597
	RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2598
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2599
#endif /* not __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2600
%}.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2601
    ^ AllocationFailure raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2602
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2603
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2604
     'hello' asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2605
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2606
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2607
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2608
asSymbolIfInterned
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2609
    "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
  2610
     This can be used to query for an existing symbol and is the same as:
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2611
	self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2612
     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
  2613
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2614
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2615
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2616
#ifdef __SCHTEAM__
18622
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2617
    STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() );
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2618
d9cc5003599e schteam change
Claus Gittinger <cg@exept.de>
parents: 18615
diff changeset
  2619
    return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull );
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2620
#else
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2621
    OBJ cls = __qClass(self);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2622
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2623
20162
b9a62e66a27d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20135
diff changeset
  2624
    if (cls != String && cls != ImmutableString) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2625
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2626
    } else {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2627
	indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2628
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2629
    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
  2630
#endif /* not __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2631
%}.
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2632
    ^ self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2633
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2634
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2635
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2636
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2637
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2638
17378
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2639
beImmutable
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2640
    "make myself write-protected"
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2641
20520
9693cc425d5d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20494
diff changeset
  2642
    super beImmutable.
17378
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2643
    self changeClassTo:ImmutableString
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2644
!
43606e6237bf class: String
Stefan Vogel <sv@exept.de>
parents: 17370
diff changeset
  2645
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2646
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2647
    "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
  2648
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2649
     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
  2650
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2651
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2652
     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
  2653
     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
  2654
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2655
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2656
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2657
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2658
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2659
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2660
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2661
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2662
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2663
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2664
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2665
     && __isSmallInteger(numSpaces)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2666
	n = __intVal(numSpaces);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2667
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2668
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2669
	 * for small strings (< 80), do it without a prescan ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2670
	 * the buffer is large enough to even convert a
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2671
	 * receiver consisting fully of tabs.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2672
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2673
	if (__stringSize(self) < 80) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2674
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2675
	    for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2676
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2677
		    any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2678
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2679
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2680
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2681
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2682
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2683
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2684
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2685
		    *dstP++ = c;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2686
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2687
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2688
			idx = 1;
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
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2692
	    if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2693
	    *dstP = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2694
	    RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2695
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2696
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2697
	 * for large strings, we compute the new size, allocate a new string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2698
	 * and expand it.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2699
	 *
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2700
	 * first, scan for size ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2701
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2702
	idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2703
	for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2704
	    if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2705
		any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2706
		while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2707
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2708
		    sz++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2709
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2710
		idx++; sz ++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2711
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2712
		sz++; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2713
		if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2714
		    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2715
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2716
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2717
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2718
	if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2719
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2720
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2721
	 * get the string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2722
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2723
	sz = OHDR_SIZE + sz + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2724
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2725
	if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2726
	    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2727
	    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2728
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2729
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2730
	     * expand
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2731
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2732
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2733
	    for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2734
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2735
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2736
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2737
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2738
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2739
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2740
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2741
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2742
		    *dstP++ = c; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2743
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2744
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2745
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2746
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2747
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2748
	    *dstP++ = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2749
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2750
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2751
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2752
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2753
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2754
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2755
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2756
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2757
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2758
, aStringOrCharacter
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2759
    "return the concatenation of myself and the argument, aStringOrCharacter as a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2760
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2761
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2762
%{
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2763
#ifdef __SCHTEAM__
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2764
    if ( aStringOrCharacter.isStringLike() && self.isStringLike() ) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2765
	STString me = self.asSTString();
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2766
	STString other = aStringOrCharacter.asSTString();
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2767
	int myLength = me.characters.length;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2768
	int otherLength = other.characters.length;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2769
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2770
	char[] newChars = new char[myLength + otherLength];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2771
	System.arraycopy(me.characters, 0, newChars, 0, myLength);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2772
	System.arraycopy(other.characters, 0, newChars, myLength, otherLength);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2773
	return context._RETURN( new STString( newChars ));
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2774
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2775
#else
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2776
    /*
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2777
     * can do it here if both are Strings/Symbols:
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2778
     */
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2779
    if (__qIsStringLike(self)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2780
	char *cp1 = (char *) __stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2781
	int l1 = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2782
	int l2;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2783
	char *cp2 = 0;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2784
	int sz;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2785
	OBJ newString;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2786
	char character;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2787
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2788
	if (__isCharacter(aStringOrCharacter)) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2789
	    if (__intVal(__characterVal(aStringOrCharacter)) <= 0 || __intVal(__characterVal(aStringOrCharacter)) > 255)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2790
		goto out;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2791
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2792
	    character = __intVal(__characterVal(aStringOrCharacter));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2793
	    l2 = 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2794
	    cp2 = &character;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2795
	} else if (__isStringLike(aStringOrCharacter)) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2796
	    l2 = __stringSize(aStringOrCharacter);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2797
	} else
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2798
	    goto out;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2799
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2800
	sz = OHDR_SIZE + l1 + l2 + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2801
	__qNew(newString, sz);      /* OBJECT ALLOCATION */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2802
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2803
	cp1 = (char *) __stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2804
	if (cp2 == 0)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2805
	    cp2 = (char *) __stringVal(aStringOrCharacter);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2806
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2807
	if (newString != nil) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2808
	    REGISTER unsigned char *dstp;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2809
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2810
	    __InstPtr(newString)->o_class = String;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2811
	    __qSTORE(newString, String);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2812
	    dstp = __stringVal(newString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2813
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2814
# if defined(bcopy4)
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2815
	    /* knowing that allocation is 4-byte aligned and
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2816
	     * size rounded up to next 4-byte, the first copy
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2817
	     * can be done word-wise.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2818
	     * that speeds up size-10-string , size-10-string
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2819
	     * by 10% on a P5/200.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2820
	     */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2821
	    {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2822
		int nw = l1 >> 2;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2823
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2824
		if (l1 & 3) nw++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2825
		bcopy4(cp1, dstp, nw);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2826
		dstp += l1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2827
	    }
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2828
# elif defined(FAST_MEMCPY)
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2829
	    memcpy(dstp, cp1, l1);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2830
	    dstp += l1;
20107
53dd0fe694cf #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20072
diff changeset
  2831
# else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2832
	    while (l1 >= 4) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2833
		*(int *)dstp = *(int *)cp1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2834
		dstp += 4; cp1 += 4;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2835
		l1 -= 4;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2836
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2837
	    while (l1--) *dstp++ = *cp1++;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2838
# endif
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2839
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2840
# ifdef bcopy4
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2841
	    if (((INT)dstp & 3) == 0) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2842
		int nw = l2 >> 2;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2843
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2844
		if (l2 & 3) nw++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2845
		bcopy4(cp2, dstp, nw);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2846
		*(dstp + l2) = '\0';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2847
		RETURN ( newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2848
	    }
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2849
# endif
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2850
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2851
# ifdef FAST_MEMCPY
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2852
	    memcpy(dstp, cp2, l2+1);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2853
	    dstp[l2] = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2854
# else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2855
	    while (l2--) *dstp++ = *cp2++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2856
	    *dstp = '\0';
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  2857
# endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2858
	    RETURN ( newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  2859
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2860
    }
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2861
out:;
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  2862
#endif /* not SCHTEAM */
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2863
%}.
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2864
    ^ super , aStringOrCharacter
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2865
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2866
    "
20070
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2867
     'hello' , ' world' asImmutableString
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2868
     'hello ' , #world
d1635271cd90 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20068
diff changeset
  2869
     'hello ' , $w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2870
     #[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
  2871
    "
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2872
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2873
    "Modified: / 01-04-2012 / 13:19:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2874
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2875
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2876
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2877
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2878
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2879
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2880
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2881
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2882
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2883
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2884
    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
  2885
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2886
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2887
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2888
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2889
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2890
    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
  2891
	    && __isStringLike(string1)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2892
	    && __isStringLike(string2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2893
	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
  2894
	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
  2895
	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
  2896
	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
  2897
	__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
  2898
	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
  2899
	    __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
  2900
	    __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
  2901
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2902
#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
  2903
	    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
  2904
	    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
  2905
	    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
  2906
	    *(dstp + len1 + len2 + len3) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2907
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2908
	    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
  2909
	    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
  2910
	    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
  2911
	    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
  2912
	    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
  2913
	    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
  2914
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2915
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2916
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2917
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2918
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2919
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2920
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2921
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2922
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2923
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2924
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2925
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2926
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2927
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2928
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2929
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2930
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2931
    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
  2932
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2933
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2934
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2935
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2936
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2937
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2938
     && __isStringLike(string1)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2939
     && __isStringLike(string2)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2940
     && __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
  2941
	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
  2942
	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
  2943
	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
  2944
	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
  2945
	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
  2946
	__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
  2947
	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
  2948
	    __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
  2949
	    __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
  2950
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2951
#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
  2952
	    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
  2953
	    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
  2954
	    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
  2955
	    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
  2956
	    *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2957
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2958
	    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
  2959
	    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
  2960
	    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
  2961
	    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
  2962
	    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
  2963
	    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
  2964
	    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
  2965
	    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
  2966
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2967
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2968
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2969
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2970
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2971
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2972
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2973
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2974
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2975
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2976
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2977
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  2978
    (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
  2979
	^ self copyFrom:1
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2980
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2981
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2982
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2983
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2984
copyFrom:start
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  2985
    "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
  2986
     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
  2987
     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
  2988
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2989
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2990
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2991
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2992
    REGISTER unsigned char *srcp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2993
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2994
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2995
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2996
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2997
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2998
#ifndef NO_PRIM_STRING
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  2999
    if (__isSmallInteger(start) && __qIsStringLike(self)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3000
	len = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3001
	index1 = __intVal(start);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3002
	if (index1 > 0) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3003
	    if (index1 <= len) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3004
		count = len - index1 + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3005
		sz = OHDR_SIZE + count + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3006
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3007
		__PROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3008
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3009
		__UNPROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3010
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3011
		if (newString != nil) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3012
		    __InstPtr(newString)->o_class = String;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3013
		    __qSTORE(newString, String);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3014
		    dstp = __stringVal(newString);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3015
		    srcp = __stringVal(self) + index1 - 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3016
#ifdef FAST_MEMCPY
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3017
		    memcpy(dstp, srcp, count);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3018
		    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3019
#else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3020
		    while (count--) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3021
			*dstp++ = *srcp++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3022
		    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3023
		    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3024
#endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3025
		    RETURN ( newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3026
		}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3027
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3028
	}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3029
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3030
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3031
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3032
    "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
  3033
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3034
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3035
    ^ super copyFrom:start
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3036
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3037
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3038
	'12345' copyFrom:3
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3039
	'12345678' copyFrom:9 -> empty string
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3040
	'12345678' copyFrom:0 -> error
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3041
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3042
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3043
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3044
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3045
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3046
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3047
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3048
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3049
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3050
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3051
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3052
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3053
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3054
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3055
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3056
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3057
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3058
#ifndef NO_PRIM_STRING
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3059
    if (__bothSmallInteger(start, stop) && __qIsStringLike(self)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3060
	len = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3061
	index1 = __intVal(start);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3062
	index2 = __intVal(stop);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3063
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3064
	if ((index1 <= index2) && (index1 > 0)) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3065
	    if (index2 <= len) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3066
		count = index2 - index1 + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3067
		sz = OHDR_SIZE + count + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3068
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3069
		__PROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3070
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3071
		__UNPROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3072
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3073
		if (newString != nil) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3074
		    __InstPtr(newString)->o_class = String;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3075
		    __qSTORE(newString, String);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3076
		    dstp = __stringVal(newString);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3077
		    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3078
#ifdef bcopy4
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3079
		    {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3080
			int nw = count >> 2;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3081
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3082
			if (count & 3) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3083
			    nw++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3084
			}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3085
			bcopy4(srcp, dstp, nw);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3086
			dstp[count] = '\0';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3087
		    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3088
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3089
# ifdef FAST_MEMCPY
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3090
		    memcpy(dstp, srcp, count);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3091
		    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3092
# else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3093
		    while (count--) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3094
			*dstp++ = *srcp++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3095
		    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3096
		    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  3097
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3098
#endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3099
		    RETURN ( newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3100
		}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3101
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3102
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3103
	/*
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3104
	 * allow empty copy
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3105
	 */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3106
	if (index1 > index2) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3107
	    __PROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3108
	    __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3109
	    __UNPROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3110
	    if (newString != nil) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3111
		__InstPtr(newString)->o_class = String;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3112
		(__stringVal(newString))[0] = '\0';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3113
		RETURN ( newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3114
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3115
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3116
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3117
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3118
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3119
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3120
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3121
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3122
    ^ super copyFrom:start to:stop
20033
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
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3125
	'12345678' copyFrom:3 to:7
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3126
	'12345678' copyFrom:3 to:3
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3127
	'12345678' copyFrom:3 to:2 -> empty string
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3128
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3129
	'12345678' copyFrom:9 to:9 -> error
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3130
	'12345678' copyFrom:3 to:9 -> error
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3131
	'12345678' copyFrom:0 to:8 -> error
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3132
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3133
	(Unicode16String with:(Character value:16r220) with:$a with:$b with:(Character value:16r221) with:(Character value:16r222))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3134
	    copyFrom:2 to:3
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3135
	((Unicode16String with:(Character value:16r220) with:$a with:$b with:(Character value:16r221) with:(Character value:16r222))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3136
	    copyFrom:2 to:3) asSingleByteString
20033
3a2d8d2bcc8c #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20003
diff changeset
  3137
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3138
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3139
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3140
copyWith:aCharacter
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3141
    "return a new string containing the receiver's characters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3142
     and the single new character, aCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3143
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3144
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3145
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3146
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3147
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3148
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3149
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3150
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3151
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3152
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3153
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3154
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3155
    if (__isCharacter(aCharacter)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3156
	unsigned int cVal = __intVal(__characterVal(aCharacter));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3157
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3158
	if ((cVal <= 0xFF) && __qIsStringLike(self)) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3159
	    count = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3160
	    sz = OHDR_SIZE + count + 1 + 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3161
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3162
	    __PROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3163
	    __qNew(newString, sz);  /* OBJECT ALLOCATION */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3164
	    __UNPROTECT_CONTEXT__
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3165
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3166
	    if (newString) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3167
		__InstPtr(newString)->o_class = String;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3168
		__qSTORE(newString, String);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3169
		dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3170
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3171
# ifdef bcopy4
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3172
		{
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3173
		    int nw = count >> 2;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3174
		    char *srcp = (char *)__stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3175
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3176
		    if (count & 3) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3177
			nw++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3178
		    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3179
		    bcopy4(srcp, dstp, nw);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3180
		    dstp += count;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3181
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3182
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3183
#  ifdef FAST_MEMCPY
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3184
		memcpy(dstp, __stringVal(self), count);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3185
		dstp += count;
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3186
#  else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3187
		{
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3188
		    REGISTER unsigned char *srcp;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3189
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3190
		    srcp = __stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3191
		    while ((*dstp = *srcp++) != '\0')
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3192
			dstp++;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3193
		}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  3194
#  endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  3195
# endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3196
		*dstp++ = cVal;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3197
		*dstp = '\0';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3198
		RETURN (newString );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3199
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  3200
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3201
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  3202
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3203
%}.
20594
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3204
    "fall back in case of non-character arg or non-single-byte character.
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3205
     will lead to an bad element signal raise or a UnicodeString to be returned"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3206
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3207
    ^ super copyWith:aCharacter
20594
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3208
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3209
    "
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3210
     '1234567' copyWith:$8
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3211
     '1234567' copyWith:(Character value:16r220)
e7f11ee8decf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20593
diff changeset
  3212
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3213
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3214
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3215
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3216
    "return a copy of the receiver"
608
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3219
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3220
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3221
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3222
    (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
  3223
	^ self copyFrom:1
608
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
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3226
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3227
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3228
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  3229
    "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
  3230
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3231
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3232
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3233
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3234
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3235
    (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
  3236
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3237
    ].
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  3238
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3239
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3240
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3241
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3242
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3243
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3244
    (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
  3245
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3246
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3247
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3248
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3249
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3250
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3251
    "return a copy of the receiver"
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3254
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3255
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3256
    "
16543
fcdac85d5bee class: String
Stefan Vogel <sv@exept.de>
parents: 16457
diff changeset
  3257
    (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
  3258
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3259
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  3260
    ^ super simpleDeepCopy
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3261
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3262
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  3263
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  3264
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3265
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3266
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3267
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3268
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3269
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3270
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3271
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3272
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3273
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  3274
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3275
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3276
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3277
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3278
    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
  3279
	byteValue = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3280
	if ((unsigned)byteValue <= 0xFF) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3281
	    l = __stringSize(self);
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3282
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3283
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3284
	    if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3285
		memset(__stringVal(self), byteValue, l);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3286
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3287
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3288
	    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3289
		INT v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3290
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3291
		v = (byteValue << 8) | byteValue;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3292
		v = (v << 16) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3293
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3294
		dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3295
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3296
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3297
		if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3298
		    memset4(dst, v, l>>2);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3299
		    l = l & 3;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3300
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3301
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3302
#  ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3303
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3304
		    UINT64 v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3305
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3306
		    v64 = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3307
		    v64 = (v64 << 32) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3308
		    while (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3309
			((UINT64 *)dst)[0] = v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3310
			dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3311
			l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3312
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3313
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3314
#  else /* no UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3315
		while (l >= 16) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3316
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3317
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3318
		    ((int *)dst)[2] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3319
		    ((int *)dst)[3] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3320
		    dst += 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3321
		    l -= 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3322
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3323
		if (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3324
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3325
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3326
		    dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3327
		    l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3328
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3329
		if (l >= 4) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3330
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3331
		    dst += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3332
		    l -= 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3333
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3334
#   if 0
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3335
		if (l >= 2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3336
		    ((short *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3337
		    dst += 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3338
		    l -= 2;
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
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3341
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3342
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  3343
# endif /* FAST_MEMSET4 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3344
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3345
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3346
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3347
	     * remaining bytes
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3348
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3349
	    while (l-- > 0)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3350
		*dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  3351
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3352
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  3353
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3354
	    RETURN ( self );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3355
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3356
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3357
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3358
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3359
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3360
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3361
     (String new:10) atAllPut:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3362
     String new:10 withAll:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3363
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3364
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3365
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3366
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3367
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3368
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3369
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3370
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3371
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3372
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3373
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3374
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3375
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  3376
    unsigned char c, cNext;
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
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3379
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3380
     && __isString(self)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3381
	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
  3382
	oldVal = __intVal(__characterVal(oldCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3383
	newVal = __intVal(__characterVal(newCharacter));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3384
	if ((oldVal <= 0xFF)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3385
	 && (newVal <= 0xFF)) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3386
	    cNext = *srcp;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3387
	    while ((c = cNext) != '\0') {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3388
		cNext = srcp[1];
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3389
		if (c == oldVal)
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3390
		    *srcp = newVal;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3391
		srcp++;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3392
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3393
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  3394
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3395
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3396
%}.
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  3397
    newCharacter isCharacter ifFalse:[self halt:'please change the sender'].
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  3398
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3399
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3400
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3401
     'helloWorld' copy replaceAll:$o with:$O
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3402
     'helloWorld' copy replaceAll:$d with:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3403
     'helloWorld' copy replaceAll:$h with:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3404
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3405
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3406
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3407
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3408
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3409
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  3410
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3411
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3412
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3413
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3414
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3415
#ifdef __SCHTEAM__
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3416
    if ( aString.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3417
     && self.isStringLike()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3418
     && start.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3419
     && stop.isSmallInteger()
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3420
     && repStart.isSmallInteger()) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3421
	STString me = self.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3422
	STString other = aString.asSTString();
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3423
	int _start = start.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3424
	int _stop = stop.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3425
	int _repStart = repStart.intValue() - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3426
	int mySize = me.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3427
	int otherSize = other.characters.length;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3428
	int count = _stop - _start + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3429
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3430
	if (_start >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3431
	 && _repStart >= 0
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3432
	 && _stop < mySize
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3433
	 && (_repStart + count) <= otherSize) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3434
	    if (count > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3435
		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
  3436
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3437
	    return context._RETURN(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3438
	}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3439
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3440
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3441
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3442
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3443
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3444
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3445
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3446
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3447
# ifndef NO_PRIM_STRING
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3448
    if (__isStringLike(aString)
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3449
     && __isString(self)
252
  3450
     && __bothSmallInteger(start, stop)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3451
	len = __stringSize(self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3452
	index1 = __intVal(start);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3453
	index2 = __intVal(stop);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3454
	count = index2 - index1 + 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3455
	if (count <= 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3456
	     RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3457
	}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3458
	if ((index2 <= len) && (index1 > 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3459
	    repLen = __stringSize(aString);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3460
	    repIndex = __intVal(repStart);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3461
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3462
		srcp = __stringVal(aString) + repIndex - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3463
		dstp = __stringVal(self) + index1 - 1;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3464
		if (aString == self) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3465
		    /* take care of overlapping copy */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3466
		    memmove(dstp, srcp, count);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3467
		    RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3468
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3469
#  ifdef bcopy4
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3470
		/* copy quadbytes if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3471
		/*
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3472
		 * no sizeof(int) here please -
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3473
		 * - 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
  3474
		 */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3475
		if ((count > 12)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3476
		 && (((unsigned INT)srcp & 3) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3477
		 && (((unsigned INT)dstp & 3) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3478
		    int n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3479
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3480
		    n = count >> 2;        /* make it quads */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3481
		    bcopy4(srcp, dstp, n);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3482
		    n <<= 2;               /* back to chars */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3483
		    dstp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3484
		    srcp += n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3485
		    count -= n;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3486
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3487
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3488
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3489
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3490
#  else
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3491
#   ifdef FAST_MEMCPY
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3492
		memcpy(dstp, srcp, count);
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3493
#   else
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3494
		/* copy longs if pointers are aligned */
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3495
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3496
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3497
		    while (count >= sizeof(INT)) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3498
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3499
			dstp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3500
			srcp += sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3501
			count -= sizeof(INT);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3502
		    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3503
		}
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3504
		while (count-- > 0) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3505
		    *dstp++ = *srcp++;
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3506
		}
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3507
#   endif
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3508
#  endif
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3509
		RETURN (self);
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3510
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  3511
	}
1
a27a279701f8 Initial revision
claus
parents:
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 /* not SCHTEAM */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3515
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3516
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3517
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3518
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3519
withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3520
    "return a string containing the chars of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3521
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3522
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  3523
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3524
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  3525
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3526
     endIndex   "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3527
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3528
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  3529
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3530
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3531
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3532
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3533
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3534
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3535
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3536
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3537
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3538
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  3539
    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
  3540
	cp = cp0 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3541
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3542
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3543
	 * 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
  3544
	 */
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3545
#ifdef UINT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3546
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3547
	    cp += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3548
	}
329
claus
parents: 314
diff changeset
  3549
#endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3550
	while (*((unsigned *)cp) == 0x20202020) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3551
	    cp += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3552
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3553
	while ((c = *cp)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3554
	 && (c <= ' ')
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3555
	 && ((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
  3556
			|| (c == '\r') || (c == '\f'))
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3557
	) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3558
	    cp++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3559
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3560
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3561
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3562
	 * 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
  3563
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3564
	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
  3565
	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
  3566
	c = *ep;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3567
	while ((ep >= cp) &&
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3568
	       (c <= ' ') &&
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3569
	       ((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
  3570
			   || (c == '\r') || (c == '\f'))) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3571
	    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
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3574
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3575
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3576
	 * no whiteSpace ?
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3577
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3578
	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
  3579
	    RETURN(self);
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
	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
  3583
	endIndex = __mkSmallInteger(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  3584
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3585
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3586
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3587
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  3588
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3589
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3590
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3591
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3592
     'hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3593
     '    hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3594
     '    hello ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3595
     '    hello  ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3596
     '    hello   ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3597
     '    hello    ' withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3598
     '        ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3599
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3600
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3601
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3602
withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3603
    "return a string containing the characters of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3604
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3605
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3606
     Notice, this is different from String>>withoutSeparators."
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
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3609
     endIndex   "{ Class: SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3610
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3611
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3612
    startIndex := 0.
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
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3615
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3616
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3617
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3618
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3619
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3620
    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
  3621
	cp = cp0 = __stringVal(self);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3622
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3623
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3624
	 * 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
  3625
	 */
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3626
#ifdef UINT64
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3627
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3628
	    cp += 8;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3629
	}
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  3630
#endif /* UINT64 */
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3631
	while (*((unsigned *)cp) == 0x20202020) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3632
	    cp += 4;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3633
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3634
	while (*cp == ' ') cp++;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3635
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3636
	/*
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3637
	 * 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
  3638
	 */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  3639
	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
  3640
	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
  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
	 * no blanks ?
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
	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
  3646
	    RETURN(self);
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
	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
  3650
	endIndex = __mkSmallInteger(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3651
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3652
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3653
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3654
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3655
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3656
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3657
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3658
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3659
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3660
     '    hello' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3661
     '    hello ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3662
     '    hello  ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3663
     '    hello   ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3664
     '    hello    ' withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3665
     '        ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3666
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3667
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3668
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3669
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3670
20844
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3671
_errorPrint
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3672
    "Do not use this in user code.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3673
     Print the receiver on standard error.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3674
     This method does NOT (by purpose) use the stream classes and
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3675
     will therefore work even in case of emergency during early startup
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3676
     or in a crash situation (MiniDebugger)."
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3677
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3678
%{  /* NOCONTEXT */
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3679
#ifdef __SCHTEAM__
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3680
    if (self.isStringLike()) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3681
        org.exept.stj.STSystem.err.print(self.asString());
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3682
        return context._RETURN(self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3683
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3684
#else
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3685
    if (__qIsStringLike(self)) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3686
        console_fprintf(stderr, "%s" , __stringVal(self));
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3687
        console_fflush(stderr);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3688
        RETURN (self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3689
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3690
#endif /* not SCHTEAM */
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3691
%}.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3692
!
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3693
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3694
_errorPrintCR
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3695
    "Do not use this in user code.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3696
     Print the receiver on standard error.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3697
     This method does NOT (by purpose) use the stream classes and
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3698
     will therefore work even in case of emergency during early startup
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3699
     or in a crash situation (MiniDebugger)."
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3700
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3701
%{  /* NOCONTEXT */
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3702
#ifdef __SCHTEAM__
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3703
    if (self.isStringLike()) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3704
        org.exept.stj.STSystem.err.println(self.asString());
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3705
        return context._RETURN(self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3706
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3707
#else
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3708
    if (__qIsStringLike(self)) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3709
        console_fprintf(stderr, "%s\n" , __stringVal(self));
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3710
        console_fflush(stderr);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3711
        RETURN (self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3712
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3713
#endif
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3714
%}.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3715
!
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3716
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3717
_print
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3718
    "Do not use this in user code.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3719
     Print the receiver on standard output.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3720
     This method does NOT (by purpose) use the stream classes and
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3721
     will therefore work even in case of emergency during early startup
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3722
     or in a crash situation (MiniDebugger)."
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3723
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3724
%{  /* NOCONTEXT */
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3725
#ifdef __SCHTEAM__
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3726
    org.exept.stj.STSystem.out.print(self.toString());
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3727
    return context._RETURN(self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3728
#else
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3729
    if (__qIsStringLike(self)) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3730
        console_fprintf(stdout, "%s" , __stringVal(self));
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3731
        console_fflush(stdout);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3732
        RETURN (self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3733
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3734
#endif
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3735
%}.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3736
!
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3737
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3738
_printCR
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3739
    "Do not use this in user code.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3740
     Print the receiver on standard output.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3741
     This method does NOT (by purpose) use the stream classes and
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3742
     will therefore work even in case of emergency during early startup
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3743
     or in a crash situation (MiniDebugger)."
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3744
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3745
%{  /* NOCONTEXT */
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3746
#ifdef __SCHTEAM__
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3747
    org.exept.stj.STSystem.out.println(self.toString());
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3748
    return context._RETURN(self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3749
#else
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3750
    if (__qIsStringLike(self)) {
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3751
        console_fprintf(stdout, "%s\n" , __stringVal(self));
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3752
        console_fflush(stdout);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3753
        RETURN (self);
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3754
    }
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3755
#endif
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3756
%}.
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3757
!
a1191adb52dc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20838
diff changeset
  3758
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3759
displayString
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3760
    "return a string used when displaying the receiver in a view."
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3761
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3762
    ^ super displayString.
17539
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3763
"/    ^ self storeString.
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3764
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3765
    "
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3766
     'hello' -> 'hello'
a195ade70e76 class: String
Claus Gittinger <cg@exept.de>
parents: 17378
diff changeset
  3767
    "
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3768
!
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3769
20879
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3770
errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3771
    "print the receiver on standard error, if the global Stderr is nil;
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3772
     otherwise, fall back to the inherited errorPrint, which sends the string to
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3773
     the Stderr stream or to a logger.
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3774
     Redefined to be able to print during early startup, 
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3775
     when the stream classes have not yet been initialized (i.e. Stderr is nil)."
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3776
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3777
    Stderr isNil ifTrue:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3778
        self _errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3779
    ] ifFalse:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3780
        super errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3781
    ].
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3782
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3783
    "
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3784
      'hello world' asUnicode16String errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3785
      (Character value:356) asString errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3786
      'Bönnigheim' errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3787
      'Bönnigheim' asUnicodeString errorPrint
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3788
    "
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3789
!
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3790
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3791
errorPrintCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3792
    "print the receiver on standard error, followed by a cr,
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3793
     if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR,
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3794
     which sends the string to the Stderr stream or to a logger.
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3795
     Redefined to be able to print during early startup, 
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3796
     when the stream classes have not yet been initialized (i.e. Stderr is nil)."
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3797
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3798
    Stderr isNil ifTrue:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3799
        self _errorPrintCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3800
    ] ifFalse:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3801
        super errorPrintCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3802
    ].
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3803
!
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3804
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3805
lowLevelErrorPrint
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3806
    "Do not use this in user code.
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3807
     Print the receiver on standard error.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3808
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3809
     will therefore work even in case of emergency during early startup
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3810
     or in a crash situation (MiniDebugger)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3811
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3812
%{  /* NOCONTEXT */
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3813
#ifdef __SCHTEAM__
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3814
    if (self.isStringLike()) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3815
        org.exept.stj.STSystem.err.print(self.asString());
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3816
        return context._RETURN(self);
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3817
    }
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3818
#else
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3819
    if (__qIsStringLike(self)) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3820
        console_fprintf(stderr, "%s" , __stringVal(self));
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3821
        console_fflush(stderr);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3822
        RETURN (self);
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3823
    }
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3824
#endif /* not SCHTEAM */
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3825
%}.
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3826
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3827
    "
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3828
      'hello world' asUnicode16String errorPrint
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3829
      (Character value:356) asString errorPrint
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3830
      'Bönnigheim' errorPrint
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3831
      'Bönnigheim' asUnicodeString errorPrint
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3832
    "
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3833
!
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3834
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3835
lowLevelErrorPrintCR
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3836
    "Do not use this in user code.
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3837
     Print the receiver on standard error.
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3838
     This method does NOT (by purpose) use the stream classes and
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3839
     will therefore work even in case of emergency during early startup
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3840
     or in a crash situation (MiniDebugger)."
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3841
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3842
%{  /* NOCONTEXT */
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3843
#ifdef __SCHTEAM__
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3844
    if (self.isStringLike()) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3845
        org.exept.stj.STSystem.err.println(self.asString());
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3846
        return context._RETURN(self);
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3847
    }
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3848
#else
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3849
    if (__qIsStringLike(self)) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3850
        console_fprintf(stderr, "%s\n" , __stringVal(self));
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3851
        console_fflush(stderr);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3852
        RETURN (self);
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3853
    }
18286
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3854
#endif
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3855
%}.
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3856
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3857
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3858
lowLevelPrint
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3859
    "Do not use this in user code.
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3860
     Print the receiver on standard output.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3861
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3862
     will therefore work even in case of emergency during early startup
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3863
     or in a crash situation (MiniDebugger)."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3864
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3865
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3866
#ifdef __SCHTEAM__
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3867
    org.exept.stj.STSystem.out.print(self.toString());
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3868
    return context._RETURN(self);
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3869
#else
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3870
    if (__qIsStringLike(self)) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3871
        console_fprintf(stdout, "%s" , __stringVal(self));
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3872
        console_fflush(stdout);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3873
        RETURN (self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3874
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3875
#endif
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3876
%}.
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3877
!
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3878
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3879
lowLevelPrintCR
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3880
    "Do not use this in user code.
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3881
     Print the receiver on standard output.
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3882
     This method does NOT (by purpose) use the stream classes and
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3883
     will therefore work even in case of emergency during early startup
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3884
     or in a crash situation (MiniDebugger)."
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3885
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3886
%{  /* NOCONTEXT */
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3887
#ifdef __SCHTEAM__
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3888
    org.exept.stj.STSystem.out.println(self.toString());
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3889
    return context._RETURN(self);
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3890
#else
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3891
    if (__qIsStringLike(self)) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3892
        console_fprintf(stdout, "%s\n" , __stringVal(self));
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3893
        console_fflush(stdout);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3894
        RETURN (self);
20494
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3895
    }
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3896
#endif
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3897
%}.
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3898
!
89fd9a43ee49 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20483
diff changeset
  3899
20879
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3900
print
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3901
    "print the receiver on standard output, if the global Stdout is nil;
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3902
     otherwise, fall back to the inherited print,
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3903
     which sends the string to the Stdout stream.
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3904
     Redefined to be able to print during early startup, 
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3905
     when the stream classes have not yet been initialized (i.e. Stdout is nil)."
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3906
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3907
    Stdout isNil ifTrue:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3908
        self _print
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3909
    ] ifFalse:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3910
        super print
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3911
    ].
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3912
!
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3913
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3914
printCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3915
    "print the receiver on standard output, followed by a cr,
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3916
     if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR,
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3917
     which sends the string to the Stdout stream.
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3918
     Redefined to be able to print during early startup, 
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3919
     when the stream classes have not yet been initialized (i.e. Stdout is nil)."
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3920
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3921
    Stdout isNil ifTrue:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3922
        self _printCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3923
    ] ifFalse:[
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3924
        super printCR
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3925
    ].
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3926
!
e0a981ba5487 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20844
diff changeset
  3927
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3928
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3929
    "non-standard but sometimes useful.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3930
     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
  3931
     which is defined by printf.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3932
     This method is NONSTANDARD and may be removed without notice.
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3933
     WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe.
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3934
     Please use the printf: method, which is both safe 
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3935
     and completely implemented in Smalltalk."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3936
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3937
%{  /* STACK: 1000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3938
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3939
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3940
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3941
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3942
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3943
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3944
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3945
    OBJ s;
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3946
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3947
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3948
    if (__isStringLike(formatString)) {
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3949
        cp = (char *)__stringVal(self);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3950
        if (__qClass(self) != String) {
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3951
            cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3952
        }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3953
again:
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3954
        /*
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3955
         * actually only needed on sparc: since thisContext is
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3956
         * in a global register, which gets destroyed by printf,
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3957
         * manually save it here - very stupid ...
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3958
         */
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3959
        __BEGIN_PROTECT_REGISTERS__
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3960
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3961
        len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3962
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3963
        __END_PROTECT_REGISTERS__
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3964
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3965
        if ((len < 0) || (len > bufsize)) {
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3966
            if (len < 0) {
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3967
                bufsize = bufsize * 2;
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3968
            } else {
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3969
                bufsize = len + 1;
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3970
            }
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3971
            if (mallocbuf)
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3972
                free(mallocbuf);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3973
            buf = mallocbuf = malloc(bufsize);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3974
            if (buf == NULL)
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3975
                goto fail;
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3976
            goto again;
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3977
        }
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3978
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3979
        s = __MKSTRING_L(buf, len);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3980
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3981
        if (mallocbuf)
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3982
            free(mallocbuf);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3983
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3984
        if (s != nil) {
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3985
            RETURN (s);
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  3986
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3987
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3988
fail:;
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  3989
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3990
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3991
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3992
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3993
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3994
     'hello' printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3995
     (String new:900) printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3996
     'hello' printfPrintString:'%%10s -> %10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3997
     'hello' printfPrintString:'%%-10s -> %-10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3998
     'hello' printfPrintString:'%%900s -> %900s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3999
     'hello' printfPrintString:'%%-900s -> %-900s'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4000
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4001
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4002
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4003
storeOn:aStream
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  4004
    "put the storeString of myself onto a aStream"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4005
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  4006
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4007
    (self includes:$') ifTrue:[
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  4008
        self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4009
    ] ifFalse:[
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  4010
        aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4011
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4012
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  4013
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  4014
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4015
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4016
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4017
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4018
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4019
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  4020
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4021
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4022
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4023
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4024
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4025
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4026
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4027
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4028
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4029
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4030
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  4031
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4032
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4033
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4034
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4035
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4036
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4037
    if (cls == String) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4038
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4039
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4040
    RETURN ( __mkSmallInteger(__stringSize(slf)
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4041
			  - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4042
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4043
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4044
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4045
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4046
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4047
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  4048
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  4049
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  4050
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  4051
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  4052
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  4053
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  4054
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  4055
19759
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4056
bytesPerCharacter
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4057
    "return the number of bytes each character has.
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4058
     Here, 1 is returned (storing single byte characters)."
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4059
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4060
    ^ 1
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4061
!
9ff833d647f6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19748
diff changeset
  4062
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4063
characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4064
    "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
  4065
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4066
%{  /* NOCONTEXT */
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4067
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4068
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4069
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4070
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4071
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4072
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4073
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4074
#if __POINTER_SIZE__ == 8
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4075
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4076
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4077
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4078
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4079
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4080
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4081
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4082
#endif
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4083
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4084
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4085
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4086
		RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4087
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4088
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4089
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4090
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4091
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4092
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4093
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4094
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4095
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4096
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4097
	    RETURN ( __mkSmallInteger(8) );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4098
	}
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4099
    }
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4100
    RETURN ( __mkSmallInteger(7) );
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4101
%}.
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4102
    ^ super characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4103
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4104
    "
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4105
     'hello world' characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4106
     'hello world' asUnicode16String characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4107
     ('hello world' , (Character value:16r88) asString) characterSize
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4108
    "
18587
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  4109
!
df2481e32531 class: String
Stefan Vogel <sv@exept.de>
parents: 18581
diff changeset
  4110
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4111
containsNon7BitAscii
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4112
    "return true, if the underlying string contains 8BitCharacters (or widers)
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4113
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4114
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4115
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4116
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4117
    REGISTER unsigned char *cp = __stringVal(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4118
    REGISTER unsigned char *last = cp + __stringSize(self);
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4119
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4120
    if (!__isStringLike(self)) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4121
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4122
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  4123
#if __POINTER_SIZE__ == 8
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4124
    if (sizeof(unsigned INT) == 8) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4125
	for ( ; (cp+8) <= last; cp += 8) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4126
	    if (*(unsigned INT *)cp & 0x8080808080808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4127
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4128
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4129
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4130
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  4131
#endif
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4132
    if (sizeof(int) == 4) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4133
	for ( ; (cp+4) <= last; cp += 4) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4134
	    if (*(unsigned int *)cp & 0x80808080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4135
		RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4136
	    }
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4137
	}
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  4138
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4139
    for ( ; (cp+2) <= last; cp += 2) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4140
	if (*(unsigned short *)cp & 0x8080) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4141
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4142
	}
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  4143
    }
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4144
    for ( ; cp < last; cp++) {
18660
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4145
	if (*cp & 0x80) {
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4146
	    RETURN ( true );
c77c8916b3e5 added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents: 18622
diff changeset
  4147
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4148
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4149
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4150
%}.
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4151
    ^ super containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4152
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4153
    "
18594
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4154
     'hello world' containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4155
     'hello world' asTwoByteString containsNon7BitAscii
f69cc45e932a class: String
Stefan Vogel <sv@exept.de>
parents: 18587
diff changeset
  4156
     ('hello world' , (Character value:16r88) asString) containsNon7BitAscii
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4157
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4158
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  4159
18968
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4160
containsNon8BitElements
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4161
    "return true, if the underlying string contains elements larger than a single byte"
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4162
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4163
    ^ false.
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4164
!
292358340956 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18932
diff changeset
  4165
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4166
isWideString
19579
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4167
    "true if I require more than one byte per character"
9a62e43aedf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19503
diff changeset
  4168
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4169
    ^ false
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4170
!
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  4171
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4172
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4173
    "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
  4174
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4175
     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
  4176
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4177
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4178
#ifdef __SCHTEAM__
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4179
    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
  4180
#else
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4181
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4182
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4183
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4184
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4185
    if (cls != String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4186
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4187
    } else {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4188
	indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4189
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4190
    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
  4191
#endif /* ! __SCHTEAM__ */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4192
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  4193
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4194
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4195
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4196
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4197
     'hello' knownAsSymbol
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4198
     'fooBarBaz' knownAsSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4199
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4200
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4201
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4202
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4203
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4204
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4205
     (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
  4206
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4207
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4208
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4209
#ifdef __SCHTEAM__
18404
ae9230dde5ca comments
Claus Gittinger <cg@exept.de>
parents: 18364
diff changeset
  4210
    return context._RETURN( STInteger._new( self.basicSize() ) );
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4211
#else
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4212
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4213
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4214
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4215
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4216
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4217
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4218
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4219
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4220
			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4221
#endif
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4222
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  4223
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4224
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4225
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  4226
stringSpecies
15525
0a0baff63fd0 class: String
Stefan Vogel <sv@exept.de>
parents: 15440
diff changeset
  4227
    ^ self species
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4228
!
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4229
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4230
utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4231
    "return the number of charcters needed when this string is
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4232
     decoded from UTF-8."
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4233
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4234
%{  /* NOCONTEXT */
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4235
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4236
    unsigned char *cp = __stringVal(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4237
    unsigned char *last = cp + __stringSize(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4238
    int max = 1;
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4239
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4240
    if (!__isStringLike(self)) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4241
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4242
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4243
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4244
    for ( ; cp < last; cp++) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4245
	unsigned char mask = *cp & 0xF0;
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4246
	if (mask != 0) {
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4247
	    if ((mask & 0xE0 )== 0xC0) {  if (max < 2) max = 2; }
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4248
	    else if (mask == 0xE0) { if (max < 3) max = 3; }
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4249
	    else if (mask == 0xF0) { max = 4; break;}
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4250
	}
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4251
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4252
    RETURN (__mkSmallInteger(max));
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4253
%}.
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4254
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4255
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4256
     'hello world' utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4257
     'ä' utf8Encoded utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4258
     'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedMaxBytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4259
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4260
!
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4261
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4262
utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4263
    "return the number of charcters needed when this string is
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4264
     decoded from UTF-8."
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4265
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4266
%{  /* NOCONTEXT */
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4267
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4268
    unsigned char *cp = __stringVal(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4269
    unsigned char *last = cp + __stringSize(self);
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4270
    unsigned INT len = 0;
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4271
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4272
    if (!__isStringLike(self)) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4273
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4274
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4275
    // count the number of start-bytes
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4276
    for ( ; cp < last; cp++) {
19877
50dae7a99a93 include string.h (MINGW)
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  4277
	if ((*cp & 0xC0) != 0x80) len++;
19839
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4278
    }
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4279
    RETURN (__mkSmallInteger(len));
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4280
%}.
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4281
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4282
    "
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4283
     'hello world' utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4284
     'ä' utf8Encoded utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4285
     'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedSize
369436ccea40 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19790
diff changeset
  4286
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4287
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4288
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4289
!String methodsFor:'sorting & reordering'!
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4290
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4291
reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4292
    "in-place reverse the characters of the string.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4293
     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
  4294
	      Please use reversed (with a d) for a functional version."
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4295
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4296
    "Q: is there a need to redefine it here ?"
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4297
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4298
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4299
#ifndef __SCHTEAM__
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4300
    REGISTER char c;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4301
    REGISTER unsigned char *hip, *lowp;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4302
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4303
    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
  4304
	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
  4305
	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
  4306
	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
  4307
	    c = *lowp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4308
	    *lowp = *hip;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4309
	    *hip = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4310
	    lowp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4311
	    hip--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4312
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4313
	RETURN ( self );
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4314
    }
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4315
    #endif
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4316
%}.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4317
    ^ super reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  4318
! !
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  4319
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4320
!String methodsFor:'substring searching'!
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4321
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4322
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
  4323
    "redefined as primitive for maximum speed (BM)"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4324
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4325
    |notFound|
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4326
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  4327
%{  /* STACK:4000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4328
#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
  4329
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4330
     && __isStringLike(aSubString)
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4331
     && (caseSensitive == true)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4332
     && (__isSmallInteger(startIndex))
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4333
     && (__intVal(startIndex) > 0)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4334
    ) {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4335
	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
  4336
	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
  4337
	int m = __stringSize(aSubString);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4338
	int n = __stringSize(self);
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  4339
#       define MAX_PATTERN_SIZE 128
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4340
#       define XSIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4341
#       define ASIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4342
#       define MAX(a,b) (a>b ? a : b)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4343
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4344
	if (m == 0) {
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4345
#if 1
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4346
	    /* 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
  4347
	    RETURN(__mkSmallInteger(0));
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4348
#else
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4349
	    /* empty string matches */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4350
	    RETURN(startIndex);
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  4351
#endif
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4352
	}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4353
	if (m <= XSIZE) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4354
	    int i, j;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4355
	    static int lastPatternSize = 0;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4356
	    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
  4357
	    static int bmGs[XSIZE+1], bmBc[ASIZE];
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4358
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4359
#           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
  4360
	       int i;                             \
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
	       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
  4363
		  bmBc[i] = m;                    \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4364
	       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
  4365
		  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
  4366
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4367
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4368
#           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
  4369
	       int f, g, i;                                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4370
								\
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4371
	       suff[m - 1] = m;                                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4372
	       g = m - 1;                                       \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4373
	       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
  4374
		  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
  4375
		     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
  4376
		  else {                                        \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4377
		     if (i < g)                                 \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4378
			g = i;                                  \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4379
		     f = i;                                     \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4380
		     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
  4381
			--g;                                    \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4382
		     suff[i] = f - g;                           \
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
	       }                                                \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4385
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4386
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4387
#           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
  4388
	       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
  4389
								\
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4390
	       suffixes(x, m, suff);                            \
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 (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
  4393
		  bmGs[i] = m;                                  \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4394
	       j = 0;                                           \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4395
	       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
  4396
		  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
  4397
		     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
  4398
			if (bmGs[j] == m)                       \
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4399
			   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
  4400
	       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
  4401
		  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
  4402
	    }
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
	    /* 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
  4405
	    if ((m == lastPatternSize)
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4406
	     && (strcmp(lastPattern, x) == 0)) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4407
		/* tables are still valid */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4408
		// 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
  4409
	    } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4410
		/* Preprocessing */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4411
		// 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
  4412
		preBmGs(x, m, bmGs);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4413
		preBmBc(x, m, bmBc);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4414
		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
  4415
		    // 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
  4416
		    strcpy(lastPattern, x);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4417
		    lastPatternSize = m;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4418
		}
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4419
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4420
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4421
	    /* Searching */
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4422
	    j = __intVal(startIndex) - 1;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4423
	    while (j <= n - m) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4424
	       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
  4425
	       if (i < 0) {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4426
		  RETURN (__mkSmallInteger(j+1));
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4427
		  j += bmGs[0];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4428
	       } else {
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4429
		  int s1 = bmGs[i];
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4430
		  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
  4431
		  j += MAX(s1, s2);
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4432
	       }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4433
	    }
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4434
	    notFound = true;
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4435
	}
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4436
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4437
#endif /* ! __SCHTEAM__ */
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4438
%}.
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4439
    notFound == true ifTrue:[
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4440
	^ exceptionValue value.
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4441
    ].
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4442
    ^ self slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4443
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4444
    "Modified: / 05-08-2012 / 12:27:31 / cg"
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4445
!
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4446
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4447
slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4448
    "naive search fallback (non-BM).
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4449
     Use this for short searchStrings (<= 2)
20620
eb26c0ba968a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20594
diff changeset
  4450
     or for caseInSensitive searches"
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4451
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4452
    |notFound|
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4453
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4454
%{
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4455
#ifndef __SCHTEAM__
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4456
    if (__qIsStringLike(self)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4457
     && __isStringLike(aSubString)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4458
     && (__isSmallInteger(startIndex))
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4459
     && (__intVal(startIndex) > 0)
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4460
    ) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4461
	unsigned char *c_pSelf = __stringVal(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4462
	unsigned char *c_substring = __stringVal(aSubString);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4463
	unsigned char *c_pSelfI, *c_pSelfMax;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4464
	int c_lenSelf = __stringSize(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4465
	int c_lenSubstring = __stringSize(aSubString);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4466
	int c_idx0Max = c_lenSelf - c_lenSubstring;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4467
	unsigned char c_first;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4468
	unsigned char c_ucFirst;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4469
	unsigned char c_lcFirst;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4470
	unsigned char c_oppositeCaseFirst;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4471
	int i;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4472
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4473
	if (c_lenSubstring == 0) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4474
#if 1
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4475
	    /* empty string does not match */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4476
	    notFound = true;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4477
	    goto getOutOfHere;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4478
#else
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4479
	    /* empty string matches */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4480
	    RETURN(startIndex);
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4481
#endif
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4482
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4483
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4484
	// searched string's length > string
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4485
	if (c_idx0Max < 0) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4486
	    notFound = true;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4487
	    goto getOutOfHere;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4488
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4489
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4490
	c_first = c_lcFirst = c_substring[0];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4491
	if (((c_first >= 'A') && (c_first <= 'Z'))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4492
	 || ((c_first >= 0xC0) && (c_first <= 0xDE))) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4493
	    c_ucFirst = c_first;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4494
	    c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4495
	} else {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4496
	    if (((c_first >= 'a') && (c_first <= 'z'))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4497
	     || ((c_first >= 0xE0) && (c_first <= 0xFE))) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4498
		c_lcFirst = c_first;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4499
		c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4500
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4501
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4502
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4503
	// idx:
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4504
	// 0123456789
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4505
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4506
	// 1234567890 - lenSelf = 10
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4507
	// abc        - lenSubstring = 3
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4508
	//            - idx0Max = 7 (last legal startIndex)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4509
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4510
	i = __intVal(startIndex) - 1;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4511
	c_pSelfI = c_pSelf + i;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4512
	c_pSelfMax = c_pSelf + c_idx0Max;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4513
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4514
	for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4515
	    int j;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4516
	    unsigned char c_selfChar;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4517
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4518
	    // find the first char
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4519
	    c_selfChar = c_pSelfI[0];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4520
	    if (c_selfChar != c_first) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4521
		if (caseSensitive == true) continue;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4522
		if (c_selfChar != c_oppositeCaseFirst) {
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4523
searchNext: ;
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4524
		    continue;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4525
		}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4526
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4527
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4528
	    // first char matches
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4529
	    // compare rest
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4530
	    for (j=1; j<c_lenSubstring; j++) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4531
		unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4532
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4533
		c_subChar = c_substring[j];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4534
		c_selfChar = c_pSelfI[j];
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4535
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4536
		if (c_selfChar == c_subChar) continue;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4537
		if (caseSensitive == true) goto searchNext;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4538
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4539
		c_lcSubChar = c_subChar;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4540
		if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z'))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4541
		 || ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4542
		    c_lcSubChar = c_subChar - 'A' + 'a';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4543
		    if (c_selfChar != c_lcSubChar) goto searchNext;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4544
		} else {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4545
		    if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z'))
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4546
		     || ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4547
			c_ucSubChar = c_subChar - 'a' + 'A';
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4548
			if (c_selfChar != c_ucSubChar) goto searchNext;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4549
		    } else {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4550
			goto searchNext;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4551
		    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4552
		}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4553
	    }
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4554
	    // if we arrive here, we have a match at i
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4555
	    RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) );
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4556
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4557
	notFound = true;
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4558
    }
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4559
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4560
    getOutOfHere: ;
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4561
#endif /* ! __SCHTEAM__ */
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4562
%}.
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4563
    "/ arrive here if either not found, or invalid arguments
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4564
    notFound == true ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20688
diff changeset
  4565
	^ exceptionValue value.
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4566
    ].
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4567
    ^ 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
  4568
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4569
    "
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4570
     'abcdefg' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4571
     'abcdefg' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4572
     'abcdefg' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4573
     'abcabcg' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4574
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4575
     'ABCDEFG' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4576
     'ABCDEFG' slowIndexOfSubCollection:'Abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4577
     'ABCDEFG' slowIndexOfSubCollection:'aBC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4578
     'ABCDEFG' slowIndexOfSubCollection:'ABC' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4579
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4580
     'ABCDEFG' slowIndexOfSubCollection:'a' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4581
     'ABCDEFG' slowIndexOfSubCollection:'A' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4582
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4583
     'ABCDEFG' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4584
     'ABCDEFG' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4585
     '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
  4586
19715
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4587
     '1234567890' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4588
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:false
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4589
     '1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4590
     '1234567890' slowIndexOfSubCollection:'234' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4591
     '1234567890' slowIndexOfSubCollection:'345' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4592
     '1231231231' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4593
     '1231231231' slowIndexOfSubCollection:'123' startingAt:2 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4594
     '1231231231' slowIndexOfSubCollection:'123' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4595
     '1231231231' slowIndexOfSubCollection:'123' startingAt:4 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4596
     '1231231231' slowIndexOfSubCollection:'123' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4597
     '1231231231' slowIndexOfSubCollection:'123' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4598
     '1231231231' slowIndexOfSubCollection:'123' startingAt:7 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4599
     '1231231231' slowIndexOfSubCollection:'123' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4600
     '1231231231' slowIndexOfSubCollection:'123' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4601
     '1231231231' slowIndexOfSubCollection:'123' startingAt:10 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4602
     '1231231231' slowIndexOfSubCollection:'123' startingAt:11 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4603
     '1231231231' slowIndexOfSubCollection:'231' startingAt:1 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4604
     '1231231231' slowIndexOfSubCollection:'231' startingAt:3 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4605
     '1231231231' slowIndexOfSubCollection:'231' startingAt:5 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4606
     '1231231231' slowIndexOfSubCollection:'231' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4607
     '1231231231' slowIndexOfSubCollection:'231' startingAt:8 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4608
     '1231231231' slowIndexOfSubCollection:'231' startingAt:9 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4609
     '1231231231' slowIndexOfSubCollection:'2310' startingAt:6 ifAbsent:nil caseSensitive:true
58d5215c623e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19579
diff changeset
  4610
     '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
  4611
    "
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4612
! !
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  4613
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4614
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4615
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4616
endsWith:aStringOrChar
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4617
    "return true, if the receiver ends with something, aStringOrChar.
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  4618
     If aStringOrChar is an empty string, true is returned"
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4619
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4620
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4621
#ifndef __SCHTEAM__
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4622
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4623
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4624
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4625
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4626
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  4627
    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
  4628
	len1 = __qSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4629
	len2 = __qSize(aStringOrChar);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4630
	if (len1 < len2) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4631
	    RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4632
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4633
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4634
	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
  4635
	src2 = __stringVal(aStringOrChar);
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4636
	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
  4637
	    if (c != *src1++) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4638
		RETURN ( false );
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4639
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4640
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4641
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4642
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4643
    if (__isCharacter(aStringOrChar)) {
16889
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4644
	int val;
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4645
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4646
	val = __intVal(__characterVal(aStringOrChar));
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4647
	if ((unsigned)val <= 0xFF) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4648
	    len1 = __stringSize(slf);
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4649
	    if (len1 > 0) {
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4650
		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
  4651
	    }
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4652
	}
18ebf0d880ba refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents: 16773
diff changeset
  4653
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4654
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4655
#endif /* ! __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4656
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4657
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4658
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4659
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4660
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4661
     'hello world' endsWith:'earth'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4662
     'hello world' endsWith:$d
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4663
     'hello world' endsWith:$e
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4664
     '' endsWith:$d
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4665
     'hello world' endsWith:#($r $l $d)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4666
     'hello world' endsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4667
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4668
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4669
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4670
isBlank
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4671
    "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
  4672
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4673
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4674
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4675
#ifndef __SCHTEAM__
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4676
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4677
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4678
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4679
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  4680
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4681
    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
  4682
	src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4683
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4684
# ifdef UINT64
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  4685
    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
  4686
	src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4687
    }
19748
44eae32d9fad #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 19745
diff changeset
  4688
# endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  4689
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4690
    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
  4691
	src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4692
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4693
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4694
    while ((c = *src++) == ' ')
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4695
	;; /* just walking along */
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4696
    if (c != '\0') {
19773
323213f1d992 memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents: 19772
diff changeset
  4697
	RETURN ( false );
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4698
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4699
    RETURN ( true );
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
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4702
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4703
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4704
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4705
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4706
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4707
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4708
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4709
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4710
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4711
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4712
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4713
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4714
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4715
	RETURN ( (__stringSize(self) == 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4716
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4717
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4718
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4719
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4720
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4721
10958
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4722
isLiteral
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4723
    "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
  4724
     (i.e. can be used in constant arrays)"
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4725
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4726
    ^ true
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4727
!
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  4728
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4729
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
  4730
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4731
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4732
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  4733
%{  /* STACK: 2000 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4734
#ifndef __SCHTEAM__
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4735
    /*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4736
     * this is very heavy used when correcting errors
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4737
     * (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
  4738
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4739
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4740
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4741
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4742
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4743
    unsigned char *s1, *s2;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4744
    int v1, v2, v3;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  4745
    INT m;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4746
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4747
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4748
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4749
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4750
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  4751
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4752
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4753
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4754
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  4755
    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
  4756
	&& __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
  4757
	&& __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
  4758
	&& __isSmallInteger(kbdTypoWeight)
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4759
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4760
	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
  4761
	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
  4762
	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
  4763
	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
  4764
	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
  4765
	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
  4766
	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
  4767
	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
  4768
	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
  4769
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4770
	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
  4771
	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
  4772
	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
  4773
	    data = fastData;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4774
	} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4775
	    /* 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
  4776
	    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
  4777
	    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
  4778
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4779
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4780
	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
  4781
	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
  4782
	    *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
  4783
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4784
	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
  4785
	    *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
  4786
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4787
	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
  4788
	    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
  4789
		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
  4790
		    m = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4791
		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
  4792
		    m = cW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4793
		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
  4794
		    m = kW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4795
		else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4796
		    m = sW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4797
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4798
		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
  4799
		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
  4800
		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
  4801
		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
  4802
		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
  4803
		    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
  4804
			m = v1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4805
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4806
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4807
		} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4808
		    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
  4809
			m = v2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4810
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4811
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4812
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4813
		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
  4814
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4815
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4816
	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
  4817
	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
  4818
	    free(data);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  4819
	RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4820
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4821
mallocFailed: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4822
#endif /* ! __SCHTEAM__ */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4823
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4824
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4825
    ^ 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
  4826
			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
  4827
			i:insrtWeight d:deleteWeight
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4828
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4829
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4830
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4831
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4832
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4833
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4834
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4835
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4836
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4837
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  4838
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4839
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4840
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4841
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4842
    "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
  4843
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4844
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4845
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4846
#ifndef __SCHTEAM__
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4847
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4848
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4849
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4850
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  4851
	RETURN ( (__stringSize(self) != 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4852
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4853
#endif /* ! __SCHTEAM__ */
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4854
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4855
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4856
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  4857
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4858
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  4859
    "return true, if the receiver starts with something, aStringOrChar.
17370
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4860
     If the argument is empty, true is returned.
2e8e3d69be55 class: String
Claus Gittinger <cg@exept.de>
parents: 16900
diff changeset
  4861
     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
  4862
     which are both inconsistent w.r.t. an empty argument."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4863
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4864
%{  /* NOCONTEXT */
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4865
#ifdef __SCHTEAM__
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4866
    if (self.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4867
	if (aStringOrChar.isSTString()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4868
	    java.lang.String me = self.asString();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4869
	    java.lang.String other = aStringOrChar.asString();
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4870
	    return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4871
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4872
	if (aStringOrChar.isSTCharacter()) {
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4873
	    char[] me = self.asSTString().characters;
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4874
	    char ch = aStringOrChar.charValue();
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4875
	    return __c__._RETURN( ((me.length > 0)
18405
140903606af8 comment
Claus Gittinger <cg@exept.de>
parents: 18404
diff changeset
  4876
				  && (me[0] == ch)) ? STObject.True : STObject.False);
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4877
	}
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4878
    }
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4879
#else
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4880
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4881
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  4882
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4883
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4884
14217
d399ca31088f changed: #startsWith:
Stefan Vogel <sv@exept.de>
parents: 14201
diff changeset
  4885
    if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4886
	src1 = __stringVal(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4887
	src2 = __stringVal(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4888
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4889
	if (src1[0] != src2[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4890
	    if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4891
		RETURN (true);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4892
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4893
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4894
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4895
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4896
	len1 = __qSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4897
	len2 = __qSize(aStringOrChar);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4898
	if (len1 < len2) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4899
	    RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4900
	}
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4901
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4902
# ifdef UINT64
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4903
	while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4904
	    if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4905
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4906
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4907
	    len2 -= sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4908
	    src1 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4909
	    src2 += sizeof(UINT64);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4910
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4911
# else
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4912
#  ifdef __UNROLL_LOOPS__
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4913
	while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4914
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4915
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4916
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4917
	    if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4918
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4919
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4920
	    if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4921
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4922
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4923
	    if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4924
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4925
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4926
	    len2 -= sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4927
	    src1 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4928
	    src2 += sizeof(INT)*4;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4929
	}
18233
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4930
#  endif /* __UNROLL_LOOPS__ */
b0bba7f5bfeb java support (experimental)
Claus Gittinger <cg@exept.de>
parents: 18215
diff changeset
  4931
# endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  4932
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4933
	while (len2 > (OHDR_SIZE+sizeof(INT))) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4934
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4935
		RETURN (false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4936
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4937
	    len2 -= sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4938
	    src1 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4939
	    src2 += sizeof(INT);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4940
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4941
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4942
	while ((c = *src2++) != '\0') {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4943
	    if (c != *src1) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4944
		RETURN ( false );
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4945
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4946
	    src1++;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4947
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4948
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4949
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  4950
    if (__isCharacter(aStringOrChar)) {
18215
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4951
	int val;
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4952
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4953
	val = __intVal(__characterVal(aStringOrChar));
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4954
	if ((unsigned)val <= 0xFF) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4955
	    len1 = __stringSize(slf);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4956
	    if (len1 > 0) {
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4957
		RETURN ( (__stringVal(slf)[0] == val) ? true : false);
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4958
	    }
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4959
	}
5940d5eff81b java preps
Claus Gittinger <cg@exept.de>
parents: 17649
diff changeset
  4960
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4961
    }
18343
d70cad49ba36 comments only
Claus Gittinger <cg@exept.de>
parents: 18306
diff changeset
  4962
#endif /* not __SCHTEAM__ */
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4963
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  4964
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4965
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4966
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4967
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  4968
     'hello world' startsWith:'hella'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4969
     'hello world' startsWith:'hi'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4970
     'hello world' startsWith:$h
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4971
     'hello world' startsWith:$H
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4972
     'hello world' startsWith:(Character value:16rFF00)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4973
     'hello world' startsWith:60
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4974
     'hello world' startsWith:#($h $e $l)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  4975
     'hello world' startsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  4976
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4977
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4978
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4979
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4980
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4981
isSingleByteString
16773
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4982
    "returns true only for strings and immutable strings.
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4983
     Must replace foo isMemberOf:String and foo class == String"
5d50150c6437 class: String
Claus Gittinger <cg@exept.de>
parents: 16771
diff changeset
  4984
16771
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4985
    ^ true
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4986
!
fd1300478406 class: String
Claus Gittinger <cg@exept.de>
parents: 16543
diff changeset
  4987
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4988
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4989
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4990
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  4991
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4992
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4993
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4994
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  4995
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4996
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  4997
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  4998
version
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  4999
    ^ '$Header$'
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  5000
!
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  5001
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  5002
version_CVS
18551
7f43475b5613 eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents: 18405
diff changeset
  5003
    ^ '$Header$'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  5004
! !
20838
93eb16aed922 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  5005