String.st
author penk
Tue, 14 Dec 2004 14:14:09 +0100
changeset 8657 1df84e8daa15
parent 8647 2f59b57bcc4d
child 8830 df7adfaf1a57
permissions -rw-r--r--
care for nil suspendedContext in description
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
159
514c749165c3 *** empty log message ***
claus
parents: 95
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
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    13
'From Smalltalk/X, Version:5.2.5 on 18-11-2004 at 14:54:53'                     !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    14
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    15
"{ Package: 'stx:libbasic' }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
    16
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    17
CharacterArray variableByteSubclass:#String
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
    18
	instanceVariableNames:''
7021
c12795ed7ddc string extensions
penk
parents: 7016
diff changeset
    19
	classVariableNames:'CRLF LF'
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
    20
	poolDictionaries:''
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
    21
	category:'Collections-Text'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    24
!String primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
%{
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
    26
3809
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    27
#include <stdio.h>
dd1df62365ee use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
    28
#define _STDIO_H_INCLUDED_
437
claus
parents: 429
diff changeset
    29
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
#include <ctype.h>
359
claus
parents: 357
diff changeset
    31
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    32
#ifdef LINUX
359
claus
parents: 357
diff changeset
    33
# define __STRINGDEFS__
claus
parents: 357
diff changeset
    34
# include <linuxIntern.h>
273
f97f3fcf8214 *** empty log message ***
claus
parents: 267
diff changeset
    35
#endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    36
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    37
/*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    38
 * old st/x creates strings with spaces in it;
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    39
 * new st/x will fill it with zeros (for st-80 compatibility)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    40
 * the define below sets old behavior.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    41
 */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    42
#define INITIALIZE_WITH_SPACE
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    43
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    44
#ifdef FAST_MEMCHR
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    45
 char *memchr();
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
    46
#endif
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
%}
216
a8abff749575 *** empty log message ***
claus
parents: 209
diff changeset
    48
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    49
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    50
!String primitiveFunctions!
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    51
%{
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    52
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    53
static int 
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    54
nextOnKeyboard(char1, char2) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    55
    /* compare two characters if they are next to each other on a (US-) keyboard */
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    56
    static char *keys[] = { "1234567890-",
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    57
                            "*qwertyuiop",
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    58
                            "**asdfghjkl:",
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    59
                            "***zxcvbnm",
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    60
                            0 };
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    61
    char **line1, **line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    62
    char *col1, *col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    63
    int diff;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    64
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    65
    for (line1 = keys; *line1 != 0; line1++) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    66
        for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    67
            continue;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    68
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    69
    if (*col1 == 0)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    70
        return(0);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    71
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    72
    for (line2 = keys; *line2 != 0; line2++) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    73
        for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    74
            continue;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    75
    }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    76
    if (*col2 == 0)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    77
        return(0);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    78
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    79
    diff = col1 - col2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    80
    if (diff > 1 || diff < -1)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    81
        return(0);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    82
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    83
    diff = line1 - line2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    84
    if (diff > 1 || diff < -1)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    85
        return(0);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    86
    return(1);
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
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    89
%}
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    90
! !
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
    91
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
!String class methodsFor:'documentation'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
copyright
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
 COPYRIGHT (c) 1988 by Claus Gittinger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
	      All Rights Reserved
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
 This software is furnished under a license and may be used
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
 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
   101
 inclusion of the above copyright notice.   This software may not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
 be provided or otherwise made available to, or used by, any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
 other person.  No title to or ownership of the software is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
 hereby transferred.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   107
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
documentation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
    Strings are ByteArrays storing Characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
    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
   113
    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
   114
    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
   115
    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
   116
    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
   117
    prevent a nonsense contents ...)
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   118
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
    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
   120
    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
   121
    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
   122
    of String (the access functions defined here can handle this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
    A little warning though: not all smalltalk systems allow subclassing String,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
    so your program may become unportable if you do so.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   125
7895
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   126
    Strings have an implicit (assumed) encoding of iso8859-1.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   127
    For strings with other encodings, either keep the encoding separately,
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   128
    or use instances of encodedString.
Claus Gittinger <cg@exept.de>
parents: 7891
diff changeset
   129
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   130
    [author:]
4800
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   131
        Claus Gittinger
1310
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   132
e910406fbecf commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   133
    [see also:]
4800
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   134
        Text StringCollection TwoByteString JISEncodedString
118dff933bf3 docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
   135
        Symbol
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   136
"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   137
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   138
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
!String class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
basicNew:anInteger
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   142
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   143
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   144
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   145
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   146
     can be directly used as separator or for formatting."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
    OBJ newString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
    REGISTER int len;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
    REGISTER unsigned char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
    REGISTER OBJ *op;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
    int nInstVars, instsize;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
252
   156
    if (__isSmallInteger(anInteger)) {
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   157
        len = __intVal(anInteger);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   158
        if (len >= 0) {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   159
            instsize = OHDR_SIZE + len + 1;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   160
            if (self == String) {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   161
                if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   162
                    /*
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   163
                     * the most common case
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   164
                     */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   165
                    __qCheckedNew(newString, instsize);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   166
                    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   167
                    __qSTORE(newString, self);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   168
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   169
                    cp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   170
357
claus
parents: 347
diff changeset
   171
#if defined(memset4) && !defined(NON_ASCII)
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   172
                    {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   173
                        /* 
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   174
                         * no sizeof(int) here please -
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   175
                         * - memset4 (if defined) fills 4-bytes on ALL machines 
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   176
                         */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   177
                        int l4 = len >> 2;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   178
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   179
                        if (len & 3) l4++;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   180
                        memset4(cp, 0x20202020, l4);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   181
                        cp[len] = '\0';
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   182
                    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   183
#else
357
claus
parents: 347
diff changeset
   184
# ifdef FAST_MEMSET
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   185
                    memset(cp, ' ', len);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   186
                    cp[len] = '\0';
357
claus
parents: 347
diff changeset
   187
# else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   188
                    while (len >= 8) {
3449
84160615c630 oops - basicNew was bad for subclasses of String.
Claus Gittinger <cg@exept.de>
parents: 3403
diff changeset
   189
#  ifndef NON_ASCII       /* i.e. EBCDIC  */
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   190
#   ifdef INT64
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   191
                        ((INT64 *)cp)[0] = 0x2020202020202020L;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   192
#   else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   193
                        ((int *)cp)[0] = 0x20202020;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   194
                        ((int *)cp)[1] = 0x20202020;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   195
#   endif
357
claus
parents: 347
diff changeset
   196
#  else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   197
                        cp[0] = cp[1] = cp[2] = cp[3] = ' ';
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   198
                        cp[4] = cp[5] = cp[6] = cp[7] = ' ';
357
claus
parents: 347
diff changeset
   199
#  endif
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   200
                        cp += 8; 
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   201
                        len -= 8;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   202
                    }
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   203
                    while (len--)
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   204
                        *cp++ = ' ';
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   205
                    *cp = '\0';
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   206
# endif /* not FAST_MEMSET */
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   207
#endif /* not memset4 */
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   208
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   209
                    RETURN (newString);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   210
                }
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   211
                nInstVars = 0;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   212
            } else {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   213
                nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   214
                instsize += __OBJS2BYTES__(nInstVars);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   215
            }
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   216
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   217
            __PROTECT_CONTEXT__;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   218
            __qNew(newString, instsize);        /* OBJECT ALLOCATION */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   219
            __UNPROTECT_CONTEXT__;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   220
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   221
            if (newString == nil) goto fail;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   222
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   223
            __InstPtr(newString)->o_class = self;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   224
            __qSTORE(newString, self);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   225
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   226
            if (nInstVars) {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   227
                /*
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   228
                 * nil-out instvars
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   229
                 */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   230
#if defined(memset4)
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   231
                memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   232
#else
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   233
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   234
                /*
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   235
                 * knowing that nil is 0
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   236
                 */
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   237
                memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   238
# else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   239
                op = __InstPtr(newString)->i_instvars;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   240
                do {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   241
                    *op++ = nil;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   242
                } while (--nInstVars);
357
claus
parents: 347
diff changeset
   243
# endif
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   244
#endif
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   245
                cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   246
            } else {
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   247
                cp = __stringVal(newString);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   248
            }
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   249
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   250
            /*
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   251
             * fill with spaces
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   252
             */
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
   253
#ifdef FAST_MEMSET
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   254
            memset(cp, ' ', len);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   255
            *(cp + len) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   256
#else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   257
            while (len >= 8) {
357
claus
parents: 347
diff changeset
   258
# ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   259
#  ifdef INT64
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   260
                ((INT64 *)cp)[0] = 0x2020202020202020L;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   261
#  else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   262
                ((int *)cp)[0] = 0x20202020;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   263
                ((int *)cp)[1] = 0x20202020;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   264
#  endif
357
claus
parents: 347
diff changeset
   265
# else
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   266
                cp[0] = cp[1] = cp[2] = cp[3] = ' ';
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   267
                cp[4] = cp[5] = cp[6] = cp[7] = ' ';
357
claus
parents: 347
diff changeset
   268
# endif
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   269
                cp += 8;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   270
                len -= 8;
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   271
            }
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   272
            while (len--)
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   273
                *cp++ = ' ';
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   274
            *cp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
#endif
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   276
            RETURN (newString);
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   277
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   279
fail: ;;
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   280
%}.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   281
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   282
     invalid argument, or out-of-memory:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   283
     use error handling in superclass
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   284
    "
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   285
    (anInteger < 0) ifTrue:[
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   286
        "
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   287
         the argument is negative,
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   288
        "
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   289
        self error:'bad (negative) argument to new:'.
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   290
        ^ nil
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   291
    ].
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
   292
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   293
    ^ (super basicNew:anInteger+1) atAllPut:(Character space)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   295
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
new:n
4802
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   297
    "return a new empty string with anInteger characters.
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   298
     In contrast to other smalltalks, this returns a string filled
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   299
     with spaces (instead of a string filled with 0-bytes).
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   300
     This makes much more sense, in that a freshly created string
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   301
     can be directly used as separator or for formatting."
0021d360c891 comments
Claus Gittinger <cg@exept.de>
parents: 4800
diff changeset
   302
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    ^ self basicNew:n
347
claus
parents: 345
diff changeset
   304
!
claus
parents: 345
diff changeset
   305
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   306
readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   307
    "read & return the next String from the (character-)stream aStream;
claus
parents: 345
diff changeset
   308
     skipping all whitespace first; return the value of exceptionBlock,
claus
parents: 345
diff changeset
   309
     if no string can be read. The sequence of characters as read from the 
claus
parents: 345
diff changeset
   310
     stream must be one as stored via storeOn: or storeString."
claus
parents: 345
diff changeset
   311
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   312
    |str collected char|
347
claus
parents: 345
diff changeset
   313
claus
parents: 345
diff changeset
   314
    "
claus
parents: 345
diff changeset
   315
     this method is not to be inherited
claus
parents: 345
diff changeset
   316
     (i.e. not ok for subclasses; Symbol, for example)
claus
parents: 345
diff changeset
   317
    "
claus
parents: 345
diff changeset
   318
    self ~~ String ifTrue:[
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   319
        ^ super readFrom:aStreamOrString onError:exceptionBlock
347
claus
parents: 345
diff changeset
   320
    ].
claus
parents: 345
diff changeset
   321
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   322
    str := aStreamOrString readStream.
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   323
347
claus
parents: 345
diff changeset
   324
    "skip whiteSpace"
6599
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   325
    str skipSeparators.
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   326
    (str next == $') ifTrue:[
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   327
        collected := WriteStream on:(String new).
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   328
        [true] whileTrue:[
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   329
            str atEnd ifTrue:[
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   330
                "/ mhmh - reached the end without a closing quote
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   331
                "/ looks like an error to me ...
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   332
                ^ exceptionBlock value
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   333
            ].
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   334
            char := str next.
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   335
            char == $' ifTrue:[
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   336
                "/ look for another quote
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   337
                str peekOrNil == $' ifFalse:[
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   338
                    ^ collected contents
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   339
                ].
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   340
                str next.
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   341
            ].
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   342
            collected nextPut:char
f4b35853b094 consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents: 6588
diff changeset
   343
        ]
347
claus
parents: 345
diff changeset
   344
    ].
claus
parents: 345
diff changeset
   345
    ^ exceptionBlock value
claus
parents: 345
diff changeset
   346
claus
parents: 345
diff changeset
   347
    "
claus
parents: 345
diff changeset
   348
     String readFrom:('''hello world''' readStream) 
claus
parents: 345
diff changeset
   349
     String readFrom:('''hello '''' world''' readStream) 
claus
parents: 345
diff changeset
   350
     String readFrom:('1 ''hello'' ' readStream)
claus
parents: 345
diff changeset
   351
     String readFrom:('1 ''hello'' ' readStream) onError:['foobar']  
