TwoByteString.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23984 ac00c411f7f6
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
     1
"{ Encoding: utf8 }"
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
235
d8e62525bfdf *** empty log message ***
claus
parents: 97
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
10223
761e2a050b69 twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents: 8094
diff changeset
    14
"{ Package: 'stx:libbasic' }"
8094
d05f69bd0097 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 5761
diff changeset
    15
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    16
"{ NameSpace: Smalltalk }"
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    17
5761
9693ef8bbadd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4219
diff changeset
    18
CharacterArray variableWordSubclass:#TwoByteString
992
f456f8f7d421 JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents: 631
diff changeset
    19
	instanceVariableNames:''
f456f8f7d421 JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents: 631
diff changeset
    20
	classVariableNames:''
f456f8f7d421 JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents: 631
diff changeset
    21
	poolDictionaries:''
f456f8f7d421 JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents: 631
diff changeset
    22
	category:'Collections-Text'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
89
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    25
!TwoByteString class methodsFor:'documentation'!
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    26
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    27
copyright
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    28
"
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    29
 COPYRIGHT (c) 1993 by Claus Gittinger
235
d8e62525bfdf *** empty log message ***
claus
parents: 97
diff changeset
    30
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
89
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    32
 This software is furnished under a license and may be used
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    33
 only in accordance with the terms of that license and with the
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    35
 be provided or otherwise made available to, or used by, any
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    36
 other person.  No title to or ownership of the software is
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    37
 hereby transferred.
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    38
"
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    39
!
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    40
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    41
documentation
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    42
"
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    43
    TwoByteStrings are like strings, but storing 16bits per character.
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    44
    The integration of them into the system is not completed ....
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    45
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    46
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    47
        Claus Gittinger
1309
24c98ca4a56d commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    48
24c98ca4a56d commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    49
    [see also:]
1382
93c125a594c3 xref in doku
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
    50
        Text JISEncodedString
1309
24c98ca4a56d commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    51
        StringCollection
89
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    52
"
1214
Claus Gittinger <cg@exept.de>
parents: 1024
diff changeset
    53
! !
Claus Gittinger <cg@exept.de>
parents: 1024
diff changeset
    54
Claus Gittinger <cg@exept.de>
parents: 1024
diff changeset
    55
!TwoByteString class methodsFor:'initialization'!
996
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    56
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    57
initialize
1253
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    58
    "initialize the class - private"
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    59
996
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    60
    self flags:(Behavior flagWords)
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    61
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    62
    "
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    63
     TwoByteString initialize
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
    64
    "
1214
Claus Gittinger <cg@exept.de>
parents: 1024
diff changeset
    65
1253
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    66
    "Modified: 22.4.1996 / 16:14:14 / cg"
89
7be0b86ef80f *** empty log message ***
claus
parents: 73
diff changeset
    67
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
!TwoByteString class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
basicNew:anInteger
22375
0baa14a9b02e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22228
diff changeset
    72
    "return a new empty string with anInteger number of characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
1024
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
    74
    ^ (super basicNew:anInteger) atAllPut:(Character space)
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
    75
22375
0baa14a9b02e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22228
diff changeset
    76
    "Modified: / 26-02-1996 / 14:38:47 / cg"
0baa14a9b02e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22228
diff changeset
    77
    "Modified (comment): / 22-11-2017 / 21:32:49 / cg"
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    78
!
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    79
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    80
uninitializedNew:anInteger
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    81
    "return a new empty string with anInteger characters"
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    82
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    83
    ^ super basicNew:anInteger
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    84
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    85
    "
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    86
        self uninitializedNew:10
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
    87
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
!TwoByteString methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
basicAt:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
    "return the character at position index, an Integer
73
a6640cc96199 *** empty log message ***
claus
parents: 63
diff changeset
    94
     - reimplemented here since we return 16-bit characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
1024
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
    96
    |val|
63
1f0cdefb013f *** empty log message ***
claus
parents: 33
diff changeset
    97
