CharacterArray.st
author Claus Gittinger <cg@exept.de>
Sun, 02 Jul 2000 14:53:36 +0200
changeset 5440 ba9207f592c9
parent 5352 61dfc2af0ab4
child 5469 8aca7ce5626f
permissions -rw-r--r--
only init once
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     1
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
     3
	      All Rights Reserved
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     4
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    11
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    12
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
    13
"{ Package: 'stx:libbasic' }"
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
    14
3926
4cc33691696a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3879
diff changeset
    15
ByteArray variableByteSubclass:#CharacterArray
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    16
	instanceVariableNames:''
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    17
	classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    18
		EncodingFailedSignal'
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    19
	poolDictionaries:''
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    20
	category:'Collections-Text'
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    21
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    22
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    23
!CharacterArray class methodsFor:'documentation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    24
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    25
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    26
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    27
 COPYRIGHT (c) 1994 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    28
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    36
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    37
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    39
documentation
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    40
"
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    41
    CharacterArray is a superclass for all kinds of Strings (i.e.
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    42
    (singleByte-)Strings, TwoByteStrings and whatever comes in the future.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    43
2537
9398b135cec4 comment
Claus Gittinger <cg@exept.de>
parents: 2520
diff changeset
    44
    This class is abstract, meaning that there are no instances of it. 
9398b135cec4 comment
Claus Gittinger <cg@exept.de>
parents: 2520
diff changeset
    45
    All this class does is provide common protocol for concrete subclasses.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    46
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    47
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    48
        Claus Gittinger
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    49
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    50
    [see also:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    51
        String TwoByteString
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1272
diff changeset
    52
        StringCollection
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    53
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    54
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    55
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    56
!CharacterArray class methodsFor:'initialization'!
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    57
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    58
initialize
5440
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    59
    DecodingFailedSignal isNil ifTrue:[    
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    60
        DecodingFailedSignal := Signal new mayProceed:true.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    61
        DecodingFailedSignal notifierString:'decoding failure'.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    62
        DecodingFailedSignal nameClass:self message:#decodingFailedSignal.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    63
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    64
        EncodingFailedSignal := QuerySignal new mayProceed:true.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    65
        EncodingFailedSignal notifierString:'encoding failure'.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    66
        EncodingFailedSignal nameClass:self message:#encodingFailedSignal.
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
    67
    ]
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    68
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    69
    "
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    70
     CharacterArray initialize
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    71
    "
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    72
2833
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
    73
    "Modified: 3.8.1997 / 18:15:59 / cg"
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    74
! !
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
    75
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
    76
!CharacterArray class methodsFor:'instance creation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    77
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    78
basicNew
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    79
    "return a new empty string"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    80
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    81
    ^ self basicNew:0
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    82
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    83
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    84
fromBytes:aByteCollection
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    85
    "return an instance of the receiver class,
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    86
     taking untranslated bytes from the argument, aByteCollection.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    87
     Only useful, when reading twoByteStrings from external sources."
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    88
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    89
    |mySize nBytes newString dstIdx|
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    90
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    91
    nBytes := aByteCollection size.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    92
    mySize := self basicNew bitsPerCharacter.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    93
    mySize == 16 ifTrue:[
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    94
        newString := self basicNew:(nBytes // 2).
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    95
        dstIdx := 1.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    96
        aByteCollection pairWiseDo:[:hi :lo |
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    97
            newString at:dstIdx put:(Character value:(hi bitShift:8)+lo).
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    98
            dstIdx := dstIdx + 1
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
    99
        ].
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   100
        ^ newString.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   101
    ].
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   102
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   103
    ^ (self basicNew:nBytes) replaceFrom:1 with:aByteCollection
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   104
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   105
    "
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   106
     TwoByteString fromBytes:#[16r21 16r21]
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   107
    "
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   108
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   109
    "Modified: 30.6.1997 / 20:08:37 / cg"
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   110
!
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   111
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   112
fromString:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   113
    "return a copy of the argument, aString"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   114
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
   115
    ^ (self basicNew:(aString size)) replaceFrom:1 with:aString
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
   116
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
   117
    "TwoByteString fromString:'hello'"
581
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   118
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   119
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   120
fromStringCollection:aCollectionOfStrings
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   121
    "return new string formed by concatenating a copy of the argument, aString"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   122
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   123
    ^ self fromStringCollection:aCollectionOfStrings separatedBy:''
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   124
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   125
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   126
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this')
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   127
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   128
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   129
    "Created: 20.11.1995 / 15:26:59 / cg"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   130
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   131
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   132
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   133
    "return new string formed by concatenating a copy of the argument, aString"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   134
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   135
    |newString first|
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   136
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   137
    newString := ''.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   138
    first := true.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   139
    aCollectionOfStrings do:[:s | 
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   140
	first ifFalse:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   141
	    newString := newString , aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   142
	] ifTrue:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   143
	    first := false
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   144
	].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   145
	newString := newString , s
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   146
    ].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   147
    ^ newString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   148
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   149
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   150
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' '
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   151
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   152
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   153
    "Created: 20.11.1995 / 15:32:17 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   154
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   155
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   156
new
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   157
    "return a new empty string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   158
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   159
    ^ self basicNew:0
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   160
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   161
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   162
!CharacterArray class methodsFor:'Signal constants'!
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   163
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   164
decodingFailedSignal
2833
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   165
    "return the signal, raised when decoding of a string is not possible
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   166
     due to invalid characters contained in the source.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   167
     This may happen for example, if a non EUC coded 8-bit string
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   168
     is attempted to be decoded into a JIS string."
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   169
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   170
    ^ DecodingFailedSignal
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   171
2833
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   172
    "Created: 28.6.1997 / 20:09:55 / cg"
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   173
    "Modified: 3.8.1997 / 18:16:47 / cg"
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   174
!
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   175
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   176
encodingFailedSignal
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   177
    "return the (query-) signal, raised when encoding of a string is not possible
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   178
     due to invalid characters contained in the source."
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   179
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   180
    ^ EncodingFailedSignal
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   181
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   182
    "Modified: 28.6.1997 / 20:09:35 / cg"
2833
f8600b7cb86d provide access to signals
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   183
    "Created: 3.8.1997 / 18:16:40 / cg"
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   184
! !
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
   185
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   186
!CharacterArray class methodsFor:'cleanup'!
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   187
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   188
lowSpaceCleanup
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   189
    "cleanup in low-memory situations"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   190
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   191
    DecoderTables := EncoderTables := nil
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   192
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   193
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   194
     CharacterArray lowSpaceCleanup
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   195
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   196
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   197
    "Created: 22.2.1996 / 16:30:30 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   198
    "Modified: 22.2.1996 / 17:58:05 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   199
! !
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   200
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   201
!CharacterArray class methodsFor:'code tables'!
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   202
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   203
classForEncoding:encodingSymbol
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   204
    "return a class capable of representing text encoded
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   205
     by encodingSymbol"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   206
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   207
    encodingSymbol == #jis ifTrue:[^ JISEncodedString].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   208
    encodingSymbol == #big5 ifTrue:[^ BIG5EncodedString].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   209
    encodingSymbol == #gb ifTrue:[^ GBEncodedString].
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   210
    encodingSymbol == #ksc ifTrue:[^ KSCEncodedString].
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   211
    encodingSymbol == #unicode ifTrue:[^ UnicodeString].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   212
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   213
    "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   214
    "/ assume its an 8-bit code
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   215
    "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   216
    ^ String
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   217
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   218
    "Modified: 30.6.1997 / 19:48:05 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   219
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   220
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   221
decoderTableFor:encoding
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   222
    "return a table to decode from an alien encoding into
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   223
     the internal (iso8859, ansi) format.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   224
     This is an experimental interface - unfinished"
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   225
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   226
    |table unrepresentableCharacterCode x80Table|
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   227
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   228
    DecoderTables notNil ifTrue:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   229
        table := DecoderTables at:encoding ifAbsent:nil.
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   230
        table notNil ifTrue:[
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   231
            table == #identity ifTrue:[^ nil].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   232
            ^ table
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   233
        ].
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   234
    ] ifFalse:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   235
        DecoderTables := IdentityDictionary new
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   236
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   237
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   238
    unrepresentableCharacterCode := 16rBF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   239
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   240
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   241
    "/ setup as identityTranslation
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   242
    "/
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   243
    table := (0 to:255) asByteArray.
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   244
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   245
    "/
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   246
    "/ hp -> iso8859
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   247
    "/
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   248
    "/ hp uses a funny encoding of the A1 .. FF characters
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   249
    "/
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   250
    "/   
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   251
    encoding == #hp ifTrue:[
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   252
        unrepresentableCharacterCode := 16rA0.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   253
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   254
        x80Table :=
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   255
            #(
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   256
               16r0080 16r0081 16r0082 16r0083 16r0084 16r0085 16r0086 16r0087  "/ 80
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   257
               16r0088 16r0089 16r008a 16r008b 16r008c 16r008d 16r008e 16r008f
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   258
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   259
               16r0090 16r0091 16r0092 16r0093 16r0094 16r0095 16r0096 16r0097  "/ 90
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   260
               16r0098 16r0099 16r009a 16r009b 16r009c 16r009d 16r009e 16r009f
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   261
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   262
               16r00a0 16r00c0 16r00c2 16r00c8 16r00c9 16r00cb 16r00ce 16r00cf  "/ a0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   263
               16r00b4 16rFFFF 16rFFFF 16r00a8 16rFFFF 16r00d9 16r00da 16r00a3
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   264
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   265
               16rFFFF 16r00dd 16r00fd 16r00b0 16r00c7 16r00e7 16r00d1 16r00f1  "/ b0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   266
               16r00a1 16r00bf 16r00a4 16r00a3 16r00a5 16r00a7 16rFFFF 16rFFFF
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   267
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   268
               16r00e2 16r00ea 16r00f4 16r00fb 16r00e1 16r00e9 16r00f3 16r00fa  "/ c0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   269
               16r00e0 16r00e8 16r00f2 16r00f9 16r00e4 16r00eb 16r00f6 16r00fc
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   270
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   271
               16r00c5 16r00ee 16r00d8 16r00c6 16r00e5 16r00ed 16r00f8 16r00e6  "/ d0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   272
               16r00c4 16r00ec 16r00d6 16r00dc 16r00c9 16r00ef 16r00df 16r00d4
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   273
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   274
               16r00c1 16r00c3 16r00e3 16r00d0 16r00f0 16r00cd 16r00cc 16r00d3  "/ e0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   275
"/                                        S ?       s ?             Y ?
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   276
               16r00d2 16r00d5 16r00f5 16rFFFF 16rFFFF 16r00da 16rFFFF 16r00ff 
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   277
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   278
               16r00de 16r00fe 16r00b7 16r00b5 16r00b6 16r00be 16r00ad 16r00bc  "/ f0
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   279
               16r00bd 16r00aa 16r00ba 16r00ab 16rFFFF 16r00bb 16r00b1 16rFFFF
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   280
            ).
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   281
    ].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   282
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   283
    "/
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   284
    "/ mac -> iso8859
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   285
    "/
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   286
    "/ You will loose the following characters:
1440
7a38f09abf92 no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   287
    "/ - all of them will be replaced by 8F
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   288
    "/
1272
b45ddd6d6ec3 assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   289
    "/  A0 (dagger)
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   290
    "/  A5 (dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   291
    "/  AA (tm - trademark)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   292
    "/  AD (not equal)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   293
    "/  B0 (infinity)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   294
    "/  B3 (less-double-equal <=)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   295
    "/  B4 (greater-equal >-)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   296
    "/  B6 (math lowercase delta)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   297
    "/  B7 (math sum)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   298
    "/  B8 (math uppercase pi)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   299
    "/  B9 (math lowercase pi)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   300
    "/  BA (math integral)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   301
    "/  BD (math omega)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   302
    "/  C3 (math union)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   303
    "/  C4 (ext latin f)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   304
    "/  C5 (math almost equal)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   305
    "/  C6 (math uppercase delta)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   306
    "/  C9 (dot-dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   307
    "/  CE (OE ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   308
    "/  CF (oe ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   309
    "/  D1 (hyphen)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   310
    "/  D2 (opening top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   311
    "/  D3 (closing top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   312
    "/  D4 (opening top quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   313
    "/  D5 (closing top quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   314
    "/  D7 (geometric: )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   315
    "/  D9 (uppercase Y diacrit )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   316
    "/  DA (slash2 )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   317
    "/  DC (single oldStyle opening quote (<) )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   318
    "/  DD (single oldStyle closing quote (>) )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   319
    "/  DE (? )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   320
    "/  DF (? )
1272
b45ddd6d6ec3 assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   321
    "/  E0 (double dagger )
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   322
    "/  E2 (opening bottom quote )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   323
    "/  E3 (opening bottom dquote )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   324
    "/  F0 (? )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   325
    "/  F5 (latin l )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   326
    "/  F6 (diacrit circumflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   327
    "/  F7 (diacrit tilde)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   328
    "/  F8 (diacrit top line)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   329
    "/  F9 (diacrit inverse circumflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   330
    "/  FA (diacrit dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   331
    "/  FB (diacrit ring)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   332
    "/  FC (diacrit cedille left)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   333
    "/  FD (diacrit dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   334
    "/  FE (diacrit cedille right)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   335
    "/  FF (diacrit circumflex2 ?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   336
    "/   
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   337
    encoding == #mac ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   338
        x80Table :=
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   339
            #( 16r00c4 16r00c5 16r00c7 16r00c9 16r00d1 16r00d6 16r00dc 16r00e1  "/ 80
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   340
               16r00e0 16r00e2 16r00e4 16r00e3 16r00e5 16r00e7 16r00e9 16r00e8
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   341
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   342
               16r00ea 16r00eb 16r00ed 16r00ec 16r00ee 16r00ef 16r00f1 16r00f3  "/ 90
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   343
               16r00f2 16r00f4 16r00f6 16r00f5 16r00fa 16r00f9 16r00fb 16r00fc
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   344
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   345
               16rFFFF 16r00b0 16r00a2 16r00a3 16r00a7 16rFFFF 16r00b6 16r00df  "/ a0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   346
               16r00ae 16r00a9 16rFFFF 16r00b4 16r00a8 16rFFFF 16r00c6 16r00d8
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   347
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   348
               16rFFFF 16r00b1 16rFFFF 16rFFFF 16r00a5 16r00b5 16rFFFF 16rFFFF  "/ b0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   349
               16rFFFF 16rFFFF 16rFFFF 16r00aa 16r00ba 16rFFFF 16r00e6 16r00f8
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   350
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   351
               16r00bf 16r00a1 16r00ac 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00ab  "/ c0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   352
               16r00bb 16rFFFF 16r00a0 16r00c1 16r00c3 16r00d5 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   353
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   354
               16r00ad 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF  "/ d0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   355
               16rFFFF 16rFFFF 16rFFFF 16r00a4 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   356
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   357
               16rFFFF 16r00b7 16rFFFF 16rFFFF 16rFFFF 16r00c2 16r00ca 16r00c1  "/ e0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   358
               16r00cb 16r00c8 16r00cd 16r00ce 16r00cf 16r00cc 16r00d3 16r00d4
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   359
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   360
               16rFFFF 16r00d2 16r00da 16r00db 16r00d9 16rFFFF 16rFFFF 16rFFFF  "/ f0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   361
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   362
            ).
657
449935f15b9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 652
diff changeset
   363
    ].
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   364
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   365
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   366
    "/ next -> iso8859
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   367
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   368
    "/ You will loose the following characters:
1440
7a38f09abf92 no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   369
    "/ - all of them will be replaced by 8F
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   370
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   371
    "/  A4 (diacrit /)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   372
    "/  A9 (diacrit quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   373
    "/  AA (top opening dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   374
    "/  AC (single oldStyle opening quote (<))
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   375
    "/  AD (single oldStyle closing quote (>))
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   376
    "/  AE (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   377
    "/  AF (?)
1272
b45ddd6d6ec3 assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   378
    "/  B2 (dagger)
b45ddd6d6ec3 assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   379
    "/  B3 (double dagger)
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   380
    "/  B7 (enter dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   381
    "/  B8 (opening bottom quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   382
    "/  B9 (opening bottom dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   383
    "/  BA (closing top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   384
    "/  BC (dot-dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   385
    "/  BD (per-mille)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   386
    "/  C0 (subscript 1)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   387
    "/  C1 (accent grave)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   388
    "/  C2 (accent degu)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   389
    "/  C3 (accent circonflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   390
    "/  C4 (accent tilde)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   391
    "/  C5 (accent line)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   392
    "/  C6 (accent circonflex reverse)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   393
    "/  C7 (accent dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   394
    "/  C8 (accent dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   395
    "/  D0 (hline)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   396
    "/  E8 (engl. pound upper case L)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   397
    "/  EA (OE ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   398
    "/  F5 (latin l)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   399
    "/  F8 (engl. pound lower case l)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   400
    "/  FE (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   401
    "/  FF (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   402
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   403
    encoding == #next ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   404
        unrepresentableCharacterCode := 16rBF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   405
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   406
        x80Table :=
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   407
            #( 16r0080 16r00c0 16r00c1 16r00c2 16r00c3 16r00c4 16r00c5 16r00c7  "/ 80
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   408
               16r00c8 16r00c9 16r00ca 16r00cb 16r00cc 16r00cd 16r00ce 16r00cf
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   409
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   410
               16r00d0 16r00d1 16r00d2 16r00d3 16r00d4 16r00d5 16r00d6 16r00d9  "/ 90
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   411
               16r00da 16r00db 16r00dc 16r00dd 16r00de 16r00b5 16r00d7 16r00f7
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   412
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   413
               16r00a9 16r00a1 16r00a2 16r00a3 16rFFFF 16r00a5 16rFFFF 16r00a7  "/ a0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   414
               16r00a4 16rFFFF 16rFFFF 16r00ab 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   415
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   416
               16r00ae 16r00ad 16rFFFF 16rFFFF 16r00b7 16r00a6 16r00b6 16rFFFF  "/ b0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   417
               16rFFFF 16rFFFF 16rFFFF 16r00bb 16rFFFF 16rFFFF 16r00ac 16r00bf
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   418
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   419
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF  "/ c0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   420
               16rFFFF 16r00b2 16r00b0 16r00b8 16r00b3 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   421
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   422
               16rFFFF 16r00b1 16r00bc 16r00bd 16r00be 16r00e0 16r00e1 16r00e2  "/ d0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   423
               16r00e3 16r00e4 16r00e5 16r00e7 16r00e8 16r00e9 16r00ea 16r00eb
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   424
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   425
               16r00ec 16r00c6 16r00ed 16r00aa 16r00ee 16r00ef 16r00f0 16r00f1  "/ e0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   426
               16rFFFF 16r00d8 16rFFFF 16r00ba 16r00f2 16r00f3 16r00f4 16r00f5
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   427
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   428
               16r00f6 16r00e6 16r00f9 16r00fa 16r00fb 16rFFFF 16r00fc 16r00fd  "/ f0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   429
               16rFFFF 16r00f8 16rFFFF 16r00df 16r00fe 16r00ff 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   430
            ).
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   431
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   432
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   433
    "/
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   434
    "/ msdos (codePage 437 [=US]) -> iso8859
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   435
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   436
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   437
    "/ You will loose the following characters:
1440
7a38f09abf92 no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   438
    "/ - all of them will be replaced by 8F
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   439
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   440
    "/  9E      (pesetas)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   441
    "/  9F      (latin f)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   442
    "/  A9      (technical not)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   443
    "/  B0 - BF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   444
    "/  C0 - CF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   445
    "/  D0 - DF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   446
    "/  E0      (greek alpha)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   447
    "/  E2 - E5 (greek)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   448
    "/  E7 - EC (greek & math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   449
    "/  EE - EF (greek & math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   450
    "/  F0      (math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   451
    "/  F2 - F5 (math & technical)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   452
    "/  F7      (math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   453
    "/  F9      (center dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   454
    "/  FB      (math sqrt)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   455
    "/  FC      (super n)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   456
    "/  FE      (block)
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   457
    "/
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   458
    encoding == #msdos437 ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   459
        unrepresentableCharacterCode := 16rBF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   460
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   461
        x80Table :=
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   462
            #(
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   463
               "/ Ccedil  uuml  eacute  acirc   auml    agrave  aring   ccedil
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   464
               16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7  "/ 80
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   465
               "/ ecirc   euml  egrave  iuml    icirc   igrave  Auml    Aring
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   466
               16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   467
               "/ Eacute  ae     AE     ocirc   ouml    ograve  ucirc   ugrave
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   468
               16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9  "/ 90
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   469
               "/ yuml    Ouml   Uuml   cent    pound   Yen     psetas  latin-f
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   470
               16r00ff 16r00d6 16r00dc 16r00a2 16r00a3 16r00a5 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   471
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   472
               "/ aacute iacute oacute  uacute  ntilde  Ntilde  asup    0sup 
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   473
               16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00b0  "/ a0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   474
               "/ iquest        lognot  1/2     1/4     iexcla  <<      >>
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   475
               16r00bf 16rFFFF 16r00ac 16r00bd 16r00bc 16r00a1 16r00ab 16r00bb
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   476
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   477
               "/ block graphics
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   478
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF  "/ b0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   479
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   480
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   481
               "/ block graphics
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   482
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF  "/ c0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   483
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   484
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   485
               "/ block graphics
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   486
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF  "/ d0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   487
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   488
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   489
               "/ alpha beta   ...                              mu
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   490
               16rFFFF 16r00df 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00b5 16rFFFF  "/ e0
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   491
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f8 16rFFFF
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   492
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   493
               "/       plusmin  gr-eq  lt-eq   integr  integr  div
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   494
               16rFFFF 16r00b1 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF  "/ f0
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   495
               "/ 0sup  dot      dot    sqr             sup2            space 
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   496
               16r00b0 16rFFFF 16r00b7 16rFFFF 16rFFFF 16r00b2 16rFFFF 16r00a0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   497
            ).
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   498
    ].
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   499
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   500
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   501
    "/
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   502
    "/ msdos (codePage 850 [=latin1]) -> iso8859
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   503
    "/
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   504
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   505
    (encoding == #msdos850 
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   506
    or:[encoding == #msdos]) ifTrue:[
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   507
        unrepresentableCharacterCode := 16rBF.
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   508
        x80Table :=
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   509
            #(
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   510
               "/ Ccedil  uuml  eacute  acirc   auml    agrave  aring   ccedil
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   511
               16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7  "/ 80
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   512
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   513
               "/ ecirc   euml  egrave  iuml    icirc   igrave  Auml    Aring
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   514
               16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   515
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   516
               "/ Eacute  ae     AE     ocirc   ouml    ograve  ucirc   ugrave
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   517
               16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9  "/ 90
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   518
               "/ yuml    Ouml   Uuml   oslash    pound Oslash  x      latin-f
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   519
               16r00ff 16r00d6 16r00dc 16r00f8 16r00a3 16r00d8 16rFFFF 16rFFFF
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   520
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   521
               "/ aacute iacute oacute  uacute  ntilde  Ntilde  asup    0sup 
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   522
               16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00da  "/ a0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   523
               "/ iquest reg    lognot  1/2     1/4     iexcla  <<      >>
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   524
               16r00bf 16r00ae 16r00ac 16r00bd 16r00bc 16r00a1 16r00ab 16r00bb
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   525
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   526
               "/                                       Aacute  Acirc   Agrave
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   527
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00c1 16r00c2 16r00c0  "/ b0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   528
               "/ cpyr                                  cent    Yen
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   529
               16r00a9 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00a2 16r00a5 16rFFFF
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   530
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   531
               "/                                               atilde  Atilde
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   532
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00e3 16r00c3  "/ c0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   533
               "/                                               
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   534
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   535
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   536
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   537
               "/               Ecirc   Euml    Egrave          Iacute  Icirc
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   538
               16rFFFF 16rFFFF 16r00ca 16r00cb 16r00c8 16rFFFF 16r00dc 16r00ce  "/ d0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   539
               "/ Iuml                                          Igrave
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   540
               16r00cf 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r007c 16r00cc 16rFFFF  
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   541
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   542
               "/ Oacute  sz    Ocirc   Ograve  otilde  Otilde   mu
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   543
               16r00d3 16r00df 16r00d4 16r00d2 16rFFFF 16r00f5 16r00b5 16rFFFF  "/ e0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   544
               "/       Uacute  Ucirc   Ugrav    yacute  Yacute             '
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   545
               16rFFFF 16r00da 16r00db 16r00d9 16r00fd 16r00dd 16rFFFF 16r0027
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   546
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   547
               "/       plusmin  =       3/4    para   sect      div            "/ f0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   548
               16rFFFF 16r00b1 16r003d 16r00be 16r00b6 16r00a7 16r00f7 16rFFFF
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   549
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   550
               "/ sup0                          sup3   sup2
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   551
               16r00b0 16rFFFF 16rFFFF 16rFFFF 16r00b3 16r00b2 16rFFFF 16r00a0
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   552
            ).
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   553
    ].
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   554
    "/ more encodings needed here ....
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   555
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   556
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   557
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   558
    "/ x80Table should contain the translation for
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   559
    "/ 0x80..0xFF characters
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   560
    "/
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   561
    x80Table isNil ifTrue:[
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   562
        table := #identity.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   563
    ] ifFalse:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   564
        x80Table keysAndValuesDo:[:idx :repl |
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   565
            |ch|
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   566
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   567
            repl == 16rFFFF ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   568
                ch := unrepresentableCharacterCode
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   569
            ] ifFalse:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   570
                ch := repl
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   571
            ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   572
            table at:(16r80 + idx) put:ch
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   573
        ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   574
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   575
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   576
    DecoderTables at:encoding put:table.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   577
    ^ table
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   578
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   579
    "
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   580
     EncoderTables := nil.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   581
     DecoderTables := nil
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   582
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   583
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   584
    "Created: 20.10.1995 / 23:04:43 / cg"
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   585
    "Modified: 1.7.1997 / 17:24:49 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   586
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   587
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   588
defaultRomanCharacterValue
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   589
    "return the characterValue for unmappable roman characters
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   590
     (only applies to jis, gb, ksc etc.)"
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   591
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   592
    |romans|
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   593
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   594
    romans := self romanTable.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   595
    romans isNil ifTrue:[^ 16r20].
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   596
    ^ romans at:1.              "/ space characters xlation
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   597
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   598
    "Created: 30.6.1997 / 18:13:24 / cg"
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   599
    "Modified: 30.6.1997 / 18:19:26 / cg"
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   600
!
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   601
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   602
encoderTableFor:encoding
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   603
    "return a table to encode from the internal (iso8859, ansi) format
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   604
     into an alien encoding.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   605
     This is an experimental interface - unfinished"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   606