3376
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   352
    "
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   353
d007727325da checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3335
diff changeset
   354
    "Modified: / 14.4.1998 / 18:46:26 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   355
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   357
uninitializedNew:anInteger
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   358
    "return a new string with anInteger characters but undefined contents.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   359
     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
   360
     used as a stream buffer."
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   361
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   362
%{  /* NOCONTEXT */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   363
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   364
    OBJ newString;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   365
    REGISTER int len;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   366
    REGISTER unsigned char *cp;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   367
    REGISTER OBJ *op;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   368
    int nInstVars, instsize;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   369
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   370
    if (__isSmallInteger(anInteger)) {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   371
        len = __intVal(anInteger);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   372
        if (len >= 0) {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   373
            instsize = OHDR_SIZE + len + 1;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   374
            if (self == String) {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   375
                if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   376
                    /*
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   377
                     * the most common case
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   378
                     */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   379
                    __qCheckedNew(newString, instsize);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   380
                    __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   381
                    __qSTORE(newString, self);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   382
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   383
                    cp = __stringVal(newString);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   384
                    cp[len] = '\0';
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   385
                    RETURN (newString);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   386
                }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   387
                nInstVars = 0;
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
                nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   390
                instsize += __OBJS2BYTES__(nInstVars);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   391
            }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   392
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   393
            __PROTECT_CONTEXT__;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   394
            __qNew(newString, instsize);        /* OBJECT ALLOCATION */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   395
            __UNPROTECT_CONTEXT__;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   396
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   397
            if (newString == nil) goto fail;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   398
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   399
            __InstPtr(newString)->o_class = self;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   400
            __qSTORE(newString, self);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   401
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   402
            if (nInstVars) {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   403
                /*
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   404
                 * nil-out instvars
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   405
                 */
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   406
#if defined(memset4)
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   407
                memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   408
#else
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   409
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   410
                /*
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   411
                 * knowing that nil is 0
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
                memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   414
# else
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   415
                op = __InstPtr(newString)->i_instvars;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   416
                do {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   417
                    *op++ = nil;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   418
                } while (--nInstVars);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   419
# endif
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   420
#endif
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   421
                cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   422
            } else {
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   423
                cp = __stringVal(newString);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   424
            }
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
            *(cp + len) = '\0';
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   427
            RETURN (newString);
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   428
        }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   429
    }
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   430
fail: ;;
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   431
%}.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   432
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   433
     invalid argument, or out-of-memory:
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   434
     use error handling in superclass
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   435
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   436
    (anInteger < 0) ifTrue:[
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   437
        "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   438
         the argument is negative,
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   439
        "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   440
        self error:'bad (negative) argument to new:'.
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   441
        ^ nil
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   442
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   444
    ^ self basicNew:anInteger
7684
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   445
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   446
    "
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   447
     String uninitializedNew:100
01cf232f73e7 added uninitializedNew:
Claus Gittinger <cg@exept.de>
parents: 7599
diff changeset
   448
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
8438
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   451
!String class methodsFor:'Compatibility-Dolphin'!
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   452
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   453
lineDelimiter
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   454
    "Dolphin compatibility: answer CR LF"
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   455
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   456
    ^ self crlf
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   457
! !
317f70e84d61 Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents: 8415
diff changeset
   458
7302
13a053c255bf category
Claus Gittinger <cg@exept.de>
parents: 7283
diff changeset
   459
!String class methodsFor:'Compatibility-Squeak'!
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   460
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   461
cr
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   462
    "return a string consisting of the cr-Character"
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   463
7283
779d0ca06226 cr is now a real cr
Claus Gittinger <cg@exept.de>
parents: 7282
diff changeset
   464
    ^ Character return asString
4993
569d1fa22e91 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
   465
4994
dbeb92c54dc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
   466
    "Modified: / 13.11.1999 / 13:53:36 / cg"
7282
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   467
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   468
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   469
crlf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   470
    "return a string consisting of the cr-lf Characters"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   471
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   472
    CRLF isNil ifTrue:[
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   473
        CRLF := String 
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   474
                    with:Character return
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   475
                    with:Character linefeed
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   476
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   477
    ^ CRLF
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   478
!
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   479
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   480
lf
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   481
    "return a string consisting of the lf Character"
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   482
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   483
    LF isNil ifTrue:[
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   484
        LF := String with:Character linefeed
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   485
    ].
75a51feb84c8 +crlf / +lf
Claus Gittinger <cg@exept.de>
parents: 7219
diff changeset
   486
    ^ LF
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   487
! !
2ee8cd2c4c8e squeak compatibility
ps
parents: 4802
diff changeset
   488
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
!String class methodsFor:'binary storage'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   491
binaryDefinitionFrom:stream manager:manager
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   492
    "read a binary representation from stream. This is only invoked
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   493
     for long strings. Short strings are stored with 1byte length."
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   494
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   495
    |s len|
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   497
    "take care of subclasses ..."
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   498
    ((self == String) or:[self == Symbol]) ifTrue:[
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7684
diff changeset
   499
        len := stream nextNumber:4.
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7684
diff changeset
   500
        s := String uninitializedNew:len.
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7684
diff changeset
   501
        stream nextBytes:len into:s startingAt:1.
7891
b35535c31c0a binaryDefinitionFrom fix for long symbols
Claus Gittinger <cg@exept.de>
parents: 7881
diff changeset
   502
        self == Symbol ifTrue:[
b35535c31c0a binaryDefinitionFrom fix for long symbols
Claus Gittinger <cg@exept.de>
parents: 7881
diff changeset
   503
            ^ s asSymbol
b35535c31c0a binaryDefinitionFrom fix for long symbols
Claus Gittinger <cg@exept.de>
parents: 7881
diff changeset
   504
        ].
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7684
diff changeset
   505
        ^ s
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   506
    ].
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   507
    ^ super binaryDefinitionFrom:stream manager:manager
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   508
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   509
    "Modified: / 2.11.1997 / 16:18:37 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   510
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   511
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   512
!String class methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   513
2680
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   514
defaultPlatformClass
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   515
    "dummy for ST-80 compatibility"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   516
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   517
    ^ self
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   518
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   519
    "Created: 6.6.1997 / 18:25:56 / cg"
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   520
!
18c85df5d930 #defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2670
diff changeset
   521
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   523
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   524
     Here, true is returned for myself, false for subclasses."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
    ^ self == String
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   527
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1251
diff changeset
   528
    "Modified: 23.4.1996 / 16:00:38 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   529
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
!String methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   532
329
claus
parents: 314
diff changeset
   533
at:index
claus
parents: 314
diff changeset
   534
    "return the character at position index, an Integer.
345
claus
parents: 329
diff changeset
   535
     Reimplemented here to avoid the additional at:->basicAt: send
claus
parents: 329
diff changeset
   536
     (which we can do here, since at: is obviously not redefined in a subclass).
329
claus
parents: 314
diff changeset
   537
     This method is the same as at:."
claus
parents: 314
diff changeset
   538
claus
parents: 314
diff changeset
   539
%{  /* NOCONTEXT */
claus
parents: 314
diff changeset
   540
claus
parents: 314
diff changeset
   541
    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
   542
    REGISTER OBJ slf, cls;
329
claus
parents: 314
diff changeset
   543
claus
parents: 314
diff changeset
   544
    if (__isSmallInteger(index)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   545
        slf = self;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   546
        cls = __qClass(slf);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   547
        indx = __intVal(index) - 1;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   548
        if (cls != String) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   549
            if (indx < 0) goto badIndex;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   550
            indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   551
        }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   552
        if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   553
            RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   554
        }
329
claus
parents: 314
diff changeset
   555
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   556
badIndex: ;
329
claus
parents: 314
diff changeset
   557
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   558
    ^ self basicAt:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   559
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   560
329
claus
parents: 314
diff changeset
   561
at:index put:aCharacter
claus
parents: 314
diff changeset
   562
    "store the argument, aCharacter at position index, an Integer.
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   563
     Return aCharacter (sigh).
345
claus
parents: 329
diff changeset
   564
     Reimplemented here to avoid the additional at:put:->basicAt:put: send
claus
parents: 329
diff changeset
   565
     (but only for Strings, since subclasses may redefine basicAt:put:).
329
claus
parents: 314
diff changeset
   566
     This method is the same as basicAt:put:."
claus
parents: 314
diff changeset
   567
claus
parents: 314
diff changeset
   568
%{  /* NOCONTEXT */
claus
parents: 314
diff changeset
   569
claus
parents: 314
diff changeset
   570
    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
   571
    REGISTER OBJ slf;
329
claus
parents: 314
diff changeset
   572
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   573
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   574
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   575
    if (__isString(slf)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   576
        if (__isCharacter(aCharacter)) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   577
            value = __intVal(_characterVal(aCharacter));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   578
            if (((unsigned)value <= 0xFF)
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   579
             && __isSmallInteger(index)) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   580
                indx = __intVal(index) - 1;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   581
                if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   582
                    __stringVal(slf)[indx] = value;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   583
                    RETURN ( aCharacter );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   584
                }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   585
            }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   586
        }
329
claus
parents: 314
diff changeset
   587
    }
claus
parents: 314
diff changeset
   588
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   589
    ^ self basicAt:index put:aCharacter
329
claus
parents: 314
diff changeset
   590
!
claus
parents: 314
diff changeset
   591
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   592
basicAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   593
    "return the character at position index, an Integer
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   594
     - reimplemented here since we return characters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   595
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   596
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   597
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   598
    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
   599
    REGISTER OBJ slf, cls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   600
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   601
    if (__isSmallInteger(index)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   602
        slf = self;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   603
        cls = __qClass(slf);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   604
        indx = __intVal(index) - 1;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   605
        if (cls != String) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   606
            if (indx < 0) goto badIndex;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   607
            indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   608
        }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   609
        if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   610
            RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   611
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   613
badIndex: ;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
%}.
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   615
    index isInteger ifFalse:[
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   616
        ^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   617
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   618
    index == super basicSize ifTrue:[
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   619
        ^ self subscriptBoundsError:index
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   620
    ].
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   621
    ^ Character value:(super basicAt:index)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   624
basicAt:index put:aCharacter
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   625
    "store the argument, aCharacter at position index, an Integer.
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   626
     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
   627
     - reimplemented here since we store characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   628
a27a279701f8 Initial revision
claus
parents:
diff changeset
   629
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   630
a27a279701f8 Initial revision
claus
parents:
diff changeset
   631
    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
   632
    REGISTER OBJ slf;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   633
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   634
1143
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   635
    slf = self;
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   636
27325100bdf4 can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   637
    if (__isCharacter(aCharacter)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   638
        value = __intVal(_characterVal(aCharacter));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   639
        if (((unsigned)value <= 0xFF)
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   640
         && __isSmallInteger(index)) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   641
            cls = __qClass(slf);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   642
            indx = __intVal(index) - 1;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   643
            if (cls != String) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   644
                if (indx < 0) goto badIndex;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   645
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   646
            }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   647
            if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   648
                __stringVal(slf)[indx] = value;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   649
                RETURN ( aCharacter );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   650
            }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   651
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   652
    }
4388
b4ca5cf130c7 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4247
diff changeset
   653
badIndex: ;
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   654
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   655
    (aCharacter isMemberOf:Character) ifFalse:[
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   656
        "
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   657
         tried to store something which is not a character
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   658
        "
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   659
        ^ self elementNotCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   660
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   661
    (aCharacter codePoint between:1 and:255) ifFalse:[
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   662
        "
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   663
         tried to store a multibyte character
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   664
        "
7219
7c7b9d76af21 subscriptBoundsError -> subscriptBoundsError:
Claus Gittinger <cg@exept.de>
parents: 7021
diff changeset
   665
        ^ self elementBoundsError:aCharacter
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   666
    ].
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   667
    "
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   668
     invalid index
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   669
    "
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   670
    index isInteger ifFalse:[
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   671
        ^ self indexNotInteger:index
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
   672
    ].
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   673
    index == super basicSize ifTrue:[
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   674
        ^ self subscriptBoundsError:index
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   675
    ].
8093
8ca1e24688d8 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   676
    super basicAt:index put:aCharacter codePoint.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   677
    ^ aCharacter 
2
claus
parents: 1
diff changeset
   678
! !
claus
parents: 1
diff changeset
   679
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   680
!String methodsFor:'binary storage'!
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   681
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   682
storeBinaryDefinitionOn:stream manager:manager
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   683
    "append a binary representation of the receiver onto stream.
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   684
     Redefined since short Strings can be stored with a special type code 
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   685
     in a more compact way.
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   686
     This is an internal interface for the binary storage mechanism."
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   687
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   688
    |myClass myBasicSize|
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   689
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   690
    "/ not for subclasses with named instVars.
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   691
    (myClass := self class) instSize ~~ 0 ifTrue:[
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   692
	^ super storeBinaryDefinitionOn:stream manager:manager
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   693
    ].
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   694
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   695
    myBasicSize := self basicSize.
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   696
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   697
    "/ can use a more compact representation;
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   698
    "/ but not for subclasses ...
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   699
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   700
    ((myClass == String) 
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   701
    and:[myBasicSize <= 255]) ifTrue:[
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   702
	"/ special encoding: <codeForString> <len> <bytes> ...
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   703
	stream nextPut:(manager codeForString); nextPut:myBasicSize.
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   704
    ] ifFalse:[
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   705
	manager putIdOfClass:myClass on:stream.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   706
	stream nextNumber:4 put:myBasicSize.
3085
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   707
    ].
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   708
    stream nextPutBytes:myBasicSize from:self startingAt:1.
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   709
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   710
    "Modified: / 2.11.1997 / 15:28:56 / cg"
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   711
! !
772b3e842c88 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2954
diff changeset
   712
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   713
!String methodsFor:'character searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   715
identityIndexOf:aCharacter
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   716
    "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
   717
     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
   718
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   719
%{  /* NOCONTEXT */
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   720
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   721
    REGISTER unsigned char *cp;
6855
5b77935e0872 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6833
diff changeset
   722
    REGISTER unsigned byteValue;
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
   723
#ifndef FAST_MEMCHR
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   724
    REGISTER int index;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   725
    REGISTER int last;
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   726
#endif
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   727
    OBJ cls;
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   728
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   729
    if (__isCharacter(aCharacter)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   730
        cp = __stringVal(self);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   731
        if ((cls = __qClass(self)) != String)
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   732
            cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   733
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   734
        byteValue = __intVal(__characterVal(aCharacter));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   735
        if (byteValue <= 0xFF) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   736
#ifdef FAST_MEMCHR
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   737
            cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   738
            if (cp) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   739
                RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   740
            }
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   741
#else
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   742
            last = __stringSize(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   743
            for (index=1; index <= last; index++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   744
                if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   745
           }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   746
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   747
        }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   748
        RETURN ( __MKSMALLINT(0));
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   749
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   750
    /* with identity compares, only characters can be in myself */
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   751
    RETURN ( __MKSMALLINT(0));
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   752
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   753
    ^ self primitiveFailed
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   754
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   755
    "
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   756
     'hello world' identityIndexOf:(Character space)                  
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   757
     'hello world' identityIndexOf:$d                      
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   758
     'hello world' identityIndexOf:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   759
     #[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
   760
     #[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
   761
    "
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   762
!
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   763
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   764
includes:aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   765
    "return true if the argument, aCharacter is included in the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   766
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   767
a27a279701f8 Initial revision
claus
parents:
diff changeset
   768
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   769
a27a279701f8 Initial revision
claus
parents:
diff changeset
   770
    REGISTER unsigned char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
    REGISTER int byteValue;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   772
#ifndef FAST_MEMCHR
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   773
    REGISTER unsigned char *last;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   774
#endif
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   775
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   777
    if (__isCharacter(aCharacter)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   778
        byteValue = __intVal(__characterVal(aCharacter));
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   779
        if (byteValue <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   780
            cp = __stringVal(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   781
            if ((cls = __qClass(self)) != String)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   782
                cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   783
#ifdef FAST_MEMCHR
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   784
            if (memchr(cp, byteValue, __stringSize(self)) != NULL) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   785
                RETURN ( true );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   786
            }
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   787
#else
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   788
            for (last=cp+__stringSize(self); cp < last; cp++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   789
                if (*cp == byteValue) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   790
                    RETURN ( true );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   791
                }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   792
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   793
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   794
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   795
        RETURN (false);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   796
    }
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   797
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   798
    ^ super includes:aCharacter
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   799
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   800
    "
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   801
     'hello world' includes:$d
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   802
     'hello world' includes:$o  
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   803
     'hello world' includes:$x  
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   804
     'hello world' includes:1    
299
bc0645db1ab0 *** empty log message ***
claus
parents: 286
diff changeset
   805
     'hello world' asTwoByteString includes:$o  
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   806
     #[0 0 1 0 0] asString includes:(Character value:1)
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   807
     #[0 0 1 0 0] asString includes:(Character value:0)
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   808
     #[1 2 3 4 5] asString includes:(Character value:0)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   809
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   810
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   811
10
claus
parents: 5
diff changeset
   812
includesAny:aCollection
claus
parents: 5
diff changeset
   813
    "return true, if the receiver includes any of the characters in the
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   814
     argument, aCollection.
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   815
     - redefined for speed if the argument is a String."
10
claus
parents: 5
diff changeset
   816
claus
parents: 5
diff changeset
   817
%{  /* NOCONTEXT */
claus
parents: 5
diff changeset
   818
claus
parents: 5
diff changeset
   819
    REGISTER unsigned char *cp;
claus
parents: 5
diff changeset
   820
    REGISTER unsigned char *matchP;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   821
    OBJ cls;
10
claus
parents: 5
diff changeset
   822
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   823
    if (__isString(aCollection)) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   824
        matchP = __stringVal(aCollection);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   825
        cp = __stringVal(self);
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   826
        if ((cls = __qClass(self)) != String)
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   827
            cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   828
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   829
        switch (__stringSize(aCollection)) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   830
            case 3:
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   831
                /* three character search */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   832
                if (strchr(cp, matchP[2])) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   833
                    RETURN ( true );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   834
                }
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   835
                /* fall into */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   836
            case 2:
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   837
                /* two character search */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   838
                if (strchr(cp, matchP[1])) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   839
                    RETURN ( true );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   840
                }
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   841
                /* fall into */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   842
            case 1:
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   843
                /* single character search */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   844
                if (strchr(cp, matchP[0])) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   845
                    RETURN ( true );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   846
                }
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   847
                /* fall into */
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   848
            case 0:
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   849
                RETURN ( false );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   850
        }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   851
        while (*cp) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   852
            if (strchr(matchP, *cp)) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   853
                RETURN ( true );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   854
            }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   855
            cp++;
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   856
        }
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   857
        RETURN ( false );
