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