1024
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
    98
    val := super basicAt:index.
63
1f0cdefb013f *** empty log message ***
claus
parents: 33
diff changeset
    99
    ^ Character value:val
1024
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
   100
9a14acfb50ee 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
   101
    "Modified: 26.2.1996 / 17:02:16 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   102
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   103
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
basicAt:index put:aCharacter
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1214
diff changeset
   105
    "store the argument, aCharacter at position index, an Integer.
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1214
diff changeset
   106
     Returns aCharacter (sigh).
73
a6640cc96199 *** empty log message ***
claus
parents: 63
diff changeset
   107
     - reimplemented here since we store 16-bit characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
8094
d05f69bd0097 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 5761
diff changeset
   109
    super basicAt:index put:aCharacter codePoint.
63
1f0cdefb013f *** empty log message ***
claus
parents: 33
diff changeset
   110
    ^ aCharacter
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1214
diff changeset
   112
    "Modified: 19.4.1996 / 11:16:22 / cg"
14123
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   113
!
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   114
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   115
unsignedShortAt:index
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   116
    "return the short at position index, an Integer"
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   117
a33fc6cc4332 added: #unsignedShortAt:
Stefan Vogel <sv@exept.de>
parents: 10223
diff changeset
   118
    ^ super basicAt:index.
1014
da30760cfd3e dummy encoding support
Claus Gittinger <cg@exept.de>
parents: 996
diff changeset
   119
! !
da30760cfd3e dummy encoding support
Claus Gittinger <cg@exept.de>
parents: 996
diff changeset
   120
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   121
!TwoByteString methodsFor:'filling and replacing'!
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   122
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   123
from:start to:stop put:aCharacter
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   124
    "fill part of the receiver with aCharacter.
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   125
     - reimplemented here for speed"
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   126
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   127
%{  /* NOCONTEXT */
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   128
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   129
    REGISTER unsigned short *dstp;
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   130
    REGISTER int count, charValue;
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   131
    
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   132
    // fprintf(stderr, "fill16...\n");
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   133
    if (__isCharacter(aCharacter)
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   134
     && __bothSmallInteger(start, stop)) {
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   135
        int len, index1, index2;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   136
        OBJ cls;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   137
        
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   138
        len = __twoByteStringSize(self);
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   139
        index1 = __intVal(start);
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   140
        index2 = __intVal(stop);
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   141
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   142
        dstp = __twoByteStringVal(self) + index1 - 1;
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   143
        if (((cls = __qClass(self)) == Unicode16String)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   144
         || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   145
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   146
            charValue = __intVal(__characterVal(aCharacter));
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   147
            if (((unsigned)charValue <= 0xFFFF)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   148
             && (index1 <= index2)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   149
             && (index1 > 0)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   150
                if (index2 <= len) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   151
                    count = index2 - index1 + 1;
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   152
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   153
#if (__POINTER_SIZE__ == 8)
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   154
                    {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   155
                        INT v4;
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   156
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   157
                        v4 = (charValue << 16) | charValue;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   158
                        v4 = (v4 << 32) | v4;
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   159
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   160
                        /* fill unaligned part */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   161
                        while ((count > 0) && (((unsigned INT)dstp & 7) != 0)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   162
                            *dstp++ = charValue;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   163
                            count--;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   164
                        }
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   165
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   166
                        /* fill aligned part */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   167
                        while (count >= 4) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   168
                            ((unsigned INT *)dstp)[0] = v4;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   169
                            dstp += 4;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   170
                            count -= 4;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   171
                        }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   172
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   173
                        /* fill rest */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   174
                        while (count > 0) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   175
                            *dstp++ = charValue;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   176
                            count--;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   177
                        }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   178
                        RETURN (self);
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   179
                    }
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   180
#endif /* 64bit */
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   181
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   182
                    while (count >= 8) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   183
                        dstp[0] = dstp[1] = dstp[2] = dstp[3] =
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   184
                        dstp[4] = dstp[5] = dstp[6] = dstp[7] = charValue;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   185
                        dstp += 8;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   186
                        count -= 8;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   187
                    }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   188
                    while (count--) {
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   189
                        *dstp++ = charValue;
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   190
                    }
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   191
                    RETURN (self);
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   192
                }
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   193
            }
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   194
        }
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   195
    }
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   196
%}.
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   197
    "
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   198
     fall back in case of non-integer index or out-of-bound index/value;
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   199
     will eventually lead to an out-of-bound signal raise
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   200
    "
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   201
    ^ super from:start to:stop put:aCharacter
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   202
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   203
    "
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   204
     (Unicode16String new:10) from:1 to:10 put:$a
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   205
     (Unicode16String new:20) from:10 to:20 put:$b
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   206
     (Unicode16String new:20) from:1 to:10 put:$c
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   207
     (Unicode16String new:20) from:1 to:10 put:$c 
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   208
     (Unicode16String new:100) from:2 to:99 put:$c 
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   209
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   210
     (Unicode16String new:10) from:0 to:9 put:$a
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   211
     (Unicode16String new:10) from:1 to:11 put:$a
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   212
    "
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   213
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   214
    "Created: / 26-03-2019 / 11:20:14 / Claus Gittinger"
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   215
    "Modified: / 27-03-2019 / 14:05:10 / Claus Gittinger"