10
claus
parents: 5
diff changeset
   858
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
   859
%}.
10
claus
parents: 5
diff changeset
   860
    ^ super includesAny:aCollection
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   861
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   862
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   863
     'hello world' includesAny:'abcd'                      
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   864
     'hello world' includesAny:'xyz'                      
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   865
     'hello world' includesAny:'xz'                      
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   866
     'hello world' includesAny:'od'                      
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   867
     'hello world' includesAny:'xd'                      
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   868
     'hello world' includesAny:'dx'                      
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   869
     'hello world' includesAny:(Array with:$a with:$b with:$d)   
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   870
     'hello world' includesAny:(Array with:$x with:$y)     
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   871
     'hello world' includesAny:(Array with:1 with:2)    
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   872
    "
10
claus
parents: 5
diff changeset
   873
!
claus
parents: 5
diff changeset
   874
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   875
indexOf:aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   876
    "return the index of the first occurrences of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   877
     in the receiver or 0 if not found - reimplemented here for speed."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   878
a27a279701f8 Initial revision
claus
parents:
diff changeset
   879
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   880
a27a279701f8 Initial revision
claus
parents:
diff changeset
   881
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
   882
    REGISTER unsigned byteValue;
2530
d329f4251a53 Ooops -- fix last fix.
Stefan Vogel <sv@exept.de>
parents: 2529
diff changeset
   883
    REGISTER int index;
6370
d82742acb152 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6369
diff changeset
   884
#ifndef FAST_MEMCHR
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   885
    REGISTER int last;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   886
#endif
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   887
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   888
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   889
    if (__isCharacter(aCharacter)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   890
        cp = __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   891
        if ((cls = __qClass(self)) != String)
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   892
            cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   893
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   894
        byteValue = __intVal(__characterVal(aCharacter));
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   895
        if (byteValue <= 0xFF) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   896
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   897
#ifdef FAST_MEMCHR
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   898
            cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   899
            if (cp) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   900
                RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   901
            }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   902
#else
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   903
            last = __stringSize(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   904
            for (index=1; index <= last; index++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   905
                if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   906
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   907
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   908
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   909
        RETURN ( __MKSMALLINT(0));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   910
    }
370
claus
parents: 368
diff changeset
   911
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
   912
    ^ super indexOf:aCharacter
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   913
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   914
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   915
     'hello world' indexOf:(Character space)                  
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   916
     'hello world' indexOf:$A                      
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   917
     'hello world' indexOf:$d                      
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   918
     #[0 0 1 0 0] asString indexOf:(Character value:1)
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)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   920
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   921
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   922
a27a279701f8 Initial revision
claus
parents:
diff changeset
   923
indexOf:aCharacter startingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
   924
    "return the index of the first occurrence of the argument, aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   925
     in myself starting at start, anInteger or 0 if not found;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   926
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   927
a27a279701f8 Initial revision
claus
parents:
diff changeset
   928
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   929
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
   930
    REGISTER int index;
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
   931
    REGISTER unsigned byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   932
    int len;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   933
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   934
252
   935
    if (__isSmallInteger(start)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   936
        if (__isCharacter(aCharacter)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   937
            byteValue = __intVal(_characterVal(aCharacter));
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   938
            if (byteValue <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   939
                index = __intVal(start);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   940
                if (index <= 0)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   941
                    index = 1;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   942
                if ((cls = __qClass(self)) != String)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   943
                    index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   944
                len = __stringSize(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   945
                if (index <= len) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   946
                    cp = __stringVal(self) + index - 1;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   947
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   948
#ifdef FAST_MEMCHR
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   949
                    cp = (unsigned char *) memchr(cp, byteValue, len+1-index);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   950
                    if (cp) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   951
                        RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   952
                    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   953
#else
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   954
                    for (; index <= len; index++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   955
                        if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   956
                    }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
   957
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   958
                }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   959
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   960
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   961
        RETURN ( __MKSMALLINT(0) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   962
    }
370
claus
parents: 368
diff changeset
   963
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   964
    ^ super indexOf:aCharacter startingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
   965
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   966
    "
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   967
     'hello world' indexOf:$0 startingAt:1 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   968
     'hello world' indexOf:$l startingAt:1 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   969
     'hello world' indexOf:$l startingAt:5  
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   970
     'hello world' indexOf:$d startingAt:5  
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   971
     #[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
   972
     #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   973
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   974
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   975
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   976
indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   977
    "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
   978
     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
   979
     - 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
   980
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   981
%{  /* NOCONTEXT */
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   982
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   983
    REGISTER unsigned char *ccp;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   984
    REGISTER unsigned char *cp;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   985
    REGISTER int index;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
   986
    unsigned char *matchP;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
   987
    unsigned char c, min, max;
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   988
    int len;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   989
    OBJ cls;
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   990
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   991
    if (__isSmallInteger(start)
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   992
     && __isString(aCollectionOfCharacters)) {
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   993
        matchP = __stringVal(aCollectionOfCharacters);
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   994
        index = __intVal(start);
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   995
        if (index <= 0)
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   996
            index = 1;
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   997
        if ((cls = __qClass(self)) != String)
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   998
            index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
   999
        len = __stringSize(self);
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1000
        if (index <= len) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1001
            cp = __stringVal(self) + index - 1;
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1002
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1003
            if (matchP[0] == 0) {
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1004
                /* matchSet is empty */
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1005
                RETURN ( __MKSMALLINT(0) );
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1006
            }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1007
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1008
            if (matchP[1] == 0) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1009
                /* only a single character match */
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1010
                unsigned char m = matchP[0];
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1011
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1012
#ifdef FAST_MEMCHR
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1013
                cp = (unsigned char *) memchr(cp, m, len-index+1);
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1014
                if (cp) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1015
                    RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1016
                }
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1017
#else
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1018
                while (c = *cp++) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1019
                    if (c == m) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1020
                        RETURN ( __MKSMALLINT(index) );
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1021
                    }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1022
                    index++;
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1023
                }
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1024
#endif
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1025
                RETURN ( __MKSMALLINT(0) );
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1026
            }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1027
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1028
            if (matchP[2] == 0) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1029
                /* two character matches */
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1030
                unsigned char m1 = matchP[0];
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1031
                unsigned char m2 = matchP[1];
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1032
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1033
                while (c = *cp++) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1034
                    if ((c == m1) || (c == m2)) {
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1035
                        RETURN ( __MKSMALLINT(index) );
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1036
                    }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1037
                    index++;
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1038
                }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1039
                RETURN ( __MKSMALLINT(0) );
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1040
            }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1041
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1042
            min = max = matchP[0];
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1043
8205
045e07212c93 indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents: 8093
diff changeset
  1044
            for (ccp = matchP+1; *ccp ; ccp++) {
045e07212c93 indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents: 8093
diff changeset
  1045
                unsigned char c = *ccp;
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1046
                if (c < min) min = c;
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1047
                else if (c > max) max = c;
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1048
            }
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1049
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1050
            while (c = *cp++) {
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1051
                if ((c >= min) && (c <= max)) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1052
                    for (ccp = matchP; *ccp ; ccp++) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1053
                        if (*ccp == c) {
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1054
                            RETURN ( __MKSMALLINT(index) );
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1055
                        }
7774
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1056
                    }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1057
                }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1058
                index++;
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1059
            }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1060
        }
a9e4385a39a7 indexOfAny: tuned
Claus Gittinger <cg@exept.de>
parents: 7746
diff changeset
  1061
        RETURN ( __MKSMALLINT(0) );
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1062
    }
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1063
%}.
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1064
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1065
    "/ 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
  1066
    "/
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1067
    ^ super indexOfAny:aCollectionOfCharacters startingAt:start
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1068
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1069
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1070
     'hello world' indexOfAny:'eoa' startingAt:1   
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1071
     'hello world' indexOfAny:'eoa' startingAt:6 
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1072
     'hello world' indexOfAny:'AOE' startingAt:1 
8006
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1073
     'hello world' indexOfAny:'o' startingAt:6    
04326d8f2410 tuned includesAny
Claus Gittinger <cg@exept.de>
parents: 7895
diff changeset
  1074
     'hello world' indexOfAny:'o' startingAt:6    
8205
045e07212c93 indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents: 8093
diff changeset
  1075
     'hello world§' indexOfAny:'#§$' startingAt:6  
516
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1076
    "
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1077
!
17a170eb1112 speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
  1078
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1079
indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1080
    "return the index of the next control character;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1081
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1082
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1083
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1084
%{  /* NOCONTEXT */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1085
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1086
#ifndef NON_ASCII       /* i.e. not EBCDIC ;-) */
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1087
    REGISTER unsigned char *cp;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1088
    REGISTER unsigned char c;
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1089
    REGISTER unsigned char *cpEnd;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1090
    int len, index;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1091
    OBJ cls;
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1092
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1093
    index = __intVal(start);
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1094
    if (index <= 0) {
4205
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1095
	index = 1;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1096
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1097
    if ((cls = __qClass(self)) != String)
4205
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1098
	index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1099
    len = __stringSize(self);
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1100
    cpEnd = __stringVal(self) + len;
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1101
    cp = __stringVal(self) + index - 1;
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1102
    if (cp < cpEnd) {
4205
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1103
	while (cp < cpEnd) {
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1104
	    if (*cp++ < ' ') {
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1105
		RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1106
	    }
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1107
	}
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1108
	RETURN ( __MKSMALLINT(0) );
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1109
    }
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1110
#endif
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1111
%}.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1112
    ^ super indexOfControlCharacterStartingAt:start
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1113
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1114
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1115
     'hello world'             indexOfControlCharacterStartingAt:1 
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1116
     'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 
3734
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1117
     '1\' withCRs indexOfControlCharacterStartingAt:1 
5d4e741062bd may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents: 3712
diff changeset
  1118
     '1\' withCRs indexOfControlCharacterStartingAt:2 
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1119
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1120
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3651
diff changeset
  1121
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1122
indexOfNonSeparatorStartingAt:start
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1123
    "return the index of the next non-whiteSpace character"
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1124
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1125
%{  /* NOCONTEXT */
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1126
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1127
    REGISTER unsigned char *cp;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1128
    REGISTER unsigned char c;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1129
    int len, index;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1130
    OBJ cls;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1131
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1132
    index = __intVal(start);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1133
    if (index <= 0) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1134
        index = 1;
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1135
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1136
    if ((cls = __qClass(self)) != String)
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1137
        index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1138
    len = __stringSize(self);
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1139
    if (index > len) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1140
        RETURN ( __MKSMALLINT(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1141
    }
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1142
    cp = __stringVal(self) + index - 1;
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1143
    while (c = *cp++) {
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1144
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1145
        if (c > ' ')
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1146
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1147
        if ((c != ' ') && (c != '\t') && (c != '\n')
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1148
         && (c != '\r') && (c != '\f')) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1149
            RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1150
        }
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1151
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1152
    RETURN ( __MKSMALLINT(0) );
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1153
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1154
    ^ super indexOfNonSeparatorStartingAt:start
3403
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1155
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1156
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1157
     'hello world' indexOfNonWhiteSpaceStartingAt:3 
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1158
     'hello world' indexOfNonWhiteSpaceStartingAt:7 
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1159
    "
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1160
!
904b613bfc7b checkin from browser
ca
parents: 3376
diff changeset
  1161
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1162
indexOfSeparatorStartingAt:start
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1163
    "return the index of the next separator character"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1164
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1165
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1166
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1167
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1168
    REGISTER unsigned char c;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1169
    int len, index;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1170
    OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1171
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1172
    index = __intVal(start);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1173
    if (index <= 0) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1174
        index = 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1175
    }
329
claus
parents: 314
diff changeset
  1176
    if ((cls = __qClass(self)) != String)
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1177
        index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1178
    len = __stringSize(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1179
    if (index > len) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1180
        RETURN ( __MKSMALLINT(0) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1181
    }
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  1182
    cp = __stringVal(self) + index - 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1183
    while (c = *cp++) {
329
claus
parents: 314
diff changeset
  1184
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1185
        if (c <= ' ')
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1186
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1187
        if ((c == ' ') || (c == '\t') || (c == '\n')
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1188
         || (c == '\r') || (c == '\f')) {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1189
            RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1190
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1191
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1192
    RETURN ( __MKSMALLINT(0) );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1193
%}.
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1194
    ^ super indexOfSeparatorStartingAt:start
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1195
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1196
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1197
     'hello world' indexOfSeparatorStartingAt:3 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1198
     'hello world' indexOfSeparatorStartingAt:7 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1199
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1200
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1201
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1202
occurrencesOf:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1203
    "count the occurrences of the argument, aCharacter in myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1204
      - reimplemented here for speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1205
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1206
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1207
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1208
    REGISTER unsigned char *cp;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1209
    REGISTER unsigned byteValue;
6828
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1210
    REGISTER int count, limit;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1211
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1212
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1213
    if (__isCharacter(aCharacter)) {
6828
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1214
        limit = __stringSize(self);
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1215
        count = 0;
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1216
        byteValue = __intVal(_characterVal(aCharacter));
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1217
        if (byteValue <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1218
            cp = __stringVal(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1219
            if ((cls = __qClass(self)) != String) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1220
                int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1221
                limit -= n;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1222
                cp += n;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1223
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1224
            while (limit > 0) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1225
                limit--;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1226
                if (*cp++ == byteValue) count++;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  1227
            }
6828
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1228
        }
f1725ea64ff1 fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents: 6766
diff changeset
  1229
        RETURN ( __MKSMALLINT(count) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1230
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1231
%}.
1950
2378ed1ae467 must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents: 1804
diff changeset
  1232
    ^ super occurrencesOf:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1233
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1234
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1235
     'hello world' occurrencesOf:$a
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1236
     'hello world' occurrencesOf:$w
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1237
     'hello world' occurrencesOf:$l 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1238
     'hello world' occurrencesOf:$x  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1239
     'hello world' occurrencesOf:1 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1240
    "
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1241
! !
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1242
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1243
!String methodsFor:'comparing'!
2
claus
parents: 1
diff changeset
  1244
8312
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1245
< aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1246
    "Compare the receiver with the argument and return true if the
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1247
     receiver is greater than the argument. Otherwise return false.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1248
     No national variants are honored; use after: for this.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1249
     In contrast to ST-80, case differences are NOT ignored, thus
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1250
     'foo' < 'Foo' will return false. 
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1251
     This may change."
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1252
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1253
%{  /* NOCONTEXT */
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1254
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1255
    int len1, len2, cmp;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1256
    REGISTER OBJ s = aString;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1257
    unsigned char *cp1, *cp2;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1258
    OBJ cls;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1259
    OBJ myCls;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1260
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1261
    if (__isNonNilObject(s)) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1262
        cls = __qClass(s);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1263
        myCls = __qClass(self);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1264
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1265
        if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1266
            cp2 = __stringVal(s);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1267
            len2 = __stringSize(s);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1268
            /*
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1269
             * care for instances of subclasses ...
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1270
             */
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1271
            if (cls != String) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1272
                int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1273
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1274
                cp2 += n;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1275
                len2 -= n;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1276
            }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1277
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1278
            cp1 = __stringVal(self);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1279
            len1 = __stringSize(self);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1280
            /*
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1281
             * care for instances of subclasses ...
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1282
             */
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1283
            if (myCls != String) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1284
                int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1285
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1286
                cp1 += n;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1287
                len1 -= n;
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1288
            }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1289
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1290
            if (len1 <= len2)
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1291
                cmp = strncmp(cp1, cp2, len1);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1292
            else
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1293
                cmp = strncmp(cp1, cp2, len2);
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1294
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1295
            if (cmp < 0) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1296
                RETURN ( true );
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1297
            }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1298
            if ((cmp == 0) && (len1 < len2)) {
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1299
                RETURN ( true );
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1300
            }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1301
            RETURN ( false );
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1302
        }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1303
    }
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1304
%}.
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1305
    ^ super < aString
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1306
!
c7a80959b9a1 Define #<
Stefan Vogel <sv@exept.de>
parents: 8295
diff changeset
  1307
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1308
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1309
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1310
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1311
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1312
     Use sameAs: to compare with case ignored."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1313
