String.st
author Claus Gittinger <cg@exept.de>
Thu, 15 May 2014 19:20:43 +0200
changeset 16457 c25394c44436
parent 16393 4d56dffdd2ca
child 16543 fcdac85d5bee
permissions -rw-r--r--
class: String changed: #asArrayOfSubstrings #asArrayOfSubstringsSeparatedBy:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    12
"{ Package: 'stx:libbasic' }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    13
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    14
CharacterArray variableByteSubclass:#String
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    15
	instanceVariableNames:''
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
    16
	classVariableNames:'CRLF CR LF TAB'
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    17
	poolDictionaries:''
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    18
	category:'Collections-Text'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    19
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    20
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    21
!String primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
%{
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
    23
3809
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    24
#include <stdio.h>
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    25
#define _STDIO_H_INCLUDED_
14752
201d3e649814 include stdlib.h to define malloc() prototypes
Stefan Vogel <sv@exept.de>
parents: 14664
diff changeset
    26
#include <stdlib.h>
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
#include <ctype.h>
359
claus
parents: 357
diff changeset
    28
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    29
#ifdef LINUX
359
claus
parents: 357
diff changeset
    30
# define __STRINGDEFS__
claus
parents: 357
diff changeset
    31
# include <linuxIntern.h>
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    32
#endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    33
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    34
/*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    35
 * old st/x creates strings with spaces in it;
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    36
 * new st/x will fill it with zeros (for st-80 compatibility)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    37
 * the define below sets old behavior.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    38
 */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    39
#define INITIALIZE_WITH_SPACE
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    40
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    41
#ifdef FAST_MEMCHR
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    42
 char *memchr();
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    43
#endif
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    44
%}
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    45
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    47
!String primitiveFunctions!
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    48
%{
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    49
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
    50
static int
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    51
nextOnKeyboard(char1, char2)
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    52
{
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    53
    /* 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
    54
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    55
    static char *us_keys[] = { "1234567890-",
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    56
			    "*qwertyuiop",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    57
			    "**asdfghjkl:",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    58
			    "***zxcvbnm",
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    59
			    0 };
10370
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    60
    static char *de_keys[] = { "1234567890-",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    61
			    "*qwertzuiop",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    62
			    "**asdfghjkl:",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    63
			    "***yxcvbnm",
b7b777d9599d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10352
diff changeset
    64
			    0 };
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
    65
    char **keys = us_keys;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    66
    char **line1, **line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    67
    char *col1, *col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    68
    int diff;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    69
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    70
    for (line1 = keys; *line1 != 0; line1++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    71
	for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    72
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    73
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    74
    if (*col1 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    75
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    76
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    77
    for (line2 = keys; *line2 != 0; line2++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    78
	for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    79
	    continue;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    80
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    81
    if (*col2 == 0)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    82
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    83
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    84
    diff = col1 - col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    85
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    86
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    87
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    88
    diff = line1 - line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    89
    if (diff > 1 || diff < -1)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
    90
	return(0);
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    91
    return(1);
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
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    94
%}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    95
! !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    96
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
!String class methodsFor:'documentation'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
copyright
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
 COPYRIGHT (c) 1988 by Claus Gittinger
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   102
	      All Rights Reserved
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
 This software is furnished under a license and may be used
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
 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
   106
 inclusion of the above copyright notice.   This software may not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
 be provided or otherwise made available to, or used by, any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
 other person.  No title to or ownership of the software is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
 hereby transferred.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   112
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
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
    Strings are ByteArrays storing Characters.
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
    Strings are kind of kludgy: to allow for easy handling by c-functions,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
    there is always one 0-byte added at the end, which is not counted
4800
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   119
    in the strings size, and is not accessable from the smalltalk level.
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   120
    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
   121
    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
   122
    prevent a nonsense contents ...)
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   123
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
    You cannot add any instvars to String, since the the run time system & compiler
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
    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
   126
    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
   127
    of String (the access functions defined here can handle this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
    A little warning though: not all smalltalk systems allow subclassing String,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
    so your program may become unportable if you do so.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   130
7895
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   131
    Strings have an implicit (assumed) encoding of iso8859-1.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   132
    For strings with other encodings, either keep the encoding separately,
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   133
    or use instances of encodedString.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   134
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   135
    [author:]
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   136
	Claus Gittinger
1310
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   137
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   138
    [see also:]
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   139
	Text StringCollection TwoByteString JISEncodedString
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   140
	Symbol
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   142
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   143
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
!String class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
basicNew:anInteger
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   147
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   148
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   149
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   150
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   151
     can be directly used as separator or for formatting."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
    OBJ newString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
    REGISTER int len;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
    REGISTER unsigned char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
    REGISTER OBJ *op;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
    int nInstVars, instsize;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   160
252
   161
    if (__isSmallInteger(anInteger)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   162
	len = __intVal(anInteger);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   163
	if (len >= 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   164
	    instsize = OHDR_SIZE + len + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   165
	    if (self == String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   166
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   167
		    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   168
		     * the most common case
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   169
		     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   170
		    __qCheckedNew(newString, instsize);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   171
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   172
		    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   173
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   174
		    cp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   175
357
claus
parents: 347
diff changeset
   176
#if defined(memset4) && !defined(NON_ASCII)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   177
		    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   178
			/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   179
			 * no sizeof(int) here please -
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   180
			 * - memset4 (if defined) fills 4-bytes on ALL machines
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   181
			 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   182
			int l4 = len >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   183
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   184
			if (len & 3) l4++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   185
			memset4(cp, 0x20202020, l4);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   186
			cp[len] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   187
		    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   188
#else
357
claus
parents: 347
diff changeset
   189
# ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   190
		    memset(cp, ' ', len);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   191
		    cp[len] = '\0';
357
claus
parents: 347
diff changeset
   192
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   193
		    while (len >= 8) {
3449
84160615c630 oops - basicNew was bad for subclasses of String.
Claus Gittinger <cg@exept.de>
parents: 3403
diff changeset
   194
#  ifndef NON_ASCII       /* i.e. EBCDIC  */
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   195
#   ifdef INT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   196
			((INT64 *)cp)[0] = 0x2020202020202020L;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   197
#   else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   198
			((int *)cp)[0] = 0x20202020;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   199
			((int *)cp)[1] = 0x20202020;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   200
#   endif
357
claus
parents: 347
diff changeset
   201
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   202
			cp[0] = cp[1] = cp[2] = cp[3] = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   203
			cp[4] = cp[5] = cp[6] = cp[7] = ' ';
357
claus
parents: 347
diff changeset
   204
#  endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   205
			cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   206
			len -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   207
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   208
		    while (len--)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   209
			*cp++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   210
		    *cp = '\0';
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   211
# endif /* not FAST_MEMSET */
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   212
#endif /* not memset4 */
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   213
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   214
		    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   215
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   216
		nInstVars = 0;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   217
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   218
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   219
		instsize += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   220
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   221
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   222
	    __PROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   223
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   224
	    __UNPROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   225
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   226
	    if (newString == nil) goto fail;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   227
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   228
	    __InstPtr(newString)->o_class = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   229
	    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   230
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   231
	    cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   232
	    if (nInstVars) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   233
		cp += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   234
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   235
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   236
		 * nil-out instvars
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   237
		 */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   238
#if defined(memset4)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   239
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   240
#else
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   241
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   242
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   243
		 * knowing that nil is 0
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   244
		 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   245
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   246
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   247
		op = __InstPtr(newString)->i_instvars;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   248
		do {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   249
		    *op++ = nil;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   250
		} while (--nInstVars);
357
claus
parents: 347
diff changeset
   251
# endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   252
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   253
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   254
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   255
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   256
	     * fill with spaces
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   257
	     */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   258
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   259
	    memset(cp, ' ', len);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   260
	    *(cp + len) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   262
	    while (len >= 8) {
357
claus
parents: 347
diff changeset
   263
# ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   264
#  ifdef INT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   265
		((INT64 *)cp)[0] = 0x2020202020202020L;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   266
#  else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   267
		((int *)cp)[0] = 0x20202020;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   268
		((int *)cp)[1] = 0x20202020;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   269
#  endif
357
claus
parents: 347
diff changeset
   270
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   271
		cp[0] = cp[1] = cp[2] = cp[3] = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   272
		cp[4] = cp[5] = cp[6] = cp[7] = ' ';
357
claus
parents: 347
diff changeset
   273
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   274
		cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   275
		len -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   276
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   277
	    while (len--)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   278
		*cp++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   279
	    *cp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   281
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   282
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   284
fail: ;;
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   285
%}.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   286
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   287
     invalid argument, or out-of-memory:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   288
     use error handling in superclass
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   289
    "
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   290
    (anInteger < 0) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   291
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   292
	 the argument is negative,
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   293
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   294
	self error:'bad (negative) argument to new:'.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   295
	^ nil
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   296
    ].
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   297
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   298
    ^ (super basicNew:anInteger+1) atAllPut:(Character space)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   299
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
new:n
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   302
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   303
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   304
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   305
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   306
     can be directly used as separator or for formatting."
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   307
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    ^ self basicNew:n
347
claus
parents: 345
diff changeset
   309
!
claus
parents: 345
diff changeset
   310
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   311
readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   312
    "read & return the next String from the (character-)stream aStream;
claus
parents: 345
diff changeset
   313
     skipping all whitespace first; return the value of exceptionBlock,
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   314
     if no string can be read. The sequence of characters as read from the
347
claus
parents: 345
diff changeset
   315
     stream must be one as stored via storeOn: or storeString."
claus
parents: 345
diff changeset
   316
claus
parents: 345
diff changeset
   317
    "
claus
parents: 345
diff changeset
   318
     this method is not to be inherited
claus
parents: 345
diff changeset
   319
     (i.e. not ok for subclasses; Symbol, for example)
claus
parents: 345
diff changeset
   320
    "
claus
parents: 345
diff changeset
   321
    self ~~ String ifTrue:[
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
   322
	^ super readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   323
    ].
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   324
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   325
claus
parents: 345
diff changeset
   326
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   327
     String readFrom:('''hello world''' readStream)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   328
     String readFrom:('''hello '''' world''' readStream)
347
claus
parents: 345
diff changeset
   329
     String readFrom:('1 ''hello'' ' readStream)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   330
     String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
3376
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   331
    "
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   332
9426
1f45fcd79d08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9367
diff changeset
   333
    "Modified: / 05-07-2006 / 16:41:29 / cg"
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   334
    "Modified: / 07-08-2006 / 15:03:09 / fm"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   337
uninitializedNew:anInteger
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   338
    "return a new string with anInteger characters but undefined contents.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   339
     Use this, if the string is filled anyway with new data, for example, if
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   340
     used as a stream buffer."
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   341
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   342
%{  /* NOCONTEXT */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   343
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   344
    OBJ newString;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   345
    REGISTER int len;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   346
    REGISTER unsigned char *cp;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   347
    REGISTER OBJ *op;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   348
    int nInstVars, instsize;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   349
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   350
    if (__isSmallInteger(anInteger)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   351
	len = __intVal(anInteger);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   352
	if (len >= 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   353
	    instsize = OHDR_SIZE + len + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   354
	    if (self == String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   355
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   356
		    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   357
		     * the most common case
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   358
		     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   359
		    __qCheckedNew(newString, instsize);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   360
		    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   361
		    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   362
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   363
		    cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   364
		    cp[len] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   365
		    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   366
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   367
		nInstVars = 0;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   368
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   369
		nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   370
		instsize += __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   371
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   372
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   373
	    __PROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   374
	    __qNew(newString, instsize);        /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   375
	    __UNPROTECT_CONTEXT__;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   376
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   377
	    if (newString == nil) goto fail;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   378
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   379
	    __InstPtr(newString)->o_class = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   380
	    __qSTORE(newString, self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   381
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   382
	    if (nInstVars) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   383
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   384
		 * nil-out instvars
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   385
		 */
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   386
#if defined(memset4)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   387
		memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   388
#else
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   389
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   390
		/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   391
		 * knowing that nil is 0
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   392
		 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   393
		memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   394
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   395
		op = __InstPtr(newString)->i_instvars;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   396
		do {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   397
		    *op++ = nil;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   398
		} while (--nInstVars);
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   399
# endif
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   400
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   401
		cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   402
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   403
		cp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   404
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   405
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   406
	    *(cp + len) = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   407
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   408
	}
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   409
    }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   410
fail: ;;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   411
%}.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   412
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   413
     invalid argument, or out-of-memory:
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   414
     use error handling in superclass
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   415
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   416
    (anInteger < 0) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   417
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   418
	 the argument is negative,
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   419
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   420
	self error:'bad (negative) argument to new:'.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   421
	^ nil
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   422
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   424
    ^ self basicNew:anInteger
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   425
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
     String uninitializedNew:100
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   428
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   429
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   430
8438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   431
!String class methodsFor:'Compatibility-Dolphin'!
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   432
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   433
lineDelimiter
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   434
    "Dolphin compatibility: answer CR LF"
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   435
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   436
    ^ self crlf
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   437
! !
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   438
7302
13a053c255bf category
Claus Gittinger <cg@exept.de>
parents: 7283
diff changeset
   439
!String class methodsFor:'Compatibility-Squeak'!
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   440
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   441
cr
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   442
    "return a string consisting of the cr-Character"
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   443
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   444
    CR isNil ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   445
	CR := String with:Character return
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   446
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   447
    ^ CR
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   448
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   449
    "Modified: / 13.11.1999 / 13:53:36 / cg"
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   450
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   451
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   452
crlf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   453
    "return a string consisting of the cr-lf Characters"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   454
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   455
    CRLF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   456
	CRLF := String
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   457
		    with:Character return
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   458
		    with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   459
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   460
    ^ CRLF
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   461
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   462
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   463
lf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   464
    "return a string consisting of the lf Character"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   465
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   466
    LF isNil ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   467
	LF := String with:Character linefeed
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   468
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   469
    ^ LF
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   470
!
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   471
12344
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   472
stringHash:aString initialHash:speciesHash
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   473
    "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
   474
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   475
    | stringSize hash low |
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   476
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   477
    stringSize := aString size.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   478
    hash := speciesHash bitAnd: 16rFFFFFFF.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   479
    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
   480
	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
   481
	"Begin hashMultiply"
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   482
	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
   483
	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
   484
    ].
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   485
    ^ hash.
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   486
!
a4cf954bb1e1 added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents: 12184
diff changeset
   487
11856
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   488
tab
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   489
    "return a string consisting of the tab-Character"
Claus Gittinger <cg@exept.de>
parents: 11824
diff changeset
   490
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   491
    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
   492
	TAB := String with:Character tab
14330
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   493
    ].
be357b5c0adb changed:
Claus Gittinger <cg@exept.de>
parents: 14301
diff changeset
   494
    ^ TAB
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   495
! !
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   496
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   497
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
   498
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
   499
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   500
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   501
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   502
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   503
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   504
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   505
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   506
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   507
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   508
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   509
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   510
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   511
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   512
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   513
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   514
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   515
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   516
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   517
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   518
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
   519
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
   520
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
   521
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
   522
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
   523
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   524
!String methodsFor:'Compatibility-VW5.4'!
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   525
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   526
asGUID
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   527
    "return self as a GUID (or UUID if not present)"
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   528
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   529
    GUID notNil ifTrue:[ ^ GUID fromString:self ].
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   530
    ^ self asUUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   531
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   532
    "
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   533
     '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asGUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   534
    "
13204
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   535
12cea2d85706 changed: #asGUID
Claus Gittinger <cg@exept.de>
parents: 13182
diff changeset
   536
    "Modified: / 12-01-2011 / 12:33:58 / cg"
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   537
! !
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
   538
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   539
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
329
claus
parents: 314
diff changeset
   541
at:index
claus
parents: 314
diff changeset
   542
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   543
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   544
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   545
     This method is the same as at:."
claus
parents: 314
diff changeset
   546
claus
parents: 314
diff changeset
   547
%{  /* NOCONTEXT */
claus
parents: 314
diff changeset
   548
claus
parents: 314
diff changeset
   549
    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
   550
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   551
claus
parents: 314
diff changeset
   552
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   553
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   554
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   555
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   556
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   557
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   558
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   559
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   560
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   561
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   562
	}
329
claus
parents: 314
diff changeset
   563
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   564
badIndex: ;
329
claus
parents: 314
diff changeset
   565
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   566
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   567
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   568
329
claus
parents: 314
diff changeset
   569
at:index put:aCharacter
claus
parents: 314
diff changeset
   570
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   571
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   572
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   573
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   574
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   575
claus
parents: 314
diff changeset
   576
%{  /* NOCONTEXT */
claus
parents: 314
diff changeset
   577
claus
parents: 314
diff changeset
   578
    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
   579
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   580
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   581
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   582
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   583
    if (__isString(slf)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   584
	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
   585
	    value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   586
	    if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   587
	     && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   588
		indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   589
		if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   590
		    __stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   591
		    RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   592
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   593
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   594
	}
329
claus
parents: 314
diff changeset
   595
    }
claus
parents: 314
diff changeset
   596
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   597
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   598
!
claus
parents: 314
diff changeset
   599
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   600
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   601
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   602
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   603
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   604
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   605
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   606
    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
   607
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   609
    if (__isSmallInteger(index)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   610
	slf = self;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   611
	cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   612
	indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   613
	if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   614
	    if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   615
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   616
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   617
	if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   618
	    RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   619
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   621
badIndex: ;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   623
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   624
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   625
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   626
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   627
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   628
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   629
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   632
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   633
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   634
     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
   635
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   636
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
    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
   640
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   641
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   642
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   643
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   644
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   645
    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
   646
	value = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   647
	if (((unsigned)value <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   648
	 && __isSmallInteger(index)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   649
	    cls = __qClass(slf);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   650
	    indx = __intVal(index) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   651
	    if (cls != String) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   652
		if (indx < 0) goto badIndex;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   653
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   654
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   655
	    if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   656
		__stringVal(slf)[indx] = value;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   657
		RETURN ( aCharacter );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   658
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   659
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   661
badIndex: ;
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   662
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   663
    (aCharacter isMemberOf:Character) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   664
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   665
	 tried to store something which is not a character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   666
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   667
	^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   668
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   669
    (aCharacter codePoint between:1 and:255) ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   670
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   671
	 tried to store a multibyte character
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   672
	"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   673
	^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   674
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   675
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   676
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   677
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   678
    index isInteger ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   679
	^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   680
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   681
    index == super basicSize ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
   682
	^ self subscriptBoundsError:index
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   683
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   684
    super basicAt:index put:aCharacter codePoint.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   685
    ^ aCharacter
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   686
!
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   687
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   688
first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   689
    "return the first character.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   690
     Reimplemented here for speed"
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   691
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   692
%{  /* NOCONTEXT */
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   693
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   694
    REGISTER int indx;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   695
    REGISTER OBJ slf, cls;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   696
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   697
    slf = self;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   698
    cls = __qClass(slf);
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   699
    indx = 0;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   700
    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
   701
	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
   702
	indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   703
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   704
    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
   705
	RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
12716
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   706
    }
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   707
badIndex: ;
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   708
%}.
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   709
    ^ super first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   710
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   711
    "
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   712
     'abc' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   713
     '' first
140435b1ac4e added: #first
Claus Gittinger <cg@exept.de>
parents: 12485
diff changeset
   714
    "
2
claus
parents: 1
diff changeset
   715
! !
claus
parents: 1
diff changeset
   716
13182
534223d5e690 changed: #browserView:
Stefan Vogel <sv@exept.de>
parents: 13116
diff changeset
   717
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   718
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   720
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   721
    "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
   722
     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
   723
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   724
    ^ self indexOf:aCharacter
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   725
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   726
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   727
     'hello world' identityIndexOf:(Character space)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   728
     '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
   729
     'hello world' identityIndexOf:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   730
     #[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
   731
     #[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
   732
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   733
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   734
    "Modified: / 10-01-2012 / 17:07:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   735
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
13923
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   737
identityIndexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   738
    "return the index of the first occurrences of the argument, aCharacter
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   739
     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
   740
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   741
    ^ self indexOf:aCharacter startingAt:index
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   742
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   743
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   744
     'hello world' identityIndexOf:(Character space)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   745
     'hello world' identityIndexOf:$d
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   746
     'hello world' identityIndexOf:1
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   747
     #[0 0 1 0 0] asString identityIndexOf:(Character value:1)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   748
     #[0 0 1 0 0] asString identityIndexOf:(Character value:0)
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   749
    "
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   750
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   751
    "Created: / 10-01-2012 / 17:10:54 / cg"
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   752
!
d5c7ee3d3d6a added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13922
diff changeset
   753
10
claus
parents: 5
diff changeset
   754
includesAny:aCollection
claus
parents: 5
diff changeset
   755
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   756
     argument, aCollection.
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   757
     - redefined for speed if the argument is a String."
10
claus
parents: 5
diff changeset
   758
claus
parents: 5
diff changeset
   759
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   760
claus
parents: 5
diff changeset
   761
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   762
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   763
    OBJ cls;
10
claus
parents: 5
diff changeset
   764
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
   765
    if (__isStringLike(aCollection)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   766
	matchP = __stringVal(aCollection);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   767
	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
   768
	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
   769
	    cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   770
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   771
	switch (__stringSize(aCollection)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   772
	    case 3:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   773
		/* three character search */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   774
		if (strchr(cp, matchP[2])) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   775
		    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   776
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   777
		/* fall into */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   778
	    case 2:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   779
		/* two character search */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   780
		if (strchr(cp, matchP[1])) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   781
		    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   782
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   783
		/* fall into */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   784
	    case 1:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   785
		/* single character search */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   786
		if (strchr(cp, matchP[0])) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   787
		    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   788
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   789
		/* fall into */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   790
	    case 0:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   791
		RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   792
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   793
	while (*cp) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   794
	    if (strchr(matchP, *cp)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   795
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   796
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   797
	    cp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   798
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   799
	RETURN ( false );
10
claus
parents: 5
diff changeset
   800
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   801
%}.
10
claus
parents: 5
diff changeset
   802
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   803
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   804
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   805
     'hello world' includesAny:'abcd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   806
     'hello world' includesAny:'xyz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   807
     'hello world' includesAny:'xz'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   808
     'hello world' includesAny:'od'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   809
     'hello world' includesAny:'xd'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   810
     'hello world' includesAny:'dx'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   811
     'hello world' includesAny:(Array with:$a with:$b with:$d)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   812
     'hello world' includesAny:(Array with:$x with:$y)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
   813
     'hello world' includesAny:(Array with:1 with:2)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   814
    "
10
claus
parents: 5
diff changeset
   815
!
claus
parents: 5
diff changeset
   816
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   817
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
   818
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   819
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   820
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   821
a27a279701f8 Initial revision
claus
parents:
diff changeset
   822
%{  /* NOCONTEXT */
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   823
#undef __UNROLL_LOOPS__
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   824
#undef FAST_MEMCHR
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
   825
#define V2
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   826
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   827
    REGISTER unsigned char *cp;
8923
ba871e13e4f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8922
diff changeset
   828
#ifdef FAST_MEMCHR
ba871e13e4f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8922
diff changeset
   829
    REGISTER unsigned char *ncp;
8925
04f0070787ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8924
diff changeset
   830
#endif
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
   831
    REGISTER INT index;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
   832
    REGISTER unsigned byteValue;
8924
eb2dd7dd459f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8923
diff changeset
   833
    int last;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   834
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   835
252
   836
    if (__isSmallInteger(start)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   837
	index = __intVal(start);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   838
	if (index > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   839
	    if (__isCharacter(aCharacter)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   840
		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
   841
		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
   842
		    last = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   843
		    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
   844
		    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
   845
			int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   846
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   847
			cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   848
			last -= numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   849
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   850
		    if (index <= last) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   851
#ifdef FAST_MEMCHR
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   852
			ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   853
			if (ncp) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   854
			    RETURN ( __mkSmallInteger(ncp - cp + 1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   855
			}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   856
#else
8928
e2ca4ffa55b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8927
diff changeset
   857
# 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
   858
			{
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   859
			    int last3 = last-3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   860
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   861
			    for (; index <= last3; index += 4) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   862
				if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   863
				if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   864
				if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   865
				if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   866
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   867
			}
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   868
# endif
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   869
# ifdef V1
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   870
			for (; index <= last; index++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   871
			    if (cp[index-1] == byteValue) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   872
				RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   873
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   874
			}
8928
e2ca4ffa55b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8927
diff changeset
   875
# endif
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
   876
# ifdef V2
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   877
			{
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   878
			    // see bit twiddling hacks
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   879
#                           define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   880
#                           define hasByteM(v,m)   hasZeroByte( (v) ^ m)
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   881
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   882
			    // the following loop checks four bytes at once
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   883
			    if (((index-1) & 0x3) == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   884
				int last4 = last-4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   885
				int m = (~0UL/255 * (byteValue));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   886
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   887
				while (index <= last4) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   888
				    unsigned int v = *(unsigned int *)(cp+index-1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   889
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   890
				    if (hasByteM(v,m)) break;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   891
				    index += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   892
				}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   893
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   894
			    while (index <= last) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   895
				if (cp[index-1] == byteValue) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   896
				    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   897
				}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   898
				index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   899
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   900
			}
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   901
# endif
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   902
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   903
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   904
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   905
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   906
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   907
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
    }
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
   909
#undef V2
370
claus
parents: 368
diff changeset
   910
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   911
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   912
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   913
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   914
     '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
   915
     '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
   916
     '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
   917
     '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
   918
     #[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
   919
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   920
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
   921
     '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
   922
     '1234567890123456a' indexOf:$b
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   923
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   924
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   925
     s := '12345678901234b'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   926
     self assert:(s indexOf:$x) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   927
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   928
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   929
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   930
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   931
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   932
     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
   933
     self assert:(s indexOf:$b) == 15.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   934
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   935
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   936
     s := ''.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   937
     self assert:(s indexOf:$1) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   938
     s := '1'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   939
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   940
     self assert:(s indexOf:$2) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   941
     s := '12'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   942
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   943
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   944
     self assert:(s indexOf:$3) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   945
     s := '123'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   946
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   947
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   948
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   949
     self assert:(s indexOf:$4) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   950
     s := '1234'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   951
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   952
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   953
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   954
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   955
     self assert:(s indexOf:$5) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   956
     s := '12345'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   957
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   958
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   959
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   960
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   961
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   962
     self assert:(s indexOf:$6) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   963
     s := '123456'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   964
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   965
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   966
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   967
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   968
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   969
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   970
     self assert:(s indexOf:$7) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   971
     s := '1234567'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   972
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   973
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   974
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   975
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   976
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   977
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   978
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   979
     self assert:(s indexOf:$8) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   980
     s := '12345678'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   981
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   982
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   983
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   984
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   985
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   986
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   987
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   988
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   989
     self assert:(s indexOf:$9) == 0.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   990
     s := '123456789'.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   991
     self assert:(s indexOf:$1) == 1.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   992
     self assert:(s indexOf:$2) == 2.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   993
     self assert:(s indexOf:$3) == 3.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   994
     self assert:(s indexOf:$4) == 4.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   995
     self assert:(s indexOf:$5) == 5.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   996
     self assert:(s indexOf:$6) == 6.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   997
     self assert:(s indexOf:$7) == 7.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   998
     self assert:(s indexOf:$8) == 8.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
   999
     self assert:(s indexOf:$9) == 9.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1000
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1001
     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
  1002
     self assert:(s indexOf:$b) == 0.
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1003
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1004
     |s|
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1005
     s := String new:1024.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1006
     s atAllPut:$a.
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1007
     s at:512 put:(Character space).
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1008
     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
  1009
	1000000 timesRepeat:[ s indexOf:(Character space) ]
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1010
     ]
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1011
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1012
     timing (ms):
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1013
	v1: 1763 normal
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1014
	    2340 +unroll
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1015
	    3308 memsrch !!
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1016
	v2: 1045
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1017
    "
13920
Claus Gittinger <cg@exept.de>
parents: 13880
diff changeset
  1018
13922
b693795611ea changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 13921
diff changeset
  1019
    "Modified: / 10-01-2012 / 17:09:34 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1020
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1021
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1022
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1023
    "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
  1024
     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
  1025
     - 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
  1026
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1027
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1028
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1029
    unsigned char *ccp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1030
    unsigned char *cp;
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1031
    INT index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1032
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1033
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1034
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1035
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1036
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1037
    if (__isSmallInteger(start)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  1038
     && __isStringLike(aCollectionOfCharacters)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1039
	matchP = __stringVal(aCollectionOfCharacters);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1040
	index = __intVal(start);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1041
	if (index > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1042
	    cp = __stringVal(self) + index - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1043
	    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
  1044
		cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1045
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1046
	    len = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1047
	    if (index <= len) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1048
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1049
		if (matchP[0] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1050
		    /* matchSet is empty */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1051
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1052
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1053
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1054
		if (matchP[1] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1055
		    /* only a single character match */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1056
		    unsigned char m = matchP[0];
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1057
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1058
    #ifdef FAST_MEMCHR
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1059
		    ccp = (unsigned char *) memchr(cp, m, len+1-index);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1060
		    if (ccp) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1061
			RETURN ( __mkSmallInteger((ccp - cp) + index + 1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1062
		    }
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1063
    #else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1064
		    while (c = *cp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1065
			if (c == m) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1066
			    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1067
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1068
			index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1069
		    }
13116
467e182438ff changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents: 12763
diff changeset
  1070
    #endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1071
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1072
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1073
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1074
		if (matchP[2] == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1075
		    /* two character matches */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1076
		    unsigned char m1 = matchP[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1077
		    unsigned char m2 = matchP[1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1078
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1079
		    while (c = *cp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1080
			if ((c == m1) || (c == m2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1081
			    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1082
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1083
			index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1084
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1085
		    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1086
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1087
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1088
		min = max = matchP[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1089
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1090
		for (ccp = matchP+1; *ccp ; ccp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1091
		    unsigned char c = *ccp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1092
		    if (c < min) min = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1093
		    else if (c > max) max = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1094
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1095
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1096
		while (c = *cp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1097
		    if ((c >= min) && (c <= max)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1098
			for (ccp = matchP; *ccp ; ccp++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1099
			    if (*ccp == c) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1100
				RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1101
			    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1102
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1103
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1104
		    index++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1105
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1106
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1107
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1108
	}
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1109
    }
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1110
%}.
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1111
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1112
    "/ 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
  1113
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1114
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1115
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1116
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1117
     'hello world' indexOfAny:'eoa' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1118
     'hello world' indexOfAny:'eoa' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1119
     'hello world' indexOfAny:'AOE' startingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1120
     'hello world' indexOfAny:'o' startingAt:6
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1121
     'hello world' indexOfAny:'o' startingAt:6
14968
744278e94f57 class: String
Stefan Vogel <sv@exept.de>
parents: 14752
diff changeset
  1122
     'hello world§' indexOfAny:'#§$' startingAt:6
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1123
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1124
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1125
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1126
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1127
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1128
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1129
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1130
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1131
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1132
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1133
#ifndef NON_ASCII       /* i.e. not EBCDIC ;-) */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1134
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1135
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1136
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1137
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1138
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1139
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1140
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1141
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1142
	index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1143
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1144
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1145
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1146
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1147
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1148
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1149
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1150
	len -= numInstBytes;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1151
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1152
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1153
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1154
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1155
	c = cp[index - 1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1156
	if (c < ' ') {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1157
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1158
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1159
	index++;
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1160
    }
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1161
    RETURN ( __mkSmallInteger(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1162
#endif
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1163
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1164
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1165
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1166
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1167
     'hello world'             indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1168
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1169
     '1\' withCRs indexOfControlCharacterStartingAt:1
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1170
     '1\' withCRs indexOfControlCharacterStartingAt:2
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1171
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1172
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1173
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1174
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1175
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1176
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1177
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1178
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1179
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1180
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1181
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1182
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1183
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1184
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1185
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1186
	index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1187
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1188
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1189
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1190
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1191
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1192
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1193
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1194
	len -= numInstBytes;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1195
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1196
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1197
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1198
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1199
	c = cp[index - 1];
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1200
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1201
	if (c > ' ')
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1202
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1203
	if ((c != ' ') && (c != '\t') && (c != '\n')
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1204
	 && (c != '\r') && (c != '\f')) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1205
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1206
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1207
	index++;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1208
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1209
    RETURN ( __mkSmallInteger(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1210
%}.
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1211
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1212
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1213
     'hello world' indexOfNonWhiteSpaceStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1214
     'hello world' indexOfNonWhiteSpaceStartingAt:7
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1215
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1216
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1217
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1218
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1219
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1220
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1221
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1222
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1223
    REGISTER unsigned char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1224
    int len, index;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1225
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1226
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1227
    index = __intVal(start);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1228
    if (index <= 0) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1229
	index = 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1230
    }
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1231
    len = __stringSize(self);
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1232
    cp = __stringVal(self);
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1233
    if ((cls = __qClass(self)) != String) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1234
	int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1235
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1236
	cp += numInstBytes;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1237
	len -= numInstBytes;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1238
    }
15044
63c3b4a82141 class: String
Claus Gittinger <cg@exept.de>
parents: 15043
diff changeset
  1239
    while (index <= len) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1240
	REGISTER unsigned char c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1241
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1242
	c = cp[index - 1];
329
claus
parents: 314
diff changeset
  1243
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1244
	if (c <= ' ')
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1245
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1246
	if ((c == ' ') || (c == '\t') || (c == '\n')
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1247
	 || (c == '\r') || (c == '\f')) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1248
	    RETURN ( __mkSmallInteger(index) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1249
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1250
	index++;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1251
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1252
    RETURN ( __mkSmallInteger(0) );
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1253
%}.
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1254
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1255
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1256
     'hello world' indexOfSeparatorStartingAt:3
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1257
     'hello world' indexOfSeparatorStartingAt:7
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1258
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1259
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1260
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1261
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1262
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1263
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1264
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1265
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1266
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1267
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1268
    REGISTER unsigned byteValue;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  1269
    REGISTER INT count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1270
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1271
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1272
    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
  1273
	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
  1274
	count = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1275
	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
  1276
	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
  1277
	    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
  1278
	    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
  1279
		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
  1280
		limit -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1281
		cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1282
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1283
	    /* 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
  1284
	     * (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
  1285
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1286
	    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
  1287
		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
  1288
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1289
		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
  1290
		limit -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1291
		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
  1292
		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
  1293
		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
  1294
		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
  1295
		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
  1296
		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
  1297
		cp += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1298
		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
  1299
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1300
	    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
  1301
		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
  1302
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1303
		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
  1304
		limit--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1305
		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
  1306
		cp ++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1307
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1308
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1309
	RETURN ( __mkSmallInteger(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1310
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1311
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1312
    ^ super occurrencesOf:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1313
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1314
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1315
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1316
     'hello world' occurrencesOf:$w
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1317
     'hello world' occurrencesOf:$l
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1318
     'hello world' occurrencesOf:$x
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1319
     'hello world' occurrencesOf:1
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1320
     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
  1321
	1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ]
11418
e70fd06cbf38 tuned occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 11347
diff changeset
  1322
     ]. 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
  1323
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1324
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1325
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1326
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1327
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1328
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1329
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1330
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1331
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1332
     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
  1333
     'foo' < 'Foo' will return false.
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1334
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1335
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1336
%{  /* NOCONTEXT */
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1337
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1338
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1339
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1340
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1341
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1342
    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
  1343
	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
  1344
	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
  1345
	    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
  1346
	    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
  1347
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1348
	     * 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
  1349
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1350
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1351
		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
  1352
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1353
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1354
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1355
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1356
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1357
	    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
  1358
	    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
  1359
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1360
	     * 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
  1361
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1362
	    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
  1363
		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
  1364
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1365
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1366
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1367
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1368
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1369
	    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
  1370
		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
  1371
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1372
		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
  1373
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1374
	    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
  1375
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1376
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1377
	    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
  1378
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1379
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1380
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1381
	}
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1382
    }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1383
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1384
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1385
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1386
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1387
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1388
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1389
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1390
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1391
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1392
375
claus
parents: 370
diff changeset
  1393
%{  /* NOCONTEXT */
claus
parents: 370
diff changeset
  1394
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1395
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1396
    unsigned char *cp1, *cp2;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1397
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1398
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1399
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1400
    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
  1401
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1402
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1403
    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
  1404
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1405
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1406
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1407
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1408
    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
  1409
	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
  1410
	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
  1411
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1412
	 * 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
  1413
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1414
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1415
	    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
  1416
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1417
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1418
	    l2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1419
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1420
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1421
	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
  1422
	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
  1423
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1424
	 * 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
  1425
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1426
	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
  1427
	    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
  1428
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1429
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1430
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1431
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1432
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1433
	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
  1434
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1435
	}
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1436
#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
  1437
	RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1438
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1439
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  1440
# 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
  1441
	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
  1442
	    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
  1443
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1444
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1445
	    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
  1446
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1447
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1448
	    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
  1449
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1450
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1451
	    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
  1452
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1453
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1454
	    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
  1455
	    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
  1456
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  1457
# 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
  1458
	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
  1459
	    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
  1460
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1461
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1462
	    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
  1463
	    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
  1464
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1465
	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
  1466
	    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
  1467
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1468
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1469
	    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
  1470
	    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
  1471
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1472
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1473
	    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
  1474
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1475
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1476
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1477
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1478
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1479
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1480
	RETURN (true);
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1481
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1482
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1483
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1484
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1485
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1486
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1487
     'foo' = 'Foo'
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1488
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1489
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1490
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1491
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1492
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1493
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1494
     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
  1495
	 1000000 timesRepeat:[]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1496
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1497
     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
  1498
	 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1499
     ].
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  1500
     tCmp - tEmpty
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1501
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1502
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1503
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1504
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1505
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1506
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1507
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1508
     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
  1509
     'foo' > 'Foo' will return true.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1510
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1511
375
claus
parents: 370
diff changeset
  1512
%{  /* NOCONTEXT */
claus
parents: 370
diff changeset
  1513
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1514
    int len1, len2, cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1515
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1516
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1517
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1518
    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
  1519
	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
  1520
	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
  1521
	    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
  1522
	    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
  1523
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1524
	     * 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
  1525
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1526
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1527
		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
  1528
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1529
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1530
		len2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1531
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1532
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1533
	    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
  1534
	    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
  1535
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1536
	     * 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
  1537
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1538
	    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
  1539
		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
  1540
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1541
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1542
		len1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1543
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1544
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1545
	    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
  1546
		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
  1547
	    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1548
		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
  1549
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1550
	    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
  1551
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1552
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1553
	    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
  1554
		RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1555
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1556
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1557
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1558
    }
370
claus
parents: 368
diff changeset
  1559
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1560
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1561
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1562
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1563
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1564
    "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
  1565
     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
  1566
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1567
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1568
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1569
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1570
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1571
    int cmp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1572
    unsigned char *cp1, *cp2;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1573
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1574
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1575
    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
  1576
	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
  1577
	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
  1578
	    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
  1579
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1580
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1581
	     * 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
  1582
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1583
	    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
  1584
		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
  1585
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1586
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1587
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1588
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1589
	    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
  1590
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1591
	     * 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
  1592
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1593
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1594
		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
  1595
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1596
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1597
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1598
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1599
#ifdef HAS_STRCOLL
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1600
	    cmp = strcoll(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1601
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1602
	    cmp = strcmp(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1603
#endif
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1604
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1605
	    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
  1606
		RETURN ( __mkSmallInteger(1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1607
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1608
	    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
  1609
		RETURN ( __mkSmallInteger(-1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1610
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1611
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1612
	}
370
claus
parents: 368
diff changeset
  1613
    }
329
claus
parents: 314
diff changeset
  1614
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1615
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1616
     currently, this operation is only defined for strings, symbols
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1617
     and subclasses.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1618
    "
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1619
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1620
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1621
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1622
compareWith:aString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1623
    "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
  1624
     greater, 0 if equal and -1 if less than the argument.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1625
     This comparison is based on the elements' codepoints -
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1626
     i.e. upper/lowercase & national characters are NOT treated specially.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1627
     'foo' compareWith: 'Foo' will return 1.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1628
     while 'foo' sameAs:'Foo' will return true"
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1629
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1630
%{  /* NOCONTEXT */
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1631
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1632
    int cmp;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1633
    unsigned char *cp1, *cp2;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1634
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1635
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1636
    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
  1637
	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
  1638
	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
  1639
	    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
  1640
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1641
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1642
	     * 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
  1643
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1644
	    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
  1645
		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
  1646
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1647
		cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1648
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1649
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1650
	    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
  1651
	    /*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1652
	     * 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
  1653
	     */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1654
	    if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1655
		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
  1656
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1657
		cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1658
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1659
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1660
	    cmp = strcmp(cp1, cp2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1661
	    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
  1662
		RETURN ( __mkSmallInteger(1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1663
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1664
	    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
  1665
		RETURN ( __mkSmallInteger(-1) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1666
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1667
	    RETURN ( __mkSmallInteger(0) );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1668
	}
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1669
    }
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1670
%}.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1671
    "
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1672
     currently, this operation is only defined for strings, symbols
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1673
     and subclasses.
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1674
    "
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1675
    ^ self primitiveFailed
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1676
!
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1677
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1678
hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1679
    "return an integer useful as a hash-key"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1680
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1681
%{  /* NOCONTEXT */
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1682
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1683
    REGISTER unsigned INT val;
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1684
    REGISTER unsigned char *cp;
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1685
    int l;
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1686
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1687
    cp = __stringVal(self);
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1688
    l = __stringSize(self);
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1689
    if (!__qIsStringLike(self)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1690
	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
  1691
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1692
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1693
	l -= n;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1694
    }
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1695
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1696
    /*
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1697
     * this is the sdbm algorithm
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1698
     */
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1699
    val = 0;
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1700
    while (l >= 4) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1701
	l -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1702
	val = ((val * 65599) & _MAX_INT) + cp[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1703
	val = ((val * 65599) & _MAX_INT) + cp[1];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1704
	val = ((val * 65599) & _MAX_INT) + cp[2];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1705
	val = ((val * 65599) & _MAX_INT) + cp[3];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1706
	cp += 4;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1707
    }
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1708
    while (l--) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1709
	val = ((val * 65599) & _MAX_INT) + *cp++;
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1710
    }
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1711
    RETURN ( __mkSmallInteger(val & _MAX_INT));
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1712
%}
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1713
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1714
    "
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1715
     'a' hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1716
     'ab' hash = 'ab' asUnicode16String hash
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1717
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1718
14653
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1719
    "Created: / 26-12-2011 / 13:53:09 / cg"
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1720
!
2f82e25f468c class: String
Stefan Vogel <sv@exept.de>
parents: 14640
diff changeset
  1721
13880
Claus Gittinger <cg@exept.de>
parents: 13205
diff changeset
  1722
hash_dragonBook
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1723
    "return an integer useful as a hash-key"
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1724
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1725
%{  /* NOCONTEXT */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1726
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1727
    REGISTER unsigned g, val;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1728
    REGISTER unsigned char *cp, *cp0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1729
    int l;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1730
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1731
    cp = __stringVal(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1732
    l = __stringSize(self);
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1733
    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
  1734
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1735
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1736
	cp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1737
	l -= n;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1738
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1739
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1740
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1741
     * this is the dragon-book algorithm
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1742
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1743
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1744
    val = 0;
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1745
    switch (l) {
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1746
    default:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1747
	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
  1748
	    val = (val << 4) + *cp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1749
	    if (g = (val & 0xF0000000)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1750
		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
  1751
		val ^= g;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1752
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1753
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1754
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1755
    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
  1756
	val = cp[5] << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1757
    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
  1758
	val = (val + cp[4]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1759
    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
  1760
	val = (val + cp[3]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1761
    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
  1762
	val = (val + cp[2]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1763
    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
  1764
	val = (val + cp[1]) << 4;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1765
    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
  1766
	val = val + cp[0];
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1767
    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
  1768
	break;
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1769
    }
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1770
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1771
    /*
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1772
     * multiply by large prime to spread values
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1773
     * This speeds up Set and Dictionary by a factor of 10!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1774
     */
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1775
    val *= 31415821;
12763
e19933d3e188 changed:
Stefan Vogel <sv@exept.de>
parents: 12727
diff changeset
  1776
    RETURN ( __mkSmallInteger(val & _MAX_INT));
10697
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1777
%}
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1778
!
77ab35cd09a5 oops: Unicode16String-hash returned different value from
sr
parents: 10677
diff changeset
  1779
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1780
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1781
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1782
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1783
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1784
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1785
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1786
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1787
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1788
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1789
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1790
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1791
    int l1, l2;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1792
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1793
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1794
    INT addrDelta;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1795
    int argIsString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1796
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1797
    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
  1798
	RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1799
    }
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1800
    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
  1801
	RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1802
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1803
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1804
    argIsString = __qIsStringLike(aString);
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  1805
    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
  1806
	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
  1807
	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
  1808
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1809
	 * 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
  1810
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1811
	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
  1812
	    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
  1813
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1814
	    cp1 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1815
	    l1 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1816
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1817
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1818
	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
  1819
	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
  1820
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1821
	 * 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
  1822
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1823
	if (!argIsString) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1824
	    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
  1825
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1826
	    cp2 += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1827
	    l2 -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1828
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1829
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1830
	if (l1 != l2) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1831
	    RETURN ( true );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1832
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1833
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1834
	addrDelta = cp2 - cp1;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  1835
# 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
  1836
	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
  1837
	    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
  1838
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1839
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1840
	    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
  1841
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1842
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1843
	    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
  1844
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1845
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1846
	    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
  1847
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1848
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1849
	    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
  1850
	    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
  1851
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  1852
# 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
  1853
	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
  1854
	    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
  1855
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1856
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1857
	    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
  1858
	    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
  1859
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1860
	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
  1861
	    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
  1862
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1863
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1864
	    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
  1865
	    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
  1866
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1867
	while (l1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1868
	    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
  1869
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1870
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1871
	    l1--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1872
	    cp1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1873
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1874
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1875
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1876
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1877
    ^ super ~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1878
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1879
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1880
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1881
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1882
asArrayOfSubstrings
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1883
    "Answer an array with all the substrings of the receiver separated by
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1884
     separator characters (space, cr, tab, linefeed, formfeed, etc).
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1885
     CG: This is ported Squeak code, and I am not sure if it is more efficient than
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1886
         the inherited one... after all: who added it anyway ?"
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1887
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1888
    | substrings start end stop |
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1889
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1890
    substrings := OrderedCollection new.
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1891
    start := 1.
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1892
    stop := self size.
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1893
    [start <= stop] whileTrue: [
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1894
        (self at: start) isSeparator ifFalse: [
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1895
            end := start + 1.
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1896
            [end <= stop and: [(self at: end) isSeparator not]]
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1897
                whileTrue: [end := end + 1].
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1898
            substrings add: (self copyFrom: start to: end - 1).
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1899
            start := end - 1
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1900
        ].
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  1901
        start := start + 1
11906
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1902
    ].
b6decf7e7d52 comment
Claus Gittinger <cg@exept.de>
parents: 11883
diff changeset
  1903
    ^ substrings asArray
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1904
!
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1905
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1906
asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1907
    "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
  1908
     with an additional 0-character. Otherwise return the receiver. This is sometimes
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1909
     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
  1910
     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
  1911
     strings are not."
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1912
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1913
    ^ self
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1914
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1915
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1916
     'abc' asAsciiZ
11882
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1917
     'abc' asWideString asAsciiZ
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1918
    "
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1919
!
95aac982923e +asAsciiZ
Claus Gittinger <cg@exept.de>
parents: 11856
diff changeset
  1920
3281
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1921
asBoldText
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1922
    "return self as a bold text"
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1923
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1924
    ^Text string: self emphasis: #bold
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1925
!
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1926
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1927
asByteArray
15938
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  1928
    "return a new ByteArray with the receiver's elements.
4a1a2bb0a449 class: String
Claus Gittinger <cg@exept.de>
parents: 15837
diff changeset
  1929
     This redefined method is faster than Collection>>#asByteArray"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1930
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1931
    |bytes sz|
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1932
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1933
    sz := self size.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1934
    bytes := ByteArray new:sz .
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1935
    bytes replaceFrom:1 to:sz with:self startingAt:1.
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1936
    ^ bytes
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1937
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1938
    "
16019
b204c9d6ce6d no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents: 15938
diff changeset
  1939
     'fooBar' asByteArray.
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1940
    "
14260
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  1941
c8e2fa654d6d comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents: 14217
diff changeset
  1942
    "Modified (comment): / 26-07-2012 / 22:55:26 / cg"
10594
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1943
!
b659646164b5 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 10371
diff changeset
  1944
9472
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1945
asExternalBytes
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1946
    |bytes sz|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1947
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1948
    sz := self size.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1949
    bytes := ExternalBytes new:(sz + 1).
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1950
    bytes replaceFrom:1 to:sz with:self startingAt:1.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1951
    bytes at:(sz + 1) put:0.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1952
    ^ bytes
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1953
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1954
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1955
     |x|
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1956
     x := 'fooBar' asExternalBytes.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1957
     x unprotectFromGC.
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1958
     ObjectMemory garbageCollect
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1959
    "
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1960
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1961
    "Modified: / 03-08-2006 / 14:45:32 / fm"
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1962
!
866785637314 +asExternalBytes
fm
parents: 9426
diff changeset
  1963
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1964
asExternalBytesUnprotected
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1965
    "Like asExternalBytes, but does not register the bytes so
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  1966
     bytes are GARBAGE-COLLECTED!!"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1967
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1968
    |bytes sz|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1969
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1970
    sz := self size.
15837
3c7779b8d275 class: String
Claus Gittinger <cg@exept.de>
parents: 15536
diff changeset
  1971
    bytes := ExternalBytes unprotectedNew:(sz + 1).
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1972
    bytes replaceFrom:1 to:sz with:self startingAt:1.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1973
    bytes at:(sz + 1) put:0.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1974
    ^ bytes
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1975
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1976
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1977
     |x|
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1978
     x := 'fooBar' asExternalBytesUnprotected.
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1979
     ObjectMemory garbageCollect
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1980
    "
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1981
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1982
    "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
  1983
    "Modified: / 30-11-2013 / 11:41:40 / cg"
14156
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1984
!
e68cbbe6d070 added: #asExternalBytesUnprotected
vrany
parents: 14074
diff changeset
  1985
12454
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1986
asImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1987
    "return a write-protected copy of myself"
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1988
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1989
    ^ self copy changeClassTo:ImmutableString
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1990
!
02a4a461f56f added: #asImmutableString
Claus Gittinger <cg@exept.de>
parents: 12344
diff changeset
  1991
16185
692971832614 class: String
Claus Gittinger <cg@exept.de>
parents: 16174
diff changeset
  1992
asMutator
16226
e9556d5a4714 class: String
Claus Gittinger <cg@exept.de>
parents: 16203
diff changeset
  1993
    "return a corresponding setter method's selector"
16185
692971832614 class: String
Claus Gittinger <cg@exept.de>
parents: 16174
diff changeset
  1994
692971832614 class: String
Claus Gittinger <cg@exept.de>
parents: 16174
diff changeset
  1995
    ^ (self,':') asSymbol
692971832614 class: String
Claus Gittinger <cg@exept.de>
parents: 16174
diff changeset
  1996
!
692971832614 class: String
Claus Gittinger <cg@exept.de>
parents: 16174
diff changeset
  1997
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  1998
asPackageId
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  1999
    "given a package-string as receiver, return a packageId object.
14566
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2000
     packageIds hide the details of module/directory handling inside the path.
e2f31e5ae55b class: String
Claus Gittinger <cg@exept.de>
parents: 14556
diff changeset
  2001
     See PackageId for the required format of those strings."
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  2002
14571
6e2375384861 class: String
Claus Gittinger <cg@exept.de>
parents: 14566
diff changeset
  2003
    ^ PackageId from: self
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2004
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2005
    "
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2006
     '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
  2007
     '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
  2008
     'stx:hello' asPackageId
9574
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2009
    "
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2010
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2011
    "Created: / 18-08-2006 / 12:19:54 / cg"
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2012
!
b2cd1336fea0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9573
diff changeset
  2013
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  2014
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2015
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2016
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2017
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2018
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  2019
11287
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2020
asSingleByteStringIfPossible
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2021
    "I am a single-byte string"
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2022
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2023
    ^ self
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2024
!
b1f83c793f6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11267
diff changeset
  2025
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2026
asSingleByteStringReplaceInvalidWith:replacementCharacter
11883
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2027
    "return the receiver converted to a 'normal' string,
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2028
     with invalid characters replaced by replacementCharacter.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2029
     Can be used to convert from 16-bit strings to 8-bit strings
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2030
     and replace characters above code-255 with some replacement.
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2031
     Dummy here, because I am already a single byte string."
36c27310fd24 comment
Claus Gittinger <cg@exept.de>
parents: 11882
diff changeset
  2032
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2033
    ^ self
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2034
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2035
    "Modified: / 07-08-2006 / 15:04:45 / fm"
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2036
!
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2037
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2038
asSymbol
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2039
    "Return a unique symbol with the name taken from the receivers characters."
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2040
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2041
%{  /* NOCONTEXT */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2042
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2043
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2044
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2045
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2046
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2047
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2048
    if (cls != String) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2049
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2050
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  2051
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2052
    if (newSymbol) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2053
	RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2054
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2055
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2056
    ^ ObjectMemory allocationFailureSignal raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2057
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2058
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2059
     'hello' asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2060
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2061
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2062
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2063
asSymbolIfInterned
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2064
    "If a symbol with the receivers characters is already known, return it. Otherwise, return nil.
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2065
     This can be used to query for an existing symbol and is the same as:
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2066
	self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2067
     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
  2068
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2069
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2070
%{  /* NOCONTEXT */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2071
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2072
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2073
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2074
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2075
    if (cls != String) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2076
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2077
    } else {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2078
	indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2079
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2080
    RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx));
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2081
%}.
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  2082
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2083
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2084
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2085
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  2086
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2087
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2088
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2089
asUUID
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2090
    "return self as a UUID"
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2091
14968
744278e94f57 class: String
Stefan Vogel <sv@exept.de>
parents: 14752
diff changeset
  2092
    ^ UUID fromString:self
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2093
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2094
    "
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2095
     '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUUID
10677
97c2b50e6d94 comment in #asUUID
Claus Gittinger <cg@exept.de>
parents: 10594
diff changeset
  2096
     'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID
14968
744278e94f57 class: String
Stefan Vogel <sv@exept.de>
parents: 14752
diff changeset
  2097
     'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B quatsch' asUUID
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2098
    "
10677
97c2b50e6d94 comment in #asUUID
Claus Gittinger <cg@exept.de>
parents: 10594
diff changeset
  2099
97c2b50e6d94 comment in #asUUID
Claus Gittinger <cg@exept.de>
parents: 10594
diff changeset
  2100
    "Modified: / 02-08-2007 / 16:43:29 / cg"
9182
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2101
!
bb8b1eeb08b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8932
diff changeset
  2102
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2103
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2104
    "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
  2105
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2106
     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
  2107
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2108
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  2109
     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
  2110
     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
  2111
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  2112
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2113
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2114
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2115
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2116
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2118
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2119
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2120
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2121
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2122
     && __isSmallInteger(numSpaces)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2123
	n = __intVal(numSpaces);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2124
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2125
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2126
	 * for small strings (< 80), do it without a prescan ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2127
	 * the buffer is large enough to even convert a
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2128
	 * receiver consisting fully of tabs.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2129
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2130
	if (__stringSize(self) < 80) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2131
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2132
	    for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2133
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2134
		    any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2135
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2136
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2137
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2138
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2139
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2140
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2141
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2142
		    *dstP++ = c;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2143
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2144
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2145
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2146
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2147
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2148
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2149
	    if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2150
	    *dstP = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2151
	    RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2152
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2153
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2154
	 * for large strings, we compute the new size, allocate a new string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2155
	 * and expand it.
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2156
	 *
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2157
	 * first, scan for size ...
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2158
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2159
	idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2160
	for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2161
	    if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2162
		any = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2163
		while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2164
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2165
		    sz++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2166
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2167
		idx++; sz ++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2168
	    } else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2169
		sz++; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2170
		if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2171
		    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2172
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2173
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2174
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2175
	if (! any) RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2176
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2177
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2178
	 * get the string
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2179
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2180
	sz = OHDR_SIZE + sz + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2181
	__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2182
	if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2183
	    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2184
	    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2185
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2186
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2187
	     * expand
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2188
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2189
	    idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2190
	    for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2191
		if (c == '\t') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2192
		    while (idx % n) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2193
			idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2194
			*dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2195
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2196
		    idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2197
		    *dstP++ = ' ';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2198
		} else {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2199
		    *dstP++ = c; idx++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2200
		    if (c == '\n') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2201
			idx = 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2202
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2203
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2204
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2205
	    *dstP++ = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2206
	    RETURN (newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2207
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2208
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2209
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  2210
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2211
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2212
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2213
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2214
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2215
, aString
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2216
    "return the concatenation of myself and the argument, aString as a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2217
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2218
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2219
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2220
    int l1, l2, sz;
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2221
    OBJ newString;
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2222
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2223
    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
  2224
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2225
	 * can do it here if both are Strings/Symbols:
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2226
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2227
	if (__qIsStringLike(self) && __qIsStringLike(aString)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2228
	    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
  2229
	    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
  2230
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2231
	    sz = OHDR_SIZE + l1 + l2 + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2232
	    __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
  2233
	    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
  2234
		char *cp1, *cp2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2235
		REGISTER unsigned char *dstp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2236
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2237
		__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
  2238
		__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
  2239
		dstp = __stringVal(newString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2240
		cp1 = (char *) __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2241
		cp2 = (char *) __stringVal(aString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2242
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2243
#ifdef bcopy4
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2244
		/* knowing that allocation is 4-byte aligned and
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2245
		 * size rounded up to next 4-byte, the first copy
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2246
		 * can be done word-wise.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2247
		 * that speeds up size-10-string , size-10-string
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2248
		 * by 10% on a P5/200.
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2249
		 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2250
		{
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2251
		    int nw = l1 >> 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2252
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2253
		    if (l1 & 3) nw++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2254
		    bcopy4(cp1, dstp, nw);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2255
		    dstp += l1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2256
		}
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2257
#else
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2258
# 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
  2259
		memcpy(dstp, cp1, l1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2260
		dstp += l1;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2261
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2262
		while (l1 >= 4) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2263
		    *(int *)dstp = *(int *)cp1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2264
		    dstp += 4; cp1 += 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2265
		    l1 -= 4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2266
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2267
		while (l1--) *dstp++ = *cp1++;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2268
# endif
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  2269
#endif
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2270
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2271
#ifdef bcopy4
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2272
		if (((INT)dstp & 3) == 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2273
		    int nw = l2 >> 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2274
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2275
		    if (l2 & 3) nw++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2276
		    bcopy4(cp2, dstp, nw);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2277
		    *(dstp + l2) = '\0';
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2278
		    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2279
		}
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  2280
#endif
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2281
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2282
#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
  2283
		memcpy(dstp, cp2, l2+1);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2284
		dstp[l2] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2285
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2286
		while (l2--) *dstp++ = *cp2++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2287
		*dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2288
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2289
		RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2290
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2291
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2292
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2293
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2294
    ^ super , aString
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2295
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2296
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2297
     'hello' , 'world' asImmutableString
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  2298
     'hello' , #world
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2299
     #[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
  2300
    "
14074
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2301
04be30a447df comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13923
diff changeset
  2302
    "Modified: / 01-04-2012 / 13:19:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2303
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2304
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2305
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2306
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2307
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2308
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2309
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2310
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2311
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2312
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2313
    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
  2314
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2315
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2316
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2317
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2318
15262
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
	    && __isStringLike(string1)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2321
	    && __isStringLike(string2)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2322
	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
  2323
	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
  2324
	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
  2325
	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
  2326
	__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
  2327
	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
  2328
	    __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
  2329
	    __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
  2330
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2331
#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
  2332
	    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
  2333
	    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
  2334
	    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
  2335
	    *(dstp + len1 + len2 + len3) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2336
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2337
	    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
  2338
	    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
  2339
	    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
  2340
	    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
  2341
	    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
  2342
	    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
  2343
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2344
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2345
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2346
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2347
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2348
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2349
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2350
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2351
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2352
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2353
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2354
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2355
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2356
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2357
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2358
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2359
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2360
    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
  2361
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2362
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2363
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2364
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2365
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2366
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2367
     && __isStringLike(string1)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2368
     && __isStringLike(string2)
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2369
     && __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
  2370
	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
  2371
	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
  2372
	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
  2373
	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
  2374
	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
  2375
	__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
  2376
	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
  2377
	    __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
  2378
	    __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
  2379
	    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2380
#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
  2381
	    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
  2382
	    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
  2383
	    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
  2384
	    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
  2385
	    *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2386
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2387
	    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
  2388
	    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
  2389
	    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
  2390
	    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
  2391
	    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
  2392
	    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
  2393
	    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
  2394
	    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
  2395
	    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2396
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2397
	    RETURN ( newString );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2398
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2399
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2400
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2401
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2402
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2403
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2404
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2405
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2406
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2407
    (self isMemberOf:String) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2408
	^ self copyFrom:1
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2409
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2410
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2411
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2412
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2413
copyFrom:start
9233
d6ecec348ca9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9182
diff changeset
  2414
    "return a new collection consisting of receivers elements from startIndex to the end of the collection.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2415
     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
  2416
     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
  2417
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2418
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2419
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2420
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2421
#if !defined(FAST_MEMCPY)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2422
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2423
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2424
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2425
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2426
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2427
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2428
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2429
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2430
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2431
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2432
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2433
    if (__isSmallInteger(start)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2434
     && ((myClass==String) || (myClass==Symbol))) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2435
	len = __stringSize(self);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2436
	index1 = __intVal(start);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2437
	if (index1 > 0) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2438
	    if (index1 <= len) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2439
		count = len - index1 + 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2440
		sz = OHDR_SIZE + count + 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2441
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2442
		__PROTECT_CONTEXT__
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2443
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2444
		__UNPROTECT_CONTEXT__
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2445
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2446
		if (newString != nil) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2447
		    __InstPtr(newString)->o_class = String;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2448
		    __qSTORE(newString, String);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2449
		    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2450
#ifdef FAST_MEMCPY
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2451
		    memcpy(dstp, __stringVal(self) + index1 - 1, count);
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2452
		    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2453
#else
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2454
		    srcp = __stringVal(self) + index1 - 1;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2455
		    while (count--) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2456
			*dstp++ = *srcp++;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2457
		    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2458
		    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2459
#endif
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2460
		    RETURN ( newString );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2461
		}
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2462
	    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  2463
	}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2464
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2465
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2466
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2467
    "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
  2468
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2469
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2470
    ^ super copyFrom:start
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2471
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2472
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2473
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2474
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2475
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2476
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2477
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2478
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2479
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2480
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2481
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2482
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2483
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2484
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2485
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2486
    OBJ myClass;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2487
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2488
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2489
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2490
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2491
    if (__bothSmallInteger(start, stop)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2492
     && ((myClass==String) || (myClass==Symbol))) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2493
	len = __stringSize(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2494
	index1 = __intVal(start);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2495
	index2 = __intVal(stop);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2496
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2497
	if ((index1 <= index2) && (index1 > 0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2498
	    if (index2 <= len) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2499
		count = index2 - index1 + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2500
		sz = OHDR_SIZE + count + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2501
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2502
		__PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2503
		__qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2504
		__UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2505
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2506
		if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2507
		    __InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2508
		    __qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2509
		    dstp = __stringVal(newString);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2510
		    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2511
#ifdef bcopy4
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2512
		    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2513
			int nw = count >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2514
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2515
			if (count & 3) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2516
			    nw++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2517
			}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2518
			bcopy4(srcp, dstp, nw);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2519
			dstp[count] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2520
		    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2521
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2522
# ifdef FAST_MEMCPY
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2523
		    memcpy(dstp, srcp, count);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2524
		    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2525
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2526
		    while (count--) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2527
			*dstp++ = *srcp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2528
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2529
		    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2530
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2531
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2532
		    RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2533
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2534
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2535
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2536
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2537
	 * allow empty copy
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2538
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2539
	if (index1 > index2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2540
	    __PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2541
	    __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2542
	    __UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2543
	    if (newString != nil) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2544
		__InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2545
		(__stringVal(newString))[0] = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2546
		RETURN ( newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2547
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2548
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2549
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2550
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2551
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2552
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2553
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2554
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2555
    ^ super copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2556
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2557
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2558
copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2559
    "return a new string containing the receivers characters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2560
     and the single new character, aCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2561
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2562
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2563
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2564
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2565
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2566
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2567
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2568
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2569
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2570
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2571
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2572
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2573
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2574
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2575
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2576
    if (__isCharacter(aCharacter)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2577
	unsigned int cVal = __intVal(__characterVal(aCharacter));
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2578
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2579
	if ((cVal <= 0xFF)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2580
	 && ((myClass==String) || (myClass==Symbol))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2581
	    count = __stringSize(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2582
	    sz = OHDR_SIZE + count + 1 + 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2583
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2584
	    __PROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2585
	    __qNew(newString, sz);  /* OBJECT ALLOCATION */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2586
	    __UNPROTECT_CONTEXT__
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2587
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2588
	    if (newString) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2589
		__InstPtr(newString)->o_class = String;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2590
		__qSTORE(newString, String);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2591
		dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2592
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2593
#ifdef bcopy4
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2594
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2595
		    int nw = count >> 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2596
		    char *srcp = (char *)__stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2597
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2598
		    if (count & 3) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2599
			nw++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2600
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2601
		    bcopy4(srcp, dstp, nw);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2602
		    dstp += count;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2603
		}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2604
#else
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2605
# ifdef FAST_MEMCPY
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2606
		memcpy(dstp, __stringVal(self), count);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2607
		dstp += count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2608
# else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2609
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2610
		    REGISTER unsigned char *srcp;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2611
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2612
		    srcp = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2613
		    while ((*dstp = *srcp++) != '\0')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2614
			dstp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2615
		}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2616
# endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2617
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2618
		*dstp++ = cVal;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2619
		*dstp = '\0';
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2620
		RETURN (newString );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2621
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2622
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2623
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2624
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2625
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2626
    "fall back in case of non-character arg;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2627
     will eventually lead to an bad element signal raise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2628
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2629
    ^ super copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2630
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2631
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2632
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2633
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2634
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2635
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2636
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2637
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2638
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2639
    (self isMemberOf:String) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2640
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2641
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2642
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2643
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2644
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  2645
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  2646
    "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
  2647
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2648
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2649
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2650
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2651
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2652
    (self isMemberOf:String) ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2653
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2654
    ].
10951
9f56be18d1dd deepCopy change
ab
parents: 10822
diff changeset
  2655
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2656
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2657
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2658
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2659
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2660
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2661
    (self isMemberOf:String) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2662
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2663
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2664
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2665
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2666
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2667
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2668
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2669
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2670
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2671
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2672
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2673
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2674
    (self isMemberOf:String) ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2675
	^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2676
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  2677
    ^ super simpleDeepCopy
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2678
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2679
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  2680
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  2681
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2682
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2683
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2684
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2685
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2686
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2687
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2688
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2689
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2690
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  2691
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2692
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2693
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2694
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2695
    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
  2696
	byteValue = __intVal(__characterVal(aCharacter));
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2697
	if ((unsigned)byteValue <= 0xFF) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2698
	    l = __stringSize(self);
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2699
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2700
#ifdef FAST_MEMSET
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2701
	    if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2702
		memset(__stringVal(self), byteValue, l);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2703
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2704
#else
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2705
	    {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2706
		INT v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2707
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2708
		v = (byteValue << 8) | byteValue;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2709
		v = (v << 16) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2710
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2711
		dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2713
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2714
		if (l > 0) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2715
		    memset4(dst, v, l>>2);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2716
		    l = l & 3;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2717
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2718
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2719
#  ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2720
		{
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2721
		    UINT64 v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2722
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2723
		    v64 = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2724
		    v64 = (v64 << 32) | v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2725
		    while (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2726
			((UINT64 *)dst)[0] = v64;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2727
			dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2728
			l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2729
		    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2730
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2731
#  else /* no UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2732
		while (l >= 16) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2733
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2734
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2735
		    ((int *)dst)[2] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2736
		    ((int *)dst)[3] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2737
		    dst += 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2738
		    l -= 16;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2739
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2740
		if (l >= 8) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2741
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2742
		    ((int *)dst)[1] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2743
		    dst += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2744
		    l -= 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2745
		}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2746
		if (l >= 4) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2747
		    ((int *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2748
		    dst += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2749
		    l -= 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2750
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2751
#   if 0
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2752
		if (l >= 2) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2753
		    ((short *)dst)[0] = v;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2754
		    dst += 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2755
		    l -= 2;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2756
		}
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2757
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2758
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  2759
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  2760
# endif /* FAST_MEMSET4 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2761
	    }
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2762
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2763
	    /*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2764
	     * remaining bytes
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2765
	     */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2766
	    while (l-- > 0)
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2767
		*dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2768
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2769
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2770
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2771
	    RETURN ( self );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2772
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2773
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2774
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2775
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2776
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2777
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2778
     (String new:10) atAllPut:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2779
     String new:10 withAll:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2780
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2781
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2782
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2783
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2784
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2785
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2786
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2787
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2788
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2789
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2790
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2791
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2792
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2793
    unsigned char c, cNext;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2794
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2795
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2796
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2797
     && __isString(self)) {
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2798
        srcp = (unsigned char *)__stringVal(self);
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2799
        oldVal = __intVal(__characterVal(oldCharacter));
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2800
        newVal = __intVal(__characterVal(newCharacter));
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2801
        if ((oldVal <= 0xFF)
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2802
         && (newVal <= 0xFF)) {
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2803
            cNext = *srcp;
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2804
            while ((c = cNext) != '\0') {
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2805
                cNext = srcp[1];
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2806
                if (c == oldVal)
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2807
                    *srcp = newVal;
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2808
                srcp++;
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2809
            }
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2810
        }
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2811
        RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2812
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2813
%}.
16203
244aa42247b7 class: String
Claus Gittinger <cg@exept.de>
parents: 16185
diff changeset
  2814
    newCharacter isCharacter ifFalse:[self halt:'please change the sender'].
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2815
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2816
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2817
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2818
     'helloWorld' copy replaceAll:$o with:$O
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2819
     'helloWorld' copy replaceAll:$d with:$*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2820
     'helloWorld' copy replaceAll:$h with:$*
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2821
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2822
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2823
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2824
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2825
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2826
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  2827
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2828
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2829
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2830
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2831
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2832
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2833
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2834
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2835
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2836
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2837
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2838
#ifndef NO_PRIM_STRING
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  2839
    if (__isStringLike(aString)
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2840
     && __isString(self)
252
  2841
     && __bothSmallInteger(start, stop)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2842
	len = __stringSize(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2843
	index1 = __intVal(start);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2844
	index2 = __intVal(stop);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2845
	count = index2 - index1 + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2846
	if (count <= 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2847
	     RETURN (self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2848
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2849
	if ((index2 <= len) && (index1 > 0)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2850
	    repLen = __stringSize(aString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2851
	    repIndex = __intVal(repStart);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2852
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2853
		srcp = __stringVal(aString) + repIndex - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2854
		dstp = __stringVal(self) + index1 - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2855
		if (aString == self) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2856
		    /* take care of overlapping copy */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2857
		    if (srcp < dstp) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2858
			/* must do a reverse copy */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2859
			srcp += count;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2860
			dstp += count;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2861
			while (count-- > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2862
			    *--dstp = *--srcp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2863
			}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2864
			RETURN (self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2865
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2866
		}
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2867
#ifdef bcopy4
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2868
		/* copy quadbytes if pointers are aligned */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2869
		/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2870
		 * no sizeof(int) here please -
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2871
		 * - bcopy4 (if defined) copies 4-bytes on ALL machines
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2872
		 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2873
		if ((count > 12)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2874
		 && (((unsigned INT)srcp & 3) == 0)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2875
		 && (((unsigned INT)dstp & 3) == 0)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2876
		    int n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2877
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2878
		    n = count >> 2;        /* make it quads */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2879
		    bcopy4(srcp, dstp, n);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2880
		    n <<= 2;               /* back to chars */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2881
		    dstp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2882
		    srcp += n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2883
		    count -= n;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2884
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2885
		while (count-- > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2886
		    *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2887
		}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2888
#else
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2889
# 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
  2890
		bcopy(srcp, dstp, count);
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2891
# else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2892
		/* copy longs if pointers are aligned */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2893
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2894
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2895
		    while (count >= sizeof(INT)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2896
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2897
			dstp += sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2898
			srcp += sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2899
			count -= sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2900
		    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2901
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2902
		while (count-- > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2903
		    *dstp++ = *srcp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2904
		}
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2905
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2906
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2907
		RETURN (self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2908
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  2909
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2910
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2911
#endif
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2912
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2913
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2914
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2915
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2916
withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2917
    "return a string containing the chars of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2918
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2919
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2920
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2921
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  2922
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2923
     endIndex   "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2924
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2925
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2926
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2927
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2928
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2929
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2930
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2931
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2932
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2933
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2934
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2935
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  2936
    if (__qClass(self) == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2937
	cp = cp0 = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2938
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2939
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2940
	 * find first non-whiteSpace from beginning
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2941
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2942
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  2943
# ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2944
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2945
	    cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2946
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2947
# endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2948
	while (*((unsigned *)cp) == 0x20202020) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2949
	    cp += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2950
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2951
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2952
	while ((c = *cp)
329
claus
parents: 314
diff changeset
  2953
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2954
	 && (c <= ' ')
329
claus
parents: 314
diff changeset
  2955
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2956
	 && ((c == ' ') || (c == '\n') || (c == '\t')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2957
			|| (c == '\r') || (c == '\f'))
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2958
	) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2959
	    cp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2960
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2961
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2962
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2963
	 * find first non-whiteSpace from end
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2964
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2965
	ep = ep0 = cp0 + __stringSize(self) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2966
	while ((ep >= cp) && (*ep == ' ')) ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2967
	c = *ep;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2968
	while ((ep >= cp) &&
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2969
#ifndef NON_ASCII
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2970
	       (c <= ' ') &&
329
claus
parents: 314
diff changeset
  2971
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2972
	       ((c == ' ') || (c == '\n') || (c == '\t')
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2973
			   || (c == '\r') || (c == '\f'))) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2974
	    ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2975
	    c = *ep;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2976
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2977
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2978
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2979
	 * no whiteSpace ?
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2980
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2981
	if ((cp == cp0) && (ep == ep0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2982
	    RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2983
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2984
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2985
	startIndex = __mkSmallInteger(cp - cp0 + 1);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  2986
	endIndex = __mkSmallInteger(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2987
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2988
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2989
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2990
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2991
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2992
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2993
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2994
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2995
     'hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2996
     '    hello' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2997
     '    hello ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2998
     '    hello  ' withoutSeparators
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  2999
     '    hello   ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3000
     '    hello    ' withoutSeparators
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3001
     '        ' withoutSeparators
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3002
    "
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3003
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3004
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3005
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3006
withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3007
    "return a string containing the characters of myself
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3008
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3009
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3010
     Notice, this is different from String>>withoutSeparators."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3011
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3012
    |startIndex "{ Class: SmallInteger }"
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3013
     endIndex   "{ Class: SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3014
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3015
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3016
    startIndex := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3017
%{
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3018
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3019
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3020
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3021
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3022
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3023
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3024
    if (__qClass(self) == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3025
	cp = cp0 = __stringVal(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3026
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3027
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3028
	 * find first non-blank from beginning
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3029
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3030
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3031
# ifdef UINT64
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3032
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3033
	    cp += 8;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3034
	}
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3035
# endif /* UINT64 */
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3036
	while (*((unsigned *)cp) == 0x20202020) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3037
	    cp += 4;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3038
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3039
#endif
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3040
	while (*cp == ' ') cp++;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3041
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3042
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3043
	 * find first non-blank from end
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3044
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3045
	ep = ep0 = cp0 + __stringSize(self) - 1;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3046
	while ((ep >= cp) && (*ep == ' ')) ep--;
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3047
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3048
	/*
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3049
	 * no blanks ?
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3050
	 */
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3051
	if ((cp == cp0) && (ep == ep0)) {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3052
	    RETURN(self);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3053
	}
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3054
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3055
	startIndex = __mkSmallInteger(cp - cp0 + 1);
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3056
	endIndex = __mkSmallInteger(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3057
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3058
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3059
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3060
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3061
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3062
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3063
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3064
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3065
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3066
     '    hello' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3067
     '    hello ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3068
     '    hello  ' withoutSpaces
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3069
     '    hello   ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3070
     '    hello    ' withoutSpaces
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3071
     '        ' withoutSpaces
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  3072
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3073
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3074
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3075
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3076
16393
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3077
displayString
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3078
    "return a string used when displaying the receiver in a view."
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3079
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3080
    ^ self.
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3081
!
4d56dffdd2ca class: String
Claus Gittinger <cg@exept.de>
parents: 16253
diff changeset
  3082
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3083
errorPrint
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3084
    "print the receiver on standard error, if the global Stderr is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3085
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3086
     the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3087
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3088
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3089
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3090
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3091
%{  /* NOCONTEXT */
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3092
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3093
    if (@global(Stderr) == nil) {
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3094
        if (__qIsStringLike(self)) {
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3095
            console_fprintf(stderr, "%s" , __stringVal(self));
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3096
            console_fflush(stderr);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3097
            RETURN (self);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3098
        }
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3099
    }
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3100
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3101
    super errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3102
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3103
    "
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3104
      'hello world' asUnicode16String errorPrint
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3105
      (Character value:356) asString errorPrint
14968
744278e94f57 class: String
Stefan Vogel <sv@exept.de>
parents: 14752
diff changeset
  3106
      'Bönnigheim' errorPrint
744278e94f57 class: String
Stefan Vogel <sv@exept.de>
parents: 14752
diff changeset
  3107
      'Bönnigheim' asUnicodeString errorPrint
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3108
    "
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3109
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3110
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3111
errorPrintCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3112
    "print the receiver on standard error, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3113
     if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3114
     which sends the string to the Stderr stream.
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3115
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3116
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3117
     (but only, as long as Stderr is nil, which is set later after startup)."
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3118
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3119
%{  /* NOCONTEXT */
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3120
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3121
    if (@global(Stderr) == nil) {
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3122
        if (__qIsStringLike(self)) {
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3123
            console_fprintf(stderr, "%s\n" , __stringVal(self));
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3124
            console_fflush(stderr);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3125
            RETURN (self);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3126
        }
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3127
    }
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3128
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3129
    super errorPrintCR
14163
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3130
!
Stefan Vogel <sv@exept.de>
parents: 14156
diff changeset
  3131
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3132
print
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3133
    "print the receiver on standard output, if the global Stdout is nil;
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3134
     otherwise, fall back to the inherited errorPrint, which sends the string to
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3135
     the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3136
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3137
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3138
     (but only, as long as Stdout is nil, which is set later after startup)."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3139
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3140
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3141
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3142
    if (@global(Stdout) == nil) {
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3143
        if (__qIsStringLike(self)) {
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3144
            console_fprintf(stdout, "%s" , __stringVal(self));
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3145
            console_fflush(stdout);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3146
            RETURN (self);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3147
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3148
    }
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3149
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3150
    super print
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3151
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3152
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3153
printCR
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3154
    "print the receiver on standard output, followed by a cr,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3155
     if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR,
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3156
     which sends the string to the Stdout stream.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3157
     This method does NOT (by purpose) use the stream classes and
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3158
     will therefore work even in case of emergency during early startup
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3159
     (but only, as long as Stdout is nil, which is set later after startup)."
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3160
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3161
%{  /* NOCONTEXT */
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3162
15440
575ddc6530a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15262
diff changeset
  3163
    if (@global(Stdout) == nil) {
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3164
        if (__qIsStringLike(self)) {
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3165
            console_fprintf(stdout, "%s\n" , __stringVal(self));
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3166
            console_fflush(stdout);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3167
            RETURN (self);
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3168
        }
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3169
    }
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3170
%}.
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3171
    super printCR
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3172
!
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  3173
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3174
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3175
    "non-standard but sometimes useful.
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3176
     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
  3177
     which is defined by printf.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3178
     This method is NONSTANDARD and may be removed without notice.
15536
9cb1483e72f2 comments
Claus Gittinger <cg@exept.de>
parents: 15525
diff changeset
  3179
     WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe.
11921
e2c2786daab1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11906
diff changeset
  3180
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3181
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3182
%{  /* STACK: 1000 */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3183
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3184
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3185
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3186
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3187
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3188
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3189
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3190
    OBJ s;
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3191
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3192
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3193
    if (__isStringLike(formatString)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3194
	cp = (char *)__stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3195
	if (__qClass(self) != String) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3196
	    cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3197
	}
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3198
again:
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3199
	/*
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3200
	 * actually only needed on sparc: since thisContext is
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3201
	 * in a global register, which gets destroyed by printf,
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3202
	 * manually save it here - very stupid ...
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3203
	 */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3204
	__BEGIN_PROTECT_REGISTERS__
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3205
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3206
	len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3207
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3208
	__END_PROTECT_REGISTERS__
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3209
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3210
	if ((len < 0) || (len > bufsize)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3211
	    if (len < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3212
		bufsize = bufsize * 2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3213
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3214
		bufsize = len + 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3215
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3216
	    if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3217
		free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3218
	    buf = mallocbuf = malloc(bufsize);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3219
	    if (buf == NULL)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3220
		goto fail;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3221
	    goto again;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3222
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3223
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3224
	s = __MKSTRING_L(buf, len);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3225
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3226
	if (mallocbuf)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3227
	    free(mallocbuf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3228
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3229
	if (s != nil) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3230
	    RETURN (s);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3231
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3232
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  3233
fail:;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3234
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3235
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3236
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3237
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3238
     'hello' printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3239
     (String new:900) printfPrintString:'%%s -> %s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3240
     'hello' printfPrintString:'%%10s -> %10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3241
     'hello' printfPrintString:'%%-10s -> %-10s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3242
     'hello' printfPrintString:'%%900s -> %900s'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3243
     'hello' printfPrintString:'%%-900s -> %-900s'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3244
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3245
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3246
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3247
storeOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3248
    "put the storeString of myself on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3249
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  3250
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3251
    (self includes:$') ifTrue:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3252
	self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3253
    ] ifFalse:[
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3254
	aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3255
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3256
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3257
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  3258
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3259
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3260
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3261
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3262
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3263
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  3264
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3265
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3266
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3267
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3268
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3269
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3270
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3271
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3272
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3273
%{  /* NOCONTEXT */
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3274
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3275
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3276
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3277
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3278
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3279
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3280
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3281
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3282
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3283
			  - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3284
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3285
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3286
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3287
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3288
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3289
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3290
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3291
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3292
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3293
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3294
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  3295
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3296
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  3297
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3298
contains8BitCharacters
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3299
    "return true, if the underlying string contains 8BitCharacters (or widers)
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3300
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3301
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3302
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3303
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3304
    REGISTER unsigned char *cp;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3305
    REGISTER unsigned char *last;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3306
    OBJ cls;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3307
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3308
    cp = __stringVal(self);
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3309
    last = cp + __stringSize(self);
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3310
    if ((cls = __qClass(self)) != String) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3311
	cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3312
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3313
#if __POINTER_SIZE__ == 8
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3314
    /* assume sizeof(long) == 4
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3315
     * if __POINTER_SIZE__ == 4
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3316
     */
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3317
    if (sizeof(long) == 8) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3318
	while ((cp+8) <= last) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3319
	    if (*(unsigned long *)cp & 0x8080808080808080) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3320
		RETURN ( true );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3321
	    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3322
	    cp += 8;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3323
	}
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3324
    }
10371
7d23f24d0598 fix compiler warnings
Stefan Vogel <sv@exept.de>
parents: 10370
diff changeset
  3325
#endif
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3326
    if (sizeof(int) == 4) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3327
	while ((cp+4) <= last) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3328
	    if (*(unsigned int *)cp & 0x80808080) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3329
		RETURN ( true );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3330
	    }
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3331
	    cp += 4;
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3332
	}
9268
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3333
    }
0d06a0818b52 contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents: 9233
diff changeset
  3334
    while ((cp+2) <= last) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3335
	if (*(unsigned short *)cp & 0x8080) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3336
	    RETURN ( true );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3337
	}
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3338
	cp += 2;
8915
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3339
    }
eb2652ce257d fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3340
    while (cp < last) {
10352
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3341
	if (*cp & 0x80) {
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3342
	    RETURN ( true );
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3343
	}
f2e9bb8906db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9665
diff changeset
  3344
	cp++;
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3345
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3346
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3347
%}.
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3348
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3349
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3350
     'hello world' contains8BitCharacters
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3351
     'hello world' asTwoByteString contains8BitCharacters
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3352
     ('hello world' , (Character value:16r88) asString) contains8BitCharacters
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3353
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3354
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3355
14556
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3356
isWideString
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3357
    ^ false
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3358
!
784826dfbcd8 class: String
Stefan Vogel <sv@exept.de>
parents: 14384
diff changeset
  3359
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3360
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3361
    "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
  3362
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3363
     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
  3364
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3365
%{  /* NOCONTEXT */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3366
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3367
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3368
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3369
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3370
    if (cls != String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3371
	indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3372
    } else {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3373
	indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3374
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3375
    RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) );
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3376
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  3377
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3378
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3379
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3380
    "
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3381
     'hello' knownAsSymbol
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3382
     'fooBarBaz' knownAsSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3383
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3384
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3385
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3386
referencesAny:aCollection
10822
a4e4c094df33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10820
diff changeset
  3387
    "redefined to speed up searching when many string instances are present"
a4e4c094df33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10820
diff changeset
  3388
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3389
    self class == String ifTrue:[^ false].
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3390
    ^ super referencesAny:aCollection
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3391
!
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3392
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3393
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3394
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3395
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3396
     (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
  3397
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3398
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3399
%{  /* NOCONTEXT */
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3400
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3401
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3402
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3403
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3404
    if (cls == String) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3405
	RETURN ( __mkSmallInteger(__stringSize(slf)) );
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3406
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3407
    RETURN ( __mkSmallInteger(__stringSize(slf)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3408
			 - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3409
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3410
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3411
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3412
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3413
stringSpecies
15525
0a0baff63fd0 class: String
Stefan Vogel <sv@exept.de>
parents: 15440
diff changeset
  3414
    ^ self species
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3415
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3416
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3417
!String methodsFor:'sorting & reordering'!
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3418
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3419
reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3420
    "in-place reverse the characters of the string.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3421
     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
  3422
	      Please use reversed (with a d) for a functional version."
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3423
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3424
    "Q: is there a need to redefine it here ?"
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3425
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3426
%{  /* NOCONTEXT */
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3427
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3428
    REGISTER char c;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3429
    REGISTER unsigned char *hip, *lowp;
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3430
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3431
    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
  3432
	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
  3433
	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
  3434
	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
  3435
	    c = *lowp;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3436
	    *lowp = *hip;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3437
	    *hip = c;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3438
	    lowp++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3439
	    hip--;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3440
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3441
	RETURN ( self );
11267
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3442
    }
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3443
%}.
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3444
    ^ super reverse
d9f1462b8c1e comment
Claus Gittinger <cg@exept.de>
parents: 11061
diff changeset
  3445
! !
10820
e4282ad95f90 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10697
diff changeset
  3446
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3447
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3448
!String methodsFor:'substring searching'!
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3449
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3450
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
  3451
    "redefined as primitive for maximum speed (BM)"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3452
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3453
    |notFound|
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3454
14384
1082868a753c changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14353
diff changeset
  3455
%{  /* STACK:4000 */
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3456
    if (__qIsStringLike(self)
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3457
     && __isStringLike(aSubString)
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3458
     && (caseSensitive == true)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3459
     && (__isSmallInteger(startIndex))
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3460
     && (__intVal(startIndex) > 0)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3461
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3462
	unsigned char *y = __stringVal(self);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3463
	unsigned char *x = __stringVal(aSubString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3464
	int m = __stringSize(aSubString);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3465
	int n = __stringSize(self);
14301
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  3466
#       define MAX_PATTERN_SIZE 128
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3467
#       define XSIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3468
#       define ASIZE 256
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3469
#       define MAX(a,b) (a>b ? a : b)
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3470
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3471
	if (m == 0) {
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  3472
#if 1
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3473
	    /* empty string does not match */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3474
	    RETURN(__mkSmallInteger(0));
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  3475
#else
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3476
	    /* empty string matches */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3477
	    RETURN(startIndex);
11824
20754d2d3b37 includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents: 11418
diff changeset
  3478
#endif
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3479
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3480
	if (m <= XSIZE) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3481
	    int i, j;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3482
	    static int lastPatternSize = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3483
	    static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 };
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3484
	    static int bmGs[XSIZE+1], bmBc[ASIZE];
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3485
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3486
#           define preBmBc(x, m, bmBc) {          \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3487
	       int i;                             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3488
						  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3489
	       for (i = 0; i < ASIZE; ++i)        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3490
		  bmBc[i] = m;                    \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3491
	       for (i = 0; i < m - 1; ++i)        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3492
		  bmBc[x[i]] = m - i - 1;         \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3493
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3494
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3495
#           define suffixes(x, m, suff) {                       \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3496
	       int f, g, i;                                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3497
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3498
	       suff[m - 1] = m;                                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3499
	       g = m - 1;                                       \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3500
	       for (i = m - 2; i >= 0; --i) {                   \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3501
		  if (i > g && suff[i + m - 1 - f] < i - g)     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3502
		     suff[i] = suff[i + m - 1 - f];             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3503
		  else {                                        \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3504
		     if (i < g)                                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3505
			g = i;                                  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3506
		     f = i;                                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3507
		     while (g >= 0 && x[g] == x[g + m - 1 - f]) \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3508
			--g;                                    \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3509
		     suff[i] = f - g;                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3510
		  }                                             \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3511
	       }                                                \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3512
	    }
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3513
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3514
#           define preBmGs(x, m, bmGs) {                        \
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3515
	       int i, j, suff[XSIZE];                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3516
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3517
	       suffixes(x, m, suff);                            \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3518
								\
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3519
	       for (i = 0; i < m; ++i)                          \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3520
		  bmGs[i] = m;                                  \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3521
	       j = 0;                                           \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3522
	       for (i = m - 1; i >= 0; --i)                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3523
		  if (suff[i] == i + 1)                         \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3524
		     for (; j < m - 1 - i; ++j)                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3525
			if (bmGs[j] == m)                       \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3526
			   bmGs[j] = m - 1 - i;                 \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3527
	       for (i = 0; i <= m - 2; ++i)                     \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3528
		  bmGs[m - 1 - suff[i]] = m - 1 - i;            \
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3529
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3530
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3531
	    /* tables only depend on pattern; so we can cache them in case the same string is searched again */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3532
	    if ((m == lastPatternSize)
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3533
	     && (strcmp(lastPattern, x) == 0)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3534
		/* tables are still valid */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3535
		// printf("valid: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3536
	    } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3537
		/* Preprocessing */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3538
		// printf("compute: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3539
		preBmGs(x, m, bmGs);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3540
		preBmBc(x, m, bmBc);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3541
		if (m <= MAX_PATTERN_SIZE) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3542
		    // printf("cache for: \"%s\"\n", lastPattern);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3543
		    strcpy(lastPattern, x);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3544
		    lastPatternSize = m;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3545
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3546
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3547
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3548
	    /* Searching */
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3549
	    j = __intVal(startIndex) - 1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3550
	    while (j <= n - m) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3551
	       for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3552
	       if (i < 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3553
		  RETURN (__mkSmallInteger(j+1));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3554
		  j += bmGs[0];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3555
	       } else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3556
		  int s1 = bmGs[i];
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3557
		  int s2 = bmBc[y[i + j]] - m + 1 + i;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3558
		  j += MAX(s1, s2);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3559
	       }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3560
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3561
	    notFound = true;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3562
	}
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3563
    }
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3564
%}.
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3565
    notFound == true ifTrue:[
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3566
	^ exceptionValue value.
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3567
    ].
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3568
    ^ 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
  3569
d8e7b4196d5e changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 14297
diff changeset
  3570
    "Modified: / 05-08-2012 / 12:27:31 / cg"
11346
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3571
! !
c2d4de8e644f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11287
diff changeset
  3572
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3573
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3574
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3575
endsWith:aStringOrChar
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3576
    "return true, if the receiver ends with something, aStringOrChar.
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3577
     If aStringOrChar is an empty string, true is returned"
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3578
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3579
%{  /* NOCONTEXT */
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3580
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3581
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3582
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  3583
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3584
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3585
12485
121288c11396 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12454
diff changeset
  3586
    if (__isStringLike(slf) && __isStringLike(aStringOrChar)) {
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3587
        len1 = __qSize(slf);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3588
        len2 = __qSize(aStringOrChar);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3589
        if (len1 < len2) {
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3590
            RETURN ( false );
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3591
        }
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3592
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3593
        src1 = __stringVal(slf) + (len1 - len2);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3594
        src2 = __stringVal(aStringOrChar);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3595
        while (c = *src2++) {
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3596
            if (c != *src1++) {
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3597
                RETURN ( false );
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3598
            }
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3599
        }
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3600
        RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3601
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3602
    if (__isCharacter(aStringOrChar)) {
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3603
        int val;
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3604
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3605
        val = __intVal(__characterVal(aStringOrChar));
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3606
        if ((unsigned)val <= 0xFF) {
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3607
            len1 = __stringSize(slf);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3608
            if (len1 > 0) {
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3609
                RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false);
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3610
            }
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3611
        }
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3612
        RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3613
    }
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3614
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3615
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3616
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3617
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3618
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3619
     'hello world' endsWith:'earth'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3620
     'hello world' endsWith:$d
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3621
     'hello world' endsWith:$e
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3622
     '' endsWith:$d
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3623
     'hello world' endsWith:#($r $l $d)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3624
     'hello world' endsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3625
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3626
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3627
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3628
isBlank
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3629
    "return true, if the receivers size is 0 or if it contains only spaces.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3630
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3631
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3632
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3633
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3634
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3635
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3636
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3637
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  3638
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3639
    if ((cls = __qClass(self)) != String)
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3640
	src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3641
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3642
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3643
# ifdef UINT64
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3644
    while (*((UINT64 *)src) == 0x2020202020202020L) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3645
	src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3646
    }
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3647
# endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3648
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3649
    while (*((unsigned *)src) == 0x20202020) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3650
	src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3651
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3652
#endif /* ascii */
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3653
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3654
    while (c = *src++) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3655
	if (c != ' ') {
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3656
	    RETURN ( false );
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3657
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3658
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3659
    RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3660
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3661
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3662
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3663
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3664
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3665
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3666
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3667
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3668
%{  /* NOCONTEXT */
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3669
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3670
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3671
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3672
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3673
	RETURN ( (__stringSize(self) == 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3674
    }
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3675
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3676
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3677
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3678
10958
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3679
isLiteral
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3680
    "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
  3681
     (i.e. can be used in constant arrays)"
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3682
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3683
    ^ true
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3684
!
100f639fdb0f category change: #isLiteral
Stefan Vogel <sv@exept.de>
parents: 10951
diff changeset
  3685
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3686
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
  3687
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3688
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3689
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  3690
%{  /* STACK: 2000 */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3691
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3692
    /*
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3693
     * this is very heavy used when correcting errors
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3694
     * (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
  3695
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3696
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3697
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3698
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3699
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3700
    unsigned char *s1, *s2;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3701
    int v1, v2, v3;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8898
diff changeset
  3702
    INT m;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3703
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3704
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3705
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3706
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3707
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  3708
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3709
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3710
    extern void *malloc();
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3711
14664
84f74f988376 class: String
Stefan Vogel <sv@exept.de>
parents: 14653
diff changeset
  3712
    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
  3713
	&& __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
  3714
	&& __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
  3715
	&& __isSmallInteger(kbdTypoWeight)
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3716
    ) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3717
	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
  3718
	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
  3719
	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
  3720
	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
  3721
	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
  3722
	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
  3723
	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
  3724
	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
  3725
	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
  3726
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3727
	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
  3728
	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
  3729
	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
  3730
	    data = fastData;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3731
	} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3732
	    /* 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
  3733
	    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
  3734
	    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
  3735
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3736
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3737
	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
  3738
	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
  3739
	    *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
  3740
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3741
	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
  3742
	    *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
  3743
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3744
	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
  3745
	    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
  3746
		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
  3747
		    m = 0;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3748
		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
  3749
		    m = cW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3750
		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
  3751
		    m = kW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3752
		else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3753
		    m = sW;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3754
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3755
		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
  3756
		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
  3757
		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
  3758
		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
  3759
		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
  3760
		    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
  3761
			m = v1;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3762
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3763
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3764
		} else {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3765
		    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
  3766
			m = v2;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3767
		    else
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3768
			m = v3;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3769
		}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3770
		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
  3771
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3772
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3773
	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
  3774
	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
  3775
	    free(data);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3776
	RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3777
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3778
mallocFailed: ;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3779
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3780
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3781
    ^ 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
  3782
			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
  3783
			i:insrtWeight d:deleteWeight
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3784
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3785
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3786
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3787
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3788
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3789
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3790
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3791
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3792
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3793
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3794
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3795
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3796
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3797
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3798
    "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
  3799
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3800
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3801
%{  /* NOCONTEXT */
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3802
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3803
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3804
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3805
    if ((cls == String) || (cls == Symbol)) {
9473
bb7785acb9d5 *** empty log message ***
fm
parents: 9472
diff changeset
  3806
	RETURN ( (__stringSize(self) != 0) ? true : false);
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3807
    }
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3808
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3809
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3810
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3811
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3812
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  3813
    "return true, if the receiver starts with something, aStringOrChar.
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  3814
     If the argument is empty, true is returned."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3815
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3816
%{  /* NOCONTEXT */
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3817
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3818
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3819
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  3820
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3821
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3822
14217
d399ca31088f changed: #startsWith:
Stefan Vogel <sv@exept.de>
parents: 14201
diff changeset
  3823
    if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3824
	src1 = __stringVal(slf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3825
	src2 = __stringVal(aStringOrChar);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3826
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3827
	if (src1[0] != src2[0]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3828
	    if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3829
		RETURN (true);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3830
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3831
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3832
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3833
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3834
	len1 = __qSize(slf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3835
	len2 = __qSize(aStringOrChar);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3836
	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
  3837
	    RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3838
	}
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3839
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3840
#ifdef UINT64
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3841
	while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3842
	    if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3843
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3844
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3845
	    len2 -= sizeof(UINT64);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3846
	    src1 += sizeof(UINT64);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3847
	    src2 += sizeof(UINT64);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3848
	}
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3849
#else
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  3850
# 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
  3851
	while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3852
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3853
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3854
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3855
	    if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3856
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3857
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3858
	    if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3859
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3860
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3861
	    if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3862
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3863
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3864
	    len2 -= sizeof(INT)*4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3865
	    src1 += sizeof(INT)*4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3866
	    src2 += sizeof(INT)*4;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3867
	}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8917
diff changeset
  3868
# endif /* __UNROLL_LOOPS__ */
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3869
#endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  3870
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3871
	while (len2 > (OHDR_SIZE+sizeof(INT))) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3872
	    if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3873
		RETURN (false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3874
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3875
	    len2 -= sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3876
	    src1 += sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3877
	    src2 += sizeof(INT);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3878
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3879
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3880
	while (c = *src2++) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3881
	    if (c != *src1) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3882
		RETURN ( false );
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3883
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3884
	    src1++;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3885
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3886
	RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3887
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3888
    if (__isCharacter(aStringOrChar)) {
15262
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3889
	int val;
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3890
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3891
	val = __intVal(__characterVal(aStringOrChar));
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3892
	if ((unsigned)val <= 0xFF) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3893
	    len1 = __stringSize(slf);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3894
	    if (len1 > 0) {
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3895
		RETURN ( (__stringVal(slf)[0] == val) ? true : false);
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3896
	    }
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3897
	}
5047292c9107 all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents: 15044
diff changeset
  3898
	RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3899
    }
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3900
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3901
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3902
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3903
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3904
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3905
     'hello world' startsWith:'hella'
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3906
     'hello world' startsWith:'hi'
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3907
     'hello world' startsWith:$h
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3908
     'hello world' startsWith:$H
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3909
     'hello world' startsWith:(Character value:16rFF00)
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3910
     'hello world' startsWith:60
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3911
     'hello world' startsWith:#($h $e $l)
8898
de2d00a37ae7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8861
diff changeset
  3912
     'hello world' startsWith:''
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3913
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3914
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3915
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3916
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3917
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  3918
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3919
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3920
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  3921
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3922
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3923
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3924
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3925
16253
94f754cff2b4 class: String
Stefan Vogel <sv@exept.de>
parents: 16226
diff changeset
  3926
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3927
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3928
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3929
version
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  3930
    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.318 2014-05-15 17:20:43 cg Exp $'
12184
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  3931
!
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  3932
e91c375c7ea9 comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents: 11922
diff changeset
  3933
version_CVS
16457
c25394c44436 class: String
Claus Gittinger <cg@exept.de>
parents: 16393
diff changeset
  3934
    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.318 2014-05-15 17:20:43 cg Exp $'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3935
! !
16174
973f21885fc1 class: String
Claus Gittinger <cg@exept.de>
parents: 16019
diff changeset
  3936