2751
1899bf26e438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2750
diff changeset
   607
    |table decoderTable unrepresentableCharacterCode|
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   608
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   609
    EncoderTables notNil ifTrue:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   610
        table := EncoderTables at:encoding ifAbsent:nil.
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   611
        table notNil ifTrue:[
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   612
            table == #identity ifTrue:[^ nil].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   613
            ^ table
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   614
        ].
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   615
    ] ifFalse:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   616
        EncoderTables := IdentityDictionary new
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   617
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   618
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   619
    "/
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   620
    "/ iso8859 -> hp
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   621
    "/
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   622
    encoding == #hp ifTrue:[
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   623
        decoderTable := self decoderTableFor:encoding.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   624
        unrepresentableCharacterCode := 16rFF.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   625
    ].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   626
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   627
    "/
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   628
    "/ iso8859 -> mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   629
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   630
    encoding == #mac ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   631
        decoderTable := self decoderTableFor:encoding.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   632
        unrepresentableCharacterCode := 16rFF.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   633
    ].
1272
b45ddd6d6ec3 assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   634
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   635
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   636
    "/ iso8859 -> msdos
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   637
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   638
    encoding == #msdos ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   639
        decoderTable := self decoderTableFor:encoding.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   640
        unrepresentableCharacterCode := 16rFF.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   641
    ].
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   642
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   643
    "/ more encodings needed here ....
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   644
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   645
    decoderTable notNil ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   646
        table := Array new:256 withAll:unrepresentableCharacterCode.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   647
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   648
        0 to:16rFF do:[:code |
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   649
            |isoCode destIdex|
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   650
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   651
            isoCode := decoderTable at:(code+1).
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   652
            table at:isoCode+1 put:code.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   653
        ]
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   654
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   655
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   656
    table isNil ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   657
        "/
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   658
        "/ cannot put a nil into an Id-Dict;
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   659
        "/ use special #identity
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   660
        "/
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   661
        table := #identity.
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   662
    ].
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   663
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   664
    EncoderTables at:encoding put:table.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   665
    ^ table
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   666
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   667
    "
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   668
     EncoderTables := nil.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   669
     DecoderTables := nil.
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   670
     CharacterArray decoderTableFor:#mac
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   671
     CharacterArray encoderTableFor:#mac
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   672
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   673
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   674
    "Created: 22.2.1996 / 16:17:58 / cg"
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   675
    "Modified: 1.7.1997 / 17:26:28 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   676
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   677
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   678
romanTable
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   679
    ^ nil
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   680
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   681
    "Created: 30.6.1997 / 15:13:52 / cg"
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   682
!
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   683
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   684
supportedEncodings
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   685
    "return an array containing symbolic names of supported encodings. 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   686
     These are internally visible supported ones only"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   687
2452
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   688
    ^ self supportedExternalEncodings at:2.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   689
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   690
    "Modified: 30.6.1997 / 14:38:25 / cg"
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   691
!
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   692
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   693
supportedExternalEncodings
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   694
    "return an array of two arrays containing the names of supported
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   695
     encodings which are supported for external resources (i.e. files).
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   696
     The first array contains user-readable strings (descriptions),
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   697
     the second contains the internally used symbolic names.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   698
     More than one external name may be mapped onto the same symbolic."
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   699
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   700
    ^ #( 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   701
         (
2250
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   702
          'iso8859      (ansi)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   703
          'iso8859-1    (latin1)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   704
          'iso8859-2    (latin2)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   705
          'iso8859-3    (latin3)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   706
          'iso8859-4    (latin4)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   707
          'iso8859-5    (cyrillic)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   708
          'iso8859-6    (arabic)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   709
          'iso8859-7    (greek)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   710
          'iso8859-8    (hebrew)'  
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   711
          'msdos US     (codepage 437)'  
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   712
          'msdos Latin1 (codepage 850)'  
2250
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   713
          'macintosh    (8 bit)' 
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   714
          'next         (8 bit)' 
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   715
          'hp           (8 bit)' 
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   716
          nil
2250
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   717
          'EUC          (extended unix code japanese)' 
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   718
          'JIS7         (jis 7bit escape codes japanese)'
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
   719
          'ISO-2022-JP  (same as jis 7bit)'
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
   720
          'SJIS         (shift jis 8bit codes japanese)'
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   721
          nil
2250
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   722
          'GB           (mainland china)'
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   723
          'BIG5         (taiwan)'
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   724
"/          'KSC          (korean)'
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   725
         )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   726
         (
2452
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   727
          #'iso8859'
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   728
          #'iso8859-1'    "/ latin1
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   729
          #'iso8859-2'    "/ latin2
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   730
          #'iso8859-3'    "/ latin3
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   731
          #'iso8859-4'    "/ latin4
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   732
          #'iso8859-5'    "/ cyrillic
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   733
          #'iso8859-6'    "/ arabic
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   734
          #'iso8859-7'    "/ greek
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   735
          #'iso8859-8'    "/ hebrew
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   736
          #'msdos437'                   
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   737
          #'msdos850'                   
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   738
          #'mac'         
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   739
          #'next'   
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   740
          #'hp'   
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   741
          nil
2452
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   742
          #'euc'   
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   743
          #'jis7'   
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
   744
          #'iso-2022-jp'   
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
   745
          #'sjis'   
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   746
          nil
2452
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   747
          #'gb'   
7262e3b2c20a fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   748
          #'big5'
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   749
"/          #'ksc'           "/ korean
2250
4b7a93d96b3f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2124
diff changeset
   750
         )
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   751
       )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   752
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   753
    "Created: 22.4.1996 / 14:39:39 / cg"
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
   754
    "Modified: 16.7.1997 / 13:47:16 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   755
! !
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   756
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
   757
!CharacterArray class methodsFor:'encoding / decoding'!
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   758
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   759
decodeFromBIG5:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   760
    "return a new string containing the characters from aString,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   761
     which is interpreted as a BIG5 encoded singleByte string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   762
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   763
     The result is a Big5EncodedString (you need a BIG5 font to display that ...)."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   764
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   765
    |newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   766
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   767
    newString := BIG5EncodedString new:aString size.
1204
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   768
    ^ self decodeFromBIG5_or_GB:aString into:newString.
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   769
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   770
    "Modified: 17.4.1996 / 18:58:29 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   771
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   772
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   773
decodeFromBIG5_or_GB:aString into:a16BitString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   774
    "return a new string containing the characters from aString,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   775
     which is interpreted as a BIG5 encoded singleByte string.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   776
     The result is a Big5EncodedString (you need a BIG5 font to display that ...).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   777
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   778
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   779
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   780
    |sz     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   781
     dstIdx "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   782
     srcIdx "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   783
     b1     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   784
     b2     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   785
     val    "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   786
     c|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   787
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   788
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   789
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   790
        dstIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   791
        srcIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   792
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   793
        [true] whileTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   794
            c := aString at:srcIdx.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   795
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   796
            "/ characters below 16rA1 are left untranslated
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   797
            "/ (romans).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   798
            "/ Translation into roman-row is done at display time.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   799
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   800
            b1 := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   801
            b1 >= 16rA1 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   802
                srcIdx := srcIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   803
                srcIdx <= sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   804
                    b2 := (aString at:srcIdx) asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   805
                    val := (b1 bitShift:8) bitOr:b2.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   806
                    c := Character value:val.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   807
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   808
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   809
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   810
            a16BitString at:dstIdx put:c.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   811
            dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   812
            srcIdx := srcIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   813
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   814
            srcIdx > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   815
                ^ a16BitString copyFrom:1 to:dstIdx-1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   816
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   817
        ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   818
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   819
    ^ a16BitString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   820
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   821
    "Created: 17.4.1996 / 16:55:54 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   822
    "Modified: 4.7.1997 / 11:01:38 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   823
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   824
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   825
decodeFromEUC:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   826
    "return a new string containing the characters from aString,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   827
     which is interpreted as an EUC encoded singleByte string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   828
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   829
     There are various JIS encodings around (New-JIS, Old-JIS and NEC-JIS);
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   830
     this one only understands New-JIS.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   831
     The result is a JISEncodedString (you need a JIS font to display that ...).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   832
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   833
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   834
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   835
    |newString 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   836
     sz     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   837
     dstIdx "{ Class: SmallInteger }"
2750
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   838
     srcIdx "{ Class: SmallInteger }"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   839
     b1     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   840
     b2     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   841
     val    "{ Class: SmallInteger }"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   842
     c c2|
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   843
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   844
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   845
    newString := JISEncodedString new:sz.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   846
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   847
        dstIdx := 1.
2750
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   848
        srcIdx := 1.
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   849
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   850
%{
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   851
        if (__isString(aString)
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   852
         && (__Class(newString) == @global(JISEncodedString))) {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   853
            int _dstIdx = 1, _srcIdx = 1;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   854
            int _sz = __intVal(sz);
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   855
            unsigned char *_cp = __stringVal(aString);
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   856
            unsigned char _c1;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   857
            unsigned short *_jcp = (unsigned short *)__stringVal(newString);
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   858
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   859
            while (_srcIdx <= _sz) {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   860
                _c1 = _cp[_srcIdx-1];
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   861
                if (_c1 < 161) {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   862
                    _jcp[_dstIdx-1] = _c1;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   863
                } else {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   864
                    _srcIdx++;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   865
                    if (_srcIdx <= _sz) {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   866
                        unsigned char _c2;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   867
                        int _val;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   868
                        int _b1, _b2;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   869
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   870
                        _b1 = _c1 - 128;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   871
                        _c2 = _cp[_srcIdx-1];
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   872
                        _b2 = _c2 - 128;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   873
                        _val = (_b1<<8) + _b2;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   874
                        if (_val < 0) {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   875
                            /* decoder errors are handled in smalltalk */
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   876
                            _srcIdx--;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   877
                            goto getOutOfHere;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   878
                        }
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   879
                        _jcp[_dstIdx-1] = _val;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   880
                    } else {
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   881
                        _jcp[_dstIdx-1] = _c1;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   882
                    }
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   883
                }
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   884
                _dstIdx++;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   885
                _srcIdx++;
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   886
            }
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   887
    getOutOfHere:
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   888
            srcIdx = __MKSMALLINT(_srcIdx);
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   889
            dstIdx = __MKSMALLINT(_dstIdx);
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   890
        }
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   891
%}.
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   892
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   893
        [srcIdx <= sz] whileTrue:[
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   894
            c := aString at:srcIdx.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   895
            b1 := c asciiValue.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   896
            b1 < 161 ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   897
                "/ characters below 16rA1 are left untranslated
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   898
                "/ (control character or roman).
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   899
                newString at:dstIdx put:c.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   900
            ] ifFalse:[
2750
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   901
                srcIdx := srcIdx + 1.
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   902
                srcIdx <= sz ifTrue:[    
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   903
                    b1 := b1 - 128.
2750
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   904
                    b2 := (c2 := aString at:srcIdx) asciiValue.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   905
                    b2 := b2 - 128.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   906
                    val := (b1 bitShift:8) bitOr:b2.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   907
                    val <= 0 ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   908
                        DecodingFailedSignal 
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   909
                            raiseWith:aString
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   910
                            errorString:'EUC decoding failed (not EUC encoded ?)'.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   911
                        newString at:dstIdx put:c.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   912
                        dstIdx := dstIdx + 1.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   913
                        newString at:dstIdx put:c2.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   914
                    ] ifFalse:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   915
                        newString at:dstIdx put:(Character value:val).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   916
                    ].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   917
                ] ifFalse:[
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   918
                    newString at:dstIdx put:c.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   919
                ].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   920
            ].
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   921
            dstIdx := dstIdx + 1.
2750
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   922
            srcIdx := srcIdx + 1.
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   923
        ].
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   924
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   925
        (dstIdx-1) ~~ sz ifTrue:[
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   926
            newString := newString copyFrom:1 to:dstIdx-1.
65927af4fe5b tuned EUC decoding
Claus Gittinger <cg@exept.de>
parents: 2749
diff changeset
   927
        ].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   928
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   929
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   930
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   931
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   932
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
   933
         'hello' decodeFrom:#euc 
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   934
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   935
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   936
    "Created: 17.4.1996 / 16:10:22 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   937
    "Modified: 4.7.1997 / 11:06:05 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   938
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   939
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   940
decodeFromGB:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   941
    "return a new string containing the characters from aString,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   942
     which is interpreted as a GB encoded singleByte string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   943
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   944
     The result is a Big5EncodedString (you need a GB font to display that ...)."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   945
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   946
    |newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   947
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   948
    newString := GBEncodedString new:aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   949
    ^ self decodeFromBIG5_or_GB:aString into:newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   950
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   951
    "Created: 17.4.1996 / 16:56:33 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   952
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   953
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   954
decodeFromJIS7:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   955
    "return a new string containing the aStrings characters,
2758
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
   956
     which are interpreted as a JIS7 or ISO2022-JP encoded singleByte string.
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
   957
     There are various JIS encodings around (New-JIS, Old-JIS, NEC-JIS and ISO2022);
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
   958
     this one understands New-JIS, ISO2022 and treats Old-JIS just the same.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   959
     The result is a JISEncodedString (you need a JIS font to display that ...).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   960
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
   961
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   962
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   963
    |newString 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   964
     sz         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   965
     dstIdx     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   966
     start      "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   967
     stop       "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   968
     n1 n2 n3  
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   969
     b1         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   970
     b2         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   971
     val        "{ Class: SmallInteger }"
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   972
     singleBytes katakana c|
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   973
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   974
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   975
    newString := JISEncodedString new:sz.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   976
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   977
        dstIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   978
        start := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   979
        singleBytes := true.
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   980
        katakana := false.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   981
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   982
        [true] whileTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   983
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   984
            "/ scan for next escape"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   985
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   986
            stop := aString indexOf:(Character esc) startingAt:start.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   987
            stop == 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   988
                stop := sz + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   989
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   990
                (stop + 2) > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   991
                    stop := sz + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   992
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   993
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   994
            singleBytes ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   995
                start to:(stop - 1) do:[:i |
2758
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
   996
                    c := aString at:i.
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
   997
                    newString at:dstIdx put:c.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   998
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   999
                ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1000
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1001
                start to:(stop - 2) by:2 do:[:i |
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1002
                    b1 := (aString at:i) asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1003
                    b2 := (aString at:i+1) asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1004
                    val := (b1 bitShift:8) bitOr:b2.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1005
                    newString at:dstIdx put:(Character value:val).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1006
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1007
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1008
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1009
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1010
            stop > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1011
                ^ newString copyFrom:1 to:dstIdx - 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1012
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1013
            start := stop.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1014
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1015
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1016
            "/ found an escape (at start) 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1017
            "/ - check for KI (<ESC> '$' 'B') or OLD-JIS-KI (<ESC> '$' '@')
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1018
            "/ and KO(ASCII) (<ESC> '(' 'B') or KO(ROMAN) (<ESC> '(' 'J')
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1019
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1020
            n1 := aString at:start.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1021
            n2 := aString at:(start + 1).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1022
            n3 := aString at:(start + 2).
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1023
            katakana := false.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1024
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1025
            (n2 == $$ and:[n3 == $B ]) ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1026
                singleBytes := false.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1027
            ] ifFalse:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1028
                (n2 == $$ and:[n3 == $@ ]) ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1029
                    singleBytes := false.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1030
                ] ifFalse:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1031
                    (n2 == $( and:[n3 == $B ]) ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1032
                        singleBytes := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1033
                    ] ifFalse:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1034
                        (n2 == $( and:[n3 == $J ]) ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1035
                            singleBytes := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1036
                        ] ifFalse:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1037
                            (n2 == $( and:[n3 == $I ]) ifTrue:[
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1038
                                singleBytes := true.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1039
                                katakana := true.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1040
                            ] ifFalse:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1041
                                singleBytes ifTrue:[
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1042
                                    newString at:dstIdx put:n1.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1043
                                    newString at:(dstIdx + 1) put:n2.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1044
                                    newString at:(dstIdx + 2) put:n3.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1045
                                    dstIdx := dstIdx + 3.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1046
                                ] ifFalse:[
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1047
                                    DecodingFailedSignal 
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1048
                                            raiseWith:aString
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1049
                                            errorString:'JIS7 decoding failed (not JIS7 encoded ?)'.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1050
                                    newString at:dstIdx put:n1.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1051
                                    newString at:(dstIdx + 1) put:n2.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1052
                                    newString at:(dstIdx + 2) put:n3.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1053
                                    dstIdx := dstIdx + 3.
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1054
                                ]
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1055
                            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1056
                        ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1057
                    ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1058
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1059
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1060
            start := start + 3.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1061
            start > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1062
                ^ newString copyFrom:1 to:dstIdx-1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1063
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1064
        ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1065
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1066
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1067
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1068
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1069
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1070
         'hello' decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1071
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1072
     ending with a crippled escape:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1073
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1074
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1075
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1076
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1077
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1078
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1079
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1080
         s := s copyWith:$A.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1081
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1082
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1083
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1084
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1085
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1086
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1087
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1088
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1089
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1090
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1091
         s := s copyWith:$A.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1092
         s decodeFromJIS7 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1093
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1094
     ending with a KANJI-in,  but no more chars:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1095
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1096
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1097
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1098
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1099
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1100
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1101
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1102
     ending with a KANJI-in, followed by $3 (KO):
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1103
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1104
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1105
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1106
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1107
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1108
         s := s , '$3'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1109
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1110
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1111
     ending with a KANJI-in, followed by $3$l$OF| (KO RE HA NI):
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1112
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1113
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1114
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1115
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1116
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1117
         s := s , '$3$l$OF|'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1118
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1119
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1120
     a KO in between:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1121
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1122
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1123
         s := 'hello' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1124
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1125
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1126
         s := s , '$3'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1127
         s := s copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1128
         s := s copyWith:$(.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1129
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1130
         s := s , 'hello'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1131
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1132
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1133
     I dont know what that means ;-):
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1134
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1135
         |s t l|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1136
         s := 'kterm ' copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1137
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1138
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1139
         s := s , '$N4A;zC<Kv%(%_%e%l!!<%?'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1140
         s := s copyWith:Character esc.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1141
         s := s copyWith:$(.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1142
         s := s copyWith:$B.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1143
         s := s , ' kterm'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1144
         t := s decodeFromJIS7.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1145
         l := Label new.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1146
         l label:t.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1147
         l font:(Font family:'k14' face:nil style:nil size:nil).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1148
         l font:(Font family:'gothic' size:17).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1149
         l font:(Font family:'mincho' size:23).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1150
         l realize
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1151
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1152
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1153
    "Created: 17.4.1996 / 16:11:57 / cg"
2758
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
  1154
    "Modified: 16.7.1997 / 12:50:55 / cg"
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1155
!
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1156
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1157
decodeFromSJIS:aString
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1158
    "return a new string containing the aStrings characters,
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1159
     which are interpreted as a Shift-JIS encoded singleByte string.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1160
     The result is a JISEncodedString (you need a JIS font to display that ...).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1161
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1162
     This is a first-class candidate for a primitive"
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1163
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1164
    |newString char1 char2
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1165
     sz         "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1166
     dstIdx     "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1167
     srcIdx     "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1168
     b1         "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1169
     b2         "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1170
     val        "{ Class: SmallInteger }"
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1171
    |
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1172
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1173
    sz := aString size.
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1174
    newString := JISEncodedString new:sz.
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1175
    sz ~~ 0 ifTrue:[
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1176
        dstIdx := 1.
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1177
        srcIdx := 1.
2749
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1178
%{
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1179
        if (1 && __isString(aString)
2749
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1180
         && (__Class(newString) == @global(JISEncodedString))) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1181
            int _dstIdx = 1, _srcIdx = 1;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1182
            int _sz = __intVal(sz);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1183
            unsigned char *_cp = __stringVal(aString);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1184
            unsigned char _c1, _c2;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1185
            unsigned short *_jcp = (unsigned short *)__stringVal(newString);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1186
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1187
            while (_srcIdx <= _sz) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1188
                int _val;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1189
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1190
                _c1 = _cp[_srcIdx-1];
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1191
                _srcIdx++;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1192
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1193
                if ((_srcIdx <= _sz)
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1194
                 && (((_c1 >= 129) && (_c1 <= 159))
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1195
                     || ((_c1 >= 224) && (_c1 <= 239)))) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1196
                    _c2 = _cp[_srcIdx-1];
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1197
                    _srcIdx++;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1198
                    if ((_c2 >= 64) && (_c2 <= 252)) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1199
                        int _adjust, _rowOffs, _cellOffs;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1200
                        int _b1, _b2;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1201
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1202
                        _adjust = (_c2 < 159) ? 1 : 0;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1203
                        _rowOffs = (_c1 < 160) ? 112 : 176;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1204
                        if (_adjust) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1205
                            _cellOffs = 31 + ((_c2 > 127) ? 1 : 0);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1206
                        } else {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1207
                            _cellOffs = 126;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1208
                        }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1209
                        _b1 = ((_c1 - _rowOffs) << 1) - _adjust;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1210
                        _b2 = (_c2 - _cellOffs);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1211
                        _val = (_b1<<8) + _b2;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1212
                        if (_val <= 0) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1213
                            /* decoder error - let smalltalk handle that */
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1214
                            _srcIdx -= 2;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1215
                            goto getOutOfHere;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1216
                        }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1217
                        _jcp[_dstIdx-1] = _val;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1218
                    } else {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1219
                        /* mhmh - append untranslated */
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1220
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1221
                        _jcp[_dstIdx-1] = _c1;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1222
                        _dstIdx++;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1223
                        _jcp[_dstIdx-1] = _c2;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1224
                    }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1225
                } else {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1226
                    if ((_c1 >= 0xA1 /* 161 */) && (_c1 <= 0xDF /* 223 */)) {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1227
                        /* HALFWIDTH KATAKANA
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1228
                         * map half-width katakana to 8E:xx
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1229
                         */
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1230
                        _val = _c1 - 128;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1231
                        _val = _val + 0x8E00;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1232
                        _jcp[_dstIdx-1] = _val;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1233
                    } else {
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1234
                        /* roman characters left untranslated */
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1235
                        _jcp[_dstIdx-1] = _c1;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1236
                    }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1237
                }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1238
                _dstIdx++;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1239
            }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1240
        getOutOfHere: ;
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1241
            dstIdx = __MKSMALLINT(_dstIdx);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1242
            srcIdx = __MKSMALLINT(_srcIdx);
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1243
        }
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1244
%}.
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1245
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1246
        [srcIdx <= sz] whileTrue:[
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1247
            "/
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1248
            "/ scan for next character in 129..159 or 224..239
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1249
            "/
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1250
            char1 := aString at:srcIdx.
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1251
            srcIdx := srcIdx + 1.
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1252
            b1 := char1 asciiValue.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1253
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1254
            ((srcIdx <= sz) 
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1255
            and:[(b1 >= 129 and:[b1 <= 159])                 "/ SJIS1 81 .. 9F
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1256
                 or:[b1 >= 224 and:[b1 <= 239]]]) ifTrue:[   "/       E0 .. EF
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1257
                char2 := aString at:srcIdx.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1258
                srcIdx := srcIdx + 1.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1259
                b2 := char2 asciiValue.
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1260
                (b2 >= 64 and:[b2 <= 252]) ifTrue:[          "/ SJIS2 40 .. FC
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1261
                    |adjust rowOffs cellOffs|
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1262
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1263
                    adjust := (b2 < 159) ifTrue:[1] ifFalse:[0].
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1264
                    rowOffs := b1 < 160 ifTrue:[112] ifFalse:[176].
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1265
                    adjust == 1 ifTrue:[
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1266
                        cellOffs := 31 + (b2 > 127 ifTrue:[1] ifFalse:[0]).
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1267
                    ] ifFalse:[
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1268
                        cellOffs := 126.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1269
                    ].
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1270
                    b1 := ((b1 - rowOffs) bitShift:1) - adjust.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1271
                    b2 := (b2 - cellOffs).
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1272
                    val := (b1 bitShift:8) + b2.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1273
                    val <= 0 ifTrue:[
2730
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1274
                        DecodingFailedSignal 
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1275
                                raiseWith:aString
2730
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1276
                                errorString:'SJIS decoding failed (not SJIS encoded ?)'.
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1277
                        newString at:dstIdx put:char1.
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1278
                        dstIdx := dstIdx + 1.
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1279
                        newString at:dstIdx put:char2.
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1280
                    ] ifFalse:[
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1281
                        newString at:dstIdx put:(Character value:val).
1fbfddfa1d3f allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents: 2728
diff changeset
  1282
                    ]
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1283
                ] ifFalse:[
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1284
                    "/ mhmh - append untranslated
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1285
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1286
                    newString at:dstIdx put:char1.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1287
                    dstIdx := dstIdx + 1.
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1288
                    newString at:dstIdx put:char2.
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1289
                ]
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  1290
            ] ifFalse:[    
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  1291
                (b1 >= 16rA1 "161" and:[b1 <= 16rDF "223"]) ifTrue:[     "/ HALFWIDTH KATAKANA
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  1292
                    "/ map half-width katakan to 8E:xx
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1293
                    val := b1 - 128.
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  1294
                    val := val + (16r8E bitShift:8).
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1295
                    newString at:dstIdx put:(Character value:val).
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1296
                ] ifFalse:[    
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1297
                    "/ roman characters left untranslated
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1298
                    newString at:dstIdx put:char1
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1299
                ]
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1300
            ].
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1301
            dstIdx := dstIdx + 1.
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1302
        ].