375
claus
parents: 370
diff changeset
  1314
%{  /* NOCONTEXT */
claus
parents: 370
diff changeset
  1315
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1316
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1317
    REGISTER OBJ s = aString;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1318
    unsigned char *cp1, *cp2;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1319
    OBJ cls;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1320
    OBJ myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1321
    INT addrDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1322
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1323
    if (s == self) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1324
        RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1325
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1326
    if (! __isNonNilObject(s)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1327
        RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1328
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1329
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1330
    cls = __qClass(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1331
    myCls = __qClass(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1332
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1333
    if ((cls == myCls) || (cls == String) || (cls == Symbol)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1334
        cp2 = __stringVal(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1335
        l2 = __stringSize(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1336
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1337
         * care for instances of subclasses ...
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1338
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1339
        if (cls != String) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1340
            int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1341
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1342
            cp2 += n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1343
            l2 -= n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1344
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1345
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1346
        cp1 = __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1347
        l1 = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1348
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1349
         * care for instances of subclasses ...
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1350
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1351
        if (myCls != String) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1352
            int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1353
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1354
            cp1 += n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1355
            l1 -= n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1356
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1357
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1358
        if (l1 != l2) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1359
            RETURN ( false );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1360
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1361
#ifdef FAST_MEMCMP
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1362
        RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1363
#else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1364
        addrDelta = cp2 - cp1;
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
  1365
# ifdef UNROLL_LOOPS
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1366
        while (l1 >= (sizeof(unsigned INT)*4)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1367
            if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1368
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1369
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1370
            if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1371
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1372
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1373
            if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1374
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1375
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1376
            if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1377
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1378
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1379
            l1 -= (sizeof(unsigned INT) * 4);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1380
            cp1 += (sizeof(unsigned INT) * 4);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1381
        }
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
  1382
# endif /* UNROLL_LOOPS */
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1383
        while (l1 >= sizeof(unsigned INT)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1384
            if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1385
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1386
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1387
            l1 -= sizeof(unsigned INT);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1388
            cp1 += sizeof(unsigned INT);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1389
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1390
        if (l1 >= sizeof(unsigned short)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1391
            if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1392
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1393
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1394
            l1 -= sizeof(unsigned short);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1395
            cp1 += sizeof(unsigned short);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1396
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1397
        while (l1) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1398
            if (*cp1 != *(cp1+addrDelta)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1399
                RETURN (false);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1400
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1401
            l1--;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1402
            cp1++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1403
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1404
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1405
        RETURN (true);
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1406
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1407
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1408
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1409
    ^ super = aString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1410
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1411
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1412
     'foo' = 'Foo' 
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1413
     'foo' sameAs: 'Foo'
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1414
     #[0 0 1 0 0] asString = #[0 0 1 0 0] asString
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1415
    "
7868
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1416
    "
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1417
     |tEmpty tCmp|
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1418
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1419
     tEmpty := Time millisecondsToRun:[
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1420
         1000000 timesRepeat:[]
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1421
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1422
     tCmp := Time millisecondsToRun:[
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1423
         1000000 timesRepeat:[ '1234567890' = '1234567890' ]
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1424
     ].
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1425
     tCmp - tEmpty   
15204449d62c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7867
diff changeset
  1426
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1427
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1428
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1429
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1430
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1431
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1432
     No national variants are honored; use after: for this.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1433
     In contrast to ST-80, case differences are NOT ignored, thus
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1434
     'foo' > 'Foo' will return true. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1435
     This may change."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1436
375
claus
parents: 370
diff changeset
  1437
%{  /* NOCONTEXT */
claus
parents: 370
diff changeset
  1438
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1439
    int len1, len2, cmp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1440
    REGISTER OBJ s = aString;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1441
    unsigned char *cp1, *cp2;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1442
    OBJ cls;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1443
    OBJ myCls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1444
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1445
    if (__isNonNilObject(s)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1446
	cls = __qClass(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1447
	myCls = __qClass(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1448
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1449
	if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1450
	    cp2 = __stringVal(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1451
	    len2 = __stringSize(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1452
	    /*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1453
	     * care for instances of subclasses ...
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1454
	     */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1455
	    if (cls != String) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1456
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1457
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1458
		cp2 += n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1459
		len2 -= n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1460
	    }
375
claus
parents: 370
diff changeset
  1461
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1462
	    cp1 = __stringVal(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1463
	    len1 = __stringSize(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1464
	    /*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1465
	     * care for instances of subclasses ...
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1466
	     */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1467
	    if (myCls != String) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1468
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1469
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1470
		cp1 += n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1471
		len1 -= n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1472
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1473
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1474
	    if (len1 <= len2)
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1475
		cmp = strncmp(cp1, cp2, len1);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1476
	    else
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1477
		cmp = strncmp(cp1, cp2, len2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1478
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1479
	    if (cmp > 0) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1480
		RETURN ( true );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1481
	    }
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1482
	    if ((cmp == 0) && (len1 > len2)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1483
		RETURN ( true );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1484
	    }
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1485
	    RETURN ( false );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1486
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1487
    }
370
claus
parents: 368
diff changeset
  1488
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1489
    ^ super > aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1490
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1491
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1492
after:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1493
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1494
     receiver should come after the argument in a sorted list. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1495
     Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1496
     The comparison is language specific, depending on the value of
1368
2b21ccc98e5e comment in #after:
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1497
     LC_COLLATE, which is initialized from the environment.
2b21ccc98e5e comment in #after:
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1498
2b21ccc98e5e comment in #after:
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1499
     STUPID:
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  1500
	#after has a completely different meaning in SeqColl ..."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1501
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1502
    ^ (self compareCollatingWith:aString) > 0
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1503
1368
2b21ccc98e5e comment in #after:
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1504
    "Modified: 10.5.1996 / 14:02:45 / cg"
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1505
!
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1506
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1507
compareCollatingWith:aString
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1508
    "Compare the receiver with the argument and return 1 if the receiver is
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1509
     greater, 0 if equal and -1 if less than the argument in a sorted list. 
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1510
     The comparison is language specific, depending on the value of
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1511
     LC_COLLATE, which is in the shell environment."
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1512
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1513
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1514
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1515
    int cmp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1516
    REGISTER OBJ s = aString;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  1517
    unsigned char *cp1, *cp2;
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  1518
    OBJ cls;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1519
    OBJ myCls;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1520
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1521
    if (__isNonNilObject(s)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1522
	cls = __qClass(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1523
	myCls = __qClass(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1524
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1525
	if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1526
	    cp1 = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1527
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1528
	    /*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1529
	     * care for instances of subclasses ...
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1530
	     */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1531
	    if (myCls != String) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1532
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1533
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1534
		cp1 += n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1535
	    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1536
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1537
	    cp2 = __stringVal(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1538
	    /*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1539
	     * care for instances of subclasses ...
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1540
	     */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1541
	    if (cls != String) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1542
		int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1543
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1544
		cp2 += n;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1545
	    }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1546
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1547
#ifdef HAS_STRCOLL
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1548
	    cmp = strcoll(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1549
#else
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1550
	    cmp = strcmp(cp1, cp2);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1551
#endif
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1552
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1553
	    if (cmp > 0) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1554
		RETURN ( __MKSMALLINT(1) );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1555
	    }
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1556
	    if (cmp < 0) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1557
		RETURN ( __MKSMALLINT(-1) );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1558
	    }
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1559
	    RETURN ( __MKSMALLINT(0) );
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1560
	}
370
claus
parents: 368
diff changeset
  1561
    }
329
claus
parents: 314
diff changeset
  1562
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1563
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1564
     currently, this operation is only defined for strings, symbols
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1565
     and subclasses.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1566
    "
1251
9a76f8683400 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1246
diff changeset
  1567
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1568
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1569
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1570
~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1571
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1572
     receiver is not equal to the argument. Otherwise return false.
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1573
     This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1574
     Actually, there is no need to redefine that method here,
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1575
     the default (= not as inherited) works ok.
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1576
     However, this may be heavily used and the redefinition saves an
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1577
     extra message send."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1578
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1579
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1580
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1581
    int l1, l2;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1582
    REGISTER OBJ s = aString;
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  1583
    unsigned char *cp1, *cp2;
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1584
    OBJ cls, myCls;
3335
054b52565a69 oops - need INT for delta
Claus Gittinger <cg@exept.de>
parents: 3314
diff changeset
  1585
    INT addrDelta;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1586
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1587
    if (s == self) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1588
        RETURN ( false );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1589
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1590
    if (! __isNonNilObject(s)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1591
        RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1592
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1593
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1594
    cls = __qClass(s);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1595
    myCls = __qClass(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1596
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1597
    if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1598
        cp1 = __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1599
        l1 = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1600
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1601
         * care for instances of subclasses ...
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1602
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1603
        if (myCls != String) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1604
            int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1605
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1606
            cp1 += n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1607
            l1 -= n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1608
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1609
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1610
        cp2 = __stringVal(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1611
        l2 = __stringSize(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1612
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1613
         * care for instances of subclasses ...
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1614
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1615
        if (cls != String) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1616
            int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1617
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1618
            cp2 += n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1619
            l2 -= n;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1620
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1621
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1622
        if (l1 != l2) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1623
            RETURN ( true );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1624
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1625
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1626
        addrDelta = cp2 - cp1;
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
  1627
# ifdef UNROLL_LOOPS
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1628
        while (l1 >= (sizeof(unsigned INT)*4)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1629
            if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1630
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1631
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1632
            if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1633
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1634
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1635
            if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1636
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1637
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1638
            if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1639
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1640
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1641
            l1 -= (sizeof(unsigned INT) * 4);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1642
            cp1 += (sizeof(unsigned INT) * 4);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1643
        }
3989
109b4e016f51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
  1644
# endif /* UNROLL_LOOPS */
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1645
        while (l1 >= sizeof(unsigned INT)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1646
            if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1647
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1648
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1649
            l1 -= sizeof(unsigned INT);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1650
            cp1 += sizeof(unsigned INT);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1651
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1652
        if (l1 >= sizeof(unsigned short)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1653
            if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1654
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1655
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1656
            l1 -= sizeof(unsigned short);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1657
            cp1 += sizeof(unsigned short);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1658
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1659
        while (l1) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1660
            if (*cp1 != *(cp1+addrDelta)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1661
                RETURN (true);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1662
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1663
            l1--;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1664
            cp1++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1665
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1666
        RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1667
    }
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  1668
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1669
    ^ super ~= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1670
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1671
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1672
!String methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1673
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1674
asArrayOfSubstrings
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1675
	"Answer an array with all the substrings of the receiver separated by
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1676
	separator characters (space, cr, tab, linefeed, formfeed, etc)."
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1677
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1678
	| substrings start end |
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1679
	substrings _ OrderedCollection new.
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1680
	start _ 1.
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1681
	[start <= self size] whileTrue: [
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1682
		(self at: start) isSeparator ifFalse: [
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1683
			end _ start + 1.
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1684
			[end <= self size and: [(self at: end) isSeparator not]]
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1685
				whileTrue: [end _ end + 1].
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1686
			substrings add: (self copyFrom: start to: end - 1).
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1687
			start _ end - 1].
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1688
		start _ start + 1].
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1689
	^ substrings asArray
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1690
!
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  1691
3281
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1692
asBoldText
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1693
    "return self as a bold text"
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1694
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1695
    ^Text string: self emphasis: #bold
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1696
!
d108dee000f7 #asBoldText added for often used bold texts in dialogs, etc.
tz
parents: 3234
diff changeset
  1697
7877
bef56f06d2f8 asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents: 7869
diff changeset
  1698
asSingleByteString
5760
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  1699
    "I am a string"
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  1700
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  1701
    ^ self
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  1702
!
00f393f89464 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5746
diff changeset
  1703
7878
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1704
asSingleByteStringReplaceInvalidWith:replacementCharacter
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1705
    "I am a string"
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1706
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1707
    ^ self
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1708
!
0e88e1019955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7877
diff changeset
  1709
2856
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1710
asString
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1711
    "I am a string"
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1712
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1713
    ^ self
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1714
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1715
    "Created: 14.8.1997 / 11:37:03 / stefan"
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1716
!
70fe48053cf1 Define #asString.
Stefan Vogel <sv@exept.de>
parents: 2680
diff changeset
  1717
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1718
asSymbol
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1719
    "return a unique symbol with the name taken from my characters."
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1720
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1721
%{  /* NOCONTEXT */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1722
    OBJ newSymbol;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1723
    OBJ cls;
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1724
    char *cp = __stringVal(self);
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1725
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1726
    /* care for instances of a subclass with instVars */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1727
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1728
    if (cls != String) {
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1729
        cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1730
    }
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1731
    newSymbol = __MKSYMBOL(cp, (OBJ *)0);
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1732
    if (newSymbol) {
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1733
        RETURN ( newSymbol);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1734
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1735
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1736
    ^ ObjectMemory allocationFailureSignal raise.
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1737
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1738
    "
7869
597a8faaf603 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7868
diff changeset
  1739
     'hello' asSymbol    
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1740
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1741
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1742
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1743
asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1744
    "if a symbol with the receivers characters is already known, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1745
     Otherwise, return nil. This can be used to query for an existing
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1746
     symbol and is the same as
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1747
        self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1748
     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
  1749
     performed once."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1750
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1751
%{  /* NOCONTEXT */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1752
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1753
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1754
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1755
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1756
    if (cls != String) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1757
        indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1758
    } else {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1759
        indx = 0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1760
    }
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1761
    RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx));
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1762
%}.
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  1763
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1764
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1765
     'hello' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1766
     'fooBarBaz' asSymbolIfInterned
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1767
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1768
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1769
2416
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1770
decodeAsLiteralArray
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1771
    "given a literalEncoding in the receiver,
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1772
     create & return the corresponding object.
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1773
     The inverse operation to #literalArrayEncoding."
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1774
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1775
    ^ self
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1776
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1777
    "Created: 25.2.1997 / 19:18:19 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1778
!
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2369
diff changeset
  1779
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1780
literalArrayEncoding
1246
132a3f6c83bf commentary
Claus Gittinger <cg@exept.de>
parents: 1240
diff changeset
  1781
    "encode myself as an array literal, from which a copy of the receiver
132a3f6c83bf commentary
Claus Gittinger <cg@exept.de>
parents: 1240
diff changeset
  1782
     can be reconstructed with #decodeAsLiteralArray."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1783
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1784
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1785
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1786
    "Modified: 1.9.1995 / 02:25:45 / claus"
1246
132a3f6c83bf commentary
Claus Gittinger <cg@exept.de>
parents: 1240
diff changeset
  1787
    "Modified: 22.4.1996 / 13:00:50 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1788
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1789
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1790
withTabsExpanded:numSpaces
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  1791
    "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
  1792
     are expanded into spaces (assuming numSpaces-col tabs).
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  1793
     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
  1794
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  1795
     This does handle multiline strings.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
  1796
     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
  1797
     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
  1798
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  1799
%{  /* STACK:700 */
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1800
    unsigned char buffer[80*8 + 10];
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  1801
    unsigned char *srcP, *dstP, *cp0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1802
    int idx, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1803
    int any = 0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1804
    OBJ newString;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1805
    char c;
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1806
    int n;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1807
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1808
    if ((__qClass(self) == String)
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1809
     && __isSmallInteger(numSpaces)) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1810
        n = __intVal(numSpaces);
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1811
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1812
        /*
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1813
         * for small strings (< 80), do it without a prescan ...
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1814
         * the buffer is large enough to even convert a
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1815
         * receiver consisting fully of tabs.
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1816
         */
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1817
        if (__stringSize(self) < 80) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1818
            idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1819
            for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1820
                if (c == '\t') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1821
                    any = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1822
                    while (idx % n) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1823
                        idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1824
                        *dstP++ = ' ';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1825
                    }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1826
                    idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1827
                    *dstP++ = ' ';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1828
                } else {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1829
                    *dstP++ = c;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1830
                    idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1831
                    if (c == '\n') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1832
                        idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1833
                    }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1834
                }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1835
            }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1836
            if (! any) RETURN(self);
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1837
            *dstP = '\0';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1838
            RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1839
        }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1840
        /*
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1841
         * for large strings, we compute the new size, allocate a new string
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1842
         * and expand it.
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1843
         *
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1844
         * first, scan for size ...
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1845
         */
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1846
        idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1847
        for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1848
            if (c == '\t') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1849
                any = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1850
                while (idx % n) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1851
                    idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1852
                    sz++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1853
                }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1854
                idx++; sz ++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1855
            } else {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1856
                sz++; idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1857
                if (c == '\n') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1858
                    idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1859
                }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1860
            }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1861
        }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1862
        if (! any) RETURN(self);
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1863
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1864
        /*
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1865
         * get the string
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1866
         */
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1867
        sz = OHDR_SIZE + sz + 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1868
        __qNew(newString, sz);  /* OBJECT ALLOCATION */
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1869
        if (newString != nil) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1870
            __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  1871
            __qSTORE(newString, String);
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1872
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1873
            /*
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1874
             * expand
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1875
             */
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1876
            idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1877
            for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1878
                if (c == '\t') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1879
                    while (idx % n) {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1880
                        idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1881
                        *dstP++ = ' ';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1882
                    }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1883
                    idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1884
                    *dstP++ = ' ';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1885
                } else {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1886
                    *dstP++ = c; idx++;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1887
                    if (c == '\n') {
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1888
                        idx = 1;
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1889
                    }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1890
                }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1891
            }
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1892
            *dstP++ = '\0';
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1893
            RETURN (newString);
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1894
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1895
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1896
%}.
5742
7c02fc4de0ae added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  1897
    ^ super withTabsExpanded:numSpaces
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1898
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1899
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1900
!String methodsFor:'copying'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1901
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1902
, aString
2
claus
parents: 1
diff changeset
  1903
    "return the concatenation of myself and the argument, aString as
claus
parents: 1
diff changeset
  1904
     a String.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1905
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1906
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1907
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1908
    int l1, l2, sz;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1909
    REGISTER OBJ s = aString;
329
claus
parents: 314
diff changeset
  1910
    REGISTER OBJ _string = String;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1911
    OBJ myClass, argClass, newString;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1912
329
claus
parents: 314
diff changeset
  1913
    if (__isNonNilObject(s)) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1914
        myClass = __qClass(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1915
        argClass = __qClass(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1916
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1917
         * can do it here if both are Strings/Symbols:
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1918
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1919
        if (((myClass == _string) || (myClass == Symbol))
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1920
         && ((argClass == _string) || (argClass == Symbol))) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1921
            l1 = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1922
            l2 = __stringSize(s);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1923
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1924
            sz = OHDR_SIZE + l1 + l2 + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1925
            __qNew(newString, sz);      /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1926
            if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1927
                char *cp1, *cp2;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1928
                REGISTER unsigned char *dstp;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1929
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1930
                __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  1931
                __qSTORE(newString, String);
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1932
                dstp = __stringVal(newString);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1933
                cp1 = (char *) __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1934
                cp2 = (char *) __stringVal(aString);
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1935
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1936
#ifdef bcopy4
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1937
                /* knowing that allocation is 4-byte aligned and
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1938
                 * size rounded up to next 4-byte, the first copy
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1939
                 * can be done word-wise.
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1940
                 * that speeds up size-10-string , size-10-string 
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1941
                 * by 10% on a P5/200.
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1942
                 */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1943
                {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1944
                    int nw = l1 >> 2;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1945
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1946
                    if (l1 & 3) nw++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1947
                    bcopy4(cp1, dstp, nw);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1948
                    dstp += l1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1949
                }
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1950
#else
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1951
# ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1952
                memcpy(dstp, cp1, l1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1953
                dstp += l1;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1954
# else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1955
                while (l1 >= 4) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1956
                    *(int *)dstp = *(int *)cp1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1957
                    dstp += 4; cp1 += 4;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1958
                    l1 -= 4;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1959
                }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1960
                while (l1--) *dstp++ = *cp1++;
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1961
# endif
3651
265d1c30eff5 tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1962
#endif
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  1963
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1964
#ifdef bcopy4
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1965
                if (((INT)dstp & 3) == 0) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1966
                    int nw = l2 >> 2;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1967
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1968
                    if (l2 & 3) nw++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1969
                    bcopy4(cp2, dstp, nw);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1970
                    *(dstp + l2) = '\0';
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1971
                    RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1972
                }
3673
bf7c72c9037b tuned string concatenation
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1973
#endif
4205
56d69caa8f92 threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents: 4154
diff changeset
  1974
                    
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1975
#ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1976
                memcpy(dstp, cp2, l2+1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1977
                dstp[l2] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1978
#else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1979
                while (l2--) *dstp++ = *cp2++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1980
                *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1981
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1982
                RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1983
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1984
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1985
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  1986
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1987
    ^ super , aString
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1988
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  1989
    "
7867
1de4b6e5ef92 comment only
Claus Gittinger <cg@exept.de>
parents: 7856
diff changeset
  1990
     'hello' , 'world'
1de4b6e5ef92 comment only
Claus Gittinger <cg@exept.de>
parents: 7856
diff changeset
  1991
     #[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
  1992
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1993
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1994
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1995
concatenate:string1 and:string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1996
    "return the concatenation of myself and the arguments, string1 and string2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1997
     This is equivalent to self , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1998
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1999
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2000
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2001
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2002
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2003
    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
  2004
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2005
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2006
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2007
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2008
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2009
    if ((__isString(self) || __isSymbol(self))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2010
     && (__isString(string1) || __isSymbol(string1))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2011
     && (__isString(string2) || __isSymbol(string2))) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2012
        len1 = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2013
        len2 = __stringSize(string1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2014
        len3 = __stringSize(string2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2015
        sz = OHDR_SIZE + len1 + len2 + len3 + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2016
        __qNew(newString, sz);  /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2017
        if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2018
            __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  2019
            __qSTORE(newString, String);
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2020
            dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2021
#ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2022
            memcpy(dstp, __stringVal(self), len1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2023
            memcpy(dstp + len1, __stringVal(string1), len2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2024
            memcpy(dstp + len1 + len2, __stringVal(string2), len3+1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2025
            *(dstp + len1 + len2 + len3) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2026
#else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2027
            srcp = __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2028
            while (len1--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2029
            srcp = __stringVal(string1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2030
            while (len2--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2031
            srcp = __stringVal(string2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2032
            while (len3--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2033
            *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2034
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2035
            RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2036
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2037
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2038
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2039
    ^ super , string1 , string2
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2040
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2041
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2042
concatenate:string1 and:string2 and:string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2043
    "return the concatenation of myself and the string arguments.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2044
     This is equivalent to self , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2045
     - generated by compiler when such a construct is detected"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2046
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2047
    |newString|
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2048
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2049
%{
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2050
    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
  2051
#if !defined(FAST_MEMCPY)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2052
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2053
#endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2054
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2055
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2056
    if ((__isString(self) || __isSymbol(self))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2057
     && (__isString(string1) || __isSymbol(string1))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2058
     && (__isString(string2) || __isSymbol(string2))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2059
     && (__isString(string3) || __isSymbol(string3))) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2060
        len1 = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2061
        len2 = __stringSize(string1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2062
        len3 = __stringSize(string2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2063
        len4 = __stringSize(string3);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2064
        sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2065
        __qNew(newString, sz);  /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2066
        if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2067
            __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  2068
            __qSTORE(newString, String);
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2069
            dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2070
#ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2071
            memcpy(dstp, __stringVal(self), len1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2072
            memcpy(dstp + len1, __stringVal(string1), len2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2073
            memcpy(dstp + len1 + len2, __stringVal(string2), len3);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2074
            memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2075
            *(dstp + len1 + len2 + len3 + len4) = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2076
#else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2077
            srcp = __stringVal(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2078
            while (len1--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2079
            srcp = __stringVal(string1);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2080
            while (len2--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2081
            srcp = __stringVal(string2);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2082
            while (len3--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2083
            srcp = __stringVal(string3);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2084
            while (len4--) *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2085
            *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2086
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2087
            RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2088
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2089
    }
519
0ab6612e060b expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  2090
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2091
    ^ super , string1 , string2 , string3
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2092
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2093
4745
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2094
copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2095
    "return a copy of the receiver"
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2096
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2097
    (self isMemberOf:String) ifTrue:[
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2098
        ^ self copyFrom:1
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2099
    ].
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2100
    ^ super copy
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2101
!
4d2460ed35a7 added #copy
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2102
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2103
copyFrom:start
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2104
    "return the substring from start, anInteger to the end.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2105
     This method will always return a string, even if the receiver 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2106
     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
  2107
     - reimplemented here for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2108
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2109
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2110
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2111
#if !defined(FAST_MEMCPY)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2112
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2113
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2114
    REGISTER unsigned char *dstp;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2115
    REGISTER int count;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2116
    int len, index1, sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2118
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2119
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2120
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2121
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2122
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2123
    if (__isSmallInteger(start)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2124
     && ((myClass==String) || (myClass==Symbol))) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2125
        len = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2126
        index1 = __intVal(start);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2127
        if (index1 > 0) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2128
            if (index1 <= len) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2129
                count = len - index1 + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2130
                sz = OHDR_SIZE + count + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2131
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2132
                __PROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2133
                __qNew(newString, sz);  /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2134
                __UNPROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2135
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2136
                if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2137
                    __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  2138
                    __qSTORE(newString, String);
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2139
                    dstp = __stringVal(newString);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2140
#ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2141
                    memcpy(dstp, __stringVal(self) + index1 - 1, count);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2142
                    dstp[count] = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2143
#else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2144
                    srcp = __stringVal(self) + index1 - 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2145
                    while (count--) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2146
                        *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2147
                    }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2148
                    *dstp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2149
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2150
                    RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2151
                }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2152
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2153
        }
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2154
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2155
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2156
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2157
    "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
  2158
     will eventually lead to an out-of-bound signal raise"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2159
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2160
    ^ super copyFrom:start
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2161
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2162
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2163
copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2164
    "return the substring starting at index start, anInteger and ending
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2165
     at stop, anInteger. This method will always return a string, even
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2166
     if the receiver is a subclass-instance. This might change if there is a need.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2167
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2168
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2169
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2170
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2171
    REGISTER unsigned char *srcp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2172
    REGISTER unsigned char *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2173
    REGISTER int count;
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2174
    int len, sz, index1, index2;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2175
    OBJ newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2176
    OBJ myClass;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2177
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2178
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2179
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2180
#ifndef NO_PRIM_STRING
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2181
    if (__bothSmallInteger(start, stop)
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2182
     && ((myClass==String) || (myClass==Symbol))) {
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2183
        len = __stringSize(self);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2184
        index1 = __intVal(start);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2185
        index2 = __intVal(stop);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2186
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2187
        if ((index1 <= index2) && (index1 > 0)) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2188
            if (index2 <= len) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2189
                count = index2 - index1 + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2190
                sz = OHDR_SIZE + count + 1;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2191
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2192
                __PROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2193
                __qNew(newString, sz);  /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2194
                __UNPROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2195
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2196
                if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2197
                    __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  2198
                    __qSTORE(newString, String);
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2199
                    dstp = __stringVal(newString);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2200
                    srcp = __stringVal(self) + index1 - 1;
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2201
#ifdef bcopy4
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2202
                    {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2203
                        int nw = count >> 2;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2204
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2205
                        if (count & 3) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2206
                            nw++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2207
                        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2208
                        bcopy4(srcp, dstp, nw);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2209
                        dstp[count] = '\0';
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2210
                    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2211
#else
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2212
# ifdef FAST_MEMCPY
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2213
                    memcpy(dstp, srcp, count);
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2214
                    dstp[count] = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2215
# else
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2216
                    while (count--) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2217
                        *dstp++ = *srcp++;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2218
                    }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2219
                    *dstp = '\0';
209
ecc004f196e6 fixed concatenate bug (crash)
claus
parents: 202
diff changeset
  2220
# endif
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2221
#endif
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2222
                    RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2223
                }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2224
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2225
        }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2226
        /*
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2227
         * allow empty copy
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2228
         */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2229
        if (index1 > index2) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2230
            __PROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2231
            __qNew(newString, OHDR_SIZE+1);     /* OBJECT ALLOCATION */
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2232
            __UNPROTECT_CONTEXT__
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2233
            if (newString != nil) {
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2234
                __InstPtr(newString)->o_class = String;
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2235
                (__stringVal(newString))[0] = '\0';
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2236
                RETURN ( newString );
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2237
            }
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2238
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2239
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2240
#endif
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2241
%}.
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2242
    "fall back in case of non-integer index or out-of-bound index;
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2243
     will eventually lead to an out-of-bound signal raise"
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2244
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2245
    ^ super copyFrom:start to:stop
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2246
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2247
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2248
copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2249
    "return a new string containing the receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2250
     and the single new character, aCharacter. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2251
     This is different from concatentation, which expects another string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2252
     as argument, but equivalent to copy-and-addLast.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2253
     Reimplemented here for more speed"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2254
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2255
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2256
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2257
    int count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2258
    int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2259
    REGISTER unsigned char *dstp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2260
    OBJ cls, newString;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2261
    OBJ myClass;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2262
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2263
    myClass = __qClass(self);
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2264
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2265
#ifndef NO_PRIM_STRING
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2266
    if (__isCharacter(aCharacter)) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2267
        unsigned int cVal = __intVal(__characterVal(aCharacter));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2268
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2269
        if ((cVal <= 0xFF)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2270
         && ((myClass==String) || (myClass==Symbol))) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2271
            count = __stringSize(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2272
            sz = OHDR_SIZE + count + 1 + 1;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2273
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2274
            __PROTECT_CONTEXT__
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2275
            __qNew(newString, sz);  /* OBJECT ALLOCATION */
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2276
            __UNPROTECT_CONTEXT__
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2277
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2278
            if (newString) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2279
                __InstPtr(newString)->o_class = String;
7856
a5758a9e6248 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7774
diff changeset
  2280
                __qSTORE(newString, String);
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2281
                dstp = __stringVal(newString);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2282
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2283
#ifdef bcopy4
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2284
                {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2285
                    int nw = count >> 2;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2286
                    char *srcp = (char *)__stringVal(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2287
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2288
                    if (count & 3) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2289
                        nw++;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2290
                    }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2291
                    bcopy4(srcp, dstp, nw);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2292
                    dstp += count;
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2293
                }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2294
#else
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2295
# ifdef FAST_MEMCPY
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2296
                memcpy(dstp, __stringVal(self), count);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2297
                dstp += count;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2298
# else
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2299
                {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2300
                    REGISTER unsigned char *srcp;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2301
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2302
                    srcp = __stringVal(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2303
                    while ((*dstp = *srcp++) != '\0')
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2304
                        dstp++;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2305
                }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2306
# endif
2887
4523d179636e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
  2307
# endif
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2308
                *dstp++ = cVal;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2309
                *dstp = '\0';
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2310
                RETURN (newString );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2311
            }
6331
3cb5595cf170 Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents: 6007
diff changeset
  2312
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2313
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2314
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2315
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2316
    "fall back in case of non-character arg;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2317
     will eventually lead to an bad element signal raise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2318
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2319
    ^ super copyWith:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2320
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2321
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2322
deepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2323
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2324
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2325
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2326
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2327
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2328
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2329
    (self isMemberOf:String) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2330
	^ self copyFrom:1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2331
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2332
    ^ super deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2333
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2334
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2335
deepCopyUsing:aDictionary
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8312
diff changeset
  2336
    "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
  2337
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2338
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2339
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2340
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2341
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2342
    (self isMemberOf:String) ifTrue:[
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  2343
        ^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2344
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  2345
    ^ super deepCopyUsing:aDictionary
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2346
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2347
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2348
shallowCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2349
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2350
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2351
    (self isMemberOf:String) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2352
	^ self copyFrom:1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2353
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2354
    ^ super shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2355
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2356
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2357
simpleDeepCopy
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2358
    "return a copy of the receiver"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2359
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2360
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2361
     could be an instance of a subclass which needs deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2362
     of its named instvars ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2363
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2364
    (self isMemberOf:String) ifTrue:[
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  2365
        ^ self copyFrom:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2366
    ].
7881
26b22247f5f1 deepCopyUsing fixed.
martin
parents: 7878
diff changeset
  2367
    ^ super simpleDeepCopy
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2368
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2369
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4123
diff changeset
  2370
!String methodsFor:'filling & replacing'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2371
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2372
atAllPut:aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2373
    "replace all elements with aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2374
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2375
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2376
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2377
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2378
#ifndef FAST_MEMSET
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2379
    REGISTER unsigned char *dst;
6766
a43b97582d4b oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents: 6599
diff changeset
  2380
#endif
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2381
    REGISTER int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2382
    REGISTER int byteValue;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2383
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2384
    if (__isCharacter(aCharacter) && __isString(self)) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2385
        byteValue = __intVal(_characterVal(aCharacter));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2386
        if ((unsigned)byteValue <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2387
            l = __stringSize(self);
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2388
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2389
#ifdef FAST_MEMSET 
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2390
            if (l > 0) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2391
                memset(__stringVal(self), byteValue, l);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2392
            }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2393
#else
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2394
            {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2395
                INT v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2396
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2397
                v = (byteValue << 8) | byteValue;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2398
                v = (v << 16) | v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2399
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2400
                dst = __stringVal(self);
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2401
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2402
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2403
                if (l > 0) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2404
                    memset4(dst, v, l>>2);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2405
                    l = l & 3;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2406
                }
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2407
# else
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2408
#  ifdef UINT64
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2409
                {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2410
                    UINT64 v64;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2411
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2412
                    v64 = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2413
                    v64 = (v64 << 32) | v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2414
                    while (l >= 8) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2415
                        ((UINT64 *)dst)[0] = v64;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2416
                        dst += 8;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2417
                        l -= 8;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2418
                    }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2419
                }
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2420
#  else /* no UINT64 */
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2421
                while (l >= 16) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2422
                    ((int *)dst)[0] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2423
                    ((int *)dst)[1] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2424
                    ((int *)dst)[2] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2425
                    ((int *)dst)[3] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2426
                    dst += 16;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2427
                    l -= 16;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2428
                }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2429
                if (l >= 8) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2430
                    ((int *)dst)[0] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2431
                    ((int *)dst)[1] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2432
                    dst += 8;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2433
                    l -= 8;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2434
                }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2435
                if (l >= 4) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2436
                    ((int *)dst)[0] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2437
                    dst += 4;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2438
                    l -= 4;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2439
                }
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2440
#   if 0
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2441
                if (l >= 2) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2442
                    ((short *)dst)[0] = v;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2443
                    dst += 2;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2444
                    l -= 2;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2445
                }
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2446
#   endif
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2447
5648
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  2448
#  endif /* UINT64 */
5bc58204662e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  2449
# endif /* FAST_MEMSET4 */
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2450
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2451
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2452
            /*
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2453
             * remaining bytes
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2454
             */
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2455
            while (l-- > 0)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2456
                *dst++ = byteValue;
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2457
3711
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2458
#endif /* no FAST_MEMSET */
bdb2e9d06d33 20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents: 3710
diff changeset
  2459
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2460
            RETURN ( self );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2461
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2462
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2463
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2464
    ^ super atAllPut:aCharacter
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2465
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2466
    "
3712
f93cb659b10d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
  2467
     (String new:10) atAllPut:$*      
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2468
     String new:10 withAll:$*     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2469
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2470
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2471
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2472
replaceAll:oldCharacter with:newCharacter
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2473
    "replace all oldCharacters by newCharacter in the receiver.
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2474
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2475
     Notice: This operation modifies the receiver, NOT a copy;
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2476
     therefore the change may affect all others referencing the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2477
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2478
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2479
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2480
    REGISTER unsigned char *srcp;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2481
    REGISTER unsigned oldVal, newVal;
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2482
    unsigned char c, cNext;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2483
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2484
    if (__isCharacter(oldCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2485
     && __isCharacter(newCharacter)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2486
     && __isString(self)) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2487
        srcp = (unsigned char *)__stringVal(self);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2488
        oldVal = __intVal(_characterVal(oldCharacter));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2489
        newVal = __intVal(_characterVal(newCharacter));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2490
        if ((oldVal <= 0xFF) 
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2491
         && (newVal <= 0xFF)) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2492
            cNext = *srcp;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2493
            while ((c = cNext) != '\0') {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2494
                cNext = srcp[1];
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2495
                if (c == oldVal)
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2496
                    *srcp = newVal;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2497
                srcp++;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2498
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2499
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  2500
        RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2501
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2502
%}.
2929
ca74fdc386cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2503
    ^ super replaceAll:oldCharacter with:newCharacter
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2504
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2505
    "
4120
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2506
     'helloWorld' copy replaceAll:$o with:$O   
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2507
     'helloWorld' copy replaceAll:$d with:$*   
5ad76c8d8e77 comment
Claus Gittinger <cg@exept.de>
parents: 3989
diff changeset
  2508
     'helloWorld' copy replaceAll:$h with:$*   
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2509
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2510
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2511
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2512
replaceFrom:start to:stop with:aString startingAt:repStart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2513
    "replace the characters starting at index start, anInteger and ending
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2514
     at stop, anInteger with characters from aString starting at repStart.
3234
4cc58bc6a8ed comment
Claus Gittinger <cg@exept.de>
parents: 3227
diff changeset
  2515
     Return the receiver.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2516
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2517
     - reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2518
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2519
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2520
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2521
    REGISTER unsigned char *srcp, *dstp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2522
    REGISTER int count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2523
    int len, index1, index2;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2524
    int repLen, repIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2525
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2526
#ifndef NO_PRIM_STRING
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2527
    if ((__isString(aString) || __isSymbol(aString))
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2528
     && __isString(self)
252
  2529
     && __bothSmallInteger(start, stop)) {
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2530
	len = __stringSize(self);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2531
	index1 = __intVal(start);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2532
	index2 = __intVal(stop);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2533
	count = index2 - index1 + 1;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2534
	if (count <= 0) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2535
	     RETURN (self);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2536
	}
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2537
	if ((index2 <= len) && (index1 > 0)) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2538
	    repLen = __stringSize(aString);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2539
	    repIndex = __intVal(repStart);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2540
	    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2541
		srcp = __stringVal(aString) + repIndex - 1;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2542
		dstp = __stringVal(self) + index1 - 1;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2543
		if (aString == self) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2544
		    /* take care of overlapping copy */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2545
		    if (srcp < dstp) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2546
			/* must do a reverse copy */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2547
			srcp += count;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2548
			dstp += count;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2549
			while (count-- > 0) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2550
			    *--dstp = *--srcp;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2551
			}
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2552
			RETURN (self);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2553
		    }
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2554
		}
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2555
#ifdef bcopy4
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2556
		/* copy quadbytes if pointers are aligned */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2557
		/* 
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2558
		 * no sizeof(int) here please -
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2559
		 * - bcopy4 (if defined) copies 4-bytes on ALL machines 
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2560
		 */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2561
		if ((count > 12)
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2562
		 && (((unsigned INT)srcp & 3) == 0)
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2563
		 && (((unsigned INT)dstp & 3) == 0)) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2564
		    int n;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2565
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2566
		    n = count >> 2;        /* make it quads */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2567
		    bcopy4(srcp, dstp, n);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2568
		    n <<= 2;               /* back to chars */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2569
		    dstp += n;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2570
		    srcp += n;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2571
		    count -= n;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2572
		}
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2573
		while (count-- > 0) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2574
		    *dstp++ = *srcp++;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2575
		}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2576
#else
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2577
# ifdef FAST_MEMCPY
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2578
		bcopy(srcp, dstp, count);
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2579
# else
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2580
		/* copy longs if pointers are aligned */
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2581
		if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0)
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2582
		 && (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2583
		    while (count >= sizeof(INT)) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2584
			*((unsigned INT *)dstp) = *((unsigned INT *)srcp);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2585
			dstp += sizeof(INT);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2586
			srcp += sizeof(INT);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2587
			count -= sizeof(INT);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2588
		    }
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2589
		}
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2590
		while (count-- > 0) {
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2591
		    *dstp++ = *srcp++;
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2592
		}
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2593
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2594
#endif
3451
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2595
		RETURN (self);
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2596
	    }
be63b5abd89a indexNotInteger error
Claus Gittinger <cg@exept.de>
parents: 3449
diff changeset
  2597
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2598
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2887
diff changeset
  2599
#endif
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2600
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2601
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
2867
015574e235fd tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2862
diff changeset
  2602
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2603
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2604
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2605
reverse                                                                         
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2606
    "in-place reverse the characters of the string.
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2607
     WARNING: this is a destructive operation, which modifies the receiver."
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2608
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2609
    "Q: is there a need to redefine it here ?"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2610
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2611
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2612
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2613
    REGISTER char c;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2614
    REGISTER unsigned char *hip, *lowp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2615
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2616
    if (__isString(self)) {
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2617
        lowp = __stringVal(self);
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2618
        hip = lowp + __stringSize(self) - 1;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2619
        while (lowp < hip) {
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2620
            c = *lowp;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2621
            *lowp = *hip;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2622
            *hip = c;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2623
            lowp++;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2624
            hip--;
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2625
        }
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7302
diff changeset
  2626
        RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2627
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2628
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2629
    ^ super reverse
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2630
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2631
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2632
withoutSeparators
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2633
    "return a string containing the chars of myself 
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2634
     without leading and trailing whitespace.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2635
     If there is no whitespace, the receiver is returned.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  2636
     Notice, this is different from String>>withoutSpaces."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2637
42
e33491f6f260 *** empty log message ***
claus
parents: 41
diff changeset
  2638
    |startIndex "{ Class: SmallInteger }"
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2639
     endIndex   "{ Class: SmallInteger }" 
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2640
     sz|
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2641
53
77ed1ef5c018 *** empty log message ***
claus
parents: 51
diff changeset
  2642
    startIndex := 0.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2643
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2644
%{
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2645
    REGISTER unsigned char *cp;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2646
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2647
    REGISTER unsigned char c;
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2648
    REGISTER unsigned char *cp0;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2649
    REGISTER unsigned char *ep0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2650
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2651
    /* ignore instances of subclasses ... */
329
claus
parents: 314
diff changeset
  2652
    if (__qClass(self) == String) {
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2653
	cp = cp0 = __stringVal(self);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2654
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2655
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2656
	 * find first non-whiteSpace from beginning
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2657
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2658
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  2659
# ifdef UINT64
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2660
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2661
	    cp += 8;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2662
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2663
# endif
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2664
	while (*((unsigned *)cp) == 0x20202020) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2665
	    cp += 4;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2666
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2667
#endif
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2668
	while ((c = *cp)
329
claus
parents: 314
diff changeset
  2669
#ifndef NON_ASCII       /* i.e. EBCDIC ;-) */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2670
	 && (c <= ' ')
329
claus
parents: 314
diff changeset
  2671
#endif
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2672
	 && ((c == ' ') || (c == '\n') || (c == '\t')
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2673
			|| (c == '\r') || (c == '\f'))
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2674
	) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2675
	    cp++;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2676
	}
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2677
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2678
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2679
	 * find first non-whiteSpace from end
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2680
	 */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2681
	ep = ep0 = cp0 + __stringSize(self) - 1;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2682
	while ((ep >= cp) && (*ep == ' ')) ep--;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2683
	c = *ep;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2684
	while ((ep >= cp) &&
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2685
#ifndef NON_ASCII
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2686
	       (c <= ' ') &&
329
claus
parents: 314
diff changeset
  2687
#endif
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2688
	       ((c == ' ') || (c == '\n') || (c == '\t')
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2689
			   || (c == '\r') || (c == '\f'))) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2690
	    ep--;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2691
	    c = *ep;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2692
	}
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2693
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2694
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2695
	 * no whiteSpace ?
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2696
	 */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2697
	if ((cp == cp0) && (ep == ep0)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2698
	    RETURN(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2699
	}
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2700
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2701
	startIndex = __MKSMALLINT(cp - cp0 + 1);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2702
	endIndex = __MKSMALLINT(ep - cp0 + 1);
51
9b7ae5e18f3e *** empty log message ***
claus
parents: 42
diff changeset
  2703
    }
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2704
%}.
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2705
    startIndex == 0 ifTrue:[^ super withoutSeparators].
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2706
40ca7cc6fb9c *** empty log message ***
claus
parents: 186
diff changeset
  2707
    startIndex > endIndex ifTrue:[^ ''].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2708
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2709
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2710
    "
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2711
     'hello' withoutSeparators    
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2712
     '    hello' withoutSeparators    
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2713
     '    hello ' withoutSeparators   
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2714
     '    hello  ' withoutSeparators  
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2715
     '    hello   ' withoutSeparators 
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2716
     '    hello    ' withoutSeparators
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2717
     '        ' withoutSeparators       
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2718
    "
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2719
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2720
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2721
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2722
withoutSpaces
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2723
    "return a string containing the characters of myself 
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2724
     without leading and trailing spaces.
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2725
     If there are no spaces, the receiver is returned unchanged.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2726
     Notice, this is different from String>>withoutSeparators."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2727
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2728
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2729
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2730
     sz blank|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2731
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2732
    startIndex := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2733
%{
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2734
    REGISTER unsigned char *cp;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2735
    REGISTER unsigned char *ep;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2736
    unsigned char *cp0;
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2737
    unsigned char *ep0;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2738
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2739
    /* ignore instances of subclasses ... */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2740
    if (__qClass(self) == String) {
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2741
	cp = cp0 = __stringVal(self);
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2742
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2743
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2744
	 * find first non-blank from beginning
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2745
	 */
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2746
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  2747
# ifdef UINT64
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2748
	while (*((UINT64 *)cp) == 0x2020202020202020L) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2749
	    cp += 8;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2750
	}
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  2751
# endif /* UINT64 */
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2752
	while (*((unsigned *)cp) == 0x20202020) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2753
	    cp += 4;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2754
	}
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2755
#endif
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2756
	while (*cp == ' ') cp++;
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2757
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2758
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2759
	 * find first non-blank from end
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2760
	 */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2761
	ep = ep0 = cp0 + __stringSize(self) - 1;
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2762
	while ((ep >= cp) && (*ep == ' ')) ep--;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  2763
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2764
	/*
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2765
	 * no blanks ?
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2766
	 */
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2767
	if ((cp == cp0) && (ep == ep0)) {
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2768
	    RETURN(self);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2769
	}
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2770
        
3111
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2771
	startIndex = __MKSMALLINT(cp - cp0 + 1);
a23fa6d08ce7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
  2772
	endIndex = __MKSMALLINT(ep - cp0 + 1);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2773
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2774
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2775
    startIndex == 0 ifTrue:[^ super withoutSpaces].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2776
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2777
    startIndex > endIndex ifTrue:[^ ''].
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2778
    ((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2779
    ^ self copyFrom:startIndex to:endIndex
2884
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2780
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2781
    "
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2782
     '    hello' withoutSpaces    
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2783
     '    hello ' withoutSpaces   
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2784
     '    hello  ' withoutSpaces  
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2785
     '    hello   ' withoutSpaces 
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2786
     '    hello    ' withoutSpaces
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2787
     '        ' withoutSpaces       
1e0bdf34b3b2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2867
diff changeset
  2788
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2789
! !
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
!String methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2792
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2793
isLiteral
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  2794
    "return true, if the receiver can be used as a literal constant in ST syntax
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2795
     (i.e. can be used in constant arrays)"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2796
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2797
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2798
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2799
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2800
print
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2801
    "print the receiver on standard output.
4631
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2802
     This method does NOT (by purpose) use the stream classes and 
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2803
     will therefore work even in case of emergency (but only, if Stdout is nil)."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2804
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2805
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2806
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2807
    if (__qClass(self) == String) {
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2808
        if (@global(Stdout) == nil) {
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  2809
#ifdef WIN32
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2810
            fprintf(stdout, "%s" , __stringVal(self));
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  2811
#else
4631
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2812
/*cg: used to have fputs here, but that seems to be NOT prepared
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2813
 * for eintr arriving and thus sometimes sends the string twice ...
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2814
 *
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2815
 *        fputs(__stringVal(self), stdout);
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2816
 */
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2817
            fwrite(__stringVal(self), 1, __stringSize(self), stdout);
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2818
            fflush(stdout);
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  2819
#endif
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2820
            RETURN (self);
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2821
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2822
    }
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2823
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2824
    ^ super print
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2825
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2826
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2827
printCR
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2828
    "print the receiver on standard output, followed by a cr.
4631
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2829
     This method does NOT (by purpose) use the stream classes and 
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2830
     will therefore work even in case of emergency (but only, if Stdout is nil)."
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2831
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2832
%{  /* NOCONTEXT */
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2833
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2834
    if (__qClass(self) == String) {
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2835
        if (@global(Stdout) == nil) {
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2836
#ifdef WIN32
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2837
            fprintf(stdout, "%s\n" , __stringVal(self));
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2838
#else
4631
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2839
/*cg: used to have fputs here, but that seems to be NOT prepared
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2840
 * for eintr arriving and thus sometimes sends the string twice ...
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2841
 *
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2842
 * fputs(__stringVal(self), stdout); fputs("\n", stdout); 
f07d1701b537 use fwrite instead of puts.
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  2843
 */
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2844
            fwrite(__stringVal(self), 1, __stringSize(self), stdout);
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2845
            fwrite("\n", 1, 1, stdout);
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2846
            fflush(stdout);
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2847
#endif
5746
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2848
            RETURN (self);
cf5e42cb72ef do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents: 5742
diff changeset
  2849
        }
3751
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2850
    }
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2851
%}.
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2852
    ^ super printCR
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2853
!
e2913a6c124b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  2854
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2855
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2856
    "non-standard but sometimes useful.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2857
     Return a printed representation of the receiver as specified by formatString, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2858
     which is defined by printf.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2859
     This method is NONSTANDARD and may be removed without notice."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2860
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2861
%{  /* STACK: 1000 */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2862
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2863
    char buffer[800];
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2864
    char *buf = buffer;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2865
    int bufsize = sizeof(buffer);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2866
    char *mallocbuf = NULL;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2867
    char *cp;
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2868
    int len;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2869
    OBJ s;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2870
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2871
    if (__isString(formatString)) {
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2872
        cp = (char *)__stringVal(self);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2873
        if (__qClass(self) != String)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2874
            cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2875
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2876
again:
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2877
        /*
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2878
         * actually only needed on sparc: since thisContext is
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2879
         * in a global register, which gets destroyed by printf,
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2880
         * manually save it here - very stupid ...
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2881
         */
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2882
        __BEGIN_PROTECT_REGISTERS__
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2883
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2884
        len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2885
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2886
        __END_PROTECT_REGISTERS__
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2887
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2888
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2889
        if (len > bufsize) {
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2890
            bufsize = len + 1;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2891
            if (mallocbuf)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2892
                free(mallocbuf);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2893
            buf = mallocbuf = malloc(bufsize);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2894
            if (buf == NULL)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2895
                goto fail;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2896
            goto again;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2897
        } else if (len < 0) {
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2898
            bufsize *= 2;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2899
            if (mallocbuf)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2900
                free(mallocbuf);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2901
            buf = mallocbuf = malloc(bufsize);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2902
            if (buf == NULL)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2903
                goto fail;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2904
            goto again;
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2905
        }
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2906
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2907
        s = __MKSTRING_L(buf, len);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2908
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2909
        if (mallocbuf)
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2910
            free(mallocbuf);
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2911
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2912
        if (s != nil) {
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2913
            RETURN (s);
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2914
        }
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2915
    }
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2916
fail:;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2917
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2918
    self primitiveFailed
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2919
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2920
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2921
     'hello' printfPrintString:'%%s -> %s'     
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2922
     (String new:900) printfPrintString:'%%s -> %s'     
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2923
     'hello' printfPrintString:'%%10s -> %10s'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2924
     'hello' printfPrintString:'%%-10s -> %-10s' 
8415
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2925
     'hello' printfPrintString:'%%900s -> %900s' 
7e0f1105bc9f Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
  2926
     'hello' printfPrintString:'%%-900s -> %-900s' 
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2927
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2928
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2929
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2930
storeOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2931
    "put the storeString of myself on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2932
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  2933
    aStream nextPut:$'.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2934
    (self includes:$') ifTrue:[
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  2935
        self printWithQuotesDoubledOn:aStream
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2936
    ] ifFalse:[
7599
188489aaaacd #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7338
diff changeset
  2937
        aStream nextPutAll:self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2938
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2939
    aStream nextPut:$'
3579
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  2940
7d9a4ec2be4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3546
diff changeset
  2941
    "Modified: / 15.6.1998 / 17:21:51 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2942
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2943
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2944
storeString
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2945
    "return a String for storing myself"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2946
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 8038
diff changeset
  2947
    ^ self basicStoreString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2948
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2949
6588
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2950
!String methodsFor:'public'!
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2951
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2952
isBinarySelector 
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2953
        "Answer a <boolean>, true if the receiver contains only chars in an ANSI binary method selector, else false."
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2954
        #'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." 
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2955
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2956
        ^self allSatisfy: [:chr| '!!%&''*+,`/<=>?@\~|-' includes: chr]
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2957
!
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2958
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2959
isUnarySelector 
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2960
        "Answer a <boolean>, true if the receiver contains only chars in an ANSI unary method selector, else false."
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2961
        #'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." 
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2962
6830
97b046007438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6828
diff changeset
  2963
        ^self allSatisfy: [ :chr | chr isLetter or:[ chr isDigit] ]
6588
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2964
! !
d2f1088e3af5 *** empty log message ***
penk
parents: 6522
diff changeset
  2965
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2966
!String methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2967
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2968
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2969
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2970
     Redefined here to exclude the 0-byte at the end."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2971
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2972
%{  /* NOCONTEXT */
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2973
    REGISTER OBJ slf, cls;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2974
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2975
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2976
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2977
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2978
    if (cls == String) {
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2979
        RETURN ( __MKSMALLINT(__stringSize(slf)) );
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2980
    }
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2981
    RETURN ( __MKSMALLINT(__stringSize(slf)
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2982
                          - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2983
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2984
    ^ super basicSize - 1
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2985
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2986
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  2987
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  2988
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  2989
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  2990
     Here, 8 is returned (storing single byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  2991
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  2992
    ^ 8
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  2993
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
  2994
    "Modified: 20.4.1996 / 23:08:42 / cg"
1218
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  2995
!
5ed62714c8d1 commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  2996
8458
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  2997
contains8BitCharacters
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  2998
    "return true, if the underlying string contains 8BitCharacters (or widers) 
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  2999
     (i.e. if it is non-ascii)"
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3000
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3001
%{  /* NOCONTEXT */
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3002
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3003
    REGISTER unsigned char *cp;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3004
    REGISTER unsigned char *last;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3005
    OBJ cls;
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3006
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3007
    cp = __stringVal(self);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3008
    if ((cls = __qClass(self)) != String) {
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3009
        cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3010
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3011
    for (last=cp+__stringSize(self); cp < last; cp++) {
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3012
        if (*cp & 0x80) {
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3013
            RETURN ( true );
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3014
        }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3015
    }
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3016
    RETURN (false);
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3017
%}.
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3018
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3019
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3020
     'hello world' contains8BitCharacters                                       
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3021
     'hello world' asTwoByteString contains8BitCharacters                       
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3022
     ('hello world' , (Character value:16r88) asString) contains8BitCharacters  
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3023
    "
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3024
!
b10d8cb3ab00 *** empty log message ***
penk
parents: 8457
diff changeset
  3025
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3026
knownAsSymbol
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3027
    "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
  3028
     system.
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3029
     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
  3030
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3031
%{  /* NOCONTEXT */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3032
    OBJ cls;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3033
    int indx;
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3034
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3035
    cls = __qClass(self);
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3036
    if (cls != String) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3037
        indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3038
    } else {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3039
        indx = 0;
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3040
    }
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3041
    RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) );
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3042
%}.
6007
f55ba7370814 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5762
diff changeset
  3043
"/    ^ self asSymbolIfInterned notNil.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3044
    self primitiveFailed
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3045
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3046
    "
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3047
     'hello' knownAsSymbol     
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3048
     'fooBarBaz' knownAsSymbol     
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3049
    "
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3050
!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3051
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3052
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3053
    "return the number of characters in myself.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3054
     Reimplemented here to avoid the additional size->basicSize send
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3055
     (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
  3056
     This method is the same as basicSize."
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3057
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3058
%{  /* NOCONTEXT */
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3059
    REGISTER OBJ cls, slf;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3060
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3061
    slf = self;
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3062
    cls = __qClass(slf);
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3063
    if (cls == String) {
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3064
        RETURN ( __MKSMALLINT(__stringSize(slf)) );
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3065
    }
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3066
    RETURN ( __MKSMALLINT(__stringSize(slf)
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3067
                         - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3068
%}.
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
  3069
    ^ self basicSize
8038
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3070
!
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3071
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3072
stringSpecies
d2884b02987c stringSpecies query
Claus Gittinger <cg@exept.de>
parents: 8006
diff changeset
  3073
    ^ String
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3074
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3075
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3076
!String methodsFor:'testing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3077
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3078
endsWith:aStringOrChar
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3079
    "return true, if the receiver ends with something, aStringOrChar."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3080
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3081
%{  /* NOCONTEXT */
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3082
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3083
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3084
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  3085
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3086
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3087
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3088
    if ((__isString(slf) || __isSymbol(slf))
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3089
     && (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3090
        len1 = __qSize(slf);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3091
        len2 = __qSize(aStringOrChar);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3092
        if (len1 < len2) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3093
            RETURN ( false );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3094
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3095
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3096
        src1 = __stringVal(slf) + (len1 - len2);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3097
        src2 = __stringVal(aStringOrChar);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3098
        while (c = *src2++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3099
            if (c != *src1++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3100
                RETURN ( false );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3101
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3102
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3103
        RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3104
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3105
    if (__isCharacter(aStringOrChar)) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3106
        int val;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3107
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3108
        val = __intVal(_characterVal(aStringOrChar));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3109
        if ((unsigned)val <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3110
            len1 = __stringSize(slf);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3111
            if (len1 > 0) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3112
                RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3113
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3114
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3115
        RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3116
    }
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3117
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3118
    ^ super endsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3119
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3120
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3121
     'hello world' endsWith:'world'
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3122
     'hello world' endsWith:'earth'
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3123
     'hello world' endsWith:$d   
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3124
     'hello world' endsWith:$e   
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3125
     '' endsWith:$d            
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3126
     'hello world' endsWith:#($r $l $d)
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  3127
     'hello world' endsWith:''   
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3128
    "
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3129
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3130
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3131
isBlank
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3132
    "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
  3133
     Q: should we care for whiteSpace in general here ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3134
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3135
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3136
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3137
    REGISTER unsigned char *src;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3138
    REGISTER unsigned char c;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3139
    OBJ cls;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3140
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  3141
    src = __stringVal(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3142
    if ((cls = __qClass(self)) != String)
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3143
        src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3144
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3145
#ifndef NON_ASCII
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3146
# ifdef UINT64
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3147
    while (*((UINT64 *)src) == 0x2020202020202020L) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3148
        src += 8;
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3149
    }
2954
a2f437a0483a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
  3150
# endif /* UINT64 */
3710
6ee8b3c37d09 allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  3151
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3152
    while (*((unsigned *)src) == 0x20202020) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3153
        src += 4;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3154
    }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3155
#endif /* ascii */
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3156
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3157
    while (c = *src++) {
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3158
        if (c != ' ') {
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3159
            RETURN ( false );
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3160
        }
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3161
    }
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3162
    RETURN ( true );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3163
%}.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  3164
    ^ super isBlank
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3165
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3166
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3167
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3168
    "return true if the receiver is empty (i.e. if size == 0)
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3169
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3170
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3171
%{  /* NOCONTEXT */
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3172
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3173
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3174
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3175
    if ((cls == String) || (cls == Symbol)) {
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3176
	RETURN ( (__stringSize(self) == 0) ? true : false);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3177
    }
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3178
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3179
    ^ self size == 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3180
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3181
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3182
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
  3183
    "parametrized levenshtein. arguments are the costs for
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3184
     substitution, case-change, insertion and deletion of a character."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3185
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
  3186
%{  /* STACK: 2000 */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3187
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3188
    /* 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3189
     * this is very heavy used when correcting errors 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3190
     * (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
  3191
     */
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3192
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3193
    unsigned short *data;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3194
    int l1, l2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3195
    REGISTER int sz;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3196
    unsigned char *s1, *s2;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3197
    int v1, v2, v3, m;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3198
    REGISTER unsigned short *dp;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3199
    REGISTER int rowDelta;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3200
    REGISTER int j;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3201
    int i;
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3202
    int iW, cW, sW, kW, dW;
1486
60c770ac10eb dont access stdout on WIN32
Claus Gittinger <cg@exept.de>
parents: 1399
diff changeset
  3203
#   define FASTSIZE 30  /* increase STACK if you increase this ... */
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3204
    unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3205
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3206
    if (__isStringLike(self) && __isStringLike(aString)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3207
        && __bothSmallInteger(insrtWeight, caseWeight)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3208
        && __bothSmallInteger(substWeight, deleteWeight)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3209
        && __isSmallInteger(kbdTypoWeight)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3210
    ) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3211
        iW = __intVal(insrtWeight);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3212
        cW = __intVal(caseWeight);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3213
        sW = __intVal(substWeight);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3214
        kW = __intVal(kbdTypoWeight);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3215
        dW = __intVal(deleteWeight);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3216
        s1 = __stringVal(self);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3217
        s2 = __stringVal(aString);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3218
        l1 = strlen(s1);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3219
        l2 = strlen(s2);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3220
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3221
        sz = (l1 < l2) ? l2 : l1;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3222
        rowDelta = sz + 1;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3223
        if (sz <= FASTSIZE) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3224
            data = fastData;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3225
        } else {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3226
            /* add ifdef ALLOCA here ... */
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3227
            data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short));
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3228
            if (! data) goto mallocFailed;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3229
        }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3230
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3231
        data[0] = 0;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3232
        for (j=1, dp=data+1; j<=sz; j++, dp++)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3233
            *dp = dp[-1] + iW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3234
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3235
        for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3236
            *dp = dp[-rowDelta] + dW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3237
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3238
        for (i=0; i<l1; i++) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3239
            for (j=0; j<l2; j++) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3240
                if (s1[i] == s2[j]) 
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3241
                    m = 0;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3242
                else if (tolower(s1[i]) == tolower(s2[j])) 
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3243
                    m = cW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3244
                else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j])))
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3245
                    m = kW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3246
                else
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3247
                    m = sW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3248
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3249
                dp = data + ((i+1)*rowDelta) + j;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3250
                v2 = dp[0] + iW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3251
                v1 = dp[-rowDelta] + m;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3252
                v3 = dp[-rowDelta+1] + dW;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3253
                if (v1 < v2) {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3254
                    if (v1 < v3)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3255
                        m = v1;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3256
                    else
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3257
                        m = v3;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3258
                } else {
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3259
                    if (v2 < v3)
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3260
                        m = v2;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3261
                    else
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3262
                        m = v3;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3263
                }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3264
                dp[1] = m;
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3265
            }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3266
        }
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3267
        m = data[l1*rowDelta + l2];
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3268
        if (sz > FASTSIZE) 
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3269
            free(data);
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3270
        RETURN ( __mkSmallInteger(m) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3271
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3272
mallocFailed: ;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3273
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3274
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3275
    ^ super levenshteinTo:aString 
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3276
                        s:substWeight k:kbdTypoWeight c:caseWeight 
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3277
                        i:insrtWeight d:deleteWeight
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3278
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3279
    "
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3280
     'ocmprt' levenshteinTo:'computer'
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3281
     'computer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3282
     'ocmputer' levenshteinTo:'computer'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3283
     'cmputer' levenshteinTo:'computer'
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3284
     'computer' levenshteinTo:'cmputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3285
     'computer' levenshteinTo:'vomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3286
     'computer' levenshteinTo:'bomputer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3287
     'Computer' levenshteinTo:'computer'
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3288
    "
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3289
!
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3290
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3291
notEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3292
    "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
  3293
     Redefined here for performance"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3294
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3295
%{  /* NOCONTEXT */
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3296
    OBJ cls;
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3297
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3298
    cls = __qClass(self);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3299
    if ((cls == String) || (cls == Symbol)) {
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3300
	RETURN ( (__stringSize(self) != 0) ? true : false);
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3301
    }
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3302
%}.
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3303
    ^ self size ~~ 0
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3304
!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3305
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3306
startsWith:aStringOrChar
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  3307
    "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
  3308
     If the argument is empty, true is returned."
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3309
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3310
%{  /* NOCONTEXT */
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3311
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3312
    int len1, len2;
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3313
    REGISTER unsigned char *src1, *src2;
2858
866ffc52ac8a oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents: 2856
diff changeset
  3314
    unsigned char c;
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3315
    REGISTER OBJ slf = self;
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3316
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3317
    if (((__qClass(slf)==String) || (__qClass(slf)==Symbol))
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3318
     && __isNonNilObject(aStringOrChar)
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3319
     && ((__qClass(aStringOrChar)==String) || (__qClass(aStringOrChar)==Symbol))) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3320
        src1 = __stringVal(slf);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3321
        src2 = __stringVal(aStringOrChar);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3322
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3323
        if (src1[0] != src2[0]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3324
            if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3325
                RETURN (true);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3326
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3327
            RETURN ( false );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3328
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3329
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3330
        len1 = __qSize(slf);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3331
        len2 = __qSize(aStringOrChar);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3332
        if (len1 < len2) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3333
            RETURN ( false );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3334
        }
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3335
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3336
#ifdef UINT64
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3337
        while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3338
            if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3339
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3340
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3341
            len2 -= sizeof(UINT64);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3342
            src1 += sizeof(UINT64);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3343
            src2 += sizeof(UINT64);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3344
        }
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3345
#else
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3346
# ifdef UNROLL_LOOPS
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3347
        while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3348
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3349
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3350
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3351
            if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3352
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3353
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3354
            if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3355
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3356
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3357
            if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3358
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3359
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3360
            len2 -= sizeof(INT)*4;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3361
            src1 += sizeof(INT)*4;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3362
            src2 += sizeof(INT)*4;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3363
        }
4247
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3364
# endif /* UNROLL_LOOPS */
42504c49fe2a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4205
diff changeset
  3365
#endif /* UINT64 */
3546
00984e13534a 8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents: 3545
diff changeset
  3366
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3367
        while (len2 > (OHDR_SIZE+sizeof(INT))) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3368
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3369
                RETURN (false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3370
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3371
            len2 -= sizeof(INT);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3372
            src1 += sizeof(INT);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3373
            src2 += sizeof(INT);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3374
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3375
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3376
        while (c = *src2++) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3377
            if (c != *src1) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3378
                RETURN ( false );
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3379
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3380
            src1++;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3381
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3382
        RETURN (true);
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3383
    }
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3384
    if (__isCharacter(aStringOrChar)) {
6833
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3385
        int val;
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3386
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3387
        val = __intVal(_characterVal(aStringOrChar));
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3388
        if ((unsigned)val <= 0xFF) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3389
            len1 = __stringSize(slf);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3390
            if (len1 > 0) {
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3391
                RETURN ( (__stringVal(slf)[0] == val) ? true : false);
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3392
            }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3393
        }
bc361f384f7f care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents: 6830
diff changeset
  3394
        RETURN ( false );
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3395
    }
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3396
%}.
2862
5cf60c544968 faster withoutSpaces
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
  3397
    ^ super startsWith:aStringOrChar
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3398
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3399
    "
3314
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3400
     'hello world' startsWith:'hello'
94046261fba0 tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents: 3281
diff changeset
  3401
     'hello world' startsWith:'hella'
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3402
     'hello world' startsWith:'hi'      
3545
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3403
     'hello world' startsWith:$h   
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3404
     'hello world' startsWith:$H   
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3405
     'hello world' startsWith:(Character value:16rFF00)   
5238e4d15d64 better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents: 3451
diff changeset
  3406
     'hello world' startsWith:60                          
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3407
     'hello world' startsWith:#($h $e $l)
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4388
diff changeset
  3408
     'hello world' startsWith:''   
1380
9873f7ae0785 category change
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  3409
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3410
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3411
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3412
!String methodsFor:'tracing'!
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3413
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  3414
traceInto:aRequestor level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3415
    "double dispatch into tracer, passing my type implicitely in the selector"
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3416
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4660
diff changeset
  3417
    ^ aRequestor traceString:self level:level from:referrer
4660
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3418
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3419
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3420
! !
eec23cd7c7ed Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4631
diff changeset
  3421
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3422
!String class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3423
2886
aa4d70a6717e repaired bad checking
Claus Gittinger <cg@exept.de>
parents: 2885
diff changeset
  3424
version
8647
2f59b57bcc4d Fix #levenshtein:... C-code.
Stefan Vogel <sv@exept.de>
parents: 8458
diff changeset
  3425
    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.211 2004-11-18 14:01:24 stefan Exp $'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3426
! !