23974
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   216
!
2601c14688d8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22375
diff changeset
   217
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   218
replaceFrom:start to:stop with:aString startingAt:repStart
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   219
    "replace the characters starting at index start, anInteger and ending
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   220
     at stop, anInteger with characters from aString starting at repStart.
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   221
     Return the receiver.
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   222
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   223
     - reimplemented here for speed"
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   224
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   225
%{  /* NOCONTEXT */
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   226
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   227
#ifndef NO_PRIM_STRING
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   228
    if (__bothSmallInteger(start, stop)) {
18576
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   229
        int len;
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   230
        int index1 = __intVal(start);
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   231
        int index2 = __intVal(stop);
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   232
        int count = index2 - index1 + 1;
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   233
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   234
        if (count <= 0) {
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   235
             RETURN (self);
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   236
        }
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   237
        len = __twoByteStringSize(self);
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   238
        if ((index2 <= len) && (index1 > 0)) {
18576
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   239
            int repIndex = __intVal(repStart);
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   240
            OBJ cls;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   241
            
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   242
            if (((cls = __qClass(self)) == Unicode16String)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   243
             || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   244
                if (__isStringLike(aString)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   245
                    int repLen = __stringSize(aString);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   246
                    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   247
                        REGISTER unsigned char *srcp = __stringVal(aString) + repIndex - 1;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   248
                        REGISTER unsigned short *dstp  = __twoByteStringVal(self) + index1 - 1;
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   249
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   250
                        while (count-- > 0) {
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   251
                            *dstp++ = *srcp++;
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   252
                        }
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   253
                        RETURN (self);
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   254
                    }
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   255
                } else  if (__isTwoByteString(aString) || __isUnicode16String(aString)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   256
                    int repLen = __twoByteStringSize(aString);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   257
                    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   258
                        REGISTER unsigned short *srcp  = __twoByteStringVal(aString) + repIndex - 1;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   259
                        REGISTER unsigned short *dstp = __twoByteStringVal(self) + index1 - 1;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   260
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   261
                        if (aString == self) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   262
                            /* take care of overlapping copy */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   263
                            memmove(dstp, srcp, count*sizeof(short));
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   264
                            RETURN (self);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   265
                        }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   266
                        if (count > 5) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   267
                            memcpy(dstp, srcp, count*sizeof(short));
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   268
                        } else {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   269
                            while (count-- > 0) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   270
                                *dstp++ = *srcp++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   271
                            }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   272
                        }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   273
                        RETURN (self);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   274
                    }
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   275
                }
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   276
            }
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   277
        }
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   278
    }
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   279
#endif
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   280
%}.
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   281
    "/ arrive here if any index arg is out o range, or the source is neither a string,
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   282
    "/ nor a two-byte string.
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   283
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   284
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   285
    "
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   286
     'hello world' asUnicode16String replaceFrom:1 to:5 with:'123456' startingAt:2
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   287
     'hello world' asUnicode16String replaceFrom:1 to:5 with:'123456' asUnicode16String startingAt:2
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   288
     'hello world' asUnicode16String replaceFrom:1 to:0 with:'123456' startingAt:2
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   289
     'hello' asUnicode16String replaceFrom:1 to:6 with:'123456' startingAt:2
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   290
     'hello world' asUnicode16String replaceFrom:1 to:1 with:'123456' startingAt:2
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   291
    "
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   292
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   293
    "Modified: / 27-03-2019 / 14:03:27 / Claus Gittinger"
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   294
! !
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   295
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
!TwoByteString methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
1017
2665a2628779 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1014
diff changeset
   298