2749
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1303
        (dstIdx-1) ~~ sz ifTrue:[
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1304
            newString := newString copyTo:dstIdx - 1.
62552ae3b004 tuned SJIS decoding
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  1305
        ]
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1306
    ].
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1307
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1308
    ^ newString
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1309
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1310
    "simple:
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1311
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1312
         'hello' decodeFrom:#sjis         
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1313
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1314
         '../../doc/online/japanese/TOP.html' asFilename contents asString
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1315
                decodeFrom:#sjis  
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1316
    "
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  1317
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  1318
    "Created: 28.6.1997 / 19:19:23 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1319
    "Modified: 4.7.1997 / 11:01:22 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1320
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1321
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1322
encodeIntoBIG5:aBIG5String
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1323
    "return a new string with aBIG5Strings characters as BIG5 encoded 16bit string,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1324
     The argument must be a BIG5String.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1325
     This is used translate 16bit BIG5 strings into the external BIG5 encoded
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1326
     representation.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1327
     The resulting string is only useful to be stored on some external file,
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1328
     not for being displayed in an ST/X view.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1329
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1330
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1331
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1332
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1333
     b  "{ Class: SmallInteger }"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1334
     c out|
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1335
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1336
    sz := aBIG5String size.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1337
    out := WriteStream on:(String new:(sz * 2)).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1338
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1339
    1 to:sz do:[:index |
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1340
        c := aBIG5String at:index.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1341
        b := c asciiValue.
1203
a43528048cb8 code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents: 1202
diff changeset
  1342
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1343
        b > 255 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1344
            "/ big5 character
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1345
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1346
            out nextPut:(Character value:(b bitShift:-8)).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1347
            out nextPut:(Character value:(b bitAnd:16rFF)).
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1348
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1349
            "/
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1350
            "/ control or roman character
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1351
            "/
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1352
            out nextPut:c
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1353
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1354
    ].
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1355
    ^ out contents
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1356
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1357
    "Created: 17.4.1996 / 17:17:50 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1358
    "Modified: 4.7.1997 / 11:01:57 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1359
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1360
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1361
encodeIntoEUC:aJISString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1362
    "return a new string with aJISStrings characters as EUC encoded 8bit string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1363
     The argument must be a JIS 16 bit character string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1364
     The resulting string is only useful to be stored on some external file,
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1365
     not for being displayed in an ST/X view.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1366
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1367
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1368
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1369
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1370
     b1 "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1371
     val "{ Class: SmallInteger }"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1372
     c romans out|
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1373
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1374
    romans := JISEncodedString romanTable.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1375
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1376
    sz := aJISString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1377
    sz == 0 ifTrue:[^ ''].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1378
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1379
    out := WriteStream on:(String new:(sz * 2)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1380
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1381
    1 to:sz do:[:srcIndex |
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1382
        b1 := (c := aJISString at:srcIndex) asciiValue.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1383
        b1 < 161 ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1384
            "/ a control or roman character    
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1385
            out nextPut:c.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1386
        ] ifFalse:[
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1387
            "/
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1388
            "/ check for a roman character
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1389
            "/ the two numbers below are romanTable min and romanTable max
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1390
            "/
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1391
            (b1 between:16r2121 and:16r2573) ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1392
                val := romans indexOf:b1.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1393
                (val ~~ 0 and:[val <= 127]) ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1394
                    out nextPut:(Character value:(val - 1 + 32))
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1395
                ] ifFalse:[
2747
0a95a87bcefa fixed euc encoding
Claus Gittinger <cg@exept.de>
parents: 2742
diff changeset
  1396
                    out nextPut:(Character value:(b1 bitShift:-8) + 128).
0a95a87bcefa fixed euc encoding
Claus Gittinger <cg@exept.de>
parents: 2742
diff changeset
  1397
                    out nextPut:(Character value:(b1 bitAnd:16rFF) + 128).
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1398
                ].
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1399
            ] ifFalse:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1400
                out nextPut:(Character value:(b1 bitShift:-8) + 128).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1401
                out nextPut:(Character value:(b1 bitAnd:16rFF) + 128).
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1402
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1403
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1404
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1405
    ^ out contents
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1406
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1407
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1408
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1409
         ('hello' decodeFrom:#euc) encodeInto:#euc    
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1410
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1411
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1412
    "Created: 17.4.1996 / 16:13:33 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1413
    "Modified: 4.7.1997 / 11:03:43 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1414
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1415
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1416
encodeIntoGB:aGBString
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1417
    "return a new string with aGBStrings characters as GB encoded 8bit string.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1418
     The argument must be a GBString.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1419
     This is used translate 16bit GB strings into the external GB encoded
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1420
     representation.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1421
     The resulting string is only useful to be stored on some external file,
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1422
     not for being displayed in an ST/X view.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1423
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1424
     This is a first-class candidate for a primitive"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1425
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1426
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1427
     b  "{ Class: SmallInteger }"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1428
     c out|
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1429
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1430
    sz := aGBString size.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1431
    out := WriteStream on:(String new:(sz * 2)).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1432
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1433
    1 to:sz do:[:index |
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1434
        c := aGBString at:index.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1435
        b := c asciiValue.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1436
        b > 255 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1437
            "/ big5 character
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1438
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1439
            out nextPut:(Character value:(b bitShift:-8)).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1440
            out nextPut:(Character value:(b bitAnd:16rFF)).
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1441
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1442
            "/
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1443
            "/ control or roman character
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1444
            "/
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1445
            out nextPut:c
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1446
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1447
    ].
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1448
    ^ out contents
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1449
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1450
    "Created: 30.6.1997 / 15:48:35 / cg"
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1451
    "Modified: 4.7.1997 / 11:02:13 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1452
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1453
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1454
encodeIntoJIS7:aJISString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1455
    "return a new string with aJISStrings characters as JIS7 encoded 7bit string,
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1456
     The receiver must be a JIS encoded character string.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1457
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1458
     The resulting string is only useful to be stored on some external file,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1459
     not for being displayed in an ST/X view."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1460
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1461
    |sz "{ Class:SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1462
     b1 "{ Class:SmallInteger }"
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1463
     val romans out inSingleByteMode c kanji roman val2|
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1464
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1465
    inSingleByteMode := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1466
    kanji := JISEncodedString jis7KanjiEscapeSequence.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1467
    roman := JISEncodedString jis7RomanEscapeSequence.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1468
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1469
    romans := JISEncodedString romanTable.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1470
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1471
    sz := aJISString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1472
    sz == 0 ifTrue:[^ ''].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1473
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1474
    out := WriteStream on:(String new:(sz * 2)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1475
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1476
    1 to:sz do:[:srcIndex |
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1477
        c := aJISString at:srcIndex.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1478
        b1 := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1479
        b1 < 33 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1480
            "/ a control character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1481
            inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1482
                out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1483
                inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1484
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1485
            out nextPut:c.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1486
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1487
            "/ check for a roman character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1488
            "/ the two numbers below are romanTable min and romanTable max
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1489
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1490
            (b1 between:16r2121 and:16r2573) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1491
                val := romans indexOf:b1.
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1492
                val2 := val - 1 + 32.
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1493
                (val ~~ 0 and:[val2 <= 16r7F]) ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1494
                    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1495
                        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1496
                        inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1497
                    ].
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1498
                    out nextPut:(Character value:val2)
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1499
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1500
                    inSingleByteMode ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1501
                        out nextPutAll:kanji.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1502
                        inSingleByteMode := false
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1503
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1504
                    out nextPut:(Character value:(b1 bitShift:-8)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1505
                    out nextPut:(Character value:(b1 bitAnd:16rFF)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1506
                ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1507
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1508
                b1 <= 255 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1509
                    "/ mhmh - unrepresentable roman (national chars)
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1510
"/                    b1 >= 160 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1511
"/                        ('no rep for ' , b1 printString) printNL.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1512
"/                    ].
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1513
                    EncodingFailedSignal
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1514
                        raiseWith:aJISString
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1515
                        errorString:'JIS7 encoding failed (contains 8-bit characters ?)'.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1516
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1517
                    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1518
                        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1519
                        inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1520
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1521
                    out nextPut:c
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1522
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1523
                    inSingleByteMode ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1524
                        out nextPutAll:kanji.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1525
                        inSingleByteMode := false
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1526
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1527
                    out nextPut:(Character value:(b1 bitShift:-8)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1528
                    out nextPut:(Character value:(b1 bitAnd:16rFF)).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1529
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1530
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1531
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1532
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1533
    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1534
        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1535
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1536
    ^ out contents
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1537
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1538
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1539
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1540
         'hello' decodeFromJIS7 encodeIntoJIS7 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1541
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1542
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1543
    "Created: 17.4.1996 / 16:17:40 / cg"
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1544
    "Modified: 16.7.1997 / 11:30:07 / cg"
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1545
!
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1546
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1547
encodeIntoSJIS:aJISString
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1548
    "return a new string with aJISStrings characters as SJIS encoded 8bit string.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1549
     The receiver must be a JIS encoded character string.
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1550
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1551
     The resulting string is only useful to be stored on some external file,
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1552
     not for being displayed in an ST/X view."
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1553
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1554
    |sz "{ Class: SmallInteger }"
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1555
     rval "{ Class: SmallInteger }"
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1556
     val  "{ Class: SmallInteger }"
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1557
     romans c out isSJIS|
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1558
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1559
    romans := JISEncodedString romanTable.
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1560
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1561
    sz := aJISString size.
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1562
    sz == 0 ifTrue:[^ ''].
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1563
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1564
    out := WriteStream on:(String new:(sz * 2)).
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1565
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1566
    1 to:sz do:[:srcIndex |
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1567
        val := (c := aJISString at:srcIndex) asciiValue.
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1568
        val <= 128 ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1569
            "/ a control or ascii character    
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1570
            out nextPut:c.
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1571
        ] ifFalse:[
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1572
            (val > 150 and:[val < 224]) ifTrue:[
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1573
                "/ ascii subset
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1574
                out nextPut:c.
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1575
            ] ifFalse:[
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1576
                "/ should not happen ...
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1577
                val <= 255 ifTrue:[
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1578
                    out nextPut:c.
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1579
                ] ifFalse:[
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1580
                    isSJIS := true.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1581
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1582
                    "/ check for HALFWIDTH KATAKANA
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1583
                    "/ 8E:xx
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1584
                    "/ NO: halfwidth katakana no longer generated
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1585
                    "/     remains there as full-width katakana
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1586
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1587
"/                    (val bitAnd:16rFF00) == 16r8E00 ifTrue:[
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1588
"/                        |b|
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1589
"/
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1590
"/                        b := (val bitAnd:16rFF) + 128.
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1591
"/                        (b >= 16rA1 "161" and:[b <= 16rDF "223"]) ifTrue:[
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1592
"/                            out nextPut:(Character value:b).
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1593
"/                            isSJIS := false.
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1594
"/                        ].
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1595
"/                    ].
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1596
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1597
                    isSJIS ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1598
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1599
                        "/ check for a roman character
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1600
                        "/ the two numbers below are romanTable min and romanTable max
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1601
                        "/
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1602
                        (val between:16r2121 and:16r2573) ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1603
                            rval := romans indexOf:val.
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1604
                            rval ~~ 0 ifTrue:[
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1605
                                rval := rval - 1 + 32.
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1606
                                rval <= 16r7F ifTrue:[ "/ do not translate halfwidth katakana
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1607
                                    out nextPut:(Character value:rval).
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1608
                                    isSJIS := false.
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1609
                                ]
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1610
                            ].
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1611
                        ].
2748
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1612
                    ].
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1613
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1614
                    isSJIS ifTrue:[
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1615
                        |b1 b2 rowOffset cellOffset|
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1616
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1617
                        b1 := (val bitShift:-8).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1618
                        b2 := (val bitAnd:16rFF).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1619
                        rowOffset := (b1 < 95) ifTrue:[112] ifFalse:[176].
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1620
                        cellOffset := b1 odd ifTrue:[(b2 > 95) ifTrue:[32] ifFalse:[31]]
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1621
                                             ifFalse:[126].
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1622
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1623
                        out nextPut:(Character value:(((b1 + 1) bitShift:-1) + rowOffset)).
3002ca130a92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
  1624
                        out nextPut:(Character value:b2 + cellOffset).
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1625
                    ]
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1626
                ]
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1627
            ]
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1628
        ].
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1629
    ].
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1630
    ^ out contents
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1631
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1632
    "simple:
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1633
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1634
         'hello' decodeFromEUC encodeIntoEUC    
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1635
    "
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1636
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1637
    "Created: 28.6.1997 / 21:13:27 / cg"
2757
3585df53a2c5 fixed sjis / jis7 encoding
Claus Gittinger <cg@exept.de>
parents: 2751
diff changeset
  1638
    "Modified: 16.7.1997 / 11:30:45 / cg"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1639
!
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1640
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1641
encodeRomans:aTwoByteString
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1642
    "return a new (usually 2-byte) string with roman characters
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1643
     encoded. The position of roman characters are encoding specific.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1644
     (see romanTable of concrete 16-bit string classes).
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1645
     Used when displaying strings."
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1646
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1647
    |sz "{ Class: SmallInteger }"
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1648
     b  "{ Class: SmallInteger }"
4294
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1649
     c i nCode romans newString|
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1650
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1651
    romans := self romanTable.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1652
    romans isNil ifTrue:[^ aTwoByteString].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1653
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1654
    sz := aTwoByteString size.
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1655
    newString := self fromString:aTwoByteString.
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1656
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1657
    1 to:sz do:[:index |
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1658
        c := aTwoByteString at:index.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1659
        b := c asciiValue.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1660
2735
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1661
        (b > 32 and:[b <= 255]) ifTrue:[
4294
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1662
            (i := b - 32 + 1) <= romans size ifTrue:[
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1663
                "/
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1664
                "/ a roman character
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1665
                "/ map to corresponding row
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1666
                "/
4294
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1667
                nCode := romans at:i.
2734
ab167dc4c5db checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2733
diff changeset
  1668
            ] ifFalse:[
4294
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1669
                nCode := self defaultRomanCharacterValue
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1670
            ].
9742a8b53d50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4244
diff changeset
  1671
            newString at:index put:(Character value:nCode).
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1672
        ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1673
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1674
    ^ newString
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1675
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1676
    "Created: 30.6.1997 / 15:43:56 / cg"
2735
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1677
    "Modified: 30.6.1997 / 21:16:20 / cg"
2731
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1678
!
0ba9228a6677 added encoding into SJIS
Claus Gittinger <cg@exept.de>
parents: 2730
diff changeset
  1679
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1680
guessEncodingFrom:aString
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1681
    "try to guess some 8-bit strings encoding by
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1682
     searching for certain escape sequences.
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1683
     Returns a string or nil.
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1684
     This may not find the strings real encoding."
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1685
2751
1899bf26e438 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2750
diff changeset
  1686
    |idx ascii|
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1687
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1688
    "/ look for JIS7 / EUC encoding ...
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1689
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1690
    (aString findString:(JISEncodedString jisISO2022EscapeSequence)) ~~ 0 ifTrue:[
2760
715d662449ea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2759
diff changeset
  1691
        ^ #'iso2020-jp'
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  1692
    ].
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1693
    (aString findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1694
        ^ #jis7
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1695
    ].
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1696
    (aString findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1697
        ^ #jis7
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1698
    ].
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1699
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1700
    "/ TODO:
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1701
2735
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1702
"/    "/ look for EUC
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1703
"/    idx := aString findFirst:[:char | |ascii|
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1704
"/                                        ((ascii := char asciiValue) >= 16rA1)     
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1705
"/                                        and:[ascii <= 16rFE]].
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1706
"/    idx ~~ 0 ifTrue:[
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1707
"/        ascii := (aString at:(idx + 1)) asciiValue.
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1708
"/        (ascii >= 16rA1 and:[ascii <= 16rFE]) ifTrue:[
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1709
"/            ^ #euc
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1710
"/        ]
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1711
"/    ].
72469efcec1b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2734
diff changeset
  1712
2721
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1713
    "/ look for SJIS ...
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1714
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1715
    "/ look for UTS ...
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1716
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1717
    ^ nil
77fedec2357e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2720
diff changeset
  1718
2760
715d662449ea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2759
diff changeset
  1719
    "Modified: 16.7.1997 / 13:54:59 / cg"
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
  1720
! !
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
  1721
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
  1722
!CharacterArray class methodsFor:'pattern matching'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  1723
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1724
matchEscapeCharacter
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1725
    "return the character used to escape a matchCharacter
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1726
     (i.e. make it a regular character in a matchPattern)"
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1727
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1728
    ^ $\
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1729
!
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1730
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1731
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1732
    "helper for match; return true if the characters from start to stop in
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1733
     aString are matching the scan in matchScan from matchStart to matchStop.
328
claus
parents: 327
diff changeset
  1734
     The matchScan is as created by asMatchScanArray.
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1735
328
claus
parents: 327
diff changeset
  1736
     This algorithm is not at all the most efficient; 
claus
parents: 327
diff changeset
  1737
     for heavy duty pattern matching, an interface (primitive) to the regex 
claus
parents: 327
diff changeset
  1738
     pattern matching package should be added."
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1739
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1740
    |matchEntry 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1741
     mStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1742
     mStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1743
     sStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1744
     sStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1745
     mSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1746
     sSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1747
     index  "{ Class: SmallInteger }"
2561
205ee33decf9 removed unused var
Claus Gittinger <cg@exept.de>
parents: 2554
diff changeset
  1748
     quickCheck matchLast nextMatchEntry
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  1749
     checkChar included|
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1750
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1751
    mStart := matchStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1752
    mStop := matchStop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1753
    sStart := start.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1754
    sStop := stop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1755
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1756
    [true] whileTrue:[
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1757
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , 
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1758
"/                    ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString).
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1759
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1760
        mSize := mStop - mStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1761
        sSize := sStop - sStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1762
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1763
        "empty strings match"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1764
        (mSize == 0) ifTrue:[^ (sSize == 0)].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1765
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1766
        matchEntry := matchScanArray at:mStart.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1767
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1768
        "/ the most common case first:
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1769
        (sSize ~~ 0 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1770
        and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1771
            "advance by one and continue"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1772
            mStart := mStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1773
            sStart := sStart + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1774
        ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1775
            (matchEntry == #any) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1776
                "restString empty -> no match"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1777
                (sSize == 0) ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1778
                "# matches single character"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1779
                ((sSize == 1) and:[mSize == 1]) ifTrue:[^ true].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1780
                "advance by one and continue"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1781
                mStart := mStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1782
                sStart := sStart + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1783
            ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1784
                (matchEntry == #anyString) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1785
                    "* alone matches anything"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1786
                    (mSize == 1) ifTrue:[^ true].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1787
                    "restString empty & matchString not empty -> no match"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1788
                    (sSize == 0) ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1789
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1790
                    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1791
                     try to avoid some of the recursion by checking last
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1792
                     character and continue with shortened strings if possible
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1793
                    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1794
                    quickCheck := false.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1795
                    (mStop >= mStart) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1796
                        matchLast := matchScanArray at:mStop.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1797
                        (matchLast ~~ #anyString) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1798
                            (matchLast == #any) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1799
                                quickCheck := true
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1800
                            ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1801
                                matchLast == (aString at:sStop) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1802
                                    quickCheck := true
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1803
                                ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1804
                                    matchLast isString ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1805
                                        quickCheck := matchLast includes:(aString at:sStop)
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1806
                                    ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1807
                                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1808
                            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1809
                        ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1810
                    ].
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1811
                    quickCheck ifTrue:[
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1812
                        "
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1813
                         quickCheck ok, advance from the right
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1814
                        "
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1815
                        mStop := mStop - 1.
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1816
                        sStop := sStop - 1
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1817
                    ] ifFalse:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1818
                        "/ no quick check; 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1819
                        "/ look for the next character(s)
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1820
                        "/ and try matching there
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1821
                        "/ (to avoid recursion)
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1822
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1823
                        mStart < mStop ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1824
                            nextMatchEntry := matchScanArray at:mStart+1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1825
                            nextMatchEntry isCharacter ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1826
                                sStart <= sStop ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1827
                                    [true] whileTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1828
                                        ignoreCase ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1829
                                            index := aString indexOf:nextMatchEntry startingAt:sStart
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1830
                                        ] ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1831
                                            index := aString findFirst:[:c | c asLowercase == nextMatchEntry asLowercase]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1832
                                                           startingAt:sStart.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1833
                                        ].
3879
d586b598394b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1834
                                        (index == 0 or:[index > sStop]) ifTrue:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1835
                                            ^ false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1836
                                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1837
                                        (self matchScan:matchScanArray 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1838
                                              from:(mStart + 1) 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1839
                                              to:mStop 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1840
                                              with:aString 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1841
                                              from:index 
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1842
                                              to:sStop 
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1843
                                              ignoreCase:ignoreCase 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1844
                                        ) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1845
                                            ^ true
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1846
                                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1847
                                        sStart := index + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1848
                                    ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1849
                                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1850
                            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1851
                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1852
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1853
                        "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1854
                         no quick check possible;
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1855
                         loop over all possible substrings
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1856
                        "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1857
                        index := sStart.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1858
                        [index <= sStop] whileTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1859
                            (self matchScan:matchScanArray 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1860
                                  from:(mStart + 1) 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1861
                                  to:mStop 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1862
                                  with:aString 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1863
                                  from:index 
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  1864
                                  to:sStop 
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1865
                                  ignoreCase:ignoreCase 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1866
                            ) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1867
                                ^ true
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1868
                            ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1869
                            index := index + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1870
                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1871
                        ^ false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1872
                    ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1873
                ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1874
                    (matchEntry isString) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1875
                        "testString empty -> no match"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1876
                        (sSize == 0) ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1877
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1878
                        included := false.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1879
                        "/ checkChar := aString at:sStart.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1880
                        included := matchEntry includes:checkChar.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1881
                        included ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1882
                            ignoreCase ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1883
                                checkChar isUppercase ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1884
                                    included := matchEntry includes:checkChar asLowercase.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1885
                                ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1886
                                    included := matchEntry includes:checkChar asUppercase.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1887
                                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1888
                            ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1889
                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1890
                        mStart := mStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1891
                        mSize := mSize - 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1892
                        included ifFalse:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1893
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1894
                        ((sSize == 1) and:[mSize == 0]) ifTrue:[^ true].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1895
                        "cut off 1st char and continue"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1896
                        sStart := sStart + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1897
                    ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1898
                        "/ must be single character
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1899
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1900
                        "testString empty ?"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1901
                        (sSize == 0) ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1902
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1903
                        "first characters equal ?"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1904
                        "/ checkChar := aString at:sStart.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1905
                        ignoreCase ifFalse:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1906
                        (checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1907
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1908
                        "advance and continue"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1909
                        mStart := mStart + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1910
                        sStart := sStart + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1911
                    ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1912
                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1913
            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1914
        ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1915
    ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1916
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1917
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1918
     |scanArray s|
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1919
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1920
     scanArray := self matchScanArrayFrom:'*hello'.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1921
     s := 'foo bar hello world'.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1922
     CharacterArray
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1923
         matchScan:scanArray
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1924
         from:1 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1925
         to:scanArray size
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1926
         with:s
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1927
         from:1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1928
         to:s size
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1929
         ignoreCase:false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1930
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1931
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1932
     |scanArray s|
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1933
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1934
     scanArray := self matchScanArrayFrom:'*hello*'.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1935
     s := 'foo bar hello world'.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1936
     CharacterArray
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1937
         matchScan:scanArray
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1938
         from:1 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1939
         to:scanArray size
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1940
         with:s
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1941
         from:1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1942
         to:s size
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1943
         ignoreCase:false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1944
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1945
3879
d586b598394b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3668
diff changeset
  1946
    "Modified: / 15.10.1998 / 13:39:25 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1947
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1948
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1949
matchScanArrayFrom:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1950
    "scan a pattern string and decompose it into a scanArray.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1951
     This is processed faster (especially with character ranges), and
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1952
     can also be reused later. (if the same pattern is to be searched again)"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1953
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1954
    |coll 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1955
     idx "{ Class: SmallInteger }"
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1956
     end c1 c2 matchSet previous escape|
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1957
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  1958
    escape := self matchEscapeCharacter.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1959
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1960
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1961
    idx := 1. end := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1962
    [idx <= end] whileTrue:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1963
        |char this|
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1964
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1965
        char := aString at:idx.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1966
        char == $* ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1967
            previous ~~ #anyString ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1968
                this := #anyString
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1969
            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1970
        ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1971
            char == $# ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1972
                previous ~~ #anyString ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1973
                    this := #any
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1974
                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1975
            ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1976
                char == $[ ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1977
                    matchSet := IdentitySet new.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1978
                    idx := idx + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1979
                    idx > end ifTrue:[^ nil].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1980
                    char := aString at:idx.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1981
                    c1 := nil.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1982
                    [char ~~ $]] whileTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1983
                        ((char == $-) and:[c1 notNil]) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1984
                            idx := idx + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1985
                            idx > end ifTrue:[^ nil].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1986
                            c2 := aString at:idx.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1987
                            c1 to:c2 do:[:c | matchSet add:c].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1988
                            c1 := nil.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1989
                            idx := idx + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1990
                        ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1991
                            (char ~~ $]) ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1992
                                matchSet add:char.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1993
                                c1 := char.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1994
                                idx := idx + 1
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1995
                            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1996
                        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1997
                        idx > end ifTrue:[^ nil].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1998
                        char := aString at:idx
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  1999
                    ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2000
                    this := matchSet asString
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2001
                ] ifFalse:[
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2002
                    char == escape ifTrue:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2003
                        idx := idx + 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2004
                        idx > end ifTrue:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2005
                            "/ mhmh - what should we do here ?
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2006
                            this := char
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2007
                        ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2008
                            this := aString at:idx.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2009
                        ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2010
                    ] ifFalse:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2011
                        this := char
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2012
                    ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2013
                ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2014
            ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2015
        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2016
        this notNil ifTrue:[coll add:this. previous := this].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2017
        idx := idx + 1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2018
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2019
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2020
    ^ coll asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2021
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2022
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2023
     String matchScanArrayFrom:'*ute*'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2024
     String matchScanArrayFrom:'**ute**'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2025
     String matchScanArrayFrom:'*uter'   
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2026
     String matchScanArrayFrom:'\*uter'   
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2027
     String matchScanArrayFrom:'[cC]#mpute[rR]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2028
     String matchScanArrayFrom:'[abcd]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2029
     String matchScanArrayFrom:'[a-k]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2030
     String matchScanArrayFrom:'*some*compl*ern*' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2031
     String matchScanArrayFrom:'[a-'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2032
     String matchScanArrayFrom:'[a-zA-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2033
     String matchScanArrayFrom:'[a-z01234A-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2034
    "
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2035
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2036
    "Modified: 2.4.1997 / 16:20:29 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2037
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2038
5301
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2039
!CharacterArray methodsFor:'Compatibility - Ansi'!
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2040
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2041
addLineDelimiters
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2042
    ^ self withCRs
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2043
! !
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2044
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2045
!CharacterArray methodsFor:'Compatibility - ST/V'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2046
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2047
byteAt:index put:aByte
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2048
    "store a byte at given index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2049
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2050
1333
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2051
"/    (aByte == 0) ifTrue:[
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2052
"/        "store a space instead"
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2053
"/        ^ super basicAt:index put:(Character space)
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2054
"/    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2055
    ^ super at:index put:(Character value:aByte)
1333
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2056
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2057
    "
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2058
     'hello' copy at:1 put:$H asciiValue; yourself
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2059
     'hello' copy byteAt:1 put:72; yourself 
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2060
     'hello' copy byteAt:1 put:0; yourself 
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2061
    "
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2062
d3fdca956f0d allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents: 1312
diff changeset
  2063
    "Modified: 6.5.1996 / 10:35:26 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2064
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2065
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2066
replChar:oldChar with:newChar
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2067
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2068
     by newChar.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2069
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2070
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  2071
    ^ self copyReplaceAll:oldChar with:newChar
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2072
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2073
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2074
     '12345678901234567890' replChar:$0 with:$* 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2075
    "
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  2076
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  2077
    "Modified: / 18.7.1998 / 22:52:57 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2078
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2079
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2080
replChar:oldChar withString:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2081
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2082
     by newString (i.e. slice in the newString in place of the oldChar).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2083
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2084
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2085
    |tmpStream|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2086
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2087
    tmpStream := WriteStream on:(self class new).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2088
    self do:[:element |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2089
	element = oldChar ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2090
	    tmpStream nextPutAll:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2091
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2092
	    tmpStream nextPut:element 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2093
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2094
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2095
    ^ tmpStream contents
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2096
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2097
   "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2098
     '12345678901234567890' replChar:$0 withString:'foo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2099
     'a string with spaces' replChar:$  withString:' foo '  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2100
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2101
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2102
4244
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2103
replString:subString withString:newString
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2104
    "return a copy of the receiver, with all sequences of subString replaced
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2105
     by newString (i.e. slice in the newString in place of the oldString)."
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2106
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2107
    |tmpStream idx idx1|
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2108
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2109
    tmpStream := WriteStream on:(self class new).
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2110
    idx := 1.
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2111
    [idx ~~ 0] whileTrue:[
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2112
        idx1 := idx.
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2113
        idx := self indexOfSubCollection:subString startingAt:idx.
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2114
        idx ~~ 0 ifTrue:[
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2115
            tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1).
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2116
            tmpStream nextPutAll:newString.
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2117
            idx := idx + subString size
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2118
        ]
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2119
    ].
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2120
    tmpStream nextPutAll:(self copyFrom:idx1).
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2121
    ^ tmpStream contents
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2122
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2123
   "
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2124
     '12345678901234567890' replString:'123' withString:'OneTwoThree' 
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2125
     '12345678901234567890' replString:'123' withString:'*' 
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2126
     '12345678901234567890' replString:'234' withString:'foo' 
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2127
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2128
     ('a string with spaces' replChar:$  withString:' foo ')
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2129
        replString:'foo' withString:'bar'
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2130
    "
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2131
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2132
    "Modified: / 31.5.1999 / 12:33:59 / cg"
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2133
!
5deefa3144fb added #replString:withString:
Claus Gittinger <cg@exept.de>
parents: 4156
diff changeset
  2134
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2135
trimBlanks
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2136
    "return a copy of the receiver without leading
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2137
     and trailing spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2138
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2139
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2140
    ^ self withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2141
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2142
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2143
     '    spaces at beginning' trimBlanks     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2144
     'spaces at end    ' trimBlanks           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2145
     '    spaces at beginning and end     ' trimBlanks    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2146
     'no spaces' trimBlanks              
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2147
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2148
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2149
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2150
!CharacterArray methodsFor:'Compatibility - ST80'!
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2151
3607
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2152
expandMacros
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2153
    "ST80 compatibility - expand '<..>' macros with
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2154
     argument strings. Similar to #bindWith:.
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2155
     Read the comment in #expandMacrosWithArguments: about
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2156
     limited compatibility issues."
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2157
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2158
    ^ self expandMacrosWithArguments:#()
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2159
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2160
    "
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2161
     'hello<n>foo' expandMacros
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2162
    "
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2163
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2164
    "Modified: / 18.6.1998 / 16:03:02 / cg"
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2165
!
4518499d5385 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  2166
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2167
expandMacrosWith:arg
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2168
    "ST80 compatibility - expand '<..>' macros with
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2169
     argument strings. Similar to #bindWith:.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2170
     Read the comment in #expandMacrosWithArguments: about
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2171
     limited compatibility issues."
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2172
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2173
    ^ self expandMacrosWithArguments:(Array with:arg)
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2174
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2175
    "Created: / 1.11.1997 / 13:01:28 / cg"
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2176
    "Modified: / 1.11.1997 / 13:30:50 / cg"
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2177
!
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2178
3630
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2179
expandMacrosWith:arg1 with:arg2
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2180
    "ST80 compatibility - expand '<..>' macros with
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2181
     argument strings. Similar to #bindWith:.
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2182
     Read the comment in #expandMacrosWithArguments: about
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2183
     limited compatibility issues."
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2184
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2185
    ^ self expandMacrosWithArguments:(Array with:arg1 with:arg2)
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2186
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2187
    "Modified: / 6.7.1998 / 21:58:14 / cg"
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2188
!
dd2f2db42638 added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  2189
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2190
expandMacrosWithArguments:argArray
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2191
    "ST80 compatibility - expand '<..>' macros with
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2192
     argument strings. Similar to #bindWith:.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2193
     WARNING: possibly not all ST80 expansions are supported here."
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2194
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2195
    "/ supported expansions:
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2196
    "/
5221
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2197
    "/   <#p>       # is arg Number; slice in the args printString
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2198
    "/   <#s>       # is arg Number; slice in the arg itself (must be a String)
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2199
    "/   <#?s1:s2>  # is arg Number; slice in s1 if the arg is true, s2 otherwise
5301
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2200
    "/   <s>        slice in the arg
5221
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2201
    "/   <n>        replace by a newLine character
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2202
    "/   <t>        replace by a tab character
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2203
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2204
    |in out c fmt nr arg s1 s2|
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2205
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2206
    in := self readStream.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2207
    out := '' writeStream.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2208
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2209
    [in atEnd] whileFalse:[
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2210
        c := in next.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2211
        c == $< ifTrue:[
5352
61dfc2af0ab4 Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  2212
            [in peek == $<] whileTrue:[
61dfc2af0ab4 Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  2213
                out nextPut:$<.
61dfc2af0ab4 Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  2214
                in next.
61dfc2af0ab4 Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  2215
            ].
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2216
            in peek == $n ifTrue:[
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2217
                out nextPut:Character cr.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2218
                in next
3608
0eab11b4b351 support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  2219
            ] ifFalse:[in peek == $t ifTrue:[
0eab11b4b351 support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  2220
                out nextPut:Character tab.
0eab11b4b351 support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  2221
                in next
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2222
            ] ifFalse:[
5301
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2223
                in peek isDigit ifFalse:[
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2224
                    nr := 1
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2225
                ] ifTrue:[
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2226
                    "/ start an argument expansion ...
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2227
                    nr := Integer readFrom:in onError:nil.
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2228
                    nr isNil ifTrue:[
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2229
                        "/ what does VW do here ?
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2230
                        self halt:'invalid format'.
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2231
                        ^ self
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2232
                    ].
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2233
                    (nr between:1 and:argArray size) ifFalse:[
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2234
                        "/ what does VW do here ?
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2235
                        self halt:'invalid format - bad argNr'.
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2236
                        ^ self
7bef885c778a compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
  2237
                    ].
5221
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2238
                ].
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2239
                arg := argArray at:nr.
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2240
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2241
                fmt := in next.
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2242
                (fmt == $p) ifTrue:[
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2243
                    "/ expand with args printString
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2244
                    out nextPutAll:arg printString.
5316
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2245
                ] ifFalse:[ (fmt == $s) ifTrue:[
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2246
                    "/ expand with arg itself
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2247
                    out nextPutAll:arg asString.
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2248
                ] ifFalse:[ (fmt == $?) ifTrue:[
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2249
                    s1 := in upTo:$:.
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2250
                    s2 := in nextUpTo:$>.
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2251
                    arg ifTrue:[
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2252
                        out nextPutAll:s1
5221
ebdd9dee7c1f expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents: 5154
diff changeset
  2253
                    ] ifFalse:[
5316
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2254
                        out nextPutAll:s2
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2255
                    ].
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2256
                ] ifFalse:[
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2257
                    "/ what does VW do here ?
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2258
                    self halt:'invalid format'.
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2259
                    ^ self
da1a85984423 reformated
Claus Gittinger <cg@exept.de>
parents: 5301
diff changeset
  2260
                ]]].
3608
0eab11b4b351 support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  2261
            ]].
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2262
            c := in next.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2263
            c ~~ $> ifTrue:[
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2264
                "/ what does VW do here ?
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2265
                self halt:'invalid format'.
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2266
                ^ self
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2267
            ]
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2268
        ] ifFalse:[
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2269
            out nextPut:c
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2270
        ].
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2271
    ].
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2272
    ^ out contents
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2273
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2274
    "
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2275
     'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName)
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2276
    "
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2277
3608
0eab11b4b351 support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  2278
    "Modified: / 18.6.1998 / 16:04:46 / cg"
3073
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2279
! !
0b361b3b168b expand macros stuff
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  2280
4409
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2281
!CharacterArray methodsFor:'Compatibility - Squeak'!
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2282
4989
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2283
capitalized
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2284
    ^ self asUppercaseFirst
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2285
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2286
    "
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2287
     'hello' capitalized
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2288
    "
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2289
!
d35f323b446c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  2290
4981
2ee8cd2c4c8e squeak compatibility
ps
parents: 4974
diff changeset
  2291
findTokens:delimiters
2ee8cd2c4c8e squeak compatibility
ps
parents: 4974
diff changeset
  2292
    ^ self asCollectionOfSubstringsSeparatedByAny:delimiters
2ee8cd2c4c8e squeak compatibility
ps
parents: 4974
diff changeset
  2293
!
2ee8cd2c4c8e squeak compatibility
ps
parents: 4974
diff changeset
  2294
4974
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2295
includesSubString:aString
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2296
    "return true, if a substring is contained in the receiver.
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2297
     The compare is case sensitive."
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2298
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2299
    ^ self includesString:aString
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2300
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2301
    "
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2302
     'hello world' includesSubString:'Hel'  
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2303
     'hello world' includesSubString:'hel'  
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2304
     'hello world' includesSubString:'llo'  
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2305
    "
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2306
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2307
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2308
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2309
!
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  2310
4409
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2311
includesSubstring:aString caseSensitive:caseSensitive
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2312
    "return true, if a substring is contained in the receiver.
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2313
     The argument, caseSensitive controls if case is ignored in the compare."
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2314
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2315
    "/ for now,  a q&d hack ...
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2316
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2317
    caseSensitive ifFalse:[
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2318
        ^ self asLowercase includesString:aString asLowercase
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2319
    ].
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2320
    ^ self includesString:aString
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2321
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2322
    "
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2323
     'hello world' includesSubstring:'Hel' caseSensitive:true  
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2324
     'hello world' includesSubstring:'Hel' caseSensitive:false 
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2325
    "
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2326
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2327
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2328
4890
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2329
!
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2330
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2331
lastSpacePosition
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2332
    ^ self lastIndexOfSeparator
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2333
!
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2334
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2335
withBlanksTrimmed
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2336
    "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2337
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2338
    ^ self withoutSpaces
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2339
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2340
    "
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2341
     '  hello    world    ' withBlanksTrimmed  
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2342
    "
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2343
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2344
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2345
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2346
!
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2347
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2348
withNoLineLongerThan: aNumber
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2349
    "Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number"
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2350
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2351
    | listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition |
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2352
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2353
    aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow'].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2354
    listOfLines _ OrderedCollection new.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2355
    currentLast _ 0.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2356
    [currentLast < self size] whileTrue:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2357
            [currentStart _ currentLast + 1.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2358
            putativeLast _ (currentStart + aNumber - 1) min: self size.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2359
            putativeLine _ self copyFrom: currentStart to: putativeLast.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2360
            (crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2361
                    [putativeLast _ currentStart + crPosition - 1.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2362
                    putativeLine _ self copyFrom: currentStart to: putativeLast].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2363
            currentLast _ putativeLast == self size
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2364
                    ifTrue:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2365
                            [putativeLast]
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2366
                    ifFalse:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2367
                            [currentStart + putativeLine lastSpacePosition - 1].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2368
            currentLast <= currentStart ifTrue:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2369
                    ["line has NO spaces; baleout!!"
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2370
                    currentLast _ putativeLast].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2371
            listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2372
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2373
    listOfLines size > 0 ifFalse: [^ ''].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2374
    resultString _ listOfLines first.
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2375
    2 to: listOfLines size do:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2376
            [:i | resultString _ resultString, Character cr asString, (listOfLines at: i)].
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2377
    ^ resultString
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2378
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2379
    "
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2380
     #(5 7 20) collect:
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2381
        [:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i]
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2382
    "
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2383
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2384
fa9abaa225ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4842
diff changeset
  2385
4409
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2386
! !
86e049b21f8d added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  2387
1978
0d49a096cf06 category rename
Claus Gittinger <cg@exept.de>
parents: 1849
diff changeset
  2388
!CharacterArray methodsFor:'Compatibility - V''Age'!
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2389
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2390
addLineDelimiter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2391
    "replace all '\'-characters by line delimiter (cr) - characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2392
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2393
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2394
    ^ self withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2395
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2396
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2397
bindWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2398
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2399
     replaced by aString.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2400
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2401
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2402
    ^ self expandPlaceholdersWith:(Array with:aString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2403
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2404
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2405
     'do you like %1 ?' bindWith:'smalltalk'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2406
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2407
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2408
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2409
bindWith:string1 with:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2410
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2411
     replaced by string1 and '%2' is replaced by string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2412
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2413
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2414
    ^ self expandPlaceholdersWith:(Array with:string1 with:string2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2415
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2416
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2417
     'do you prefer %1 or rather %2 ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2418
	bindWith:'smalltalk' with:'c++'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2419
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2420
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2421
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2422
bindWith:str1 with:str2 with:str3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2423
    "return a copy of the receiver, where a '%1', '%2' and '%3' escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2424
     are replaced by str1, str2 and str3 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2425
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2426
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2427
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2428
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2429
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2430
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2431
	bindWith:'smalltalk' with:'c++' with:'c'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2432
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2433
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2434
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2435
bindWith:str1 with:str2 with:str3 with:str4
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2436
    "return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2437
     are replaced by str1, str2, str3 and str4 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2438
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2439
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2440
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2441
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2442
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2443
     'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2444
	bindWith:'smalltalk' with:'c++' with:'c' with:'assembler'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2445
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2446
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2447
2344
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2448
bindWith:str1 with:str2 with:str3 with:str4 with:str5
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2449
    "return a copy of the receiver, where a '%1' .. '%5' escapes
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2450
     are replaced by str1 .. str5 respectively.
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2451
     This has been added for VisualAge compatibility."
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2452
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2453
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5)
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2454
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2455
    "Created: 31.1.1997 / 16:25:42 / cg"
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2456
!
b3788119533f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2250
diff changeset
  2457
5343
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2458
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2459
    "return a copy of the receiver, where a '%1' .. '%6' escapes
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2460
     are replaced by str1 .. str5 respectively.
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2461
     This has been added for VisualAge compatibility."
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2462
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2463
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2464
                                         with:str3 with:str4 
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2465
                                         with:str5 with:str6)
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2466
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2467
!
bac9bc59a698 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5342
diff changeset
  2468
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2469
bindWithArguments:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2470
    "return a copy of the receiver, where a '%i' escape
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2471
     is replaced by the coresponding string from the argument array.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2472
     'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2473
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2474
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2475
    ^ self expandPlaceholdersWith:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2476
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2477
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2478
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2479
	bindWithArguments:#('smalltalk' 'c++' 'c')
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2480
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2481
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2482
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2483
subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2484
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2485
     Words are separated by whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2486
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2487
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2488
    ^ self asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2489
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2490
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2491
     'hello world, this is smalltalk' subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2492
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2493
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2494
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2495
subStrings:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2496
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2497
     Words are separated by separatorCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2498
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2499
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2500
    ^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2501
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2502
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2503
     'foo:bar:baz:smalltalk' subStrings:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2504
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2505
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2506
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2507
trimSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2508
    "return a copy of the receiver without leading and trailing whiteSpace"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2509
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2510
    ^ self withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2511
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2512
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2513
!CharacterArray methodsFor:'character searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2514
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2515
includesMatchCharacters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2516
    "return true if the receiver includes any meta characters (i.e. $* or $#) 
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2517
     for match operations; false if not.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2518
     Here, do not care for $\ escapes"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2519
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2520
    ^ self includesAny:'*#['
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2521
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2522
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2523
     '*foo' includesMatchCharacters   
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2524
     '\*foo' includesMatchCharacters  
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2525
     '\*foo' includesUnescapedMatchCharacters  
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2526
     '*foo' includesMatchCharacters   
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2527
     '\\*foo' includesMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2528
     'foo*' includesMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2529
     'foo\*' includesMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2530
     'foo\' includesMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2531
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2532
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2533
    "Modified: 2.4.1997 / 18:12:34 / cg"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2534
!
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2535
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2536
includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2537
    "return true if the receiver really includes any meta characters (i.e. $* or $#) 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2538
     for match operations; false if not.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2539
     Here, care for $\ escapes"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2540
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2541
    |idx sz specialChars escape|
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2542
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2543
    idx := 1.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2544
    sz := self size.
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2545
    specialChars := '*#[\'.
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2546
    (escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2547
        specialChars := specialChars copy.
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2548
        specialChars at:specialChars size put:escape
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2549
    ].
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2550
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2551
    [true] whileTrue:[
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2552
        idx := self indexOfAny:specialChars startingAt:idx.
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2553
        idx == 0 ifTrue:[^ false].
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2554
        (self at:idx) == escape ifFalse:[^ true].
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2555
        idx := idx + 2.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2556
        idx > sz ifTrue:[^ false].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2557
    ].    
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2558
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2559
    "
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2560
     '*foo' includesUnescapedMatchCharacters    
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2561
     '\*foo' includesUnescapedMatchCharacters 
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2562
     '\\foo' includesUnescapedMatchCharacters  
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  2563
     '\\\$foo' includesUnescapedMatchCharacters  
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2564
     '*foo' includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2565
     '\\*foo' includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2566
     'foo*' includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2567
     'foo\*' includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2568
     'foo\' includesUnescapedMatchCharacters
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2569
    "
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2570
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2571
    "Modified: 2.4.1997 / 17:08:52 / cg"
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2572
    "Created: 2.4.1997 / 17:23:26 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2573
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2574
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2575
indexOfControlCharacterStartingAt:startIndex
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2576
    "return the index of the next control character;
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2577
     starting the search at startIndex, searching forward;
3668
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2578
     that is a character with asciiValue < 32.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2579
     Return 0 if none is found."
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2580
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2581
    |start  "{ Class: SmallInteger }"
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2582
     mySize "{ Class: SmallInteger }"|
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2583
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2584
    start := startIndex.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2585
    mySize := self size.
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2586
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2587
    start to:mySize do:[:index |
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2588
        (self at:index) isControlCharacter ifTrue:[^ index]
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2589
    ].
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2590
    ^ 0
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2591
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2592
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2593
     'hello world' asTwoByteString            indexOfControlCharacterStartingAt:1
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2594
     'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2595
    "
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2596
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2597
    "Modified: / 21.7.1998 / 17:25:07 / cg"
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2598
!
76271941f044 added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
  2599
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2600
indexOfNonSeparatorStartingAt:startIndex
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2601
    "return the index of the next non-whitespace character,
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2602
     starting the search at startIndex, searching forward;
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2603
     return 0 if no non-separator was found"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2604
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2605
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2606
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2607
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2608
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2609
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2610
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2611
    start to:mySize do:[:index |
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2612
        (self at:index) isSeparator ifFalse:[^ index]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2613
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2614
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2615
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2616
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2617
     '    hello world' indexOfNonSeparatorStartingAt:1 
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2618
     '    ' indexOfNonSeparatorStartingAt:1            
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2619
     'a   ' indexOfNonSeparatorStartingAt:2            
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2620
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2621
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2622
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2623
     |s index1 index2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2624
     s := '   foo    bar      baz'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2625
     index1 := s indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2626
     index2 := s indexOfSeparatorStartingAt:index1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2627
     s copyFrom:index1 to:index2 - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2628
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2629
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2630
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2631
indexOfSeparator
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2632
    "return the index of the first whitespace character;
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2633
     starting the search at the beginning, searching forward;
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2634
     return 0 if no separator was found"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2635
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2636
    ^ self indexOfSeparatorStartingAt:1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2637
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2638
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2639
     'hello world' indexOfSeparator 
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2640
     'helloworld' indexOfSeparator  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2641
     'hello   ' indexOfSeparator    
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2642
     '   hello' indexOfSeparator    
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2643
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2644
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2645
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2646
indexOfSeparatorStartingAt:startIndex
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2647
    "return the index of the next whitespace character,
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2648
     starting the search at startIndex, searching forward;
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2649
     return 0 if no separator was found"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2650
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2651
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2652
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2653
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2654
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2655
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2656
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2657
    start to:mySize do:[:index |
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2658
        (self at:index) isSeparator ifTrue:[^ index]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2659
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2660
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2661
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2662
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2663
     'hello world' indexOfSeparatorStartingAt:3   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2664
     ' hello world' indexOfSeparatorStartingAt:3  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2665
     'hello world ' indexOfSeparatorStartingAt:3  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2666
     'hello world ' indexOfSeparatorStartingAt:6  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2667
     'hello world ' indexOfSeparatorStartingAt:7  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2668
     'helloworld ' indexOfSeparatorStartingAt:7   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2669
     'helloworld' indexOfSeparatorStartingAt:7   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2670
    "
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2671
!
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2672
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2673
lastIndexOfSeparator
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2674
    "return the last index of the whitespace character.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2675
     (i.e. start the search at the end and search backwards);
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2676
     Returns 0 if no separator is found."
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2677
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2678
    ^ self lastIndexOfSeparatorStartingAt:(self size)
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2679
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2680
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2681
     'hello world' lastIndexOfSeparator  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2682
     'helloworld' lastIndexOfSeparator      
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2683
     'hel lo wor ld' lastIndexOfSeparator   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2684
     'hel   ' lastIndexOfSeparator 6  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2685
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2686
!
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2687
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2688
lastIndexOfSeparatorStartingAt:startIndex
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2689
    "return the index of the previous whitespace character,
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2690
     starting the search at startIndex (and searching backwards);
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2691
     returns 0 if no separator was found"
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2692
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2693
    |start  "{ Class: SmallInteger }"
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2694
     mySize "{ Class: SmallInteger }"|
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2695
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2696
    start := startIndex.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2697
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2698
    start to:1 by:-1 do:[:index |
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2699
        (self at:index) isSeparator ifTrue:[^ index]
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  2700
    ].
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2701
    ^ 0
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2702
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2703
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2704
     'hello world' lastIndexOfSeparatorStartingAt:3
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2705
     'hello world' lastIndexOfSeparatorStartingAt:7
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2706
     'helloworld' lastIndexOfSeparatorStartingAt:7 
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2707
     ' helloworld' lastIndexOfSeparatorStartingAt:7 
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  2708
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2709
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2710
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2711
!CharacterArray methodsFor:'comparing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2712
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2713
< something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2714
    "Compare the receiver with the argument and return true if the
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2715
     receiver is less than the argument. Otherwise return false.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2716
     This comparison is based on the elements ascii code - 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2717
     i.e. upper/lowercase & national characters are NOT treated specially."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2718
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2719
    ^ (something > self)
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2720
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2721
    "Modified: 22.4.1996 / 15:54:54 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2722
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2723
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2724
<= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2725
    "Compare the receiver with the argument and return true if the
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2726
     receiver is less than or equal to the argument. Otherwise return false.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2727
     This comparison is based on the elements ascii code - 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2728
     i.e. upper/lowercase & national characters are NOT treated specially."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2729
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2730
    ^ (self > something) not
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2731
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2732
    "Modified: 22.4.1996 / 15:54:56 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2733
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2734
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2735
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2736
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2737
     receiver is equal to the argument. Otherwise return false.
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2738
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2739
     This compare does NOT ignore case differences, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2740
     therefore 'foo' = 'Foo' will return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2741
     Since this is incompatible to ST-80 (at least, V2.x) , this may change."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2742
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2743
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2744
     otherSize |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2745
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2746
    aString species == self species ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2747
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2748
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2749
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2750
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2751
    1 to:mySize do:[:index |
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2752
        (self at:index) = (aString at:index) ifFalse:[^ false].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2753
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2754
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2755
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2756
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2757
     'foo' = 'Foo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2758
     'foo' = 'bar'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2759
     'foo' = 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2760
    "
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2761
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2762
    "Modified: 22.4.1996 / 15:53:58 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2763
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2764
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2765
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2766
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2767
     receiver is greater than the argument. Otherwise return false.
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2768
     This comparison is based on the elements ascii code - 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2769
     i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2770
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2771
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2772
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2773
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2774
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2775
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2776
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2777
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2778
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2779
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2780
    1 to:n do:[:index |
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2781
        c1 := self at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2782
        c2 := aString at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2783
        c1 > c2 ifTrue:[^ true].
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2784
        c1 < c2 ifTrue:[^ false].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2785
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2786
    ^ mySize > otherSize
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2787
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2788
    "Modified: 22.4.1996 / 15:55:00 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2789
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2790
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2791
>= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2792
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2793
     receiver is greater than or equal to the argument.
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2794
     Otherwise return false.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2795
     This comparison is based on the elements ascii code - 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2796
     i.e. upper/lowercase & national characters are NOT treated specially."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2797
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2798
    ^ (something > self) not
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2799
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2800
    "Modified: 22.4.1996 / 15:55:03 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2801
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2802
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2803
compareWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2804
    "Compare the receiver with the argument and return 1 if the receiver is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2805
     greater, 0 if equal and -1 if less than the argument. 
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2806
     This comparison is based on the elements ascii code - 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2807
     i.e. upper/lowercase & national characters are NOT treated specially.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2808
     'foo' compareWith: 'Foo' will return 1.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2809
     while 'foo' sameAs:'Foo' will return true"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2810
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2811
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2812
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2813
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2814
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2815
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2816
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2817
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2818
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2819
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2820
    1 to:n do:[:index |
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2821
        c1 := self at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2822
        c2 := aString at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2823
        c1 > c2 ifTrue:[^ 1].
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2824
        c1 < c2 ifTrue:[^ -1].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2825
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2826
    mySize > otherSize ifTrue:[^ 1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2827
    mySize < otherSize ifTrue:[^ -1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2828
    ^ 0
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2829
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2830
    "Modified: 22.4.1996 / 15:56:07 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2831
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2832
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2833
hash
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2834
    "return an integer useful as a hash-key"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2835
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2836
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2837
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2838
    REGISTER unsigned g, val;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2839
    REGISTER unsigned char *cp, *cp0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2840
    int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2841
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  2842
    cp = __stringVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  2843
    l = __stringSize(self);
3987
b3a2a7377640 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3985
diff changeset
  2844
    if (__qClass(self) != @global(String)) {
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2845
        int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2846
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2847
        cp += n;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2848
        l -= n;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2849
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2850
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2851
    /*
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2852
     * this is the dragon-book algorithm 
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2853
     */
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2854
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2855
    val = 0;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2856
    switch (l) {
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2857
    default:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2858
        for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2859
            val = (val << 4) + *cp;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2860
            if (g = (val & 0xF0000000)) {
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2861
                val ^= g >> 24;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2862
                val ^= g;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2863
            }
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2864
        }
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2865
        break;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2866
    case 7:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2867
        val = cp[6] << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2868
    case 6:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2869
        val = (val + cp[5]) << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2870
    case 5:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2871
        val = (val + cp[4]) << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2872
    case 4:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2873
        val = (val + cp[3]) << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2874
    case 3:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2875
        val = (val + cp[2]) << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2876
    case 2:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2877
        val = (val + cp[1]) << 4;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2878
    case 1:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2879
        val = val + cp[0];
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2880
    case 0:
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2881
        break;
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2882
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2883
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2884
    /*
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2885
     * multiply by large prime to spread values
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2886
     * This speeds up Set and Dictionary by a factor of 10!
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2887
     */
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2888
    val *= 31415821;
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2889
    RETURN ( __MKSMALLINT(val & 0x3fffffff));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2890
%}
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3926
diff changeset
  2891
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2892
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2893
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2894
sameAs:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2895
    "Compare the receiver with the argument like =, but ignore
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2896
     case differences. 
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2897
     Return true or false."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2898
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2899
    |mySize "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2900
     otherSize c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2901
3195
0a1a7a4c6184 oops- sameAs returned self instead of true
Claus Gittinger <cg@exept.de>
parents: 3073
diff changeset
  2902
    self == aString ifTrue:[^ true].
2581
d06e3bbfc294 faster #sameAs: if string is identical
Claus Gittinger <cg@exept.de>
parents: 2561
diff changeset
  2903
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2904
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2905
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2906
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2907
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2908
    1 to:mySize do:[:index |
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2909
        c1 := self at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2910
        c2 := aString at:index.
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2911
        c1 == c2 ifFalse:[
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2912
            c1 asLowercase = c2 asLowercase ifFalse:[^ false].
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2913
        ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2914
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2915
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2916
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2917
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2918
     'foo' sameAs: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2919
     'foo' sameAs: 'bar' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2920
     'foo' sameAs: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2921
    "
1252
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2922
105280fd8d72 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1250
diff changeset
  2923
    "Modified: 22.4.1996 / 15:56:17 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2924
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2925
5242
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2926
sameAs:aString ignoreCase:ignoreCase
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2927
    "Compare the receiver with the argument.
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2928
     If ignoreCase is true, this is the same as #sameAs:,
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2929
     if false, this is the same as #=."
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2930
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2931
    ignoreCase ifTrue:[
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2932
        ^ self sameAs:aString
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2933
    ].
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2934
    ^ self = aString
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2935
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2936
    "
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2937
     'foo' sameAs:'Foo' ignoreCase:false  
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2938
     'foo' sameAs:'foo' ignoreCase:true   
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2939
    "
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2940
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2941
!
0da078635576 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5230
diff changeset
  2942
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2943
sameCharacters:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2944
    "count & return the number of characters which are the same
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2945
     (ignoring case) in the receiver and the argument, aString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2946
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2947
    |n "{ Class: SmallInteger }"
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  2948
     c1 c2 cnt|
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2949
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2950
    n := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2951
    n := n min:(aString size).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2952
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2953
    cnt := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2954
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2955
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2956
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2957
	((c1 == c2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2958
	or:[c1 asLowercase = c2 asLowercase]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2959
	    cnt := cnt + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2960
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2961
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2962
    ^ cnt
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2963
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2964
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2965
     'foobarbaz' sameCharacters: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2966
     'foobarbaz' sameCharacters: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2967
     'foobarbaz' sameCharacters: 'baz'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2968
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2969
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2970
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2971
!CharacterArray methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2972
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2973
asArrayOfSubstrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2974
    "return an array of substrings from the receiver, interpreting
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2975
     separators (i.e. spaces & newlines) as word-delimiters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2976
     This is a compatibility method - the actual work is done in
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2977
     asCollectionOfWords."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2978
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2979
    ^ self asCollectionOfWords asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2980
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2981
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2982
     '1 one two three four 5 five' asArrayOfSubstrings  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2983
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2984
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2985
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2986
asCollectionOfLines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2987
    "return a collection containing the lines (separated by cr) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2988
     of the receiver. If multiple cr's occur in a row, the result will
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2989
     contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2990
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2991
    ^ self asCollectionOfSubstringsSeparatedBy:Character cr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2992
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2993
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2994
     '1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2995
     '1 one\\\\2 two\3 three' withCRs asCollectionOfLines  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2996
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2997
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2998
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2999
asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3000
    "return a collection containing the lines (separated by aCharacter) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3001
     of the receiver. If aCharacter occurs multiple times in a row, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3002
     the result will contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3003
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3004
    |lines myClass
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3005
     numberOfLines "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3006
     startIndex    "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3007
     stopIndex     "{ Class:SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3008
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3009
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3010
     count first, to avoid regrowing of the OC
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3011
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3012
    numberOfLines := (self occurrencesOf:aCharacter) + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3013
    lines := OrderedCollection new:numberOfLines.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3014
    myClass := self species.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3015
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3016
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3017
    1 to:numberOfLines do:[:lineNr |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3018
	stopIndex := self indexOf:aCharacter startingAt:startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3019
	stopIndex == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3020
	    stopIndex := self size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3021
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3022
	    stopIndex := stopIndex - 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3023
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3024
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3025
	(stopIndex < startIndex) ifTrue: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3026
	    lines add:(myClass new:0)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3027
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3028
	    lines add:(self copyFrom:startIndex to:stopIndex)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3029
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3030
	startIndex := stopIndex + 2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3031
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3032
    ^ lines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3033
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3034
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3035
     '1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3036
     '1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3037
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3038
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3039
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3040
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3041
    "return a collection containing the words (separated by any character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3042
     from aCollectionOfSeparators) of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3043
     This allows breaking up strings using any character as separator."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3044
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3045
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3046
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3047
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3048
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3049
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3050
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3051
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3052
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3053
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3054
	"skip multiple separators"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3055
	[aCollectionOfSeparators includes:(self at:start)] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3056
	    start := start + 1 .
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3057
	    start > mySize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3058
		^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3059
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3060
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3061
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3062
	stop := self indexOfAny:aCollectionOfSeparators startingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3063
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3064
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3065
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3066
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3067
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3068
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3069
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3070
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3071
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3072
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3073
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3074
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3075
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3076
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3077
     'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3078
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3079
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3080
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3081
asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3082
    "return a collection containing the words (separated by whitespace) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3083
     of the receiver. Multiple occurences of whitespace characters will
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3084
     be treated like one - i.e. whitespace is skipped."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3085
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3086
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3087
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3088
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3089
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3090
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3091
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3092
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3093
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3094
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3095
	start := self indexOfNonSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3096
	start == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3097
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3098
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3099
	stop := self indexOfSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3100
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3101
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3102
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3103
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3104
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3105
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3106
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3107
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3108
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3109
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3110
     'hello world isnt this nice' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3111
     '    hello    world   isnt   this   nice  ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3112
     'hello' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3113
     '' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3114
     '      ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3115
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3116
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3117
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3118
asComposedText
1312
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3119
    "ST-80 compatibility 
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3120
     - ST/X does not (as today) support composedTexts."
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3121
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3122
    ^ ComposedText fromString:self
1312
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3123
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3124
    "Modified: 27.4.1996 / 13:30:30 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3125
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3126
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3127
asFilename
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3128
    "return a Filename with pathname taken from the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3129
1423
d9f177657164 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3130
    ^ Filename named:self string
d9f177657164 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3131
d9f177657164 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3132
    "Modified: 20.5.1996 / 09:38:15 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3133
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3134
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3135
asFixedPoint
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3136
    "read a fixedPoint number from the receiver.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3137
     Notice, that errors may occur during the read, so you better
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3138
     setup some signal handler when using this method."
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3139
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3140
    ^ FixedPoint readFromString:self
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3141
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3142
    "
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3143
     '0.123' asFixedPoint    
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3144
     '12345' asFixedPoint    
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3145
     '(1/5)' asFixedPoint
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3146
     'foo' asFixedPoint
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3147
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFixedPoint] 
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3148
    "
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3149
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3150
    "Modified: / 25.10.1997 / 15:19:00 / cg"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3151
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3152
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3153
asFixedPoint:scale
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3154
    "read a fixedPoint number with scale number of post-decimal digits
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3155
     from the receiver. Scale controls the number of displayed digits,
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3156
     not the number of actually valid digits.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3157
     Notice, that errors may occur during the read, so you better
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3158
     setup some signal handler when using this method."
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3159
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3160
    ^ (FixedPoint readFromString:self) scale:scale
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3161
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3162
    "
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3163
     '0.123' asFixedPoint:2     
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3164
     '123456' asFixedPoint:2    
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3165
     ('3.14157' asFixedPoint:1) asFixedPoint:5    
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3166
    "
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3167
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3168
    "Modified: / 25.10.1997 / 15:21:57 / cg"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3169
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
  3170
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3171
asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3172
    "read a float number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3173
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3174
     setup some signal handler when using this method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3175
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3176
    ^ (Number readFromString:self) asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3177
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3178
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3179
     '0.123' asFloat 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3180
     '12345' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3181
     '(1/5)' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3182
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3183
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3184
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3185
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3186
asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3187
    "read an integer from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3188
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3189
     setup some signal handler when using this method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3190
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3191
    ^ Integer readFromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3192
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3193
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3194
     '12345678901234567890' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3195
     '-1234' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3196
     '0.123' asInteger   <- reader stops at ., returning 0 here
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3197
     '0.123' asNumber    <- returns what you expect
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3198
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3199
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3200
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3201
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3202
asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3203
    "return a copy of myself in lowercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3204
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3205
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3206
     mySize "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3207
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3208
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3209
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3210
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3211
	newStr at:i put:(self at:i) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3212
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3213
    ^ newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3214
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3215
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3216
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3217
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3218
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3219
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3220
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3221
asLowercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3222
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3223
     converted to lowercase."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3224
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3225
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3226
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3227
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3228
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3229
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3230
	newString at:1 put:(newString at:1) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3231
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3232
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3233
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3234
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3235
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3236
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3237
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3238
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3239
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3240
asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3241
    "read a number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3242
     Notice, that (in contrast to ST-80) errors may occur during the read, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3243
     so you better setup some signal handler when using this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3244
     This may change if ANSI specifies it."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3245
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3246
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3247
"/  ^ Number readFromString:self onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3248
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3249
    ^ Number readFromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3250
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3251
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3252
     '123'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3253
     '123.567' asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3254
     '(5/6)'   asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3255
     'foo'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3256
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3257
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3258
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3259
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3260
asNumberFromFormatString:ignored
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3261
    "read a number from the receiver, ignoring any nonDigit characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3262
     This is typically used to convert from strings which include
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3263
     dollar-signs or millenium digits. However, this method also ignores
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3264
     the decimal point (if any) and therefore should be used with care."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3265
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3266
    |tempString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3267
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3268
    tempString := self collect:[:char | char isDigit].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3269
    ^ Number readFromString:tempString onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3270
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3271
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3272
     'USD 123' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3273
     'DM 123'  asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3274
     '123'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3275
     '123.567' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3276
     '(5/6)'   asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3277
     'foo'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3278
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3279
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3280
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3281
asSingleByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3282
    "return the receiver converted to a 'normal' string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3283
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3284
    ^ String fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3285
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3286
2732
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3287
asSingleByteStringReplaceInvalidWith:replacementCharacter
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3288
    "return the receiver converted to a 'normal' string,
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3289
     with invalid characters replaced by replacementCharacter.
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3290
     Can be used to convert from 16-bit strings to 8-bit strings
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3291
     and replace characters above code-255 with some replacement."
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3292
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3293
    |newString|
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3294
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3295
    newString := String new:(self size).
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3296
    1 to:self size do:[:idx |
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3297
        |char|
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3298
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3299
        char := self at:idx.
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3300
        char asciiValue <= 16rFF ifTrue:[
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3301
            newString at:idx put:char
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3302
        ] ifFalse:[
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3303
            newString at:idx put:replacementCharacter
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3304
        ].
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3305
    ].
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3306
    ^ newString
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3307
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3308
    "Created: 30.6.1997 / 13:02:14 / cg"
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3309
!
79d06cdc7428 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2731
diff changeset
  3310
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3311
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3312
    "return myself - I am a string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3313
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3314
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3315
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3316
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3317
asStringCollection
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3318
    "return a collection of lines from myself."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3319
1393
7afc79a4cc11 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1388
diff changeset
  3320
    ^ StringCollection from:self "string"
7afc79a4cc11 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1388
diff changeset
  3321
7afc79a4cc11 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1388
diff changeset
  3322
    "Modified: 13.5.1996 / 20:36:59 / cg"
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3323
!
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3324
1434
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3325
asSymbol
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3326
    "return a unique symbol with the name taken from my characters.
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3327
     The receiver must be a singleByte-String; twoByteSymbols are
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3328
     (currently) not allowed."
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3329
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3330
    ^ self string asSymbol
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3331
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3332
    "Created: 22.5.1996 / 15:56:11 / cg"
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3333
!
a317ba02d685 allow aText asSymbol
Claus Gittinger <cg@exept.de>
parents: 1429
diff changeset
  3334
1435
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3335
asSymbolIfInterned
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3336
    "if a symbol with the receivers characters is already known, return it.
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3337
     Otherwise, return nil. This can be used to query for an existing
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3338
     symbol and is the same as
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3339
        self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3340
     but slightly faster, since the symbol lookup operation is only
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3341
     performed once.
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3342
     The receiver must be a singleByte-String; twoByteSymbols are
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3343
     (currently) not allowed."
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3344
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3345
    ^ self string asSymbolIfInterned
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3346
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3347
    "Created: 22.5.1996 / 16:37:04 / cg"
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3348
!
3ee1fde2aa58 allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents: 1434
diff changeset
  3349
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3350
asText
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3351
    "return a Text-object (collection of lines) from myself."
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3352
4974
cde2ee5adeb0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4890
diff changeset
  3353
    Text isNil ifTrue:[^ self].
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3354
    ^ Text fromString:self
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3355
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3356
    "Created: 12.5.1996 / 10:41:14 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3357
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3358
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3359
asTwoByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3360
    "return the receiver converted to a two-byte string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3361
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3362
    ^ TwoByteString fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3363
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3364
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3365
asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3366
    "return a copy of myself in uppercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3367
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3368
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3369
     mySize "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3370
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3371
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3372
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3373
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3374
	newStr at:i put:(self at:i) asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3375
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3376
    ^ newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3377
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3378
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3379
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3380
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3381
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3382
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3383
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3384
asUppercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3385
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3386
     converted to uppercase."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3387
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3388
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3389
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3390
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3391
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3392
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3393
	newString at:1 put:(newString at:1) asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3394
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3395
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3396
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3397
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3398
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3399
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3400
     'HelloWorld' asUppercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3401
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3402
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3403
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3404
string
1312
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3405
    "return the receiver - for ST-80 compatibility"
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3406
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3407
    ^ self
1312
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3408
0003988bb066 commentary
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  3409
    "Modified: 27.4.1996 / 13:29:30 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3410
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3411
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3412
tokensBasedOn:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3413
    "this is an ST-80 alias for the ST/X method
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3414
	asCollectionOfSubstringsSeparatedBy:"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3415
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3416
    ^ self asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3417
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3418
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3419
     'hello:world:isnt:this nice' tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3420
     'foo,bar,baz' tokensBasedOn:$,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3421
     '/etc/passwd' asFilename readStream nextLine tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3422
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3423
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3424
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3425
!CharacterArray methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3426
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3427
, aStringOrCharacter
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3428
    "redefined to allow characters and mixed strings to be appended.
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3429
     This is nonStandard, but convenient"
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3430
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3431
    |myWidth otherWidth|
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3432
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3433
    aStringOrCharacter isCharacter ifTrue:[
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3434
        ^ self , aStringOrCharacter asString
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3435
    ].
1396
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3436
    aStringOrCharacter isText ifTrue:[
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3437
        ^ aStringOrCharacter concatenateFromString:self
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3438
    ].
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3439
    aStringOrCharacter isString ifTrue:[
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3440
        (otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3441
            otherWidth > myWidth ifTrue:[
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3442
                ^ (aStringOrCharacter species fromString:self) , aStringOrCharacter
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3443
            ].
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3444
            ^ self , (self species fromString:aStringOrCharacter)
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3445
        ].
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3446
    ].
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3447
    ^ super , aStringOrCharacter
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3448
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3449
    "
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3450
     'hello' , $1    
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3451
     'hello' , '1'   
1411
a3b3ab3044c6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1396
diff changeset
  3452
     'hello' , (' world' asText allBold) 
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3453
     'hello' , (JISEncodedString fromString:' world') 
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3454
     (JISEncodedString fromString:'hello') , ' world'
1411
a3b3ab3044c6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1396
diff changeset
  3455
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1411
diff changeset
  3456
     Transcript showCR:
1411
a3b3ab3044c6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1396
diff changeset
  3457
         (Text string:'hello' emphasis:#italic) , (Text string:' world' emphasis:#bold) 
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3458
    "
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3459
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3460
    "Modified: 28.6.1997 / 00:13:17 / cg"
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3461
!
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  3462
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3463
concatenate:string1 and:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3464
    "return the concatenation of myself and the arguments, string1 and string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3465
     This is equivalent to self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3466
     - generated by compiler when such a construct is detected and the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3467
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3468
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3469
    ^ self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3470
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3471
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3472
concatenate:string1 and:string2 and:string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3473
    "return the concatenation of myself and the string arguments.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3474
     This is equivalent to self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3475
     - generated by compiler when such a construct is detected and the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3476
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3477
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3478
    ^ self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3479
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3480
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3481
!CharacterArray methodsFor:'displaying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3482
2762
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3483
displayOn:aGC x:x y:y from:start to:stop
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3484
    "display the receiver on a GC"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3485
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3486
    "q&d hack"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3487
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3488
    (self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3489
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3490
    "Modified: 12.5.1996 / 12:49:33 / cg"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3491
!
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3492
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3493
displayOn:aGc x:x y:y opaque:opq
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3494
    "display the receiver in a graphicsContext - this method allows
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3495
     strings to be used like DisplayObjects."
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3496
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3497
    |s|
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3498
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3499
    s := self string.
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3500
    opq ifTrue:[
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3501
        aGc displayOpaqueString:s x:x y:y.
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3502
    ] ifFalse:[
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3503
        aGc displayString:s x:x y:y.
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3504
    ].
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3505
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3506
    "Modified: 11.5.1996 / 14:42:48 / cg"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3507
!
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  3508
2762
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3509
displayOpaqueOn:aGC x:x y:y from:start to:stop
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3510
    "display the receiver on a GC"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3511
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3512
    "q&d hack"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3513
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3514
    (self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3515
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3516
    "Created: 12.5.1996 / 12:29:37 / cg"
59c71fa02ba2 displayOn / displayOpaqueOn fixed
ca
parents: 2760
diff changeset
  3517
    "Modified: 12.5.1996 / 12:49:19 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3518
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3519
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3520
!CharacterArray methodsFor:'emphasis'!
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3521
1396
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3522
emphasis
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3523
    "return the emphasis.
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3524
     Since characterArrays do not hold any emphasis information,
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3525
     nil (no emphasis) is returned here."
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3526
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3527
    ^ RunArray new:self size withAll:nil
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3528
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3529
    "Created: 14.5.1996 / 13:58:58 / cg"
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3530
!
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3531
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3532
emphasisAt:characterIndex
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3533
    "return the emphasis at some index.
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3534
     Since characterArrays do not hold any emphasis information,
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3535
     nil (no emphasis) is returned here."
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3536
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3537
    ^ nil
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3538
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3539
    "Created: 11.5.1996 / 14:13:27 / cg"
1396
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3540
!
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3541
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3542
emphasisCollection
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3543
    "return the emphasis.
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3544
     Since characterArrays do not hold any emphasis information,
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3545
     nil (no emphasis) is returned here."
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3546
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3547
    ^ RunArray new:(self size)
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3548
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3549
    "Created: 14.5.1996 / 13:58:58 / cg"
5b5386311dbd concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
  3550
    "Modified: 14.5.1996 / 15:02:29 / cg"
3404
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3551
!
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3552
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3553
emphasizeAllWith:emphasis
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3554
    ^ self asText emphasizeAllWith:emphasis
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3555
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3556
    "
5a9ab54bcbd5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3337
diff changeset
  3557
     Transcript showCR:('hello' emphasizeAllWith:#bold)
3599
fea09a812f55 comment
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  3558
     Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red))
fea09a812f55 comment
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  3559
     Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red))
fea09a812f55 comment
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  3560
    "
fea09a812f55 comment
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  3561
fea09a812f55 comment
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  3562
    "Modified: / 17.6.1998 / 12:51:44 / cg"
5097
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3563
!
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3564
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3565
makeSelectorBoldIn:aClass
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3566
    "the receiver represents some source code for
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3567
     a method in aClass.
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3568
     Change myself to boldify the selector.
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3569
     Not yet implemented (could easily use the syntaxHighlighter
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3570
     for this ...)"
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3571
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3572
    ^ self
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3573
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3574
    "Modified: / 13.12.1999 / 21:49:11 / cg"
4aa597a8a724 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4989
diff changeset
  3575
    "Created: / 13.12.1999 / 21:49:24 / cg"
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3576
! !
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  3577
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3578
!CharacterArray methodsFor:'encoding/decoding'!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3579
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3580
decodeFrom:encodingSymbol
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3581
    "given the receiver encoded as described by encodingSymbol, 
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3582
     convert it into internal ST/X encoding and return a corresponding CharacterArray.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3583
     Currently, only a few encodings are supported 
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3584
     (and those are untested/incomplete):
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3585
        #euc
997
6c7f1815ed02 more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents: 991
diff changeset
  3586
        #jis7
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  3587
        #sjis
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3588
        #mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3589
        #msdos
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3590
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3591
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3592
    |newString table|
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3593
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3594
    encodingSymbol == #'x-jis7' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3595
        ^ JISEncodedString decodeFromJIS7:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3596
    ].
2758
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
  3597
    encodingSymbol == #'x-iso2022-jp' ifTrue:[
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
  3598
        ^ JISEncodedString decodeFromJIS7:self
31e822490f77 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2757
diff changeset
  3599
    ].
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3600
    encodingSymbol == #'iso2022-jp' ifTrue:[
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3601
        ^ JISEncodedString decodeFromJIS7:self
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3602
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3603
    encodingSymbol == #'x-sjis' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3604
        ^ JISEncodedString decodeFromSJIS:self
2720
98c21d9a07c0 allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents: 2692
diff changeset
  3605
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3606
    encodingSymbol == #'x-shift-jis' ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3607
        ^ JISEncodedString decodeFromSJIS:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3608
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3609
    encodingSymbol == #'x-euc-jp' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3610
        ^ JISEncodedString decodeFromEUC:self
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3611
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3612
    encodingSymbol == #big5 ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3613
        ^ BIG5EncodedString decodeFromBIG5:self
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3614
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3615
    encodingSymbol == #gb2312 ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3616
        ^ GBEncodedString decodeFromGB:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3617
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3618
    encodingSymbol == #'x-euc-gb' ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3619
        ^ GBEncodedString decodeFromEUC:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3620
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3621
    encodingSymbol == #'x-euc-kr' ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3622
        ^ KSCEncodedString decodeFromEUC:self
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3623
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3624
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3625
    encodingSymbol == #ucs2 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3626
        ^ UnicodeString decodeFromUCS2:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3627
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3628
    encodingSymbol == #ucs4 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3629
        ^ UnicodeString decodeFromUCS4:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3630
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3631
    encodingSymbol == #utf7 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3632
        ^ UnicodeString decodeFromUTF7:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3633
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3634
    encodingSymbol == #utf8 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3635
        ^ UnicodeString decodeFromUTF8:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3636
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3637
    encodingSymbol == #utf16 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3638
        ^ UnicodeString decodeFromUTF16:self
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3639
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3640
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3641
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3642
    "/ soon obsolete ...
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3643
    encodingSymbol == #jis7 ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3644
        ^ JISEncodedString decodeFromJIS7:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3645
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3646
    encodingSymbol == #sjis ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3647
        ^ JISEncodedString decodeFromSJIS:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3648
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3649
    encodingSymbol == #euc ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3650
        ^ JISEncodedString decodeFromEUC:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3651
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3652
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3653
    encodingSymbol == #gb ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3654
        ^ GBEncodedString decodeFromGB:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3655
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3656
    encodingSymbol == #ksc ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3657
        ^ KSCEncodedString decodeFromKSC:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3658
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3659
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3660
    table := self class decoderTableFor:encodingSymbol.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3661
    table isNil ifTrue:[^ self].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3662
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3663
    newString := self class new:self size.
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3664
    newString replaceFrom:self translateBy:table.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3665
    newString = self ifTrue:[^ self].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3666
    ^ newString
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3667
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3668
    "Created: 22.2.1996 / 15:06:49 / cg"
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3669
    "Modified: 16.7.1997 / 13:45:33 / cg"
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3670
!
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3671
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3672
encodeForDisplayInto:encodingSymbol
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3673
    "given the receiver in internal ST/X encoding, 
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3674
     convert it into the format as described by encodingSymbol
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3675
     for display.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3676
     The receiver may contain roman characters in 0..255, which
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3677
     are translated according to the encodings roman translation.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3678
     For example: in JIS, roman $a is found at 16r2361.
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3679
    "
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3680
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3681
    |newString table|
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3682
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3683
    encodingSymbol isNil ifTrue:[^ self].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3684
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3685
    "/ notice: this method may not be moved to
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3686
    "/ concrete TwoByte classes; it is also invoked
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3687
    "/ to convert singleByte strings ...
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3688
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3689
    (encodingSymbol startsWith:'jis') ifTrue:[
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3690
        newString := JISEncodedString encodeRomans:self.
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3691
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3692
        "/ jisx0208.1983 has no half-width katakana
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3693
        (encodingSymbol startsWith:'jisx0208.1983') ifTrue:[
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3694
            newString := JISEncodedString encodeHalfWidthKatakana:newString.
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3695
        ].
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3696
        ^ newString
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3697
    ].
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3698
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3699
    (encodingSymbol startsWith:'big5') ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3700
        ^ BIG5EncodedString encodeRomans:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3701
    ].
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3702
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3703
    (encodingSymbol startsWith:'gb') ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3704
        ^ GBEncodedString encodeRomans:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3705
    ].
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3706
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3707
    (encodingSymbol startsWith:'ksc') ifTrue:[   
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3708
        ^ KSCEncodedString encodeRomans:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3709
    ].
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3710
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3711
    (encodingSymbol startsWith:'uni') ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3712
        ^ UnicodeString encodeRomans:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3713
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3714
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3715
    table := self class encoderTableFor:encodingSymbol.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3716
    table isNil ifTrue:[^ self].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3717
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3718
    newString := self class new:self size.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3719
    newString replaceFrom:self translateBy:table.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3720
    newString = self ifTrue:[^ self].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3721
    ^ newString
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3722
2742
3add77872fea care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
  3723
    "Modified: 2.7.1997 / 15:02:56 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3724
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3725
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3726
encodeInto:encodingSymbol
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3727
    "given the receiver in internal ST/X encoding, 
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3728
     convert it into the format as described by encodingSymbol
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3729
     and return a corresponding CharacterArray.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3730
     Currently, only a few encodings are supported 
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3731
     (and those are untested/incomplete):
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3732
        #x-euc-jp
2760
715d662449ea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2759
diff changeset
  3733
        #x-jis7 (== iso2022-jp)
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3734
        #x-sjis
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3735
        #x-shift-jis
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3736
        #big5
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3737
        #gb
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3738
        #mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3739
        #msdos
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3740
        #next
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3741
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3742
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3743
    |newString table|
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3744
1204
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
  3745
"/  self encoding storeString print. ' -> ' print. encodingSymbol storeString printNL.
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3746
1028
234d62b7f4fe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1027
diff changeset
  3747
    encodingSymbol isNil ifTrue:[^ self].
234d62b7f4fe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1027
diff changeset
  3748
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3749
    encodingSymbol == #'x-jis7' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3750
        ^ JISEncodedString encodeIntoJIS7:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3751
    ].
2759
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3752
    encodingSymbol == #'x-iso2022-jp' ifTrue:[
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3753
        ^ JISEncodedString encodeIntoJIS7:self
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3754
    ].
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3755
    encodingSymbol == #'iso2022-jp' ifTrue:[
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3756
        ^ JISEncodedString encodeIntoJIS7:self
1fbcf236b4ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2758
diff changeset
  3757
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3758
    encodingSymbol == #'x-sjis' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3759
        ^ JISEncodedString encodeIntoSJIS:self
1013
0e54ddc990cb more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents: 1012
diff changeset
  3760
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3761
    encodingSymbol == #'x-shift-jis' ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3762
        ^ JISEncodedString encodeIntoSJIS:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3763
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3764
    encodingSymbol == #'x-euc-jp' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3765
        ^ JISEncodedString encodeIntoEUC:self
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3766
    ].
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3767
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3768
    encodingSymbol == #big5 ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3769
        ^ BIG5EncodedString encodeIntoBIG5:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3770
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3771
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3772
    encodingSymbol == #gb2312 ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3773
        ^ GBEncodedString encodeIntoGB:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3774
    ].
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3775
    encodingSymbol == #'x-euc-gb' ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3776
        ^ GBEncodedString encodeIntoGB:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3777
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3778
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3779
    encodingSymbol == #'x-euc-kr' ifTrue:[
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3780
        ^ KSCEncodedString encodeIntoKSC:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3781
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3782
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3783
    encodingSymbol == #ucs2 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3784
        ^ UnicodeString encodeIntoUCS2:self
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3785
    ].
2733
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3786
    encodingSymbol == #ucs4 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3787
        ^ UnicodeString encodeIntoUCS4:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3788
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3789
    encodingSymbol == #utf7 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3790
        ^ UnicodeString encodeIntoUTF7:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3791
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3792
    encodingSymbol == #utf8 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3793
        ^ UnicodeString encodeIntoUTF8:self
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3794
    ].
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3795
    encodingSymbol == #utf16 ifTrue:[
e8734d3c9415 fixed BIG5 encoding stuff
Claus Gittinger <cg@exept.de>
parents: 2732
diff changeset
  3796
        ^ UnicodeString encodeIntoUTF16:self
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3797
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3798
2736
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3799
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3800
    "/ to be obsoleted ...
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3801
    encodingSymbol == #jis7 ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3802
        ^ JISEncodedString encodeIntoJIS7:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3803
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3804
    encodingSymbol == #sjis ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3805
        ^ JISEncodedString encodeIntoSJIS:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3806
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3807
    encodingSymbol == #euc ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3808
        ^ JISEncodedString encodeIntoEUC:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3809
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3810
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3811
    encodingSymbol == #gb ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3812
        ^ GBEncodedString encodeIntoGB:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3813
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3814
    encodingSymbol == #ksc ifTrue:[
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3815
        ^ KSCEncodedString encodeIntoKSC:self
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3816
    ].
840f97eb7b73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2735
diff changeset
  3817
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3818
    table := self class encoderTableFor:encodingSymbol.
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3819
    table isNil ifTrue:[^ self].
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3820
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3821
    newString := self class new:self size.
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3822
    newString replaceFrom:self translateBy:table.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3823
    newString = self ifTrue:[^ self].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3824
    ^ newString
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3825
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3826
    "Created: 22.2.1996 / 15:07:31 / cg"
2760
715d662449ea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2759
diff changeset
  3827
    "Modified: 16.7.1997 / 13:56:21 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3828
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3829
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3830
replaceFrom:aString decode:encoding 
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3831
    "this is an experimental interface - unfinished"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3832
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3833
    ^ self replaceFrom:aString translateBy:(self class decoderTableFor:encoding)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3834
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3835
    "Created: 20.10.1995 / 23:00:09 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3836
    "Modified: 22.2.1996 / 16:08:26 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3837
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3838
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3839
replaceFrom:aString encode:encoding 
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3840
    "this is an experimental interface - unfinished"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3841
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3842
    ^ self replaceFrom:aString translateBy:(self class encoderTableFor:encoding)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3843
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3844
    "Modified: 20.10.1995 / 23:08:16 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3845
    "Created: 22.2.1996 / 16:08:34 / cg"
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3846
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3847
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3848
replaceFrom:aString translateBy:encodingTable 
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3849
    "replace the receivers characters by translations coming from
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  3850
     an encoding table."
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3851
2520
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3852
    |mySize  "{ Class: SmallInteger }" 
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3853
     maxCode "{ Class: SmallInteger }"
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3854
     char 
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3855
     oldCode "{ Class: SmallInteger }"
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3856
     newCode|
1023
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  3857
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3858
    self replaceFrom:1 with:aString.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3859
    encodingTable isNil ifTrue:[^ self].
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3860
2520
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3861
    maxCode := encodingTable size.
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3862
    mySize := self size.
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3863
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3864
    1 to:mySize do:[:index |
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3865
        char := aString at:index.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3866
        oldCode := char asciiValue.
2520
4a7a2f2f0132 tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents: 2519
diff changeset
  3867
        oldCode >= maxCode ifFalse:[
1023
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  3868
            newCode := encodingTable at:(oldCode + 1).
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  3869
            newCode ~~ oldCode ifTrue:[
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  3870
                self at:index put:(Character value:newCode)
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  3871
            ]
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3872
        ]
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3873
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3874
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3875
    "Created: 22.2.1996 / 16:07:26 / cg"
2740
8649f17f9148 added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  3876
    "Modified: 1.7.1997 / 17:18:06 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3877
! !
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  3878
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3879
!CharacterArray methodsFor:'padded copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3880
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3881
centerPaddedTo:newSize
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3882
     "return a new string consisting of the receivers characters,
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3883
     plus spaces up to length and center the receivers characters in
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3884
     the resulting string.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3885
     If the receivers size is equal or greater than the length argument, 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3886
     the original receiver is returned unchanged."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3887
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3888
     ^ self centerPaddedTo:newSize with:(Character space)
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3889
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3890
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3891
     'foo' centerPaddedTo:10            
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3892
     123 printString centerPaddedTo:10 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3893
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3894
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3895
    "Created: 25.11.1995 / 10:53:57 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3896
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3897
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3898
centerPaddedTo:size with:padCharacter
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3899
    "return a new string of length size, which contains the receiver
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3900
     centered (i.e. padded on both sides).
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3901
     Characters are filled with padCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3902
     If the receivers size is equal or greater than the length argument, 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3903
     the original receiver is returned unchanged."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3904
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3905
    |len s|
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3906
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3907
    len := self size.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3908
    (len < size) ifTrue:[
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3909
	s := self species new:size withAll:padCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3910
	s replaceFrom:(size - len) // 2  + 1 with:self.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3911
	^ s
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3912
    ]
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3913
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3914
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3915
     'foo' centerPaddedTo:11 with:$.     
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3916
     'fooBar' centerPaddedTo:5 with:$.      
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3917
     123 printString centerPaddedTo:10 with:$.        
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3918
     (' ' , 123 printString) centerPaddedTo:10 with:$.        
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3919
     (Float pi printString) centerPaddedTo:15 with:(Character space)  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3920
     (Float pi printString) centerPaddedTo:15 with:$-           
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3921
     (' ' , Float pi class name) centerPaddedTo:15 with:$.     
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3922
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3923
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3924
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3925
decimalPaddedTo:size and:afterPeriod at:decimalCharacter
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3926
    "return a new string of overall length size, which contains the receiver
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3927
     aligned at the decimal-period column and afterPeriod characters to the right
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3928
     of the period. The periodCharacter is passed as arguments (allowing for US and European formats
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3929
     to be padded).
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3930
     If the receivers size is equal or greater than the length argument, 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3931
     the original receiver is returned unchanged.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3932
     (sounds complicated ? -> see examples below)."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3933
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3934
    ^ self 
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3935
	decimalPaddedTo:size 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3936
	and:afterPeriod 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3937
	at:decimalCharacter
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3938
	withLeft:(Character space)
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3939
	right:$0
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3940
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3941
    "                                                    
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3942
     '123' decimalPaddedTo:10 and:3 at:$.      -> '   123    '  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3943
     '123' decimalPaddedTo:10 and:3 at:$.      -> '   123.000'  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3944
     '123.' decimalPaddedTo:10 and:3 at:$.     -> '   123.000' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3945
     '123.1' decimalPaddedTo:10 and:3 at:$.    -> '   123.100'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3946
     '123.1' decimalPaddedTo:10 and:3 at:$.    -> '   123.1  ' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3947
     '123.123' decimalPaddedTo:10 and:3 at:$.  -> '   123.123'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3948
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3949
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3950
    "Created: 23.12.1995 / 13:11:52 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3951
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3952
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3953
decimalPaddedTo:size and:afterPeriod at:decimalCharacter withLeft:leftPadChar right:rightPadChar
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3954
    "return a new string of overall length size, which contains the receiver
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3955
     aligned at the decimal-period column and afterPeriod characters to the right
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3956
     of the period.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3957
     Characters on the left are filled with leftPadChar.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3958
     If rightPadChar is nil, characters on the right are filled with leftPadCharacter too;
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3959
     otherwise, if missing, a decimal point is added and right characters filled with this.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3960
     If the receivers size is equal or greater than the length argument, 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3961
     the original receiver is returned unchanged.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3962
     (sounds complicated ? -> see examples below)."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3963
5230
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3964
    |s idx n rest|
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3965
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3966
    idx := self indexOf:decimalCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3967
    idx == 0 ifTrue:[
5230
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3968
        "/
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3969
        "/ no decimal point found; adjust string to the left of the period column
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3970
        "/
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3971
        rightPadChar isNil ifTrue:[
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3972
            s := self , (self species new:afterPeriod + 1 withAll:leftPadChar)
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3973
        ] ifFalse:[
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3974
            s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar).
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3975
        ].
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3976
    ] ifFalse:[
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3977
5230
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3978
        "/ the number of after-decimalPoint characters
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3979
        n := self size - idx.
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3980
        rest := afterPeriod - n.
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3981
        rest > 0 ifTrue:[
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3982
            s := (self species new:rest withAll:(rightPadChar ? leftPadChar)).
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3983
        ] ifFalse:[
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3984
            s := ''
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3985
        ].
655c21ffe6cc care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents: 5221
diff changeset
  3986
        s := self , s.
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3987
    ].
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3988
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3989
    ^ s leftPaddedTo:size with:leftPadChar
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3990
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3991
    "                                                    
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3992
     '123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil     -> '   123    '  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3993
     '123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0      -> '   123.000'  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3994
     '123.' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0     -> '   123.000' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3995
     '123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0    -> '   123.100'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3996
     '123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil   -> '   123.1  ' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3997
     '123.123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0  -> '   123.123'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3998
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3999
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  4000
    "Modified: 23.12.1995 / 13:08:18 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  4001
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  4002
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4003
leftPaddedTo:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4004
    "return a new string of length size, which contains the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4005
     right-adjusted (i.e. padded on the left).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4006
     Characters on the left are filled with spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4007
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4008
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4009
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4010
    ^ self leftPaddedTo:size with:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4011
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4012
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4013
     'foo' leftPaddedTo:10  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4014
     'fooBar' leftPaddedTo:5      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4015
     123 printString leftPaddedTo:10        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4016
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4017
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4018
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4019
paddedTo:newSize
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4020
     "return a new string consisting of the receivers characters,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4021
     plus spaces up to length.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4022
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4023
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4024
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4025
     ^ self paddedTo:newSize with:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4026
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4027
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4028
     'foo' paddedTo:10            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4029
     123 printString paddedTo:10 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4030
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  4031
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  4032
328
claus
parents: 327
diff changeset
  4033
!CharacterArray methodsFor:'pattern matching'!
claus
parents: 327
diff changeset
  4034
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4035
compoundMatch:aString
3253
735ed6008eef Fix typo
Stefan Vogel <sv@exept.de>
parents: 3195
diff changeset
  4036
    "like match, but the receiver may be a compound match pattern,
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4037
     consisting of multiple simple patterns, separated by semicolons.
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4038
     This is usable with fileName pattern fields."
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4039
5124
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4040
    ^self compoundMatch:aString ignoreCase:false
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4041
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4042
    "
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4043
     'f*' match:'foo'       
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4044
     'b*' match:'foo'       
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4045
     'f*;b*' match:'foo'    
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4046
     'f*;b*' match:'bar'    
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4047
     'f*;b*' compoundMatch:'foo' 
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4048
     'f*;b*' compoundMatch:'bar' 
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4049
    "
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4050
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4051
    "Modified: / 30.1.1998 / 11:40:18 / stefan"
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4052
    "Modified: / 16.12.1999 / 01:22:08 / cg"
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4053
!
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4054
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4055
compoundMatch:aString ignoreCase:ignoreCase
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4056
    "like match, but the receiver may be a compound match pattern,
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4057
     consisting of multiple simple patterns, separated by semicolons.
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4058
     This is usable with fileName pattern fields."
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4059
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4060
    |matchers|
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4061
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4062
    matchers := self asCollectionOfSubstringsSeparatedBy:$;.
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4063
    matchers do:[:aPattern |
5124
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4064
        (aPattern match:aString ignoreCase:ignoreCase) ifTrue:[^ true].
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4065
    ].
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4066
    ^ false.
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4067
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4068
    "
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4069
     'f*' match:'foo'       
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4070
     'b*' match:'foo'       
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4071
     'f*;b*' match:'foo'    
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4072
     'f*;b*' match:'bar'    
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4073
     'f*;b*' compoundMatch:'foo' 
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4074
     'f*;b*' compoundMatch:'bar' 
5124
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4075
     'f*;b*' compoundMatch:'Foo' ignoreCase:true 
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4076
    "
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4077
3253
735ed6008eef Fix typo
Stefan Vogel <sv@exept.de>
parents: 3195
diff changeset
  4078
    "Modified: / 15.4.1997 / 15:50:33 / cg"
735ed6008eef Fix typo
Stefan Vogel <sv@exept.de>
parents: 3195
diff changeset
  4079
    "Modified: / 30.1.1998 / 11:40:18 / stefan"
5124
727f88b16fb3 case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents: 5097
diff changeset
  4080
    "Created: / 16.12.1999 / 01:21:35 / cg"
2551
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4081
!
46c18418fb05 added compoundMatch
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
  4082
328
claus
parents: 327
diff changeset
  4083
findMatchString:matchString
368
a3c21a89ec37 *** empty log message ***
claus
parents: 360
diff changeset
  4084
    "like findString/indexOfSubCollection, but allowing match patterns.
328
claus
parents: 327
diff changeset
  4085
     find matchstring; if found, return the index;
claus
parents: 327
diff changeset
  4086
     if not found, return 0."
claus
parents: 327
diff changeset
  4087
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  4088
    ^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 
328
claus
parents: 327
diff changeset
  4089
!
claus
parents: 327
diff changeset
  4090
claus
parents: 327
diff changeset
  4091
findMatchString:matchString startingAt:index
claus
parents: 327
diff changeset
  4092
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  4093
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  4094
     if not found, return 0."
claus
parents: 327
diff changeset
  4095
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  4096
    ^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 
328
claus
parents: 327
diff changeset
  4097
!
claus
parents: 327
diff changeset
  4098
claus
parents: 327
diff changeset
  4099
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock
claus
parents: 327
diff changeset
  4100
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  4101
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  4102
     if not found, return the result of evaluating exceptionBlock.
claus
parents: 327
diff changeset
  4103
     This is a q&d hack - not very efficient"
claus
parents: 327
diff changeset
  4104
2916
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4105
    |firstChar firstSet
328
claus
parents: 327
diff changeset
  4106
     startIndex "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  4107
     matchSize  "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  4108
     mySize     "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  4109
     realMatchString|
claus
parents: 327
diff changeset
  4110
claus
parents: 327
diff changeset
  4111
    matchSize := matchString size.
claus
parents: 327
diff changeset
  4112
    matchSize == 0 ifTrue:[^ index]. "empty string matches"
claus
parents: 327
diff changeset
  4113
claus
parents: 327
diff changeset
  4114
    realMatchString := matchString.
claus
parents: 327
diff changeset
  4115
    (realMatchString endsWith:$*) ifFalse:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4116
        realMatchString := realMatchString , '*'.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4117
        matchSize := matchSize + 1
328
claus
parents: 327
diff changeset
  4118
    ].
claus
parents: 327
diff changeset
  4119
claus
parents: 327
diff changeset
  4120
    mySize := self size.
claus
parents: 327
diff changeset
  4121
    firstChar := realMatchString at:1.
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4122
    firstChar == self class matchEscapeCharacter ifTrue:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4123
        firstChar := realMatchString at:2.
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4124
    ].
328
claus
parents: 327
diff changeset
  4125
claus
parents: 327
diff changeset
  4126
    firstChar asString includesMatchCharacters ifTrue:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4127
        index to:mySize do:[:col |
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4128
            (realMatchString match:self from:col to:mySize ignoreCase:ignoreCase)
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4129
            ifTrue:[^ col]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4130
        ].
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4131
        ^ exceptionBlock value.
328
claus
parents: 327
diff changeset
  4132
    ].
2916
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4133
    ignoreCase ifTrue:[
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4134
        firstSet := String with:(firstChar asUppercase) with:(firstChar asLowercase).
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4135
        startIndex := self indexOfAny:firstSet startingAt:index.
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4136
    ] ifFalse:[
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4137
        startIndex := self indexOf:firstChar startingAt:index.
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4138
    ].
328
claus
parents: 327
diff changeset
  4139
    [startIndex == 0] whileFalse:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4140
        (realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase)
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4141
        ifTrue:[^ startIndex].
2916
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4142
        ignoreCase ifTrue:[
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4143
            startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1).
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4144
        ] ifFalse:[
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4145
            startIndex := self indexOf:firstChar startingAt:(startIndex + 1).
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4146
        ].
328
claus
parents: 327
diff changeset
  4147
    ].
claus
parents: 327
diff changeset
  4148
    ^ exceptionBlock value
claus
parents: 327
diff changeset
  4149
claus
parents: 327
diff changeset
  4150
    "
claus
parents: 327
diff changeset
  4151
     'one two three four' findMatchString:'o[nu]'
claus
parents: 327
diff changeset
  4152
     'one two three four' findMatchString:'o[nu]' startingAt:3
2916
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4153
     'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 
328
claus
parents: 327
diff changeset
  4154
    "
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4155
2916
dd8672addeca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  4156
    "Modified: 13.9.1997 / 06:31:22 / cg"
328
claus
parents: 327
diff changeset
  4157
!
claus
parents: 327
diff changeset
  4158
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4159
includesMatchString:matchString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4160
    "like includesString, but allowing match patterns.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4161
     find matchstring; if found, return true, otherwise return false"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4162
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4163
    ^ (self findMatchString:matchString) ~~ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4164
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4165
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4166
     'hello world' includesMatchString:'h*'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4167
     'hello world' includesMatchString:'h[aeiou]llo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4168
     'hello world' includesMatchString:'wor*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4169
     'hello world' includesMatchString:'woR*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4170
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4171
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4172
328
claus
parents: 327
diff changeset
  4173
match:aString
claus
parents: 327
diff changeset
  4174
    "return true if aString matches self, where self may contain meta-match 
claus
parents: 327
diff changeset
  4175
     characters $* (to match any string) or $# (to match any character).
claus
parents: 327
diff changeset
  4176
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  4177
     Lower/uppercase are considered different.
claus
parents: 343
diff changeset
  4178
     NOTICE: match-meta character interpretation is like in unix-matching, 
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4179
             NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  4180
claus
parents: 327
diff changeset
  4181
    ^ self match:aString from:1 to:aString size ignoreCase:false
claus
parents: 327
diff changeset
  4182
claus
parents: 327
diff changeset
  4183
    "
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4184
     '\*f*' match:'f' 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4185
     '\*f*' match:'*f' 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4186
     '*\*f*' match:'*f' 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4187
     '*f*' match:'*f' 
328
claus
parents: 327
diff changeset
  4188
     '*ute*' match:'computer' 
claus
parents: 327
diff changeset
  4189
     '*uter' match:'computer' 
claus
parents: 327
diff changeset
  4190
     'uter*' match:'computer' 
claus
parents: 327
diff changeset
  4191
     '*ute*' match:'' 
claus
parents: 327
diff changeset
  4192
     '[abcd]*' match:'computer' 
claus
parents: 327
diff changeset
  4193
     '[abcd]*' match:'komputer' 
claus
parents: 327
diff changeset
  4194
     '*some*compl*ern*' match:'this is some more complicated pattern match' 
claus
parents: 327
diff changeset
  4195
     '*some*compl*ern*' match:'this is another complicated pattern match' 
3537
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  4196
     '*-hh' match:'anton-h'
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  4197
    "
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  4198
916534e86f0c fixed match
Claus Gittinger <cg@exept.de>
parents: 3527
diff changeset
  4199
    "Modified: / 9.6.1998 / 18:50:00 / cg"
328
claus
parents: 327
diff changeset
  4200
!
claus
parents: 327
diff changeset
  4201
claus
parents: 327
diff changeset
  4202
match:aString from:start to:stop ignoreCase:ignoreCase
claus
parents: 327
diff changeset
  4203
    "return true if part of aString matches myself, 
claus
parents: 327
diff changeset
  4204
     where self may contain meta-match 
claus
parents: 327
diff changeset
  4205
     characters $* (to match any string) or $# (to match any character)
claus
parents: 327
diff changeset
  4206
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  4207
     If ignoreCase is true, lower/uppercase are considered the same.
claus
parents: 343
diff changeset
  4208
     NOTICE: match-meta character interpretation is like in unix-matching, 
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4209
             NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  4210
claus
parents: 327
diff changeset
  4211
    |matchScanArray|
claus
parents: 327
diff changeset
  4212
claus
parents: 327
diff changeset
  4213
    "
claus
parents: 327
diff changeset
  4214
     keep the matchScanArray from the most recent match -
claus
parents: 327
diff changeset
  4215
     avoids parsing the pattern over-and over if multiple searches
claus
parents: 327
diff changeset
  4216
     are done with the same pattern.
claus
parents: 327
diff changeset
  4217
    "
claus
parents: 327
diff changeset
  4218
    (PreviousMatch notNil
claus
parents: 327
diff changeset
  4219
    and:[PreviousMatch key = self]) ifTrue:[
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4220
        matchScanArray := PreviousMatch value
328
claus
parents: 327
diff changeset
  4221
    ] ifFalse:[
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4222
        matchScanArray := self class matchScanArrayFrom:self.
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4223
        matchScanArray isNil ifTrue:[
3926
4cc33691696a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3879
diff changeset
  4224
            'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR.
4cc33691696a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3879
diff changeset
  4225
            ^ self = aString    
4cc33691696a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3879
diff changeset
  4226
"/            ^ false
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4227
        ].
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4228
        PreviousMatch := self -> matchScanArray.
328
claus
parents: 327
diff changeset
  4229
    ].
claus
parents: 327
diff changeset
  4230
claus
parents: 327
diff changeset
  4231
    ^ self class
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4232
        matchScan:matchScanArray 
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4233
        from:1 to:matchScanArray size
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4234
        with:aString 
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4235
        from:start to:stop 
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4236
        ignoreCase:ignoreCase
328
claus
parents: 327
diff changeset
  4237
claus
parents: 327
diff changeset
  4238
    "
claus
parents: 327
diff changeset
  4239
     '*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true 
claus
parents: 327
diff changeset
  4240
     '*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true  
claus
parents: 327
diff changeset
  4241
    "
1429
5729275971ae printNL -> printCR
Claus Gittinger <cg@exept.de>
parents: 1423
diff changeset
  4242
3926
4cc33691696a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3879
diff changeset
  4243
    "Modified: / 10.11.1998 / 21:43:46 / cg"
359
claus
parents: 357
diff changeset
  4244
!
claus
parents: 357
diff changeset
  4245
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4246
match:aString ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4247
    "return true if aString matches self, where self may contain meta-match 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4248
     characters $* (to match any string) or $# (to match any character)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4249
     or [...] to match a set of characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4250
     If ignoreCase is true, lower/uppercase are considered the same.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4251
     NOTICE: match-meta character interpretation is like in unix-matching, 
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4252
             NOT the ST-80 meaning."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4253
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4254
    ^ self match:aString from:1 to:aString size ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4255
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4256
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4257
     '*ute*' match:'COMPUTER' ignoreCase:true  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4258
     '*uter' match:'COMPUTER' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4259
     '[abcd]*' match:'computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4260
     '[abcd]*' match:'Computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4261
     '[a-k]*' match:'komputer' ignoreCase:false   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4262
     '[a-k]*' match:'zomputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4263
     '[a-k]*' match:'Komputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4264
     '[a-k]*' match:'Komputer' ignoreCase:true     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4265
     '*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4266
     '*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4267
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4268
     Time millisecondsToRun:[
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4269
        Symbol allInstancesDo:[:sym |
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4270
            '[ab]*' match:sym ignoreCase:false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4271
        ]
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4272
     ]. 
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4273
     Time millisecondsToRun:[
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4274
        Symbol allInstancesDo:[:sym |
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4275
            '*at:*' match:sym ignoreCase:false
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4276
        ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4277
     ]. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4278
    "
2519
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4279
07674cea76dd allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents: 2452
diff changeset
  4280
    "Modified: 2.4.1997 / 17:28:58 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4281
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4282
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4283
!CharacterArray methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4284
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4285
article
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4286
    "return an article string for the receiver."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4287
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4288
    |firstChar|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4289
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4290
    firstChar := (self at:1) asLowercase. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4291
    (firstChar isVowel or:[firstChar == $x]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4292
	firstChar ~~ $u ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4293
	     ^ 'an'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4294
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4295
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4296
    ^ 'a'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4297
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4298
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4299
displayString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4300
    "return a string to display the receiver - use storeString to have
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4301
     quotes around."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4302
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4303
    ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4304
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4305
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4306
printOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4307
    "print the receiver on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4308
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4309
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4310
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4311
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4312
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4313
    "return a string for printing - thats myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4314
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4315
    ^ self
3578
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4316
!
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4317
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4318
printWithQuotesDoubledOn:aStream
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4319
    "put the raw storeString of myself on aStream"
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4320
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4321
    self do:[:thisChar |
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4322
        (thisChar == $') ifTrue:[aStream nextPut:thisChar].
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4323
        aStream nextPut:thisChar
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4324
    ]
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4325
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4326
    "Modified: / 15.6.1998 / 17:21:17 / cg"
46dc8399fdf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3537
diff changeset
  4327
    "Created: / 15.6.1998 / 17:22:13 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4328
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4329
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4330
!CharacterArray methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4331
4429
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4332
bitsPerCharacter
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4333
    "return the underlying strings bitsPerCharacter 
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4334
     (i.e. is it a regular String or a TwoByteString)"
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4335
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4336
    ^ self string bitsPerCharacter
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4337
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4338
    "
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4339
     'hello' bitsPerCharacter        
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4340
     'hello' asText allBold bitsPerCharacter 
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4341
    "
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4342
!
564b0fd9168e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  4343
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4344
encoding
1311
367f740d21e7 commentary
Claus Gittinger <cg@exept.de>
parents: 1308
diff changeset
  4345
    "return the strings encoding, as a symbol.
367f740d21e7 commentary
Claus Gittinger <cg@exept.de>
parents: 1308
diff changeset
  4346
     Here, by default, we assume #iso8859 encoding.
1241
431675180b54 commentary
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  4347
     This has to be redefined in XXXEncodedString subclasses."
1012
19fd2f72269f keep track of encoding of 16bit strings
Claus Gittinger <cg@exept.de>
parents: 1008
diff changeset
  4348
1311
367f740d21e7 commentary
Claus Gittinger <cg@exept.de>
parents: 1308
diff changeset
  4349
    ^ #iso8859
367f740d21e7 commentary
Claus Gittinger <cg@exept.de>
parents: 1308
diff changeset
  4350
367f740d21e7 commentary
Claus Gittinger <cg@exept.de>
parents: 1308
diff changeset
  4351
    "Modified: 27.4.1996 / 13:23:49 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4352
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4353
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  4354
hasChangeOfEmphasis
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  4355
    ^ false
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  4356
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4357
    "Created: 12.5.1996 / 12:31:39 / cg"
1375
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  4358
!
f035bb7468f5 additions for new Text class
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
  4359
1388
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4360
heightOn:aGC
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4361
    "return the size of the recevier in device units if displayed on aGC"
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4362
3337
c2d24038c1fe need device font for height query
ca
parents: 3253
diff changeset
  4363
    ^ (aGC font on:aGC device) heightOf:self
1388
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4364
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4365
    "
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4366
     'hello world' heightOn:(View new)                 
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4367
    "
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4368
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4369
    "Created: 12.5.1996 / 20:09:29 / cg"
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4370
    "Modified: 12.5.1996 / 20:32:05 / cg"
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4371
!
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4372
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4373
isString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4374
    "return true, if the receiver is some kind of string;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4375
     true is returned here - redefinition of Object>>isString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4376
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4377
    ^ true
1235
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4378
!
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4379
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4380
leftIndent
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4381
    "if the receiver starts with spaces, return the number of spaces
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4382
     at the left - otherwise, return 0.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4383
     If the receiver consists of spaces only, return the receivers size."
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4384
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4385
    |index "{Class: SmallInteger }"
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4386
     end   "{Class: SmallInteger }"|
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4387
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4388
    index := 1.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4389
    end := self size.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4390
    [index <= end] whileTrue:[
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4391
        (self at:index) isSeparator ifFalse:[^ index - 1].
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4392
        index := index + 1
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4393
    ].
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4394
    ^ end
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4395
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4396
    "
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4397
     '    hello' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4398
     'foo      ' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4399
     '         ' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4400
    "
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4401
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  4402
    "Modified: 20.4.1996 / 19:28:43 / cg"
1388
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4403
!
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4404
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4405
widthOn:aGC
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4406
    "return ths size of the recevier in device units if displayed on aGC"
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4407
2554
309ee6707322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  4408
    ^ (aGC font on:aGC device) widthOf:self
1388
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4409
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4410
    "
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4411
     'hello world' widthOn:(View new)                 
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4412
    "
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4413
e47b4b894530 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
  4414
    "Created: 12.5.1996 / 20:09:29 / cg"
2554
309ee6707322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  4415
    "Modified: 17.4.1997 / 12:50:23 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4416
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4417
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4418
!CharacterArray methodsFor:'special string converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4419
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4420
chopTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4421
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4422
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4423
     in the middle have been removed for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4424
     of maxLen."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4425
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4426
    |sz n1 n2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4427
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4428
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4429
	n1 := n2 := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4430
	maxLen odd ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4431
	    n2 := n1 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4432
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4433
	^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4434
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4435
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4436
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4437
     '12345678901234'   chopTo:15            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4438
     '123456789012345'  chopTo:15         
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4439
     '1234567890123456' chopTo:15      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4440
     'aShortString' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4441
     'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4442
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4443
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4444
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4445
contractAtBeginningTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4446
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4447
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4448
     at the beginning have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4449
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4450
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4451
    |sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4452
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4453
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4454
	^ '...' , (self copyFrom:(sz - (maxLen - 4))) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4455
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4456
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4457
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4458
     '12345678901234' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4459
     '123456789012345' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4460
     '1234567890123456' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4461
     'aShortString' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4462
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4463
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4464
!
359
claus
parents: 357
diff changeset
  4465
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4466
contractAtEndTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4467
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4468
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4469
     at the end have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4470
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4471
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4472
    |sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4473
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4474
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4475
	^ self copyReplaceFrom:maxLen - 3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4476
			    with:'...'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4477
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4478
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4479
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4480
     '12345678901234' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4481
     '123456789012345' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4482
     '1234567890123456' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4483
     'aShortString' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4484
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4485
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4486
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4487
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4488
contractTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4489
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4490
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4491
     in the middle have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4492
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4493
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4494
    |sz "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4495
     halfSize "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4496
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4497
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4498
	halfSize := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4499
	^ self copyReplaceFrom:halfSize - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4500
			    to:sz - maxLen + halfSize + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4501
			    with:'...'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4502
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4503
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4504
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4505
     '12345678901234' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4506
     '123456789012345' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4507
     '1234567890123456' contractTo:15        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4508
     'aShortString' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4509
     'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4510
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4511
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4512
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4513
expandPlaceholdersWith:argArrayOrDictionary
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4514
    "return a copy of the receiver, where all %i escapes are
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4515
     replaced by corresponding arguments' printStrings from the argArrayOrDictionary.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4516
     I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4517
     in the new string 'hello world; how is this'.
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4518
     As an extension, the argument may also be a dictionary, providing
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4519
     values for character keys.
4842
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4520
     In this case, %a .. %z and %(...) are also allowed.
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4521
     (%1..%9 require a numeric key in the dictionary, however)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4522
     To get a '%' character, use a '%%'-escape.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4523
     See also bindWith:... for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4524
4842
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4525
    |expandedString next v key
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4526
     idx   "{ SmallInteger }"
4842
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4527
     idx2  "{ SmallInteger }"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4528
     start "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4529
     stop  "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4530
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4531
    expandedString := self species new:0.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4532
    stop := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4533
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4534
    [start <= stop] whileTrue:[
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4535
        idx := self indexOf:$% startingAt:start.
2737
9f29aecea39d care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents: 2736
diff changeset
  4536
        (idx == 0 or:[idx == stop]) ifTrue:[
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4537
            ^ expandedString , (self copyFrom:start to:stop)
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4538
        ].
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4539
        "found a %"
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4540
        expandedString := expandedString , (self copyFrom:start to:(idx - 1)).
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4541
        next := self at:(idx + 1).
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4542
        (next == $%) ifTrue:[
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4543
            expandedString := expandedString , '%'
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4544
        ] ifFalse:[
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4545
            (next between:$1 and:$9) ifTrue:[
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4546
                v := argArrayOrDictionary at:(next digitValue)
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4547
            ] ifFalse:[
4842
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4548
                next == $( ifTrue:[
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4549
                    idx2 := self indexOf:$) startingAt:idx+2.
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4550
                    key := self copyFrom:idx+2 to:idx2-1.
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4551
                    idx := idx2 - 1.
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4552
                    v := argArrayOrDictionary at:key asSymbol
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4553
                ] ifFalse:[
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4554
                    v := argArrayOrDictionary at:next
0086acd80497 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  4555
                ]
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4556
            ].
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4557
            expandedString := expandedString , v printString
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4558
        ].
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4559
        start := idx + 2
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4560
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4561
    ^  expandedString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4562
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4563
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4564
     'hello %1' expandPlaceholdersWith:#('world') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4565
     'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4566
     'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') 
1308
cf41289a7ce2 commentary
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
  4567
     '%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) 
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4568
    "
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  4569
4410
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4570
    "
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4571
     |dict|
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4572
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4573
     dict := Dictionary new.
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4574
     dict at:1 put:'one'.
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4575
     dict at:$a put:'AAAAA'.
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4576
     'hello %1 %a' expandPlaceholdersWith:dict 
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4577
    "
2bdc0c89a42e enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  4578
2737
9f29aecea39d care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents: 2736
diff changeset
  4579
    "Modified: 1.7.1997 / 00:53:24 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4580
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4581
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4582
withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4583
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4584
     with all \-characters replaced by cr-characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4585
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4586
    ^ self copyReplaceAll:$\ with:(Character cr)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4587
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4588
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4589
     'hello\world' withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4590
    "
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4591
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4592
    "Modified: / 18.7.1998 / 22:53:02 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4593
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4594
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4595
withEscapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4596
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4597
     with all \X-character escapes replaced by corresponding-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4598
     (similar to the way C-language Strings are converted).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4599
     The following escapes are supported:
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4600
        \r      return character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4601
        \n      newline character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4602
        \b      backspace character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4603
        \f      formfeed character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4604
        \t      tab character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4605
        \e      escape character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4606
        \\      the \ character itself
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4607
        \nnn    three digit octal number defining the characters ascii value
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4608
        \other  other
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4609
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4610
     Notice, that \' is NOT a valid escape, since the general syntax of
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4611
     string constants is not affected by this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4612
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4613
     Although easily implementable, this is NOT done automatically
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4614
     by the compiler (due to a lack of a language standard for this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4615
     However, the compiler may detect sends ot #withEscapes to string literals
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4616
     and place a modified string constant into the binary/byte-code.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4617
     Therefore, no runtime penalty will be payed for using these escapes.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4618
     (not in pre 2.11 versions)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4619
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4620
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4621
    |sz      "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4622
     newSize "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4623
     srcIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4624
     dstIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4625
     val     "{ SmallInteger }"
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4626
     newString next hasEmphasis e| 
359
claus
parents: 357
diff changeset
  4627
claus
parents: 357
diff changeset
  4628
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4629
     first, count the number of escapes, to allow preallocation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4630
     of the new string ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4631
     (it is faster to scan the string twice than to reallocate it multiple
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4632
      times in a WriteStream)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4633
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4634
    sz := newSize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4635
    srcIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4636
    [(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4637
        srcIdx == sz ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4638
            newSize := newSize - 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4639
            srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4640
            next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4641
            next == $0 ifTrue:[
3527
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4642
                [srcIdx < sz and:[next isDigit]] whileTrue:[
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4643
                    newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx.
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4644
                ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4645
            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4646
        ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4647
        srcIdx := srcIdx + 1.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4648
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4649
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4650
    newSize == sz ifTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4651
        ^ self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4652
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4653
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4654
    newString := self species new:newSize.
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4655
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4656
    hasEmphasis := self hasChangeOfEmphasis.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4657
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4658
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4659
     copy over, replace escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4660
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4661
    srcIdx := dstIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4662
    [srcIdx <= sz] whileTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4663
        next := self at:srcIdx.
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4664
        hasEmphasis ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4665
            e := self emphasisAt:srcIdx
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4666
        ].
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4667
        srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4668
        next == $\ ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4669
            srcIdx <= sz ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4670
                next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4671
                srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4672
                next == $r ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4673
                    next := Character return
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4674
                ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4675
                    next == $n ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4676
                        next := Character nl
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4677
                    ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4678
                        next == $b ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4679
                            next := Character backspace
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4680
                        ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4681
                            next == $f ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4682
                                next := Character newPage
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4683
                            ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4684
                                next == $t ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4685
                                    next := Character tab
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4686
                                ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4687
                                    next == $e ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4688
                                        next := Character esc
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4689
                                    ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4690
                                        next == $0 ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4691
                                            val := 0.
3527
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4692
                                            [next notNil and:[next isDigit]] whileTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4693
                                                val := val * 8 + next digitValue.
3527
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4694
                                                srcIdx <= sz ifTrue:[
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4695
                                                    next := self at:srcIdx.
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4696
                                                    srcIdx := srcIdx + 1.
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4697
                                                ] ifFalse:[
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4698
                                                    next := nil
55b61fce23f0 oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents: 3404
diff changeset
  4699
                                                ]
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4700
                                            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4701
                                            next := Character value:val.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4702
                                        ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4703
                                    ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4704
                                ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4705
                            ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4706
                        ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4707
                    ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4708
                ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4709
            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4710
        ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4711
        newString at:dstIdx put:next.
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4712
        hasEmphasis ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4713
            newString emphasisAt:dstIdx put:e
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4714
        ].
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4715
        dstIdx := dstIdx + 1.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4716
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4717
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4718
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4719
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4720
     'hello world' withEscapes  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4721
     'hello\world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4722
     'hello\world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4723
     'hello world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4724
     'hello\tworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4725
     'hello\nworld\na\n\tnice\n\t\tstring' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4726
     'hello\tworld\n' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4727
     'hello\010world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4728
     'hello\r\nworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4729
    "
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  4730
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4731
    "Modified: 12.5.1996 / 12:53:34 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4732
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4733
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4734
withMatchEscapes
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4735
    "return a copy of the receiver with all match characters escaped
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4736
     by $\ characters (to be usable as a match string).
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4737
     Return the receiver, if there are none."
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4738
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4739
    |in out c escape|
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4740
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4741
    escape := self class matchEscapeCharacter.
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4742
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4743
    in := self readStream.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4744
    out := '' writeStream.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4745
    [in atEnd] whileFalse:[
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4746
        c := in next.
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4747
        (c == escape or:['*[#' includes:c]) ifTrue:[
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4748
            out nextPut:$\.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4749
        ].
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4750
        out nextPut:c.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4751
    ].
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4752
    ^ out contents.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4753
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4754
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4755
     '*foo' withMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4756
     '\*foo' withMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4757
     '*foo' withMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4758
     '\\*foo' withMatchEscapes 
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4759
     'foo*' withMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4760
     'foo\*' withMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4761
     'foo\' withMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4762
     'f*o*o' withMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4763
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4764
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4765
    "Modified: 2.4.1997 / 18:13:04 / cg"
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4766
!
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4767
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4768
withTabs
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4769
    "return a string consisting of the receivers characters
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4770
     where leading spaces are replaced by tabulator characters (assuming 8-col tabs).
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4771
     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: 678
diff changeset
  4772
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4773
     Limitation: only the very first spaces are replaced 
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4774
		 (i.e. if the receiver contains newLine characters,
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4775
		  no tabs are inserted after those lineBreaks)"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4776
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4777
    |idx   "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4778
     nTabs "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4779
     newString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4780
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4781
    idx := self findFirst:[:c | (c ~~ Character space)].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4782
    nTabs := (idx-1) // 8.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4783
    nTabs == 0 ifTrue:[^ self].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4784
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4785
    "any tabs"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4786
    newString := self class new:(self size - (nTabs * 7)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4787
    newString atAll:(1 to:nTabs) put:(Character tab).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4788
    newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4789
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4790
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4791
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4792
     '12345678901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4793
     '       8901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4794
     '        901234567890' withTabs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4795
     '               67890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4796
     '                7890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4797
     '                 890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4798
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4799
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4800
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4801
withTabsExpanded
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4802
    "return a string consisting of the receivers characters,
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4803
     where all tabulator characters are expanded into spaces (assuming 8-col tabs). 
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4804
     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: 678
diff changeset
  4805
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4806
     This does handle multiline strings."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4807
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4808
    |col    "{ SmallInteger }" 
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4809
     str ch
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4810
     dstIdx "{ SmallInteger }"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4811
     newSz  "{ SmallInteger }"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4812
     sz "{ SmallInteger }"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4813
     hasEmphasis e|
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4814
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4815
    (self includes:(Character tab)) ifFalse:[^ self].
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4816
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4817
    sz := self size.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4818
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4819
    "/ count the new size first, instead of
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4820
    "/ multiple resizing (better for large strings)
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4821
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4822
    col := 1. newSz := 0.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4823
    1 to:sz do:[:srcIdx |
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4824
        ch := self at:srcIdx.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4825
        ch == Character tab ifFalse:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4826
            col := col + 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4827
            newSz := newSz + 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4828
            ch == Character cr ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4829
                col := 1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4830
            ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4831
        ] ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4832
            (col \\ 8) to:8 do:[:ii |
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4833
                newSz := newSz + 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4834
                col := col + 1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4835
            ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4836
        ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4837
    ].
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4838
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4839
    str := self species new:newSz.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4840
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4841
    hasEmphasis := self hasChangeOfEmphasis.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4842
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4843
    col := 1. dstIdx := 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4844
    1 to:sz do:[:srcIdx |
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4845
        ch := self at:srcIdx.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4846
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4847
        ch == Character tab ifFalse:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4848
            col := col + 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4849
            ch == Character cr ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4850
                col := 1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4851
            ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4852
            hasEmphasis ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4853
                e := self emphasisAt:srcIdx.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4854
                str emphasisAt:dstIdx put:e
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4855
            ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4856
            str at:dstIdx put:ch.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4857
            dstIdx := dstIdx + 1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4858
        ] ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4859
            (col \\ 8) to:8 do:[:ii |
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4860
                str at:dstIdx put:Character space.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4861
                dstIdx := dstIdx + 1.
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4862
                col := col + 1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4863
            ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4864
        ]
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4865
    ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4866
    ^ str
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4867
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4868
    "
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4869
     ('1' , Character tab asString , 'x') withTabsExpanded          
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4870
     ('12345' , Character tab asString , 'x') withTabsExpanded      
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4871
     ('123456' , Character tab asString , 'x') withTabsExpanded     
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4872
     ('1234567' , Character tab asString , 'x') withTabsExpanded   
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4873
     ('12345678' , Character tab asString , 'x') withTabsExpanded   
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4874
     ('123456789' , Character tab asString , 'x') withTabsExpanded 
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4875
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4876
     (String with:Character tab
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4877
             with:Character tab
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4878
             with:$1) withTabsExpanded
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4879
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4880
     (String with:Character tab
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4881
             with:$1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4882
             with:Character tab
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4883
             with:$2) withTabsExpanded  
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4884
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4885
     (String with:Character tab
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4886
             with:$1
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4887
             with:Character cr
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4888
             with:Character tab
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4889
             with:$2) withTabsExpanded  
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4890
    "
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  4891
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  4892
    "Modified: 12.5.1996 / 13:05:10 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4893
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4894
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4895
withoutCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4896
    "return a new collection consisting of receivers elements
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4897
     with all cr-characters replaced by \-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4898
     This is the reverse operation of withCRs."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4899
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4900
    ^ self copyReplaceAll:(Character cr) with:$\
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4901
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4902
     'hello
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4903
world' withoutCRs
359
claus
parents: 357
diff changeset
  4904
    "
3656
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4905
347ea0413b68 use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3630
diff changeset
  4906
    "Modified: / 18.7.1998 / 22:53:08 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4907
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4908
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4909
withoutLeadingSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4910
    "return a copy of myself without leading separators.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4911
     Notice: this does remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4912
     Returns an empty string, if the receiver consist only of whitespace."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4913
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4914
    |index|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4915
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4916
    index := self indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4917
    index ~~ 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4918
	index == 1 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4919
	    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4920
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4921
	^ self copyFrom:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4922
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4923
    ^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4924
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4925
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4926
     '    foo    ' withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4927
     'foo    '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4928
     '    foo'     withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4929
     '       '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4930
     'foo'         withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4931
     ('  ' , Character tab asString , ' foo   ') withoutLeadingSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4932
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4933
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4934
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4935
withoutMatchEscapes
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4936
    "return a copy of the receiver with all $\ removed or
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4937
     the receiver, if there are none."
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4938
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4939
    |in out c escape|
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4940
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4941
    escape := self class matchEscapeCharacter.
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4942
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4943
    in := self readStream.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4944
    out := self species new writeStream.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4945
    [in atEnd] whileFalse:[
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4946
        c := in next.
5342
5010cea0ffd4 match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents: 5316
diff changeset
  4947
        c == escape ifTrue:[
4117
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4948
            in atEnd ifFalse:[
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4949
                c := in next.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4950
            ]
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4951
        ].
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4952
        out nextPut:c.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4953
    ].
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4954
    ^ out contents.
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4955
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4956
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4957
     '*foo' withoutMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4958
     '\*foo' withoutMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4959
     '*foo' withoutMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4960
     '\\*foo' withoutMatchEscapes 
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4961
     'foo*' withoutMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4962
     'foo\*' withoutMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4963
     'foo\' withoutMatchEscapes  
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4964
     'f\*o\*o' withoutMatchEscapes   
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4965
    "
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4966
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4967
    "Modified: 30.6.1997 / 13:40:23 / cg"
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4968
!
1b98af571a04 comments;
Claus Gittinger <cg@exept.de>
parents: 3987
diff changeset
  4969
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4970
withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4971
    "return a copy of myself without leading and trailing whitespace.
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  4972
     (but whiteSpace in-between is preserved)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4973
     Whitespace is space, tab, newline, formfeed.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4974
     Use withoutSpaces, if you want to remove spaces only."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4975
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4976
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4977
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4978
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4979
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4980
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4981
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4982
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4983
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4984
    [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  4985
        startIndex := startIndex + 1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4986
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4987
    [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  4988
        endIndex := endIndex - 1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4989
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4990
    startIndex > endIndex ifTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  4991
        ^ ''
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4992
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4993
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  4994
        ^ self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4995
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4996
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4997
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4998
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  4999
     '    foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5000
     '    foo' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5001
     'foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5002
     '       ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5003
     ('  foo' , Character tab asString , '    ') withoutSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5004
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5005
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5006
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5007
withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5008
    "return a copy of myself without leading and trailing spaces.
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5009
     (but spaces in-between are preserved)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5010
     Notice: this does NOT remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5011
     Use withoutSeparators for this."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5012
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5013
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5014
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5015
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5016
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5017
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5018
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5019
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5020
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5021
    [(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5022
        startIndex := startIndex + 1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5023
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5024
    [(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5025
        endIndex := endIndex - 1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5026
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5027
    startIndex > endIndex ifTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5028
        ^ ''
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5029
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5030
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5031
        ^ self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5032
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5033
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5034
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5035
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5036
     '    foo    ' withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5037
     'foo    '     withoutSpaces   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5038
     '    foo'     withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5039
     '       '     withoutSpaces   
4156
3079a5a94617 comments
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
  5040
     'a     b'     withoutSpaces   
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5041
     ('  foo' , Character tab asString , '    ') withoutSpaces inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5042
    "
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5043
!
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5044
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5045
withoutTrailingSeparators
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5046
    "return a copy of myself without trailing separators.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5047
     Notice: this does remove tabs, newline or any other whitespace.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5048
     Returns an empty string, if the receiver consist only of whitespace."
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5049
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5050
    |index|
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5051
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5052
    index := self size.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5053
    [index ~~ 0] whileTrue:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5054
	(self at:index) isSeparator ifFalse:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5055
	    ^ self copyTo:index
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5056
	].
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5057
	index := index - 1
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5058
    ].
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5059
    ^ ''
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5060
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5061
    "
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5062
     '    foo    ' withoutTrailingSeparators  
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5063
     'foo    '     withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5064
     '    foo'     withoutTrailingSeparators  
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5065
     '       '     withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5066
     'foo'         withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5067
     ('  ' , Character tab asString , ' foo   ') withoutTrailingSeparators inspect 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5068
     ('   foo' , Character tab asString) withoutTrailingSeparators inspect 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  5069
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5070
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5071
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5072
!CharacterArray methodsFor:'substring searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5073
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5074
findString:subString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5075
    "find a substring. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5076
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5077
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  5078
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5079
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5080
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5081
     'hello world' findString:'llo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5082
     'hello world' findString:'ole'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5083
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5084
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5085
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5086
findString:subString ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5087
    "find a substring. If found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5088
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5089
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5090
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5091
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5092
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5093
findString:subString startingAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5094
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5095
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5096
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  5097
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:0
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5098
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5099
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5100
     'hello yello' findString:'llo' startingAt:1   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5101
     'hello yello' findString:'llo' startingAt:5   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5102
     'hello yello' findString:'llo' startingAt:15   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5103
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5104
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5105
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5106
findString:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5107
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5108
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5109
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5110
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5111
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5112
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5113
includesString:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5114
    "return true, if a substring is contained in the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5115
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  5116
    ^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5117
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5118
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5119
     'hello world' includesString:'hel' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5120
     'hello world' includesString:'rld' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5121
     'hello world' includesString:'llo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5122
     'hello world' includesString:'LLO'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5123
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5124
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5125
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5126
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5127
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5128
     if not found, return the result of evaluating exceptionBlock.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5129
     This is a q&d hack - not very efficient"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5130
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5131
    |firstChar found
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5132
     startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5133
     subSize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5134
     mySize     "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5135
     runIdx     "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5136
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5137
    subSize := subString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5138
    subSize == 0 ifTrue:[^ index]. "empty string matches"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5139
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5140
    firstChar := subString at:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5141
    startIndex := self indexOf:firstChar startingAt:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5142
    [startIndex == 0] whileFalse:[
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5143
        runIdx := startIndex.
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5144
        found := true.
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5145
        1 to:subSize do:[:i |
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5146
            runIdx > mySize ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5147
                found := false
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5148
            ] ifFalse:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5149
                (subString at:i) ~= (self at:runIdx) ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5150
                    found := false
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5151
                ]
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5152
            ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5153
            runIdx := runIdx + 1
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5154
        ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5155
        found ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5156
            ^ startIndex
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5157
        ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5158
        startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5159
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5160
    ^ exceptionBlock value
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5161
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  5162
    "Modified: 23.2.1996 / 15:35:15 / cg"
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5163
!
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5164
652
Claus Gittinger <cg@exept.de>
parents: 651
diff changeset
  5165
restAfter:keyword withoutSeparators:strip
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5166
    "compare the left of the receiver with keyword,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5167
     if it matches return the right. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5168
     Finally, if strip is true, remove whiteSpace.
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5169
     This method is used to match and extract lines of the form:
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5170
	something: rest
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 735
diff changeset
  5171
     where we are interested in rest, but only if the receiver string
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5172
     begins with something. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5173
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5174
     You may wonder why such a specialized method exists here
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5175
     - this is so common when processing mailboxes,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5176
     rcs files, nntp/pop3 responses, that is was considered worth
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5177
     a special method here to avoid having the code below a hundred
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5178
     times in variuos places."
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5179
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5180
    |rest|
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5181
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5182
    (self startsWith:keyword) ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5183
	rest := self copyFrom:(keyword size + 1).
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5184
	strip ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5185
	    rest := rest withoutSeparators
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5186
	].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5187
	^ rest
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5188
    ].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5189
    ^ nil
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5190
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5191
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5192
     'foo: hello world' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5193
     'funny: something' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5194
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5195
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5196
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:false 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5197
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5198
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5199
    "Created: 25.11.1995 / 11:04:18 / cg"
328
claus
parents: 327
diff changeset
  5200
! !
claus
parents: 327
diff changeset
  5201
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
  5202
!CharacterArray methodsFor:'testing'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5203
1613
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5204
continuesWith:aString startingAt:startIndex
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5205
    "return true, if the receiver beginning at startIndex
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5206
     contains the characters in aString."
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5207
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5208
    |sz  "{Class: SmallInteger }"
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5209
     idx "{Class: SmallInteger }"|
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5210
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5211
    sz := aString size.
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5212
    idx := startIndex.
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5213
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5214
    1 to:sz do:[:i |
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5215
        (self at:idx) ~~ (aString at:i) ifTrue:[^ false].
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5216
        idx := idx + 1
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5217
    ].
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5218
    ^ true
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5219
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5220
    "
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5221
     'hello world' continuesWith:'world' startingAt:6                
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5222
     'hello world' continuesWith:'world' startingAt:7                
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5223
    "
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5224
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5225
    "Created: 12.5.1996 / 15:46:40 / cg"
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5226
    "Modified: 26.7.1996 / 19:08:36 / cg"
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5227
!
cf7be5555874 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
  5228
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5229
countWords
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5230
    "return the number of words, which are separated by separators"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5231
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5232
    |tally "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5233
     start "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5234
     mySize "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5235
     stop ch|
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5236
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5237
    tally := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5238
    start := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5239
    mySize := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5240
    [start <= mySize] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5241
	ch := self at:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5242
	ch isSeparator ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5243
	    start := start + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5244
	] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5245
	    stop := self indexOfSeparatorStartingAt:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5246
	    (stop == 0) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5247
		stop := mySize + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5248
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5249
	    tally := tally + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5250
	    start := stop
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5251
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5252
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5253
    ^ tally
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5254
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5255
    "
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5256
     'hello world isnt this nice' countWords'
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  5257
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5258
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5259
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5260
endsWith:aString
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5261
    "return true, if the receiver ends with something, aString."
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5262
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5263
    |s|
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5264
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5265
    (s := self string) ~~ self ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5266
        ^ s endsWith:aString
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5267
    ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5268
    ^ super endsWith:aString
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5269
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5270
    "
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5271
     'hello world' endsWith:'world'                 
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5272
     'hello world' asText allBold endsWith:'world'  
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5273
    "
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5274
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5275
    "Modified: 12.5.1996 / 15:49:18 / cg"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5276
!
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5277
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5278
isAlphaNumeric
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5279
    "return true, if the receiver is some alphanumeric word;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5280
     i.e. consists of a letter followed by letters or digits."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5281
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5282
    self size == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5283
	"mhmh what is this ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5284
	^ false
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5285
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5286
    (self at:1) isLetter ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5287
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5288
	char isLetterOrDigit ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5289
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5290
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5291
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5292
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5293
     'helloWorld' isAlphaNumeric  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5294
     'foo1234' isAlphaNumeric    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5295
     'f1234' isAlphaNumeric      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5296
     '1234' isAlphaNumeric       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5297
     '+' isAlphaNumeric         
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5298
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5299
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5300
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5301
isBlank
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5302
    "return true, if the receiver contains spaces only"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5303
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5304
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5305
	char ~~ Character space ifTrue:[^ false].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5306
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5307
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5308
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5309
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5310
levenshteinTo:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5311
    "return the levenshtein distance to the argument, aString;
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5312
     this value corrensponds to the number of replacements that have to be
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5313
     made to get aString from the receiver.
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5314
     See IEEE transactions on Computers 1976 Pg 172 ff."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5315
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5316
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5317
     in the following, we assum that ommiting a character
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5318
     is less of an error than inserting an extra character.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5319
     Therefore the different insertion (i) and deletion (d)
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5320
     values.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5321
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5322
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5323
    ^ self levenshteinTo:aString s:4 c:1 i:2 d:6
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5324
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5325
    "
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5326
     'ocmprt' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5327
     'computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5328
     'ocmputer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5329
     'cmputer' levenshteinTo:'computer'
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  5330
     'computer' levenshteinTo:'cmputer'
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5331
     'Computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5332
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5333
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5334
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5335
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5336
    "parametrized levenshtein. 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5337
     return the levenshtein distance to the argument, aString;
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5338
     this value corrensponds to the number of replacements that have to be
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5339
     made to get aString from the receiver.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5340
     The arguments are the costs for substitution, case-change, insertion and 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5341
     deletion of a character.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5342
     See IEEE transactions on Computers 1976 Pg 172 ff"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5343
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5344
    |d  "delta matrix"
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5345
     len1 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5346
     len2 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5347
     dim  "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5348
     prevRow row col 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  5349
     dimPlus1 "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5350
     min pp c1 c2|
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5351
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5352
    len1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5353
    len2 := aString size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5354
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5355
    "create the help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5356
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5357
    dim := len1 max:len2.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5358
    dimPlus1 := dim + 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5359
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5360
    d := Array new:dimPlus1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5361
    1 to:dimPlus1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5362
	d at:i put:(Array new:dimPlus1)
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5363
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5364
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5365
    "init help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5366
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5367
    (d at:1) at:1 put:0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5368
    row := d at:1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5369
    1 to:dim do:[:j |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5370
	row at:(j + 1) put:( (row at:j) + insrtWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5371
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5372
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5373
    1 to:dim do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5374
	 (d at:(i + 1)) at:1 put:(  ((d at:i) at:1) + deleteWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5375
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5376
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5377
    1 to:len1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5378
	c1 := self at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5379
	1 to:len2 do:[:j |
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5380
	    c2 := aString at:j.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5381
	    (c1 == c2) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5382
		pp := 0
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5383
	    ] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5384
		(c1 asLowercase == c2 asLowercase) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5385
		    pp := caseWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5386
		] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5387
		    pp := substWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5388
		]
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5389
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5390
	    prevRow := d at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5391
	    row := d at:(i + 1).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5392
	    col := j + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5393
	    min := (prevRow at:j) + pp.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5394
	    min := min min:( (row at:j) + insrtWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5395
	    min := min min:( (prevRow at:col) + deleteWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5396
	    row at:col put: min
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5397
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5398
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5399
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5400
    ^ (d at:(len1 + 1)) at:(len2 + 1)
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5401
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5402
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5403
numArgs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5404
    "treating the receiver as a message selector, return how many arguments would it take"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5405
2051
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5406
    |binopChars firstChar|
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5407
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5408
    (self size > 2) ifFalse:[
2051
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5409
        binopChars := Scanner binarySelectorCharacters.
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5410
        firstChar := self at:1.
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5411
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5412
        (self size == 1) ifTrue:[
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5413
            ((binopChars occurrencesOf:firstChar) == 0) ifTrue:[^ 0].
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5414
            ^ 1
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5415
        ].
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5416
        ((binopChars occurrencesOf:firstChar) == 0) ifFalse:[
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5417
            ((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1]
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5418
        ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5419
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5420
    ^ self occurrencesOf:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5421
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5422
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5423
     'foo:bar:' numArgs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5424
     #foo:bar: numArgs    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5425
     'hello' numArgs       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5426
     '+' numArgs   
2051
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5427
     '|' numArgs   
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5428
     '?' numArgs   
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5429
    "
2051
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5430
08fd6a693ee3 ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
  5431
    "Modified: 4.1.1997 / 14:16:14 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5432
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5433
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5434
partsIfSelector
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5435
    "treat the receiver as a message selector, return a collection of parts."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5436
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5437
    |idx1 "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5438
     coll idx2 sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5439
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5440
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5441
    idx1 := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5442
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5443
    [true] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5444
	idx2 := self indexOf:$: startingAt:idx1 + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5445
	(idx2 == 0 or:[idx2 == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5446
	    coll add:(self copyFrom:idx1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5447
	    ^ coll
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5448
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5449
	coll add:(self copyFrom:idx1 to:idx2).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5450
	idx1 := idx2 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5451
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5452
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5453
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5454
     'foo:bar:' partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5455
     #foo:bar: partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5456
     'hello' partsIfSelector       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5457
     '+' partsIfSelector           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5458
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5459
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  5460
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5461
spellAgainst: aString 
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5462
    "return an integer between 0 and 100 indicating how similar 
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5463
     the argument is to the receiver.  No case conversion is done.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5464
     This algorithm is much simpler (but also less exact) than the
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5465
     levenshtein distance. Experiment which is better for your
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5466
     application."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5467
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5468
    | i1     "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5469
      i2     "{ Class: SmallInteger }"
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5470
      next1  "{ Class: SmallInteger }"
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5471
      next2  "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5472
      size1  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5473
      size2  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5474
      score  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5475
      maxLen "{ Class: SmallInteger }" |
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5476
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5477
    size1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5478
    size2 := aString size.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5479
    maxLen := size1 max:size2.
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5480
    score := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5481
    i1 := i2 := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5482
    [i1 <= size1 and: [i2 <= size2]] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5483
	next1 := i1 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5484
	next2 := i2 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5485
	(self at:i1) == (aString at:i2) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5486
	    score := score+1.             
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5487
	    i1 := next1.                    
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5488
	    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5489
	] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5490
	    (i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5491
		i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5492
	    ] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5493
		(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5494
		    i1 := next1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5495
		] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5496
		    i1 := next1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5497
		    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5498
		] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5499
	    ] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5500
	] 
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5501
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5502
1124
53f6970d9d7d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1059
diff changeset
  5503
    score == maxLen ifTrue: [^ 100].
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5504
    ^ 100 * score // maxLen
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5505
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5506
    " 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5507
     'Smalltalk' spellAgainst: 'Smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5508
     'Smalltalk' spellAgainst: 'smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5509
     'Smalltalk' spellAgainst: 'smalltalk' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5510
     'Smalltalk' spellAgainst: 'smalltlk'  
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5511
     'Smalltalk' spellAgainst: 'Smalltolk'   
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  5512
    "
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5513
!
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5514
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5515
startsWith:aString
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4294
diff changeset
  5516
    "return true, if the receiver starts with something, aString.
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4294
diff changeset
  5517
     If the argument is empty, true is returned."
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5518
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5519
    |s|
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5520
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5521
    (s := self string) ~~ self ifTrue:[
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5522
        ^ s startsWith:aString
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5523
    ].
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5524
    ^ super startsWith:aString
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5525
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5526
    "
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5527
     'hello world' startsWith:'hello'                 
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5528
     'hello world' asText allBold startsWith:'hello'  
4389
3655a0fea430 definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents: 4294
diff changeset
  5529
     'hello world' asText allBold startsWith:''  
1381
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5530
    "
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5531
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5532
    "Created: 12.5.1996 / 15:46:40 / cg"
c920ec16a98f Text fixes
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
  5533
    "Modified: 12.5.1996 / 15:49:24 / cg"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5534
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  5535
4662
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5536
!CharacterArray methodsFor:'tracing'!
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5537
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4662
diff changeset
  5538
traceInto:aRequestor level:level from:referrer
4662
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5539
    "double dispatch into tracer, passing my type implicitely in the selector"
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5540
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4662
diff changeset
  5541
    ^ aRequestor traceCharacterArray:self level:level from:referrer
4662
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5542
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5543
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5544
! !
bbddd04872e1 Added tracing support.
Claus Gittinger <cg@exept.de>
parents: 4429
diff changeset
  5545
1849
9f35f5934ec6 added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents: 1669
diff changeset
  5546
!CharacterArray class methodsFor:'documentation'!
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  5547
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  5548
version
5440
ba9207f592c9 only init once
Claus Gittinger <cg@exept.de>
parents: 5352
diff changeset
  5549
    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.184 2000-07-02 12:53:36 cg Exp $'
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  5550
! !
2728
7569e45a4d15 raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents: 2721
diff changeset
  5551
CharacterArray initialize!