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