bitsPerCharacter
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
   299
    "return the number of bits each character has.
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
   300
     Here, 16 is returned (storing double byte characters)."
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
   301
1017
2665a2628779 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1014
diff changeset
   302
    ^ 16
1239
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
   303
91a688ac83de commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
   304
    "Modified: 20.4.1996 / 23:08:38 / cg"
14557
427740fc4329 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 14123
diff changeset
   305
!
427740fc4329 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 14123
diff changeset
   306
19758
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   307
bytesPerCharacter
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   308
    "return the number of bytes each character has.
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   309
     Here, 2 is returned (storing double byte characters)."
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   310
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   311
    ^ 2
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   312
!
9cb10401a691 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19581
diff changeset
   313
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   314
characterSize
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   315
    "answer the size in bits of my largest character (actually only 7, 8 or 16)"
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   316
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   317
%{  /* NOCONTEXT */
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   318
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   319
    REGISTER unsigned short *sp = __twoByteStringVal(self);
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   320
    REGISTER unsigned short *last = sp + __twoByteStringSize(self);
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   321
    OBJ cls = __qClass(self);
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   322
    int has8BitChars = 0;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   323
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   324
    if (cls != Unicode16String) {
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   325
        sp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) / 2;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   326
    }
18586
b8798de459f4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18576
diff changeset
   327
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   328
#if __POINTER_SIZE__ == 8
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   329
    if (sizeof(unsigned INT) == 8) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   330
        if (!has8BitChars) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   331
            for ( ; (sp+4) <= last; sp += 4) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   332
                if (*(unsigned INT *)sp & 0xFF80FF80FF80FF80) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   333
                    /* there are at least 8-bit chars - check for more */
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   334
                    has8BitChars = 1;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   335
                    break;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   336
                }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   337
            }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   338
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   339
        for ( ; (sp+4) <= last; sp += 4) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   340
            if (*(unsigned INT *)sp & 0xFF00FF00FF00FF00) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   341
                RETURN(__mkSmallInteger(16));
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   342
            }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   343
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   344
    }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   345
#endif
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   346
    if (sizeof(unsigned int) == 4) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   347
        if (!has8BitChars) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   348
            for ( ; (sp+2) <= last; sp += 2) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   349
                if (*(unsigned int *)sp & 0xFF80FF80) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   350
                    /* there are at least 8-bit chars - check for more */
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   351
                    has8BitChars = 1;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   352
                    break;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   353
                }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   354
            }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   355
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   356
        for ( ; (sp+2) <= last; sp += 2) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   357
            if (*(unsigned int *)sp & 0xFF00FF00) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   358
                RETURN(__mkSmallInteger(16));
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   359
            }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   360
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   361
    }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   362
    if (!has8BitChars) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   363
        for ( ; sp < last; sp++) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   364
            if (*sp & 0xFF80) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   365
                /* there are at least 8-bit chars - check for more */
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   366
                has8BitChars = 1;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   367
                break;
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   368
            }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   369
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   370
    }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   371
    for ( ; sp < last; sp++) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   372
        if (*sp & 0xFF00) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   373
            RETURN(__mkSmallInteger(16));
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   374
        }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   375
    }
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   376
    RETURN (__mkSmallInteger(has8BitChars ? 8 : 7));
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   377
%}.
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   378
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   379
    "
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   380
     'hello world' asUnicode16String characterSize
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   381
     'hello worldüäö' asUnicode16String characterSize
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   382
     'a' asUnicode16String characterSize
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   383
     'ü' asUnicode16String characterSize
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   384
     'aa' asUnicode16String characterSize
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   385
     'aü' asUnicode16String characterSize
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   386
     'aaa' asUnicode16String characterSize
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   387
     'aaü' asUnicode16String characterSize
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   388
     'aaaü' asUnicode16String characterSize
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   389
     'aaaa' asUnicode16String characterSize
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   390
     'aaaaü' asUnicode16String characterSize
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   391
    "
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   392
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   393
    "Modified: / 27-03-2019 / 14:06:56 / Claus Gittinger"
18586
b8798de459f4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18576
diff changeset
   394
!
b8798de459f4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18576
diff changeset
   395
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   396
containsNon7BitAscii
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   397
    "return true, if the underlying string contains 8BitCharacters (or widers)
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   398
     (i.e. if it is non-ascii)"
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   399
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   400
%{  /* NOCONTEXT */
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   401
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   402
    REGISTER unsigned short *sp = __twoByteStringVal(self);
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   403
    REGISTER unsigned short *last = sp + __twoByteStringSize(self);
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   404
    OBJ cls = __qClass(self);
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   405
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   406
    if (cls != Unicode16String) {
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   407
        sp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) / 2;
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   408
    }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   409
#if __POINTER_SIZE__ == 8
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   410
    if (sizeof(unsigned INT) == 8) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   411
        for ( ; (sp+4) <= last; sp += 4) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   412
            if (*(unsigned INT *)sp & 0xFF80FF80FF80FF80) {
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   413
                RETURN ( true );
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   414
            }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   415
        }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   416
    }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   417
#endif
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   418
    if (sizeof(unsigned int) == 4) {
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   419
        for ( ; (sp+2) <= last; sp += 2) {
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   420
            if (*(unsigned int *)sp & 0xFF80FF80) {
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   421
                RETURN ( true );
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   422
            }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   423
        }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   424
    }
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   425
    for ( ; sp < last; sp++) {
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   426
        if (*sp & 0xFF80) {
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   427
            RETURN ( true );
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   428
        }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   429
    }
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   430
    RETURN (false);
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   431
%}.
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   432
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   433
    "
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   434
     'hello world' asUnicode16String containsNon7BitAscii
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   435
     'hello worldüäö' asUnicode16String containsNon7BitAscii
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   436
     'ü' asUnicode16String containsNon7BitAscii
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   437
     'aü' asUnicode16String containsNon7BitAscii
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   438
     'aaü' asUnicode16String containsNon7BitAscii
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   439
     'aaaü' asUnicode16String containsNon7BitAscii
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   440
     'aaaaü' asUnicode16String containsNon7BitAscii
18593
e69a425e3823 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 18586
diff changeset
   441
     'aaaaa' asUnicode16String containsNon7BitAscii
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   442
    "
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   443
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   444
    "Modified: / 27-03-2019 / 14:07:10 / Claus Gittinger"
17621
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   445
!
098adea6b2d4 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 16750
diff changeset
   446
14557
427740fc4329 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 14123
diff changeset
   447
isWideString
19581
8f0e91223fb3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 18606
diff changeset
   448
    "true if I require more than one byte per character"
8f0e91223fb3 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 18606
diff changeset
   449
14557
427740fc4329 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 14123
diff changeset
   450
    ^ true
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   451
!
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   452
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   453
occurrencesOf:aCharacter
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   454
    "count the occurrences of the argument, aCharacter in myself
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   455
      - reimplemented here for speed"
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   456
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   457
%{  /* NOCONTEXT */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   458
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   459
    REGISTER unsigned charValue;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   460
    REGISTER INT count, limit;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   461
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   462
    if (__isCharacter(aCharacter)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   463
        limit = __unicode16StringSize(self);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   464
        count = 0;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   465
        charValue = __intVal(__characterVal(aCharacter));
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   466
        if (charValue <= 0xFFFF) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   467
            OBJ cls;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   468
            REGISTER unsigned short* cp;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   469
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   470
            cp = __unicode16StringVal(self);
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   471
            if (((cls = __qClass(self)) == Unicode16String)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   472
             || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   473
                /* loop unrolled and software-pipelined
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   474
                 * (gives 30-40% speedup on Intel-DUO using borland bcc55)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   475
                 */
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   476
                while (limit >= 4) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   477
                    register unsigned short c1, c2;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   478
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   479
                    c1 = cp[0];
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   480
                    limit -= 4;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   481
                    c2 = cp[1];
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   482
                    if (c1 == charValue) count++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   483
                    c1 = cp[2];
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   484
                    if (c2 == charValue) count++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   485
                    c2 = cp[3];
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   486
                    if (c1 == charValue) count++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   487
                    cp += 4;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   488
                    if (c2 == charValue) count++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   489
                }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   490
                while (limit > 0) {
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   491
                    register unsigned short c;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   492
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   493
                    c = cp[0];
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   494
                    limit--;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   495
                    if (c == charValue) count++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   496
                    cp++;
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   497
                }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   498
            }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   499
            RETURN ( __mkSmallInteger(count) );
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   500
        }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   501
    }
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   502
%}.
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   503
    ^ super occurrencesOf:aCharacter
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   504
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   505
    "
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   506
     'hello world' occurrencesOf:$a
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   507
     'hello world' occurrencesOf:$w
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   508
     'hello world' occurrencesOf:$l
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   509
     'hello world' occurrencesOf:$x
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   510
     'hello world' occurrencesOf:1
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   511
     Time millisecondsToRun:[
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   512
        |s|
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   513
        
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   514
        s := 'abcdefghijklmn' asUnicode16String. 
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   515
        1000000 timesRepeat:[ s occurrencesOf:$x ]
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   516
     ]. 60 60 60 70 (untuned: 670 710 740)
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   517
    "
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   518
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   519
    "Created: / 27-03-2019 / 13:58:55 / Claus Gittinger"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
22226
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   522
!TwoByteString methodsFor:'testing'!
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   523
22228
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   524
isSingleByteCollection
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   525
    "return true, if the receiver has access methods for bytes;
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   526
     i.e. #at: and #at:put: accesses a byte and are equivalent to #byteAt: and byteAt:put:
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   527
     and #replaceFrom:to: is equivalent to #replaceBytesFrom:to:. 
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   528
     false is returned here since at: returns 2-byte characters and not bytes 
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   529
      - the method is redefined from UninterpretedBytes."
f9b1fd876cbb #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22226
diff changeset
   530
22226
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   531
    ^ false
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   532
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   533
    "Created: / 30-08-2017 / 23:30:36 / cg"
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   534
! !
0604a0bec563 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 19840
diff changeset
   535
631
d43deb0ec558 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   536
!TwoByteString class methodsFor:'documentation'!
d43deb0ec558 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   537
d43deb0ec558 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   538
version
18576
724284508398 class: TwoByteString
Stefan Vogel <sv@exept.de>
parents: 17621
diff changeset
   539
    ^ '$Header$'
23984
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   540
!
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   541
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   542
version_CVS
ac00c411f7f6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23974
diff changeset
   543
    ^ '$Header$'
631
d43deb0ec558 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   544
! !
8094
d05f69bd0097 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 5761
diff changeset
   545
16750
394404a33691 class: TwoByteString
Claus Gittinger <cg@exept.de>
parents: 14557
diff changeset
   546
996
560a05298da9 I really store shorts ...
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
   547
TwoByteString initialize!